summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsu_v <suv-sf@users.sourceforge.net>2015-10-20 12:09:50 +0000
committer~suv <suv-sf@users.sourceforge.net>2015-10-20 12:09:50 +0000
commit87d0a984dec7a5f4cfce15a38b365f162ad21c49 (patch)
tree082975fb1ed11ce3b72a2b99d86c06a4a3d2e269
parentExtensions. Restack - add options to reverse, shuffle Z-order of selection (b... (diff)
downloadinkscape-87d0a984dec7a5f4cfce15a38b365f162ad21c49.tar.gz
inkscape-87d0a984dec7a5f4cfce15a38b365f162ad21c49.zip
Extensions. Restack - fix indentation level (follow-up to rev 14424, bug #1498583)
(bzr r14425)
-rwxr-xr-xshare/extensions/restack.py215
1 files changed, 107 insertions, 108 deletions
diff --git a/share/extensions/restack.py b/share/extensions/restack.py
index b76e0f765..67d738a13 100755
--- a/share/extensions/restack.py
+++ b/share/extensions/restack.py
@@ -76,114 +76,113 @@ class Restack(inkex.Effect):
inkex.errormsg(_("There is no selection to restack."))
def restack_positional(self):
- if 1: # to be removed (workaround for smaller bzr diff)
- objects = {}
- objlist = []
- file = self.args[ -1 ]
-
- if self.options.nb_direction == '"custom"':
- self.options.direction = "aa"
-
- # process selection to get list of objects to be arranged
- firstobject = self.selected[self.options.ids[0]]
- if len(self.selected) == 1 and firstobject.tag == inkex.addNS('g', 'svg'):
- parentnode = firstobject
- for child in parentnode.iterchildren():
- objects[child.get('id')] = child
- else:
- parentnode = self.current_layer
- objects = self.selected
-
- #get all bounding boxes in file by calling inkscape again with the --query-all command line option
- #it returns a comma separated list structured id,x,y,w,h
- if bsubprocess:
- p = Popen('inkscape --query-all "%s"' % (file), shell=True, stdout=PIPE, stderr=PIPE)
- err = p.stderr
- f = p.communicate()[0]
- try:
- reader=csv.CSVParser().parse_string(f) #there was a module cvs.py in earlier inkscape that behaved differently
- except:
- reader=csv.reader(f.split( os.linesep ))
- err.close()
- else:
- _,f,err = os.popen3('inkscape --query-all "%s"' % ( file ) )
- reader=csv.reader( f )
- err.close()
-
- #build a dictionary with id as the key
- dimen = dict()
- for line in reader:
- if len(line) > 0:
- dimen[line[0]] = map( float, line[1:])
-
- if not bsubprocess: #close file if opened using os.popen3
- f.close
-
- #find the center of all selected objects **Not the average!
- x,y,w,h = dimen[objects.keys()[0]]
- minx = x
- miny = y
- maxx = x + w
- maxy = y + h
-
- for id, node in objects.iteritems():
- # get the bounding box
- x,y,w,h = dimen[id]
- if x < minx:
- minx = x
- if (x + w) > maxx:
- maxx = x + w
- if y < miny:
- miny = y
- if (y + h) > maxy:
- maxy = y + h
-
- midx = (minx + maxx) / 2
- midy = (miny + maxy) / 2
-
- #calculate distances for each selected object
- for id, node in objects.iteritems():
- # get the bounding box
- x,y,w,h = dimen[id]
-
- # calc the comparison coords
- if self.options.xanchor == "l":
- cx = x
- elif self.options.xanchor == "r":
- cx = x + w
- else: # middle
- cx = x + w / 2
-
- if self.options.yanchor == "t":
- cy = y
- elif self.options.yanchor == "b":
- cy = y + h
- else: # middle
- cy = y + h / 2
-
- #direction chosen
- if self.options.direction == "tb" or (self.options.direction == "aa" and self.options.angle == 270):
- objlist.append([cy,id])
- elif self.options.direction == "bt" or (self.options.direction == "aa" and self.options.angle == 90):
- objlist.append([-cy,id])
- elif self.options.direction == "lr" or (self.options.direction == "aa" and (self.options.angle == 0 or self.options.angle == 360)):
- objlist.append([cx,id])
- elif self.options.direction == "rl" or (self.options.direction == "aa" and self.options.angle == 180):
- objlist.append([-cx,id])
- elif self.options.direction == "aa":
- distance = math.hypot(cx,cy)*(math.cos(math.radians(-self.options.angle)-math.atan2(cy, cx)))
- objlist.append([distance,id])
- elif self.options.direction == "ro":
- distance = math.hypot(midx - cx, midy - cy)
- objlist.append([distance,id])
- elif self.options.direction == "ri":
- distance = -math.hypot(midx - cx, midy - cy)
- objlist.append([distance,id])
-
- objlist.sort()
- #move them to the top of the object stack in this order.
- for item in objlist:
- parentnode.append( objects[item[1]])
+ objects = {}
+ objlist = []
+ file = self.args[ -1 ]
+
+ if self.options.nb_direction == '"custom"':
+ self.options.direction = "aa"
+
+ # process selection to get list of objects to be arranged
+ firstobject = self.selected[self.options.ids[0]]
+ if len(self.selected) == 1 and firstobject.tag == inkex.addNS('g', 'svg'):
+ parentnode = firstobject
+ for child in parentnode.iterchildren():
+ objects[child.get('id')] = child
+ else:
+ parentnode = self.current_layer
+ objects = self.selected
+
+ #get all bounding boxes in file by calling inkscape again with the --query-all command line option
+ #it returns a comma separated list structured id,x,y,w,h
+ if bsubprocess:
+ p = Popen('inkscape --query-all "%s"' % (file), shell=True, stdout=PIPE, stderr=PIPE)
+ err = p.stderr
+ f = p.communicate()[0]
+ try:
+ reader=csv.CSVParser().parse_string(f) #there was a module cvs.py in earlier inkscape that behaved differently
+ except:
+ reader=csv.reader(f.split( os.linesep ))
+ err.close()
+ else:
+ _,f,err = os.popen3('inkscape --query-all "%s"' % ( file ) )
+ reader=csv.reader( f )
+ err.close()
+
+ #build a dictionary with id as the key
+ dimen = dict()
+ for line in reader:
+ if len(line) > 0:
+ dimen[line[0]] = map( float, line[1:])
+
+ if not bsubprocess: #close file if opened using os.popen3
+ f.close
+
+ #find the center of all selected objects **Not the average!
+ x,y,w,h = dimen[objects.keys()[0]]
+ minx = x
+ miny = y
+ maxx = x + w
+ maxy = y + h
+
+ for id, node in objects.iteritems():
+ # get the bounding box
+ x,y,w,h = dimen[id]
+ if x < minx:
+ minx = x
+ if (x + w) > maxx:
+ maxx = x + w
+ if y < miny:
+ miny = y
+ if (y + h) > maxy:
+ maxy = y + h
+
+ midx = (minx + maxx) / 2
+ midy = (miny + maxy) / 2
+
+ #calculate distances for each selected object
+ for id, node in objects.iteritems():
+ # get the bounding box
+ x,y,w,h = dimen[id]
+
+ # calc the comparison coords
+ if self.options.xanchor == "l":
+ cx = x
+ elif self.options.xanchor == "r":
+ cx = x + w
+ else: # middle
+ cx = x + w / 2
+
+ if self.options.yanchor == "t":
+ cy = y
+ elif self.options.yanchor == "b":
+ cy = y + h
+ else: # middle
+ cy = y + h / 2
+
+ #direction chosen
+ if self.options.direction == "tb" or (self.options.direction == "aa" and self.options.angle == 270):
+ objlist.append([cy,id])
+ elif self.options.direction == "bt" or (self.options.direction == "aa" and self.options.angle == 90):
+ objlist.append([-cy,id])
+ elif self.options.direction == "lr" or (self.options.direction == "aa" and (self.options.angle == 0 or self.options.angle == 360)):
+ objlist.append([cx,id])
+ elif self.options.direction == "rl" or (self.options.direction == "aa" and self.options.angle == 180):
+ objlist.append([-cx,id])
+ elif self.options.direction == "aa":
+ distance = math.hypot(cx,cy)*(math.cos(math.radians(-self.options.angle)-math.atan2(cy, cx)))
+ objlist.append([distance,id])
+ elif self.options.direction == "ro":
+ distance = math.hypot(midx - cx, midy - cy)
+ objlist.append([distance,id])
+ elif self.options.direction == "ri":
+ distance = -math.hypot(midx - cx, midy - cy)
+ objlist.append([distance,id])
+
+ objlist.sort()
+ #move them to the top of the object stack in this order.
+ for item in objlist:
+ parentnode.append( objects[item[1]])
def restack_z_order(self):
parentnode = None