Mercurial > MadButterfly
comparison pyink/MBScene.py @ 1148:153a87b4edb7
Merge
author | wycc |
---|---|
date | Fri, 24 Dec 2010 15:18:05 +0800 |
parents | 5cfa73d7e80f 6409a83b68e7 |
children | 0ffef2df6201 |
comparison
equal
deleted
inserted
replaced
1147:5cfa73d7e80f | 1148:153a87b4edb7 |
---|---|
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 def notifyChildAdded(self,node,child,prev): | 101 def notifyChildAdded(self,node,child,prev): |
102 pass | 102 pass |
103 | |
103 def notifyChildRemoved(self,node,child,prev): | 104 def notifyChildRemoved(self,node,child,prev): |
104 pass | 105 pass |
106 | |
105 def notifyChildOrderChanged(self,node,child,prev): | 107 def notifyChildOrderChanged(self,node,child,prev): |
106 pass | 108 pass |
109 | |
107 def notifyContentChanged(self,node,old_content,new_content): | 110 def notifyContentChanged(self,node,old_content,new_content): |
108 pass | 111 pass |
112 | |
109 def notifyAttributeChanged(self,node, name, old_value, new_value): | 113 def notifyAttributeChanged(self,node, name, old_value, new_value): |
110 self.ui.updateUI() | 114 self.ui.updateUI() |
115 pass | |
116 | |
111 class LayerAddRemoveWatcher(pybInkscape.PYNodeObserver): | 117 class LayerAddRemoveWatcher(pybInkscape.PYNodeObserver): |
112 def __init__(self,ui): | 118 def __init__(self,ui): |
113 self.ui = ui | 119 self.ui = ui |
120 pass | |
121 | |
114 def notifyChildAdded(self,node,child,prev): | 122 def notifyChildAdded(self,node,child,prev): |
115 self.ui.updateUI() | 123 self.ui.updateUI() |
124 pass | |
125 | |
116 def notifyChildRemoved(self,node,child,prev): | 126 def notifyChildRemoved(self,node,child,prev): |
117 self.ui.updateUI() | 127 self.ui.updateUI() |
128 pass | |
129 | |
118 def notifyChildOrderChanged(self,node,child,prev): | 130 def notifyChildOrderChanged(self,node,child,prev): |
119 self.ui.updateUI() | 131 self.ui.updateUI() |
132 pass | |
133 | |
120 def notifyContentChanged(self,node,old_content,new_content): | 134 def notifyContentChanged(self,node,old_content,new_content): |
121 self.ui.updateUI() | 135 self.ui.updateUI() |
136 pass | |
137 | |
122 def notifyAttributeChanged(self,node, name, old_value, new_value): | 138 def notifyAttributeChanged(self,node, name, old_value, new_value): |
123 self.ui.updateUI() | 139 self.ui.updateUI() |
140 pass | |
141 | |
124 class MBScene(): | 142 class MBScene(): |
125 def __init__(self,desktop,win): | 143 def __init__(self,desktop,win): |
126 self.desktop = desktop | 144 self.desktop = desktop |
127 self.window = win | 145 self.window = win |
128 self.layers = [] | 146 self.layers = [] |
155 try: | 173 try: |
156 self.nameEditor.set_text(o.getAttribute("inkscape:label")) | 174 self.nameEditor.set_text(o.getAttribute("inkscape:label")) |
157 except: | 175 except: |
158 self.nameEditor.set_text('') | 176 self.nameEditor.set_text('') |
159 pass | 177 pass |
178 pass | |
160 | 179 |
161 def confirm(self,msg): | 180 def confirm(self,msg): |
162 vbox = gtk.VBox() | 181 vbox = gtk.VBox() |
163 vbox.pack_start(gtk.Label(msg)) | 182 vbox.pack_start(gtk.Label(msg)) |
164 self.button = gtk.Button('OK') | 183 self.button = gtk.Button('OK') |
230 if self.scenemap==None: | 249 if self.scenemap==None: |
231 #self.desktop.doc().root().repr.setAttribute("xmlns:ns0","http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd") | 250 #self.desktop.doc().root().repr.setAttribute("xmlns:ns0","http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd") |
232 self.dom.setAttribute("xmlns:ns0","http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd") | 251 self.dom.setAttribute("xmlns:ns0","http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd") |
233 scenes = self.document.createElement("ns0:scenes") | 252 scenes = self.document.createElement("ns0:scenes") |
234 node.appendChild(scenes) | 253 node.appendChild(scenes) |
254 pass | |
255 pass | |
256 | |
235 def update(self): | 257 def update(self): |
236 doc = self.dom | 258 doc = self.dom |
237 rdoc = self.document | 259 rdoc = self.document |
238 for node in doc.childList(): | 260 for node in doc.childList(): |
239 if node.name() == 'svg:metadata': | 261 if node.name() == 'svg:metadata': |
243 ns = rdoc.createElement("ns0:scenes") | 265 ns = rdoc.createElement("ns0:scenes") |
244 node.appendChild(ns) | 266 node.appendChild(ns) |
245 for layer in range(0,len(self._framelines)): | 267 for layer in range(0,len(self._framelines)): |
246 lobj = self._framelines[layer] | 268 lobj = self._framelines[layer] |
247 lobj.addScenes(rdoc,ns) | 269 lobj.addScenes(rdoc,ns) |
248 | 270 pass |
271 pass | |
272 pass | |
273 pass | |
274 pass | |
275 pass | |
249 | 276 |
250 def parseScene(self): | 277 def parseScene(self): |
251 """ | 278 """ |
252 In this function, we will collect all items for the current | 279 In this function, we will collect all items for the current |
253 scene and then relocate them back to the appropriate scene | 280 scene and then relocate them back to the appropriate scene |
267 self.width = float(doc.getAttribute("width")) | 294 self.width = float(doc.getAttribute("width")) |
268 self.height= float(doc.getAttribute("height")) | 295 self.height= float(doc.getAttribute("height")) |
269 except: | 296 except: |
270 self.width = 640 | 297 self.width = 640 |
271 self.height=480 | 298 self.height=480 |
299 pass | |
272 | 300 |
273 for node in doc.childList(): | 301 for node in doc.childList(): |
274 print node.name() | 302 print node.name() |
275 if node.name() == 'svg:metadata': | 303 if node.name() == 'svg:metadata': |
276 self.parseMetadata(node) | 304 self.parseMetadata(node) |
374 txt.setAttribute("y","0") | 402 txt.setAttribute("y","0") |
375 txt.setAttribute("width","100") | 403 txt.setAttribute("width","100") |
376 txt.setAttribute("height","100") | 404 txt.setAttribute("height","100") |
377 txt.setAttribute("style","fill:#ff00") | 405 txt.setAttribute("style","fill:#ff00") |
378 ns.appendChild(txt) | 406 ns.appendChild(txt) |
379 gid = self.last_line.node.label()+self.newID() | 407 gid = self.last_line.node.getAttribute('inkscape:label')+self.newID() |
380 self.ID[gid]=1 | 408 self.ID[gid]=1 |
381 ns.setAttribute("id",gid) | 409 ns.setAttribute("id",gid) |
382 ns.setAttribute("inkscape:groupmode","layer") | 410 ns.setAttribute("inkscape:groupmode","layer") |
383 self.last_line.node.appendChild(ns) | 411 self.last_line.node.appendChild(ns) |
384 print 'Add key ', x | 412 print 'Add key ', x |
419 self.update() | 447 self.update() |
420 self.last_line._draw_all_frames() | 448 self.last_line._draw_all_frames() |
421 self.last_line.update() | 449 self.last_line.update() |
422 return | 450 return |
423 i = i + 1 | 451 i = i + 1 |
452 pass | |
453 pass | |
454 | |
424 def extendScene(self): | 455 def extendScene(self): |
425 nth = self.last_frame | 456 nth = self.last_frame |
426 layer = self.last_line | 457 layer = self.last_line |
427 i = 0 | 458 i = 0 |
428 while i < len(layer._keys): | 459 while i < len(layer._keys): |
494 | 525 |
495 | 526 |
496 | 527 |
497 def setCurrentScene(self,nth): | 528 def setCurrentScene(self,nth): |
498 """ | 529 """ |
499 Update the scene group according to the curretn scene data. There are a couple of cases. | 530 Update the scene group according to the curretn scene |
500 1. If the type of the scene is normal, we display it when it contains the current | 531 data. There are a couple of cases. |
501 frame. Otherwise hide it. | 532 1. If the type of the scene is normal, we display it when |
502 2. If the type of the scene is relocate or scale, we need to duplicate the scene group | 533 it contains the current frame. Otherwise hide it. |
503 and then modify its transform matrix according to the definition of the scene. Then, | 534 2. If the type of the scene is relocate or scale, we need |
504 hide the original scenr group and display the duplciate scene group. In addition, | 535 to duplicate the scene group and then modify its |
505 we may need to delete the old duplicated scene group as well. | 536 transform matrix according to the definition of the |
506 | 537 scene. Then, hide the original scenr group and display |
507 For each layer, we will always use the duplicated scene group whose name as dup. | 538 the duplciate scene group. In addition, we may need to |
508 We will put the duplicated scene group inside it. We will create this group if it is not | 539 delete the old duplicated scene group as well. |
540 | |
541 For each layer, we will always use the duplicated scene | |
542 group whose name as dup. | |
543 We will put the duplicated scene group inside it. We will | |
544 create this group if it is not | |
509 available. | 545 available. |
510 """ | 546 """ |
511 self.current = nth | 547 self.current = nth |
512 self.tween.updateMapping() | 548 self.tween.updateMapping() |
513 for layer in self._framelines: | 549 for layer in self._framelines: |
524 layer.duplicateGroup.setAttribute("sodipodi:insensitive","1") | 560 layer.duplicateGroup.setAttribute("sodipodi:insensitive","1") |
525 layer.duplicateGroup.setAttribute("style","") | 561 layer.duplicateGroup.setAttribute("style","") |
526 layer.layer.node.appendChild(layer.duplicateGroup) | 562 layer.layer.node.appendChild(layer.duplicateGroup) |
527 pass | 563 pass |
528 # Create a new group | 564 # Create a new group |
529 #layer.duplicateGroup = None | 565 #layer.duplicateGroup = None |
530 | |
531 | |
532 while i < len(layer._keys): | 566 while i < len(layer._keys): |
533 s = layer._keys[i] | 567 s = layer._keys[i] |
534 print s.ref.getAttribute("id"),s.idx,s.left_tween,s.right_tween | 568 print s.ref.getAttribute("id"),s.idx,s.left_tween,s.right_tween |
535 if s.right_tween is False: | 569 if s.right_tween is False: |
536 if nth == s.idx+1: | 570 if nth == s.idx+1: |
581 | 615 |
582 def enterGroup(self,obj): | 616 def enterGroup(self,obj): |
583 for l in self.layers: | 617 for l in self.layers: |
584 for s in l.node.childList(): | 618 for s in l.node.childList(): |
585 if s.getAttribute('id') == obj.getAttribute("id"): | 619 if s.getAttribute('id') == obj.getAttribute("id"): |
586 self.desktop.setCurrentLayer(self.DOMtoItem(s)) | 620 self.desktop.setCurrentLayer(s.spitem) |
587 | 621 pass |
622 pass | |
623 pass | |
624 pass | |
625 | |
588 def selectSceneObject(self,frameline, nth): | 626 def selectSceneObject(self,frameline, nth): |
589 i = 0 | 627 i = 0 |
590 while i < len(frameline._keys): | 628 while i < len(frameline._keys): |
591 s = frameline._keys[i] | 629 s = frameline._keys[i] |
592 if s.right_tween is False: | 630 if s.right_tween is False: |
606 else: | 644 else: |
607 pass | 645 pass |
608 i = i + 2 | 646 i = i + 2 |
609 pass | 647 pass |
610 pass | 648 pass |
649 | |
611 def setTweenType(self,typ): | 650 def setTweenType(self,typ): |
612 if typ == 'normal': | 651 if typ == 'normal': |
613 self.tweenTypeSelector.set_active(0) | 652 self.tweenTypeSelector.set_active(0) |
614 elif typ == 'relocate': | 653 elif typ == 'relocate': |
615 self.tweenTypeSelector.set_active(1) | 654 self.tweenTypeSelector.set_active(1) |
616 elif typ == 'scale': | 655 elif typ == 'scale': |
617 self.tweenTypeSelector.set_active(2) | 656 self.tweenTypeSelector.set_active(2) |
618 | 657 pass |
619 | 658 pass |
620 | 659 |
621 def newCell(self,file): | 660 def newCell(self,file): |
622 img = gtk.Image() | 661 img = gtk.Image() |
623 img.set_from_file(file) | 662 img.set_from_file(file) |
624 btn = gtk.EventBox() | 663 btn = gtk.EventBox() |
632 self.last_frame = frame | 671 self.last_frame = frame |
633 self.last_line.active_frame(frame) | 672 self.last_line.active_frame(frame) |
634 self.lockui = True | 673 self.lockui = True |
635 self.doEditScene(frame) | 674 self.doEditScene(frame) |
636 self.lockui = False | 675 self.lockui = False |
637 | 676 pass |
638 | 677 |
639 def _remove_active_frame(self,widget,event): | 678 def _remove_active_frame(self,widget,event): |
640 """ | 679 """ |
641 Hide all hover frames. This is a hack. We should use the lost focus event | 680 Hide all hover frames. This is a hack. We should use the lost focus event |
642 instead in the future to reduce the overhead. | 681 instead in the future to reduce the overhead. |
643 """ | 682 """ |
644 for f in self._framelines: | 683 for f in self._framelines: |
645 if f != widget: | 684 if f != widget: |
646 f.hide_hover() | 685 f.hide_hover() |
686 pass | |
687 pass | |
688 pass | |
647 | 689 |
648 def _create_framelines(self): | 690 def _create_framelines(self): |
649 import frameline | 691 import frameline |
650 self.scrollwin = gtk.ScrolledWindow() | 692 self.scrollwin = gtk.ScrolledWindow() |
651 self.scrollwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) | 693 self.scrollwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) |
716 | 758 |
717 self.last_cell = cell | 759 self.last_cell = cell |
718 color = cell.get_colormap().alloc_color("green") | 760 color = cell.get_colormap().alloc_color("green") |
719 cell.modify_bg(gtk.STATE_NORMAL, color) | 761 cell.modify_bg(gtk.STATE_NORMAL, color) |
720 pass | 762 pass |
763 | |
721 def duplicateKeyScene(self): | 764 def duplicateKeyScene(self): |
722 self.last_line.add_keyframe(self.last_frame) | 765 self.last_line.add_keyframe(self.last_frame) |
723 # Search for the current scene | 766 # Search for the current scene |
724 i = 0 | 767 i = 0 |
725 while i < len(self.last_line._keys): | 768 while i < len(self.last_line._keys): |
735 self.show() | 778 self.show() |
736 self.doEditScene(None) | 779 self.doEditScene(None) |
737 return | 780 return |
738 last_key = key | 781 last_key = key |
739 i = i + 1 | 782 i = i + 1 |
783 pass | |
784 pass | |
785 | |
740 def duplicateSceneGroup(self,gid): | 786 def duplicateSceneGroup(self,gid): |
741 # Search for the duplicated group | 787 # Search for the duplicated group |
742 doc = self.dom | 788 doc = self.dom |
743 rdoc = self.document | 789 rdoc = self.document |
744 orig = None | 790 orig = None |
747 for t in node.childList(): | 793 for t in node.childList(): |
748 if t.name() == "svg:g": | 794 if t.name() == "svg:g": |
749 if t.getAttribute("id") == gid: | 795 if t.getAttribute("id") == gid: |
750 orig = t | 796 orig = t |
751 break | 797 break |
798 pass | |
799 pass | |
800 pass | |
801 pass | |
752 if orig == None: | 802 if orig == None: |
753 return None | 803 return None |
754 ns = orig.duplicate(rdoc) | 804 ns = orig.duplicate(rdoc) |
755 gid = self.last_line.node.getAttribute('id')+self.newID() | 805 gid = self.last_line.node.getAttribute("inkscape:label")+self.newID() |
756 self.ID[gid]=1 | 806 self.ID[gid]=1 |
757 ns.setAttribute("id",gid) | 807 ns.setAttribute("id",gid) |
758 ns.setAttribute("inkscape:groupmode","layer") | 808 ns.setAttribute("inkscape:groupmode","layer") |
759 self.last_line.node.appendChild(ns) | 809 self.last_line.node.appendChild(ns) |
760 return ns | 810 return ns |
768 self.lockui=True | 818 self.lockui=True |
769 self.insertKeyScene() | 819 self.insertKeyScene() |
770 self.lockui=False | 820 self.lockui=False |
771 # self.grid.show_all() | 821 # self.grid.show_all() |
772 return | 822 return |
823 | |
773 def doDuplicateKeyScene(self,w): | 824 def doDuplicateKeyScene(self,w): |
774 self.lockui = True | 825 self.lockui = True |
775 self.duplicateKeyScene() | 826 self.duplicateKeyScene() |
776 self.lockui = False | 827 self.lockui = False |
777 | 828 |
790 pass | 841 pass |
791 | 842 |
792 def changeObjectLabel(self,w): | 843 def changeObjectLabel(self,w): |
793 o = self.desktop.selection.list()[0] | 844 o = self.desktop.selection.list()[0] |
794 o.setAttribute("inkscape:label", self.nameEditor.get_text()) | 845 o.setAttribute("inkscape:label", self.nameEditor.get_text()) |
846 pass | |
795 | 847 |
796 def addNameEditor(self,hbox): | 848 def addNameEditor(self,hbox): |
797 self.nameEditor = gtk.Entry(max=40) | 849 self.nameEditor = gtk.Entry(max=40) |
798 hbox.pack_start(self.nameEditor,expand=False,fill=False) | 850 hbox.pack_start(self.nameEditor,expand=False,fill=False) |
799 self.editDone = gtk.Button('Set') | 851 self.editDone = gtk.Button('Set') |
800 hbox.pack_start(self.editDone,expand=False,fill=False) | 852 hbox.pack_start(self.editDone,expand=False,fill=False) |
801 self.editDone.connect('clicked', self.changeObjectLabel) | 853 self.editDone.connect('clicked', self.changeObjectLabel) |
854 pass | |
802 | 855 |
803 def doRun(self,arg): | 856 def doRun(self,arg): |
804 """ | 857 """ |
805 Execute the current animation till the last frame. | 858 Execute the current animation till the last frame. |
806 """ | 859 """ |
841 hbox.pack_start(btn,expand=False,fill=False) | 894 hbox.pack_start(btn,expand=False,fill=False) |
842 self.addNameEditor(hbox) | 895 self.addNameEditor(hbox) |
843 self.addTweenTypeSelector(hbox) | 896 self.addTweenTypeSelector(hbox) |
844 | 897 |
845 pass | 898 pass |
899 | |
846 def onTweenTypeChange(self,w): | 900 def onTweenTypeChange(self,w): |
847 n = self.tweenTypeSelector.get_active() | 901 n = self.tweenTypeSelector.get_active() |
848 if self.last_line == None: | 902 if self.last_line == None: |
849 return | 903 return |
850 frameline = self.last_line | 904 frameline = self.last_line |
871 pass | 925 pass |
872 if found == -1: return | 926 if found == -1: return |
873 self.last_line.set_tween_type(found,self.tweenTypeSelector.get_active_text()) | 927 self.last_line.set_tween_type(found,self.tweenTypeSelector.get_active_text()) |
874 self.last_line.update() | 928 self.last_line.update() |
875 self.update() | 929 self.update() |
930 pass | |
876 | 931 |
877 def addTweenTypeSelector(self,hbox): | 932 def addTweenTypeSelector(self,hbox): |
878 tweenbox = gtk.HBox() | 933 tweenbox = gtk.HBox() |
879 label = gtk.Label('Tween Type') | 934 label = gtk.Label('Tween Type') |
880 tweenbox.pack_start(label) | 935 tweenbox.pack_start(label) |
885 self.tweenTypeSelector.append_text('scale') | 940 self.tweenTypeSelector.append_text('scale') |
886 self.tweenTypeSelector.set_active(0) | 941 self.tweenTypeSelector.set_active(0) |
887 tweenbox.pack_start(self.tweenTypeSelector, expand=False,fill=False) | 942 tweenbox.pack_start(self.tweenTypeSelector, expand=False,fill=False) |
888 hbox.pack_start(tweenbox,expand=False,fill=False) | 943 hbox.pack_start(tweenbox,expand=False,fill=False) |
889 self.tweenTypeSelector.connect('changed', self.onTweenTypeChange) | 944 self.tweenTypeSelector.connect('changed', self.onTweenTypeChange) |
945 pass | |
890 | 946 |
891 def onQuit(self, event): | 947 def onQuit(self, event): |
892 self.OK = False | 948 self.OK = False |
893 gtk.main_quit() | 949 gtk.main_quit() |
894 pass | 950 pass |
901 def updateUI(self,node=None,arg=None): | 957 def updateUI(self,node=None,arg=None): |
902 if self.lockui: return | 958 if self.lockui: return |
903 self.lockui = True | 959 self.lockui = True |
904 self._updateUI() | 960 self._updateUI() |
905 self.lockui = False | 961 self.lockui = False |
962 pass | |
963 | |
906 def _updateUI(self,node=None,arg=None): | 964 def _updateUI(self,node=None,arg=None): |
907 if self.last_update!= None: | 965 if self.last_update!= None: |
908 glib.source_remove(self.last_update) | 966 glib.source_remove(self.last_update) |
909 self.last_update = glib.timeout_add(300,self.show) | 967 self.last_update = glib.timeout_add(300,self.show) |
968 pass | |
969 | |
910 def show(self): | 970 def show(self): |
911 self.OK = True | 971 self.OK = True |
912 self.dom = self.desktop.doc().root().repr | 972 self.dom = self.desktop.doc().root().repr |
913 self.document = self.desktop.doc().rdoc | 973 self.document = self.desktop.doc().rdoc |
914 self.tween = TweenObject(self.document,self.dom) | 974 self.tween = TweenObject(self.document,self.dom) |