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