Mercurial > MadButterfly
annotate inkscape/AssignSymbol.py @ 257:50d253d0fcba
Simple image loader and image shape.
- img_ldr.c is a simple image loader that rooted on a directory
specified when a loader instance been created.
- sh_image_t is corresponding shape of image tag in SVG.
- This changeset is still buggy. It need more testing.
- svg2code.py is not ready for image tag.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Thu, 15 Jan 2009 16:46:47 +0800 |
parents | 1958bb2a87a2 |
children | 5006e4abdda5 |
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) |
248
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
216
diff
changeset
|
49 if node.tag != '{http://www.w3.org/2000/svg}g': |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
216
diff
changeset
|
50 self.confirm('Only group element can be converted into a symbol') |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
216
diff
changeset
|
51 return |
203
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
52 self.node = node |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
53 vbox = gtk.VBox() |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
54 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
|
55 self.text = gtk.Entry() |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
56 try: |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
57 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
|
58 except: |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
59 self.text.set_text(self.defaultname) |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
60 vbox.pack_start(self.text) |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
61 self.button = gtk.Button('OK') |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
62 self.button.connect("clicked", self.onAssign) |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
63 vbox.pack_start(self.button) |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
64 self.window.add(vbox) |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
65 self.window.show_all() |
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 |
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 |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
70 a=AssignSymbol() |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
71 a.affect() |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
72 |
1d485bf96480
Add a sample inkscape extention to assign symbol name to an SVG element.
wycc
parents:
diff
changeset
|
73 # vim: set ts=4 |