comparison pyink/MBScene.py @ 1144:257beac7c982

Add blank line between methods.
author Thinker K.F. Li <thinker@codemud.net>
date Fri, 24 Dec 2010 12:21:25 +0800
parents dd6c60c6f41e
children 6409a83b68e7
comparison
equal deleted inserted replaced
1143:18d718a76a45 1144:257beac7c982
96 _scenes = '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scenes' 96 _scenes = '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scenes'
97 _scene = '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene' 97 _scene = '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene'
98 class LayerAttributeWatcher(pybInkscape.PYNodeObserver): 98 class LayerAttributeWatcher(pybInkscape.PYNodeObserver):
99 def __init__(self,ui): 99 def __init__(self,ui):
100 self.ui = ui 100 self.ui = ui
101
101 def notifyChildAdded(self,node,child,prev): 102 def notifyChildAdded(self,node,child,prev):
102 pass 103 pass
104
103 def notifyChildRemoved(self,node,child,prev): 105 def notifyChildRemoved(self,node,child,prev):
104 pass 106 pass
107
105 def notifyChildOrderChanged(self,node,child,prev): 108 def notifyChildOrderChanged(self,node,child,prev):
106 pass 109 pass
110
107 def notifyContentChanged(self,node,old_content,new_content): 111 def notifyContentChanged(self,node,old_content,new_content):
108 pass 112 pass
113
109 def notifyAttributeChanged(self,node, name, old_value, new_value): 114 def notifyAttributeChanged(self,node, name, old_value, new_value):
110 self.ui.updateUI() 115 self.ui.updateUI()
116 pass
117
111 class LayerAddRemoveWatcher(pybInkscape.PYNodeObserver): 118 class LayerAddRemoveWatcher(pybInkscape.PYNodeObserver):
112 def __init__(self,ui): 119 def __init__(self,ui):
113 self.ui = ui 120 self.ui = ui
121 pass
122
114 def notifyChildAdded(self,node,child,prev): 123 def notifyChildAdded(self,node,child,prev):
115 self.ui.updateUI() 124 self.ui.updateUI()
125 pass
126
116 def notifyChildRemoved(self,node,child,prev): 127 def notifyChildRemoved(self,node,child,prev):
117 self.ui.updateUI() 128 self.ui.updateUI()
129 pass
130
118 def notifyChildOrderChanged(self,node,child,prev): 131 def notifyChildOrderChanged(self,node,child,prev):
119 self.ui.updateUI() 132 self.ui.updateUI()
133 pass
134
120 def notifyContentChanged(self,node,old_content,new_content): 135 def notifyContentChanged(self,node,old_content,new_content):
121 self.ui.updateUI() 136 self.ui.updateUI()
137 pass
138
122 def notifyAttributeChanged(self,node, name, old_value, new_value): 139 def notifyAttributeChanged(self,node, name, old_value, new_value):
123 self.ui.updateUI() 140 self.ui.updateUI()
141 pass
142
124 class MBScene(): 143 class MBScene():
125 def __init__(self,desktop,win): 144 def __init__(self,desktop,win):
126 self.desktop = desktop 145 self.desktop = desktop
127 self.window = win 146 self.window = win
128 self.layers = [] 147 self.layers = []
153 try: 172 try:
154 self.nameEditor.set_text(o.getAttribute("inkscape:label")) 173 self.nameEditor.set_text(o.getAttribute("inkscape:label"))
155 except: 174 except:
156 self.nameEditor.set_text('') 175 self.nameEditor.set_text('')
157 pass 176 pass
177 pass
158 178
159 def confirm(self,msg): 179 def confirm(self,msg):
160 vbox = gtk.VBox() 180 vbox = gtk.VBox()
161 vbox.pack_start(gtk.Label(msg)) 181 vbox.pack_start(gtk.Label(msg))
162 self.button = gtk.Button('OK') 182 self.button = gtk.Button('OK')
226 if self.scenemap==None: 246 if self.scenemap==None:
227 #self.desktop.doc().root().repr.setAttribute("xmlns:ns0","http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd") 247 #self.desktop.doc().root().repr.setAttribute("xmlns:ns0","http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd")
228 self.dom.setAttribute("xmlns:ns0","http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd") 248 self.dom.setAttribute("xmlns:ns0","http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd")
229 scenes = self.document.createElement("ns0:scenes") 249 scenes = self.document.createElement("ns0:scenes")
230 node.appendChild(scenes) 250 node.appendChild(scenes)
251 pass
252 pass
253
231 def update(self): 254 def update(self):
232 doc = self.dom 255 doc = self.dom
233 rdoc = self.document 256 rdoc = self.document
234 for node in doc.childList(): 257 for node in doc.childList():
235 if node.name() == 'svg:metadata': 258 if node.name() == 'svg:metadata':
239 ns = rdoc.createElement("ns0:scenes") 262 ns = rdoc.createElement("ns0:scenes")
240 node.appendChild(ns) 263 node.appendChild(ns)
241 for layer in range(0,len(self._framelines)): 264 for layer in range(0,len(self._framelines)):
242 lobj = self._framelines[layer] 265 lobj = self._framelines[layer]
243 lobj.addScenes(rdoc,ns) 266 lobj.addScenes(rdoc,ns)
244 267 pass
268 pass
269 pass
270 pass
271 pass
272 pass
245 273
246 def parseScene(self): 274 def parseScene(self):
247 """ 275 """
248 In this function, we will collect all items for the current 276 In this function, we will collect all items for the current
249 scene and then relocate them back to the appropriate scene 277 scene and then relocate them back to the appropriate scene
263 self.width = float(doc.getAttribute("width")) 291 self.width = float(doc.getAttribute("width"))
264 self.height= float(doc.getAttribute("height")) 292 self.height= float(doc.getAttribute("height"))
265 except: 293 except:
266 self.width = 640 294 self.width = 640
267 self.height=480 295 self.height=480
296 pass
268 297
269 for node in doc.childList(): 298 for node in doc.childList():
270 print node.name() 299 print node.name()
271 if node.name() == 'svg:metadata': 300 if node.name() == 'svg:metadata':
272 self.parseMetadata(node) 301 self.parseMetadata(node)
304 lyobj.current_scene.append(scene) 333 lyobj.current_scene.append(scene)
305 pass 334 pass
306 pass 335 pass
307 pass 336 pass
308 pass 337 pass
309
310 338
311 self.collectID() 339 self.collectID()
312 self.dumpID() 340 self.dumpID()
313 pass 341 pass
314 342
415 self.update() 443 self.update()
416 self.last_line._draw_all_frames() 444 self.last_line._draw_all_frames()
417 self.last_line.update() 445 self.last_line.update()
418 return 446 return
419 i = i + 1 447 i = i + 1
448 pass
449 pass
450
420 def extendScene(self): 451 def extendScene(self):
421 nth = self.last_frame 452 nth = self.last_frame
422 layer = self.last_line 453 layer = self.last_line
423 i = 0 454 i = 0
424 while i < len(layer._keys): 455 while i < len(layer._keys):
490 521
491 522
492 523
493 def setCurrentScene(self,nth): 524 def setCurrentScene(self,nth):
494 """ 525 """
495 Update the scene group according to the curretn scene data. There are a couple of cases. 526 Update the scene group according to the curretn scene
496 1. If the type of the scene is normal, we display it when it contains the current 527 data. There are a couple of cases.
497 frame. Otherwise hide it. 528
498 2. If the type of the scene is relocate or scale, we need to duplicate the scene group 529 1. If the type of the scene is normal, we display it when
499 and then modify its transform matrix according to the definition of the scene. Then, 530 it contains the current frame. Otherwise hide it.
500 hide the original scenr group and display the duplciate scene group. In addition, 531
501 we may need to delete the old duplicated scene group as well. 532 2. If the type of the scene is relocate or scale, we need
502 533 to duplicate the scene group and then modify its
503 For each layer, we will always use the duplicated scene group whose name as dup. 534 transform matrix according to the definition of the
504 We will put the duplicated scene group inside it. We will create this group if it is not 535 scene. Then, hide the original scenr group and display
536 the duplciate scene group. In addition, we may need to
537 delete the old duplicated scene group as well.
538
539 For each layer, we will always use the duplicated scene
540 group whose name as dup. We will put the duplicated scene
541 group inside it. We will create this group if it is not
505 available. 542 available.
506 """ 543 """
507 self.current = nth 544 self.current = nth
508 self.tween.updateMapping() 545 self.tween.updateMapping()
509 for layer in self._framelines: 546 for layer in self._framelines:
559 def enterGroup(self,obj): 596 def enterGroup(self,obj):
560 for l in self.layers: 597 for l in self.layers:
561 for s in l.node.childList(): 598 for s in l.node.childList():
562 if s.getAttribute('id') == obj.getAttribute("id"): 599 if s.getAttribute('id') == obj.getAttribute("id"):
563 self.desktop.setCurrentLayer(s.spitem) 600 self.desktop.setCurrentLayer(s.spitem)
564 601 pass
602 pass
603 pass
604 pass
605
565 def selectSceneObject(self,frameline, nth): 606 def selectSceneObject(self,frameline, nth):
566 i = 0 607 i = 0
567 while i < len(frameline._keys): 608 while i < len(frameline._keys):
568 s = frameline._keys[i] 609 s = frameline._keys[i]
569 if s.right_tween is False: 610 if s.right_tween is False:
583 else: 624 else:
584 pass 625 pass
585 i = i + 2 626 i = i + 2
586 pass 627 pass
587 pass 628 pass
629
588 def setTweenType(self,typ): 630 def setTweenType(self,typ):
589 if typ == 'normal': 631 if typ == 'normal':
590 self.tweenTypeSelector.set_active(0) 632 self.tweenTypeSelector.set_active(0)
591 elif typ == 'relocate': 633 elif typ == 'relocate':
592 self.tweenTypeSelector.set_active(1) 634 self.tweenTypeSelector.set_active(1)
593 elif typ == 'scale': 635 elif typ == 'scale':
594 self.tweenTypeSelector.set_active(2) 636 self.tweenTypeSelector.set_active(2)
595 637 pass
596 638 pass
597 639
598 def newCell(self,file): 640 def newCell(self,file):
599 img = gtk.Image() 641 img = gtk.Image()
600 img.set_from_file(file) 642 img.set_from_file(file)
601 btn = gtk.EventBox() 643 btn = gtk.EventBox()
609 self.last_frame = frame 651 self.last_frame = frame
610 self.last_line.active_frame(frame) 652 self.last_line.active_frame(frame)
611 self.lockui = True 653 self.lockui = True
612 self.doEditScene(frame) 654 self.doEditScene(frame)
613 self.lockui = False 655 self.lockui = False
614 656 pass
615 657
616 def _remove_active_frame(self,widget,event): 658 def _remove_active_frame(self,widget,event):
617 """ 659 """
618 Hide all hover frames. This is a hack. We should use the lost focus event 660 Hide all hover frames. This is a hack. We should use the lost focus event
619 instead in the future to reduce the overhead. 661 instead in the future to reduce the overhead.
620 """ 662 """
621 for f in self._framelines: 663 for f in self._framelines:
622 if f != widget: 664 if f != widget:
623 f.hide_hover() 665 f.hide_hover()
666 pass
667 pass
668 pass
624 669
625 def _create_framelines(self): 670 def _create_framelines(self):
626 import frameline 671 import frameline
627 self.scrollwin = gtk.ScrolledWindow() 672 self.scrollwin = gtk.ScrolledWindow()
628 self.scrollwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) 673 self.scrollwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
693 738
694 self.last_cell = cell 739 self.last_cell = cell
695 color = cell.get_colormap().alloc_color("green") 740 color = cell.get_colormap().alloc_color("green")
696 cell.modify_bg(gtk.STATE_NORMAL, color) 741 cell.modify_bg(gtk.STATE_NORMAL, color)
697 pass 742 pass
743
698 def duplicateKeyScene(self): 744 def duplicateKeyScene(self):
699 self.last_line.add_keyframe(self.last_frame) 745 self.last_line.add_keyframe(self.last_frame)
700 # Search for the current scene 746 # Search for the current scene
701 i = 0 747 i = 0
702 while i < len(self.last_line._keys): 748 while i < len(self.last_line._keys):
712 self.show() 758 self.show()
713 self.doEditScene(None) 759 self.doEditScene(None)
714 return 760 return
715 last_key = key 761 last_key = key
716 i = i + 1 762 i = i + 1
763 pass
764 pass
765
717 def duplicateSceneGroup(self,gid): 766 def duplicateSceneGroup(self,gid):
718 # Search for the duplicated group 767 # Search for the duplicated group
719 doc = self.dom 768 doc = self.dom
720 rdoc = self.document 769 rdoc = self.document
721 orig = None 770 orig = None
724 for t in node.childList(): 773 for t in node.childList():
725 if t.name() == "svg:g": 774 if t.name() == "svg:g":
726 if t.getAttribute("id") == gid: 775 if t.getAttribute("id") == gid:
727 orig = t 776 orig = t
728 break 777 break
778 pass
779 pass
780 pass
781 pass
729 if orig == None: 782 if orig == None:
730 return None 783 return None
731 ns = orig.duplicate(rdoc) 784 ns = orig.duplicate(rdoc)
732 gid = self.last_line.node.getAttribute("inkscape:label")+self.newID() 785 gid = self.last_line.node.getAttribute("inkscape:label")+self.newID()
733 self.ID[gid]=1 786 self.ID[gid]=1
745 self.lockui=True 798 self.lockui=True
746 self.insertKeyScene() 799 self.insertKeyScene()
747 self.lockui=False 800 self.lockui=False
748 # self.grid.show_all() 801 # self.grid.show_all()
749 return 802 return
803
750 def doDuplicateKeyScene(self,w): 804 def doDuplicateKeyScene(self,w):
751 self.lockui = True 805 self.lockui = True
752 self.duplicateKeyScene() 806 self.duplicateKeyScene()
753 self.lockui = False 807 self.lockui = False
754 808
766 #self.grid.show_all() 820 #self.grid.show_all()
767 pass 821 pass
768 def changeObjectLabel(self,w): 822 def changeObjectLabel(self,w):
769 o = self.desktop.selection.list()[0] 823 o = self.desktop.selection.list()[0]
770 o.setAttribute("inkscape:label", self.nameEditor.get_text()) 824 o.setAttribute("inkscape:label", self.nameEditor.get_text())
825 pass
826
771 def addNameEditor(self,hbox): 827 def addNameEditor(self,hbox):
772 self.nameEditor = gtk.Entry(max=40) 828 self.nameEditor = gtk.Entry(max=40)
773 hbox.pack_start(self.nameEditor,expand=False,fill=False) 829 hbox.pack_start(self.nameEditor,expand=False,fill=False)
774 self.editDone = gtk.Button('Set') 830 self.editDone = gtk.Button('Set')
775 hbox.pack_start(self.editDone,expand=False,fill=False) 831 hbox.pack_start(self.editDone,expand=False,fill=False)
776 self.editDone.connect('clicked', self.changeObjectLabel) 832 self.editDone.connect('clicked', self.changeObjectLabel)
777 833 pass
834
778 def addButtons(self,hbox): 835 def addButtons(self,hbox):
779 #btn = gtk.Button('Edit') 836 #btn = gtk.Button('Edit')
780 #btn.connect('clicked', self.doEditScene) 837 #btn.connect('clicked', self.doEditScene)
781 #hbox.pack_start(btn,expand=False,fill=False) 838 #hbox.pack_start(btn,expand=False,fill=False)
782 btn = gtk.Button('Insert Key') 839 btn = gtk.Button('Insert Key')
792 btn.connect('clicked', self.doDuplicateKeyScene) 849 btn.connect('clicked', self.doDuplicateKeyScene)
793 hbox.pack_start(btn,expand=False,fill=False) 850 hbox.pack_start(btn,expand=False,fill=False)
794 self.addNameEditor(hbox) 851 self.addNameEditor(hbox)
795 self.addTweenTypeSelector(hbox) 852 self.addTweenTypeSelector(hbox)
796 pass 853 pass
854
797 def onTweenTypeChange(self,w): 855 def onTweenTypeChange(self,w):
798 n = self.tweenTypeSelector.get_active() 856 n = self.tweenTypeSelector.get_active()
799 if self.last_line == None: 857 if self.last_line == None:
800 return 858 return
801 frameline = self.last_line 859 frameline = self.last_line
822 pass 880 pass
823 if found == -1: return 881 if found == -1: return
824 self.last_line.set_tween_type(found,self.tweenTypeSelector.get_active_text()) 882 self.last_line.set_tween_type(found,self.tweenTypeSelector.get_active_text())
825 self.last_line.update() 883 self.last_line.update()
826 self.update() 884 self.update()
885 pass
827 886
828 def addTweenTypeSelector(self,hbox): 887 def addTweenTypeSelector(self,hbox):
829 tweenbox = gtk.HBox() 888 tweenbox = gtk.HBox()
830 label = gtk.Label('Tween Type') 889 label = gtk.Label('Tween Type')
831 tweenbox.pack_start(label) 890 tweenbox.pack_start(label)
836 self.tweenTypeSelector.append_text('scale') 895 self.tweenTypeSelector.append_text('scale')
837 self.tweenTypeSelector.set_active(0) 896 self.tweenTypeSelector.set_active(0)
838 tweenbox.pack_start(self.tweenTypeSelector, expand=False,fill=False) 897 tweenbox.pack_start(self.tweenTypeSelector, expand=False,fill=False)
839 hbox.pack_start(tweenbox,expand=False,fill=False) 898 hbox.pack_start(tweenbox,expand=False,fill=False)
840 self.tweenTypeSelector.connect('changed', self.onTweenTypeChange) 899 self.tweenTypeSelector.connect('changed', self.onTweenTypeChange)
900 pass
841 901
842 def onQuit(self, event): 902 def onQuit(self, event):
843 self.OK = False 903 self.OK = False
844 gtk.main_quit() 904 gtk.main_quit()
845 pass 905 pass
852 def updateUI(self,node=None,arg=None): 912 def updateUI(self,node=None,arg=None):
853 if self.lockui: return 913 if self.lockui: return
854 self.lockui = True 914 self.lockui = True
855 self._updateUI() 915 self._updateUI()
856 self.lockui = False 916 self.lockui = False
917 pass
918
857 def _updateUI(self,node=None,arg=None): 919 def _updateUI(self,node=None,arg=None):
858 if self.last_update!= None: 920 if self.last_update!= None:
859 glib.source_remove(self.last_update) 921 glib.source_remove(self.last_update)
860 self.last_update = glib.timeout_add(300,self.show) 922 self.last_update = glib.timeout_add(300,self.show)
923 pass
924
861 def show(self): 925 def show(self):
862 self.OK = True 926 self.OK = True
863 self.dom = self.desktop.doc().root().repr 927 self.dom = self.desktop.doc().root().repr
864 self.document = self.desktop.doc().rdoc 928 self.document = self.desktop.doc().rdoc
865 self.tween = TweenObject(self.document,self.dom) 929 self.tween = TweenObject(self.document,self.dom)