summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Wüst <sebi@timewaster.de>2013-11-03 01:11:28 +0000
committerSebastian Wüst <sebi@timewaster.de>2013-11-03 01:11:28 +0000
commitfac095aac7e613ac44076d7a45ab71a8771a04c7 (patch)
treeba8a9818b96fdac046bcfc5d13992471146fde82
parentbetter PEP 8 compatibility (diff)
downloadinkscape-fac095aac7e613ac44076d7a45ab71a8771a04c7.tar.gz
inkscape-fac095aac7e613ac44076d7a45ab71a8771a04c7.zip
a 'bit' shorter lines
(bzr r12417.1.35)
-rw-r--r--share/extensions/hpgl_decoder.py27
-rw-r--r--share/extensions/hpgl_encoder.py31
-rw-r--r--share/extensions/plotter.py3
3 files changed, 39 insertions, 22 deletions
diff --git a/share/extensions/hpgl_decoder.py b/share/extensions/hpgl_decoder.py
index 88c4a9a95..1b6106430 100644
--- a/share/extensions/hpgl_decoder.py
+++ b/share/extensions/hpgl_decoder.py
@@ -39,9 +39,11 @@ class hpglDecoder:
self.scaleY = options.resolutionY / 90.0 # dots/inch to dots/pixels
self.warnings = []
- def getSvg(self): # parse hpgl data
+ def getSvg(self):
+ # parse hpgl data
# prepare document
- self.doc = inkex.etree.parse(StringIO('<svg xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" width="%s" height="%s"></svg>' % (self.options.docWidth, self.options.docHeight)))
+ self.doc = inkex.etree.parse(StringIO('<svg xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" width="%s" height="%s"></svg>' %
+ (self.options.docWidth, self.options.docHeight)))
actualLayer = 0
self.layers = {}
if self.options.showMovements:
@@ -54,12 +56,15 @@ class hpglDecoder:
path = ''
for i, command in enumerate(hpglData):
if command.strip() != '':
- if command[:2] == 'IN': # if Initialize command, ignore
+ if command[:2] == 'IN':
+ # if Initialize command, ignore
pass
- elif command[:2] == 'SP': # if Select Pen command
+ elif command[:2] == 'SP':
+ # if Select Pen command
actualLayer = command[2:]
self.createLayer(actualLayer)
- elif command[:2] == 'PU': # if Pen Up command
+ elif command[:2] == 'PU':
+ # if Pen Up command
if ' L ' in path:
self.addPathToLayer(path, actualLayer)
if self.options.showMovements and i != len(hpglData) - 1:
@@ -68,7 +73,8 @@ class hpglDecoder:
self.addPathToLayer(path, 0)
path = 'M %f,%f' % self.getParameters(command[2:])
oldCoordinates = self.getParameters(command[2:])
- elif command[:2] == 'PD': # if Pen Down command
+ elif command[:2] == 'PD':
+ # if Pen Down command
parameterString = command[2:]
if parameterString.strip() != '':
parameterString = parameterString.replace(';', '').strip()
@@ -88,7 +94,8 @@ class hpglDecoder:
return (self.doc, self.warnings)
def createLayer(self, layerNumber):
- self.layers[layerNumber] = inkex.etree.SubElement(self.doc.getroot(), 'g', {inkex.addNS('groupmode', 'inkscape'): 'layer', inkex.addNS('label', 'inkscape'): 'Drawing Pen ' + layerNumber})
+ self.layers[layerNumber] = inkex.etree.SubElement(self.doc.getroot(), 'g',
+ {inkex.addNS('groupmode', 'inkscape'): 'layer', inkex.addNS('label', 'inkscape'): 'Drawing Pen ' + layerNumber})
def addPathToLayer(self, path, layerNumber):
lineColor = '000000'
@@ -96,13 +103,15 @@ class hpglDecoder:
lineColor = 'ff0000'
inkex.etree.SubElement(self.layers[layerNumber], 'path', {'d': path, 'style': 'stroke:#' + lineColor + '; stroke-width:0.4; fill:none;'})
- def getParameters(self, parameterString): # process coordinates
+ def getParameters(self, parameterString):
+ # process coordinates
if parameterString.strip() == '':
return []
# remove command delimiter
parameterString = parameterString.replace(';', '').strip()
# split parameter
parameter = parameterString.split(',')
- return (float(parameter[0]) / self.scaleX, self.options.docHeight - float(parameter[1]) / self.scaleY) # convert to svg coordinate system
+ # convert to svg coordinate system and return
+ return (float(parameter[0]) / self.scaleX, self.options.docHeight - float(parameter[1]) / self.scaleY)
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99 \ No newline at end of file
diff --git a/share/extensions/hpgl_encoder.py b/share/extensions/hpgl_encoder.py
index 35d9300fb..a5060d2c5 100644
--- a/share/extensions/hpgl_encoder.py
+++ b/share/extensions/hpgl_encoder.py
@@ -55,7 +55,7 @@ class hpglEncoder:
'''
self.doc = effect.document.getroot()
self.options = effect.options
- self.divergenceX = 'False' # dirty hack: i need to know if this was set to a number before, but since False is evaluated to 0 it can not be determined, therefore the string.
+ self.divergenceX = 'False'
self.divergenceY = 'False'
self.sizeX = 'False'
self.sizeY = 'False'
@@ -101,7 +101,8 @@ class hpglEncoder:
elif self.options.useToolOffset:
self.options.offsetX += self.options.toolOffset
self.options.offsetY += self.options.toolOffset
- self.groupmat = [[[self.mirrorX * self.scaleX * self.viewBoxTransformX, 0.0, - self.divergenceX + self.options.offsetX], [0.0, self.mirrorY * self.scaleY * self.viewBoxTransformY, - self.divergenceY + self.options.offsetY]]]
+ self.groupmat = [[[self.mirrorX * self.scaleX * self.viewBoxTransformX, 0.0, - self.divergenceX + self.options.offsetX],
+ [0.0, self.mirrorY * self.scaleY * self.viewBoxTransformY, - self.divergenceY + self.options.offsetY]]]
self.groupmat[0] = simpletransform.composeTransform(self.groupmat[0], simpletransform.parseTransform('rotate(' + self.options.orientation + ')'))
self.vData = [['', -1.0, -1.0], ['', -1.0, -1.0], ['', -1.0, -1.0], ['', -1.0, -1.0]]
# store first hpgl commands
@@ -182,20 +183,23 @@ class hpglEncoder:
oldPosX = posX
oldPosY = posY
- def getLength(self, x1, y1, x2, y2, absolute=True): # calc absoulute or relative length between two points
+ def getLength(self, x1, y1, x2, y2, absolute=True):
+ # calc absoulute or relative length between two points
length = math.sqrt((x2 - x1) ** 2.0 + (y2 - y1) ** 2.0)
if absolute:
length = math.fabs(length)
return length
- def changeLength(self, x1, y1, x2, y2, offset): # change length of line
+ def changeLength(self, x1, y1, x2, y2, offset):
+ # change length of line
if offset < 0:
offset = max( - self.getLength(x1, y1, x2, y2), offset)
x = x2 + (x2 - x1) / self.getLength(x1, y1, x2, y2, False) * offset
y = y2 + (y2 - y1) / self.getLength(x1, y1, x2, y2, False) * offset
return [x, y]
- def getAlpha(self, x1, y1, x2, y2, x3, y3): # get alpha of point 2
+ def getAlpha(self, x1, y1, x2, y2, x3, y3):
+ # get alpha of point 2
temp1 = (x1 - x2) ** 2 + (y1 - y2) ** 2 + (x3 - x2) ** 2 + (y3 - y2) ** 2 - (x1 - x3) ** 2 - (y1 - y3) ** 2
temp2 = 2 * math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) * math.sqrt((x3 - x2) ** 2 + (y3 - y2) ** 2)
return math.acos(max(min(temp1 / temp2, 1.0), -1.0))
@@ -217,15 +221,19 @@ class hpglEncoder:
if self.vData[2][0] == 'PD': # If the 3rd entry in the cache is a pen down command make the line longer by the tool offset
pointThree = self.changeLength(self.vData[1][1], self.vData[1][2], self.vData[2][1], self.vData[2][2], self.options.toolOffset)
self.storePoint('PD', pointThree[0], pointThree[1])
- elif self.vData[0][1] != -1.0: # Elif the 1st entry in the cache is filled with data and the 3rd entry is a pen up command shift the 3rd entry by the current tool offset position according to the 2nd command
+ elif self.vData[0][1] != -1.0:
+ # Elif the 1st entry in the cache is filled with data and the 3rd entry is a pen up command shift
+ # the 3rd entry by the current tool offset position according to the 2nd command
pointThree = self.changeLength(self.vData[0][1], self.vData[0][2], self.vData[1][1], self.vData[1][2], self.options.toolOffset)
pointThree[0] = self.vData[2][1] - (self.vData[1][1] - pointThree[0])
pointThree[1] = self.vData[2][2] - (self.vData[1][2] - pointThree[1])
self.storePoint('PU', pointThree[0], pointThree[1])
- else: # Else just write the 3rd entry
+ else:
+ # Else just write the 3rd entry
pointThree = [self.vData[2][1], self.vData[2][2]]
self.storePoint('PU', pointThree[0], pointThree[1])
- if self.vData[3][0] == 'PD': # If the 4th entry in the cache is a pen down command guide tool to next line with a circle between the prolonged 3rd and 4th entry
+ if self.vData[3][0] == 'PD':
+ # If the 4th entry in the cache is a pen down command guide tool to next line with a circle between the prolonged 3rd and 4th entry
if self.getLength(self.vData[2][1], self.vData[2][2], self.vData[3][1], self.vData[3][2]) >= self.options.toolOffset:
pointFour = self.changeLength(self.vData[3][1], self.vData[3][2], self.vData[2][1], self.vData[2][2], - self.options.toolOffset)
else:
@@ -271,8 +279,9 @@ class hpglEncoder:
else:
# store point
if not self.options.center:
+ # only positive values are allowed (usually)
if x < 0:
- x = 0 # only positive values are allowed (usually)
+ x = 0
if y < 0:
y = 0
# do not repeat command
@@ -280,8 +289,6 @@ class hpglEncoder:
self.hpgl += ',%d,%d' % (x, y)
else:
self.hpgl += ';%s%d,%d' % (command, x, y)
- self.lastPoint[0] = command
- self.lastPoint[1] = x
- self.lastPoint[2] = y
+ self.lastPoint = [command, x, y]
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99 \ No newline at end of file
diff --git a/share/extensions/plotter.py b/share/extensions/plotter.py
index d0d42c671..6ff6adeaf 100644
--- a/share/extensions/plotter.py
+++ b/share/extensions/plotter.py
@@ -76,7 +76,8 @@ class MyEffect(inkex.Effect):
else:
type, value, traceback = sys.exc_info()
raise ValueError, ("", type, value), traceback
- # TODO: Get preview to work. This requires some work on the C++ side to be able to determine if it is a preview or a final run. (Remember to set <effect needs-live-preview='false'> to true)
+ # TODO: Get preview to work. This requires some work on the C++ side to be able to determine if it is
+ # a preview or a final run. (Remember to set <effect needs-live-preview='false'> to true)
'''
# reparse data for preview
self.options.showMovements = True