Mercurial > MadButterfly
comparison pyink/MBScene.py @ 1064:16c69756ef5d
Add NodeObserver to monitor the change of the layer and update it in the scene editor.
author | wycc |
---|---|
date | Tue, 30 Nov 2010 03:52:43 +0800 |
parents | 148ce30a861d |
children | afa42d5836cc |
comparison
equal
deleted
inserted
replaced
1049:9d4f02715987 | 1064:16c69756ef5d |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # -*- indent-tabs-mode: t; tab-width: 8; python-indent: 4; -*- | 2 # -*- indent-tabs-mode: t; tab-width: 8; python-indent: 4; -*- |
3 # vim: sw=4:ts=8:sts=4 | 3 # vim: sw=4:ts=8:sts=4 |
4 import pygtk | 4 import pygtk |
5 import gtk | 5 import gtk |
6 import glib | |
6 from copy import deepcopy | 7 from copy import deepcopy |
7 from lxml import etree | 8 from lxml import etree |
8 import random | 9 import random |
9 import traceback | 10 import traceback |
10 import time | 11 import time |
12 import pybInkscape | |
11 | 13 |
12 # Please refer to | 14 # Please refer to |
13 # http://www.assembla.com/wiki/show/MadButterfly/Inkscape_extention | 15 # http://www.assembla.com/wiki/show/MadButterfly/Inkscape_extention |
14 # for the designed document. | 16 # for the designed document. |
15 | 17 |
53 pass | 55 pass |
54 pass | 56 pass |
55 | 57 |
56 _scenes = '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scenes' | 58 _scenes = '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scenes' |
57 _scene = '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene' | 59 _scene = '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene' |
58 | 60 class LayerAttributeWatcher(pybInkscape.PYNodeObserver): |
61 def __init__(self,ui): | |
62 self.ui = ui | |
63 def notifyChildAdded(self,node,child,prev): | |
64 pass | |
65 def notifyChildRemoved(self,node,child,prev): | |
66 pass | |
67 def notifyChildOrderChanged(self,node,child,prev): | |
68 pass | |
69 def notifyContentChanged(self,node,old_content,new_content): | |
70 pass | |
71 def notifyAttributeChanged(self,node, name, old_value, new_value): | |
72 self.ui.updateUI() | |
73 class LayerAddRemoveWatcher(pybInkscape.PYNodeObserver): | |
74 def __init__(self,ui): | |
75 self.ui = ui | |
76 def notifyChildAdded(self,node,child,prev): | |
77 self.ui.updateUI() | |
78 def notifyChildRemoved(self,node,child,prev): | |
79 self.ui.updateUI() | |
80 def notifyChildOrderChanged(self,node,child,prev): | |
81 self.ui.updateUI() | |
82 def notifyContentChanged(self,node,old_content,new_content): | |
83 self.ui.updateUI() | |
84 def notifyAttributeChanged(self,node, name, old_value, new_value): | |
85 self.ui.updateUI() | |
59 class MBScene(): | 86 class MBScene(): |
60 def __init__(self,desktop,win): | 87 def __init__(self,desktop,win): |
61 self.desktop = desktop | 88 self.desktop = desktop |
62 self.window = win | 89 self.window = win |
63 self.layers = [] | 90 self.layers = [] |
64 self.layers.append(Layer(None)) | 91 self.layers.append(Layer(None)) |
65 self.scenemap = None | 92 self.scenemap = None |
93 self.top = None | |
94 self.last_update = None | |
66 pass | 95 pass |
67 | 96 |
68 def confirm(self,msg): | 97 def confirm(self,msg): |
69 vbox = gtk.VBox() | 98 vbox = gtk.VBox() |
70 vbox.pack_start(gtk.Label(msg)) | 99 vbox.pack_start(gtk.Label(msg)) |
154 """ | 183 """ |
155 self.layers = [] | 184 self.layers = [] |
156 self.scenemap = None | 185 self.scenemap = None |
157 doc = self.desktop.doc().root() | 186 doc = self.desktop.doc().root() |
158 | 187 |
188 #obs = pybInkscape.PYNodeObserver() | |
189 obs = LayerAddRemoveWatcher(self) | |
190 doc.repr.addObserver(obs) | |
159 for node in doc.childList(): | 191 for node in doc.childList(): |
160 if node.repr.name() == 'svg:metadata': | 192 if node.repr.name() == 'svg:metadata': |
161 self.parseMetadata(node) | 193 self.parseMetadata(node) |
162 pass | 194 pass |
163 elif node.repr.name() == 'svg:g': | 195 elif node.repr.name() == 'svg:g': |
164 oldscene = None | 196 oldscene = None |
165 #print layer.attrib.get("id") | 197 obs = LayerAttributeWatcher(self) |
198 node.repr.addObserver(obs) | |
166 lyobj = Layer(node) | 199 lyobj = Layer(node) |
167 self.layers.append(lyobj) | 200 self.layers.append(lyobj) |
168 lyobj.current_scene = [] | 201 lyobj.current_scene = [] |
169 for scene in node.childList(): | 202 for scene in node.childList(): |
170 if scene.repr.name() == 'svg:g': | 203 if scene.repr.name() == 'svg:g': |
463 ## \brief Update conetent of frameliens according layers. | 496 ## \brief Update conetent of frameliens according layers. |
464 # | 497 # |
465 def _update_framelines(self): | 498 def _update_framelines(self): |
466 for frameline in self._framelines: | 499 for frameline in self._framelines: |
467 layer = frameline.layer | 500 layer = frameline.layer |
468 frameline.label.set_text(frameline.node.label()) | 501 if frameline.node.label()==None: |
502 frameline.label.set_text('???') | |
503 else: | |
504 frameline.label.set_text(frameline.node.label()) | |
469 for scene in layer.scenes: | 505 for scene in layer.scenes: |
470 frameline.add_keyframe(scene.start-1,scene.node.repr) | 506 frameline.add_keyframe(scene.start-1,scene.node.repr) |
471 if scene.start != scene.end: | 507 if scene.start != scene.end: |
472 frameline.add_keyframe(scene.end-1,scene.node.repr) | 508 frameline.add_keyframe(scene.end-1,scene.node.repr) |
473 frameline.tween(scene.start-1) | 509 frameline.tween(scene.start-1) |
528 def onOK(self,event): | 564 def onOK(self,event): |
529 self.OK = True | 565 self.OK = True |
530 gtk.main_quit() | 566 gtk.main_quit() |
531 pass | 567 pass |
532 | 568 |
533 | 569 def updateUI(self): |
570 if self.last_update!= None: | |
571 glib.source_remove(self.last_update) | |
572 self.last_update = glib.timeout_add(300,self.show) | |
534 def show(self): | 573 def show(self): |
535 self.OK = True | 574 self.OK = True |
536 self.parseScene() | 575 self.parseScene() |
537 self._create_framelines() | 576 self._create_framelines() |
538 self._update_framelines() | 577 self._update_framelines() |
578 if self.top == None: | |
579 self.top = gtk.VBox(False,0) | |
580 self.desktop.getToplevel().child.child.pack_end(self.top,expand=False) | |
581 else: | |
582 self.top.remove(self.startWindow) | |
539 vbox = gtk.VBox(False,0) | 583 vbox = gtk.VBox(False,0) |
540 self.desktop.getToplevel().child.child.pack_end(vbox,expand=False) | 584 self.startWindow = vbox |
541 self.window = vbox | 585 self.top.pack_start(vbox,expand=False) |
542 vbox = gtk.VBox(False,0) | |
543 self.window.pack_start(vbox,expand=False) | |
544 vbox.pack_start(self.scrollwin,expand=False) | 586 vbox.pack_start(self.scrollwin,expand=False) |
545 self.vbox = vbox | |
546 hbox=gtk.HBox(False,0) | 587 hbox=gtk.HBox(False,0) |
547 self.addButtons(hbox) | 588 self.addButtons(hbox) |
548 vbox.pack_start(hbox,expand=False) | 589 vbox.pack_start(hbox,expand=False) |
549 | 590 |
550 # self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) | 591 # self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) |
551 # self.window.connect("destroy", gtk.main_quit) | 592 # self.window.connect("destroy", gtk.main_quit) |
552 # self.window.set_position(gtk.WIN_POS_MOUSE) | 593 # self.window.set_position(gtk.WIN_POS_MOUSE) |
553 | 594 |
554 self.window.show_all() | 595 self.top.show_all() |
555 pass | 596 self.last_update = None |
597 return False | |
556 pass | 598 pass |