comparison inkscape/AssignSymbol.py @ 203:1d485bf96480

Add a sample inkscape extention to assign symbol name to an SVG element.
author wycc
date Wed, 10 Dec 2008 09:17:16 +0800
parents
children f61b709bbd0f
comparison
equal deleted inserted replaced
202:75ec0124202a 203:1d485bf96480
1 #!/usr/bin/python
2 import inkex
3 import pygtk
4 import gtk
5
6 class AssignSymbol(inkex.Effect):
7 def effect(self):
8 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
9 self.window.set_position(gtk.WIN_POS_MOUSE)
10 self.defaultname = 'input symbol name here'
11 self.fillcontent()
12 self.window.show_all()
13 self.window.connect("delete_event", gtk.main_quit)
14 gtk.main()
15 def onQuit(self,data):
16 gtk.main_quit()
17 def onAssign(self,data):
18 text = self.text.get_text()
19 if text != self.defaultname:
20 self.node.set("mbname",text)
21 gtk.main_quit()
22
23 def confirm(self,msg):
24 vbox = gtk.VBox()
25 vbox.pack_start(gtk.Label(msg))
26 self.button = gtk.Button('OK')
27 vbox.pack_start(self.button)
28 self.button.connect("clicked", self.onQuit)
29 self.window.add(vbox)
30 def dumpattr(self,n):
31 s = ""
32 for a,v in n.attrib.items():
33 s = s + ("%s=%s" % (a,v))
34 return s
35
36 def dump(self,node,l=0):
37 print " " * l*2,"<", node.tag, self.dumpattr(node),">"
38 for n in node:
39 self.dump(n,l+1)
40 print " " * l * 2,"/>"
41
42 def fillcontent(self):
43 if len(self.selected) != 1:
44 self.confirm('Please select on group only')
45 return
46 for id,node in self.selected.iteritems():
47 #self.dump(node)
48 self.node = node
49 vbox = gtk.VBox()
50 vbox.pack_start(gtk.Label('Please input the symbol name'))
51 self.text = gtk.Entry()
52 try:
53 self.text.set_text(node.get("mbname"))
54 except:
55 self.text.set_text(self.defaultname)
56 vbox.pack_start(self.text)
57 self.button = gtk.Button('OK')
58 self.button.connect("clicked", self.onAssign)
59 vbox.pack_start(self.button)
60 self.window.add(vbox)
61 self.window.show_all()
62
63
64
65
66 a=AssignSymbol()
67 a.affect()
68
69 # vim: set ts=4