comparison inkscape/MB_EditClickButton.py @ 220:ad5c7a5c2c39

Add extention to the inkscape to edit one of the active/normal/click frame of a button. There is one unsolved issue. Users can not know the current frame easily unless they check the XML node editor. We should try to show something in the UI. However, I have no found any goo dway to do this. We may need to modify the inkscape directly for this function in the future.
author wycc@wycc-desktop
date Sun, 14 Dec 2008 11:23:34 +0800
parents
children
comparison
equal deleted inserted replaced
217:8d9d717c9300 220:ad5c7a5c2c39
1 #!/usr/bin/python
2 import inkex
3 import pygtk
4 import gtk
5 from copy import deepcopy
6
7 class ConvertToButton(inkex.Effect):
8 def effect(self):
9 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
10 self.window.set_position(gtk.WIN_POS_MOUSE)
11 self.defaultname = 'input symbol name here'
12 if self.fillcontent() == False:
13 self.window.show_all()
14 self.window.connect("delete_event", gtk.main_quit)
15 gtk.main()
16 def onQuit(self,data):
17 gtk.main_quit()
18 def onAssign(self,data):
19 text = self.text.get_text()
20 if text != self.defaultname:
21 self.node.set("mbname",text)
22 gtk.main_quit()
23
24 def confirm(self,msg):
25 vbox = gtk.VBox()
26 vbox.pack_start(gtk.Label(msg))
27 self.button = gtk.Button('OK')
28 vbox.pack_start(self.button)
29 self.button.connect("clicked", self.onQuit)
30 self.window.add(vbox)
31 def dumpattr(self,n):
32 s = ""
33 for a,v in n.attrib.items():
34 s = s + ("%s=%s" % (a,v))
35 return s
36
37 def dump(self,node,l=0):
38 print " " * l*2,"<", node.tag, self.dumpattr(node),">"
39 for n in node:
40 self.dump(n,l+1)
41 print " " * l * 2,"/>"
42
43 def hide_frame(self,frame):
44 frame.set('style','display:none')
45 def show_frame(self,frame):
46 frame.set('style','')
47
48
49 def fillcontent(self):
50 if len(self.selected) != 1:
51 self.confirm('Please select one group only')
52 return False
53 for id,node in self.selected.iteritems():
54 #self.dump(node)
55 name = node.get("mbname")
56 if name == None:
57 self.confirm("The MadButterFly symbol is not defined yet. Please convert it to the symbol before convert it to button.")
58 return False
59 for frame in node:
60 if frame.get('mbname') == name+'_click':
61 self.show_frame(frame)
62 else:
63 self.hide_frame(frame)
64 return True
65
66
67 a=ConvertToButton()
68 a.affect()
69
70 # vim: set ts=4