Mercurial > MadButterfly
annotate inkscape/AssignSymbol.py @ 336:995eb2c1a1aa
Merge
author | wycc |
---|---|
date | Sat, 07 Mar 2009 14:25:20 +0800 |
parents | 5006e4abdda5 |
children |
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) |
216 | 21 self.node.set("id",text) |
203
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
22 gtk.main_quit() |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
23 |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
24 def confirm(self,msg): |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
25 vbox = gtk.VBox() |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
26 vbox.pack_start(gtk.Label(msg)) |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
27 self.button = gtk.Button('OK') |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
28 vbox.pack_start(self.button) |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
29 self.button.connect("clicked", self.onQuit) |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
30 self.window.add(vbox) |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
31 def dumpattr(self,n): |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
32 s = "" |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
33 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
|
34 s = s + ("%s=%s" % (a,v)) |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
35 return s |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
36 |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
37 def dump(self,node,l=0): |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
38 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
|
39 for n in node: |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
40 self.dump(n,l+1) |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
41 print " " * l * 2,"/>" |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
42 |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
43 def fillcontent(self): |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
44 if len(self.selected) != 1: |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
45 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
|
46 return |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
47 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
|
48 #self.dump(node) |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
49 self.node = node |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
50 vbox = gtk.VBox() |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
51 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
|
52 self.text = gtk.Entry() |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
53 try: |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
54 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
|
55 except: |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
56 self.text.set_text(self.defaultname) |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
57 vbox.pack_start(self.text) |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
58 self.button = gtk.Button('OK') |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
59 self.button.connect("clicked", self.onAssign) |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
60 vbox.pack_start(self.button) |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
61 self.window.add(vbox) |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
62 self.window.show_all() |
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 |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
67 a=AssignSymbol() |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
68 a.affect() |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
69 |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
70 # vim: set ts=4 |