inkstitch/reorder.py

40 wiersze
904 B
Python
Czysty Zwykły widok Historia

2016-10-20 00:47:30 +00:00
#!/usr/bin/python
#
# Remove selected objects from the document and readd them in the order they
# were selected.
import sys
sys.path.append("/usr/share/inkscape/extensions")
import os
import inkex
class Reorder(inkex.Effect):
2016-11-07 00:30:49 +00:00
2016-10-20 00:47:30 +00:00
def get_selected_in_order(self):
selected = []
for i in self.options.ids:
path = '//*[@id="%s"]' % i
for node in self.document.xpath(path, namespaces=inkex.NSS):
selected.append(node)
return selected
def effect(self):
objects = self.get_selected_in_order()
for obj in objects[1:]:
obj.getparent().remove(obj)
insert_parent = objects[0].getparent()
insert_pos = insert_parent.index(objects[0])
insert_parent.remove(objects[0])
insert_parent[insert_pos:insert_pos] = objects
if __name__ == '__main__':
e = Reorder()
e.affect()