Mercurial > MadButterfly
changeset 248:1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
* Reimplement the button editor. We will use another instance of the inkscape to edit the content of a button.
author | wycc |
---|---|
date | Sat, 03 Jan 2009 08:43:29 +0800 |
parents | d9a78c859660 |
children | ab8284c8dcee |
files | inkscape/AssignSymbol.py inkscape/MB_EditActiveButton.py inkscape/MB_EditButton.inx inkscape/MB_EditButton.py inkscape/MB_EditClickButton.py inkscape/MB_EditNormalButton.py inkscape/MB_Frame.py inkscape/MB_button_select_click.inx inkscape/MB_button_select_normal.inx inkscape/README.mbext |
diffstat | 10 files changed, 225 insertions(+), 254 deletions(-) [+] |
line wrap: on
line diff
--- a/inkscape/AssignSymbol.py Thu Jan 01 08:32:03 2009 +0800 +++ b/inkscape/AssignSymbol.py Sat Jan 03 08:43:29 2009 +0800 @@ -46,6 +46,9 @@ return for id,node in self.selected.iteritems(): #self.dump(node) + if node.tag != '{http://www.w3.org/2000/svg}g': + self.confirm('Only group element can be converted into a symbol') + return self.node = node vbox = gtk.VBox() vbox.pack_start(gtk.Label('Please input the symbol name'))
--- a/inkscape/MB_EditActiveButton.py Thu Jan 01 08:32:03 2009 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -#!/usr/bin/python -import inkex -import pygtk -import gtk -from copy import deepcopy - -class ConvertToButton(inkex.Effect): - def effect(self): - self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) - self.window.set_position(gtk.WIN_POS_MOUSE) - self.defaultname = 'input symbol name here' - if self.fillcontent() == False: - self.window.show_all() - self.window.connect("delete_event", gtk.main_quit) - gtk.main() - def onQuit(self,data): - gtk.main_quit() - def onAssign(self,data): - text = self.text.get_text() - if text != self.defaultname: - self.node.set("mbname",text) - gtk.main_quit() - - def confirm(self,msg): - vbox = gtk.VBox() - vbox.pack_start(gtk.Label(msg)) - self.button = gtk.Button('OK') - vbox.pack_start(self.button) - self.button.connect("clicked", self.onQuit) - self.window.add(vbox) - def dumpattr(self,n): - s = "" - for a,v in n.attrib.items(): - s = s + ("%s=%s" % (a,v)) - return s - - def dump(self,node,l=0): - print " " * l*2,"<", node.tag, self.dumpattr(node),">" - for n in node: - self.dump(n,l+1) - print " " * l * 2,"/>" - - def hide_frame(self,frame): - frame.set('style','display:none') - def show_frame(self,frame): - frame.set('style','') - - - def fillcontent(self): - if len(self.selected) != 1: - self.confirm('Please select one group only') - return False - for id,node in self.selected.iteritems(): - #self.dump(node) - name = node.get("mbname") - if name == None: - self.confirm("The MadButterFly symbol is not defined yet. Please convert it to the symbol before convert it to button.") - return False - for frame in node: - if frame.get('mbname') == name+'_active': - self.show_frame(frame) - else: - self.hide_frame(frame) - return True - - -a=ConvertToButton() -a.affect() - -# vim: set ts=4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inkscape/MB_EditButton.inx Sat Jan 03 08:43:29 2009 +0800 @@ -0,0 +1,17 @@ +<inkscape-extension> + <name>Edit Button</name> + <id>MadButterfly.EditButton</id> + <dependency type="executable" location="extensions">MB_EditButton.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <effect> + <object-type>any</object-type> + <effects-menu> + <submenu _name="MadButterfly"> + <submenu _name="Button"/> + </submenu> + </effects-menu> + </effect> + <script> + <command reldir="extensions" interpreter="python">MB_EditButton.py</command> + </script> +</inkscape-extension>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inkscape/MB_EditButton.py Sat Jan 03 08:43:29 2009 +0800 @@ -0,0 +1,158 @@ +#!/usr/bin/python +import inkex +import pygtk +import gtk +from copy import deepcopy +from lxml import etree +import os +import tempfile + +class ConvertToButton(inkex.Effect): + def effect(self): + self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) + self.window.set_position(gtk.WIN_POS_MOUSE) + self.defaultname = 'input symbol name here' + if self.fillcontent() == False: + self.window.show_all() + self.window.connect("delete_event", gtk.main_quit) + gtk.main() + def onQuit(self,data): + gtk.main_quit() + def onAssign(self,data): + text = self.text.get_text() + if text != self.defaultname: + self.node.set("mbname",text) + gtk.main_quit() + + def confirm(self,msg): + vbox = gtk.VBox() + vbox.pack_start(gtk.Label(msg)) + self.button = gtk.Button('OK') + vbox.pack_start(self.button) + self.button.connect("clicked", self.onQuit) + self.window.add(vbox) + def dumpattr(self,n): + s = "" + for a,v in n.attrib.items(): + s = s + ("%s=%s" % (a,v)) + return s + + def dump(self,node,l=0): + print " " * l*2,"<", node.tag, self.dumpattr(node),">" + for n in node: + self.dump(n,l+1) + print " " * l * 2,"/>" + + def hide_frame(self,frame): + frame.set('style','display:none') + def show_frame(self,frame): + frame.set('style','') + + def EditNormalButton(self,event,node): + self.EditButton(node,'_normal') + + def EditActiveButton(self,event,node): + self.EditButton(node,'_active') + + def EditClickButton(self,event,node): + self.EditButton(node,'_click') + + def EditFrame(self,node): + # Generate a SVG file with node and invoke inkscape to edit it + svg = etree.Element('svg') + for n in node: + svg.append(deepcopy(n)) + fd,fname = tempfile.mkstemp(suffix='.svg') + f = os.fdopen(fd,"w") + f.write(etree.tostring(svg)) + f.close() + os.system("inkscape %s >/dev/null 2>/dev/null" % fname) + svg = etree.parse(fname) + os.unlink(fname) + newnode=[] + for n in svg.getroot(): + if n.tag == '{http://www.w3.org/2000/svg}g': + newnode.append(n) + if n.tag == '{http://www.w3.org/2000/svg}rect': + newnode.append(n) + if n.tag == '{http://www.w3.org/2000/svg}text': + newnode.append(n) + return newnode + + + + + def duplicateAttribute(self,new,old): + for k,v in old.attrib.items(): + new.set(k,v) + + + def EditButton(self,node,mode): + name = node.get('mbname') + for frame in node: + if frame.get('mbname') == name+mode: + newnode = self.EditFrame(frame) + oldframe = deepcopy(frame) + frame.clear() + self.duplicateAttribute(frame,oldframe) + for n in newnode: + frame.append(n) + return + def DisplayNormalButton(self,event,node): + self.displayButton(node,'_normal') + def DisplayActiveButton(self,event,node): + self.displayButton(node,'_active') + def DisplayClickButton(self,event,node): + self.displayButton(node,'_click') + def displayButton(self,node,mode): + name = node.get('mbname') + for n in node: + if n.get('mbname') == name+mode: + n.set('style','') + else: + n.set('style','display:none') + gtk.main_quit() + + + + def fillcontent(self): + if len(self.selected) != 1: + self.confirm('Please select one group only') + return False + for id,node in self.selected.iteritems(): + #self.dump(node) + name = node.get("mbname") + if name == None: + self.confirm("The MadButterFly symbol is not defined yet. Please convert it to the symbol before convert it to button.") + return False + type = node.get("mbtype") + if type != 'button': + self.confirm('This is not a button') + return False + hbox = gtk.HBox() + self.window.add(hbox) + button = gtk.Button('Edit Normal') + hbox.pack_start(button) + button.connect("clicked", self.EditNormalButton,node) + button = gtk.Button('Edit Active') + hbox.pack_start(button) + button.connect("clicked", self.EditActiveButton,node) + button = gtk.Button('Edit Click') + hbox.pack_start(button) + button.connect("clicked", self.EditClickButton,node) + button = gtk.Button('Display Normal') + hbox.pack_start(button) + button.connect("clicked", self.DisplayNormalButton,node) + button = gtk.Button('Display Active') + hbox.pack_start(button) + button.connect("clicked", self.DisplayActiveButton,node) + button = gtk.Button('Display Click') + hbox.pack_start(button) + button.connect("clicked", self.DisplayClickButton,node) + return False + + +a=ConvertToButton() +a.affect() + +# vim: set ts=4
--- a/inkscape/MB_EditClickButton.py Thu Jan 01 08:32:03 2009 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -#!/usr/bin/python -import inkex -import pygtk -import gtk -from copy import deepcopy - -class ConvertToButton(inkex.Effect): - def effect(self): - self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) - self.window.set_position(gtk.WIN_POS_MOUSE) - self.defaultname = 'input symbol name here' - if self.fillcontent() == False: - self.window.show_all() - self.window.connect("delete_event", gtk.main_quit) - gtk.main() - def onQuit(self,data): - gtk.main_quit() - def onAssign(self,data): - text = self.text.get_text() - if text != self.defaultname: - self.node.set("mbname",text) - gtk.main_quit() - - def confirm(self,msg): - vbox = gtk.VBox() - vbox.pack_start(gtk.Label(msg)) - self.button = gtk.Button('OK') - vbox.pack_start(self.button) - self.button.connect("clicked", self.onQuit) - self.window.add(vbox) - def dumpattr(self,n): - s = "" - for a,v in n.attrib.items(): - s = s + ("%s=%s" % (a,v)) - return s - - def dump(self,node,l=0): - print " " * l*2,"<", node.tag, self.dumpattr(node),">" - for n in node: - self.dump(n,l+1) - print " " * l * 2,"/>" - - def hide_frame(self,frame): - frame.set('style','display:none') - def show_frame(self,frame): - frame.set('style','') - - - def fillcontent(self): - if len(self.selected) != 1: - self.confirm('Please select one group only') - return False - for id,node in self.selected.iteritems(): - #self.dump(node) - name = node.get("mbname") - if name == None: - self.confirm("The MadButterFly symbol is not defined yet. Please convert it to the symbol before convert it to button.") - return False - for frame in node: - if frame.get('mbname') == name+'_click': - self.show_frame(frame) - else: - self.hide_frame(frame) - return True - - -a=ConvertToButton() -a.affect() - -# vim: set ts=4
--- a/inkscape/MB_EditNormalButton.py Thu Jan 01 08:32:03 2009 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -#!/usr/bin/python -import inkex -import pygtk -import gtk -from copy import deepcopy - -class ConvertToButton(inkex.Effect): - def effect(self): - self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) - self.window.set_position(gtk.WIN_POS_MOUSE) - self.defaultname = 'input symbol name here' - if self.fillcontent() == False: - self.window.show_all() - self.window.connect("delete_event", gtk.main_quit) - gtk.main() - def onQuit(self,data): - gtk.main_quit() - def onAssign(self,data): - text = self.text.get_text() - if text != self.defaultname: - self.node.set("mbname",text) - gtk.main_quit() - - def confirm(self,msg): - vbox = gtk.VBox() - vbox.pack_start(gtk.Label(msg)) - self.button = gtk.Button('OK') - vbox.pack_start(self.button) - self.button.connect("clicked", self.onQuit) - self.window.add(vbox) - def dumpattr(self,n): - s = "" - for a,v in n.attrib.items(): - s = s + ("%s=%s" % (a,v)) - return s - - def dump(self,node,l=0): - print " " * l*2,"<", node.tag, self.dumpattr(node),">" - for n in node: - self.dump(n,l+1) - print " " * l * 2,"/>" - - def hide_frame(self,frame): - frame.set('style','display:none') - def show_frame(self,frame): - frame.set('style','') - - - def fillcontent(self): - if len(self.selected) != 1: - self.confirm('Please select one group only') - return False - for id,node in self.selected.iteritems(): - #self.dump(node) - name = node.get("mbname") - if name == None: - self.confirm("The MadButterFly symbol is not defined yet. Please convert it to the symbol before convert it to button.") - return False - for frame in node: - if frame.get('mbname') == name+'_normal': - self.show_frame(frame) - else: - self.hide_frame(frame) - return True - - -a=ConvertToButton() -a.affect() - -# vim: set ts=4
--- a/inkscape/MB_Frame.py Thu Jan 01 08:32:03 2009 +0800 +++ b/inkscape/MB_Frame.py Sat Jan 03 08:43:29 2009 +0800 @@ -83,12 +83,12 @@ pass - def parseScene(self): """ In this function, we will collect all items for the current scene and then relocate them back to the appropriate scene object. """ self.layer = [] + self.scenemap = None for node in self.document.getroot(): if node.tag == '{http://www.w3.org/2000/svg}metadata': self.parseMetadata(node) @@ -468,20 +468,53 @@ btn=gtk.Button('Extend scene') btn.connect('clicked', self.doExtendScene) hbox.pack_start(btn) + def onQuit(self, event): + self.OK = False + gtk.main_quit() + def onOK(self,event): + self.OK = True + gtk.main_quit() + + def onConfirmDelete(self): + if self.scenemap == None: + vbox = gtk.VBox() + vbox.pack_start(gtk.Label('Convert the SVG into a MadButterfly SVG file. All current element will be delted')) + hbox = gtk.HBox() + self.button = gtk.Button('OK') + hbox.pack_start(self.button) + self.button.connect('clicked', self.onOK) + self.button = gtk.Button('Cancel') + hbox.pack_start(self.button) + self.button.connect("clicked", self.onQuit) + vbox.pack_start(hbox) + self.window.add(vbox) + self.window.show_all() + gtk.main() + self.window.remove(vbox) + + def effect(self): + self.OK = False self.parseScene() self.showGrid() self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("destroy", gtk.main_quit) self.window.set_position(gtk.WIN_POS_MOUSE) - vbox = gtk.VBox() - self.window.add(vbox) - vbox.add(self.scrollwin) - self.vbox = vbox - hbox=gtk.HBox() - self.addButtons(hbox) - vbox.add(hbox) + if self.scenemap == None: + self.onConfirmDelete() + if self.OK: + vbox = gtk.VBox() + self.window.add(vbox) + vbox.add(self.scrollwin) + self.vbox = vbox + hbox=gtk.HBox() + self.addButtons(hbox) + vbox.add(hbox) + else: + return + self.window.set_size_request(600,200) + self.window.show_all() gtk.main()
--- a/inkscape/MB_button_select_click.inx Thu Jan 01 08:32:03 2009 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -<inkscape-extension> - <name>Edit Click button</name> - <id>MadButterfly.EditClickButton</id> - <dependency type="executable" location="extensions">MB_EditClickButton.py</dependency> - <dependency type="executable" location="extensions">inkex.py</dependency> - <effect> - <object-type>any</object-type> - <effects-menu> - <submenu _name="MadButterfly"> - <submenu _name="Button"/> - </submenu> - </effects-menu> - </effect> - <script> - <command reldir="extensions" interpreter="python">MB_EditClickButton.py</command> - </script> -</inkscape-extension> -
--- a/inkscape/MB_button_select_normal.inx Thu Jan 01 08:32:03 2009 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -<inkscape-extension> - <name>Edit Normal button</name> - <id>MadButterfly.EditNormalButton</id> - <dependency type="executable" location="extensions">MB_EditNormalButton.py</dependency> - <dependency type="executable" location="extensions">inkex.py</dependency> - <effect> - <object-type>any</object-type> - <effects-menu> - <submenu _name="MadButterfly"> - <submenu _name="Button"/> - </submenu> - </effects-menu> - </effect> - <script> - <command reldir="extensions" interpreter="python">MB_EditNormalButton.py</command> - </script> -</inkscape-extension> -
--- a/inkscape/README.mbext Thu Jan 01 08:32:03 2009 +0800 +++ b/inkscape/README.mbext Sat Jan 03 08:43:29 2009 +0800 @@ -51,3 +51,9 @@ This function will invoke another inkscape to edit the selected button. In the new inkscape, all three group will be visible and put in different layer. We can move them and edit them. When we close the inkscape, the MB extention will collect the new content and update the groups in the original SVG file. By this way, we can edit the button in any SVG file. +Button + +--- Convert to button + +--- Edit Button + +---- Normal Frame + +---- Active Frame + +---- Click Frame