Mercurial > MadButterfly
comparison pyink/MBScene.py @ 1141:8f0ee167c5b2
Fix the issue of the new DOM implementation
author | wycc |
---|---|
date | Thu, 23 Dec 2010 00:00:46 +0800 |
parents | d4dbcb93aee0 a2b068594412 |
children | dd6c60c6f41e e14ec6d1a661 |
comparison
equal
deleted
inserted
replaced
1140:d4dbcb93aee0 | 1141:8f0ee167c5b2 |
---|---|
149 self.nameEditor.set_text('') | 149 self.nameEditor.set_text('') |
150 self.last_select = None | 150 self.last_select = None |
151 return | 151 return |
152 self.last_select = o | 152 self.last_select = o |
153 try: | 153 try: |
154 self.nameEditor.set_text(o.repr.attribute("inkscape:label")) | 154 self.nameEditor.set_text(o.getAttribute("inkscape:label")) |
155 except: | 155 except: |
156 self.nameEditor.set_text('') | 156 self.nameEditor.set_text('') |
157 pass | 157 pass |
158 | 158 |
159 def confirm(self,msg): | 159 def confirm(self,msg): |
184 self.current = 1 | 184 self.current = 1 |
185 for n in node.childList(): | 185 for n in node.childList(): |
186 if n.name() == 'ns0:scenes': | 186 if n.name() == 'ns0:scenes': |
187 self.scenemap={} | 187 self.scenemap={} |
188 try: | 188 try: |
189 cur = int(n.attribute("current")) | 189 cur = int(n.getAttribute("current")) |
190 except: | 190 except: |
191 cur = 1 | 191 cur = 1 |
192 self.current = cur | 192 self.current = cur |
193 | 193 |
194 for s in n.childList(): | 194 for s in n.childList(): |
195 if s.name() == 'ns0:scene': | 195 if s.name() == 'ns0:scene': |
196 try: | 196 try: |
197 start = int(s.attribute("start")) | 197 start = int(s.getAttribute("start")) |
198 except: | 198 except: |
199 traceback.print_exc() | 199 traceback.print_exc() |
200 continue | 200 continue |
201 try: | 201 try: |
202 end = s.attribute("end") | 202 end = s.getAttribute("end") |
203 if end == None: | 203 if end == None: |
204 end = start | 204 end = start |
205 pass | 205 pass |
206 except: | 206 except: |
207 end = start | 207 end = start |
208 pass | 208 pass |
209 try: | 209 try: |
210 typ = s.attribute('type') | 210 typ = s.getAttribute('type') |
211 if typ == None: | 211 if typ == None: |
212 typ = 'normal' | 212 typ = 'normal' |
213 except: | 213 except: |
214 traceback.print_exc() | 214 traceback.print_exc() |
215 typ = 'normal' | 215 typ = 'normal' |
216 link = s.attribute("ref") | 216 link = s.getAttribute("ref") |
217 self.scenemap[link] = [int(start),int(end),typ] | 217 self.scenemap[link] = [int(start),int(end),typ] |
218 if cur >= start and cur <= end: | 218 if cur >= start and cur <= end: |
219 self.currentscene = link | 219 self.currentscene = link |
220 pass | 220 pass |
221 pass | 221 pass |
258 #doc.addObserver(obs) | 258 #doc.addObserver(obs) |
259 addEventListener(doc,'DOMNodeInserted',self.updateUI,None) | 259 addEventListener(doc,'DOMNodeInserted',self.updateUI,None) |
260 addEventListener(doc,'DOMNodeRemoved',self.updateUI,None) | 260 addEventListener(doc,'DOMNodeRemoved',self.updateUI,None) |
261 doc.childList() | 261 doc.childList() |
262 try: | 262 try: |
263 self.width = float(doc.attribute("width")) | 263 self.width = float(doc.getAttribute("width")) |
264 self.height= float(doc.attribute("height")) | 264 self.height= float(doc.getAttribute("height")) |
265 except: | 265 except: |
266 self.width = 640 | 266 self.width = 640 |
267 self.height=480 | 267 self.height=480 |
268 | 268 |
269 for node in doc.childList(): | 269 for node in doc.childList(): |
281 lyobj.current_scene = [] | 281 lyobj.current_scene = [] |
282 for scene in node.childList(): | 282 for scene in node.childList(): |
283 print scene.getCenter() | 283 print scene.getCenter() |
284 if scene.name() == 'svg:g': | 284 if scene.name() == 'svg:g': |
285 try: | 285 try: |
286 label = scene.attribute('inkscape:label') | 286 label = scene.getAttribute('inkscape:label') |
287 if label == 'dup': | 287 if label == 'dup': |
288 node.removeChild(scene) | 288 node.removeChild(scene) |
289 except: | 289 except: |
290 pass | 290 pass |
291 | 291 |
292 try: | 292 try: |
293 scmap = self.scenemap[scene.getId()] | 293 scmap = self.scenemap[scene.getAttribute('id')] |
294 if scmap == None: | 294 if scmap == None: |
295 lyobj.current_scene.append(scene) | 295 lyobj.current_scene.append(scene) |
296 continue | 296 continue |
297 except: | 297 except: |
298 lyobj.current_scene.append(scene) | 298 lyobj.current_scene.append(scene) |
319 self.collectID_recursive(n) | 319 self.collectID_recursive(n) |
320 pass | 320 pass |
321 pass | 321 pass |
322 | 322 |
323 def collectID_recursive(self,node): | 323 def collectID_recursive(self,node): |
324 self.ID[node.getId()] = 1 | 324 try: |
325 self.ID[node.getAttribute('id')] = 1 | |
326 except: | |
327 pass | |
325 for n in node.childList(): | 328 for n in node.childList(): |
326 self.collectID_recursive(n) | 329 self.collectID_recursive(n) |
327 pass | 330 pass |
328 pass | 331 pass |
329 | 332 |
341 pass | 344 pass |
342 pass | 345 pass |
343 | 346 |
344 def getLayer(self, layer): | 347 def getLayer(self, layer): |
345 for l in self.layers: | 348 for l in self.layers: |
346 if l.node.getId() == layer: | 349 if l.node.getAttribute('id') == layer: |
347 return l | 350 return l |
348 pass | 351 pass |
349 return None | 352 return None |
350 | 353 |
351 | 354 |
518 layer.duplicateGroup = None | 521 layer.duplicateGroup = None |
519 | 522 |
520 | 523 |
521 while i < len(layer._keys): | 524 while i < len(layer._keys): |
522 s = layer._keys[i] | 525 s = layer._keys[i] |
523 print s.ref.attribute("id"),s.idx,s.left_tween,s.right_tween | 526 print s.ref.getAttribute("id"),s.idx,s.left_tween,s.right_tween |
524 if s.right_tween is False: | 527 if s.right_tween is False: |
525 if nth == s.idx+1: | 528 if nth == s.idx+1: |
526 s.ref.setAttribute("style","") | 529 s.ref.setAttribute("style","") |
527 else: | 530 else: |
528 s.ref.setAttribute("style","display:none") | 531 s.ref.setAttribute("style","display:none") |
551 i = i + 2 | 554 i = i + 2 |
552 pass | 555 pass |
553 pass | 556 pass |
554 pass | 557 pass |
555 | 558 |
559 def DOMtoItem(self,obj): | |
560 """ | |
561 Find the corresponding PYSPObject object for a DOM object. | |
562 """ | |
563 return self.DOMtoItem_recursive(self.desktop.doc().root(),obj) | |
564 | |
565 def DOMtoItem_recursive(self,tree,obj): | |
566 nodes = tree.childList() | |
567 for s in nodes: | |
568 if s.getId() == obj.getAttribute('id'): | |
569 return s | |
570 d = self.DOMtoItem_recursive(s,obj) | |
571 if d != None: return d | |
572 | |
573 | |
556 def enterGroup(self,obj): | 574 def enterGroup(self,obj): |
557 for l in self.layers: | 575 for l in self.layers: |
558 for s in l.node.childList(): | 576 for s in l.node.childList(): |
559 if s.getId() == obj.attribute("id"): | 577 if s.getAttribute('id') == obj.getAttribute("id"): |
560 self.desktop.setCurrentLayer(s) | 578 self.desktop.setCurrentLayer(self.DOMtoItem(s)) |
561 | 579 |
562 def selectSceneObject(self,frameline, nth): | 580 def selectSceneObject(self,frameline, nth): |
563 i = 0 | 581 i = 0 |
564 while i < len(frameline._keys): | 582 while i < len(frameline._keys): |
565 s = frameline._keys[i] | 583 s = frameline._keys[i] |
646 # | 664 # |
647 self._framelines = [] | 665 self._framelines = [] |
648 for i in range(len(self.layers)-1,-1,-1): | 666 for i in range(len(self.layers)-1,-1,-1): |
649 line = frameline.frameline(nframes) | 667 line = frameline.frameline(nframes) |
650 hbox = gtk.HBox() | 668 hbox = gtk.HBox() |
651 label = gtk.Label(self.layers[i].node.label()) | 669 label = gtk.Label(self.layers[i].node.getAttribute("inkscape:label")) |
652 label.set_size_request(100,0) | 670 label.set_size_request(100,0) |
653 hbox.pack_start(label,expand=False,fill=True) | 671 hbox.pack_start(label,expand=False,fill=True) |
654 hbox.pack_start(line) | 672 hbox.pack_start(line) |
655 line.set_size_request(nframes * 10, 20) | 673 line.set_size_request(nframes * 10, 20) |
656 vbox.pack_start(hbox, False) | 674 vbox.pack_start(hbox, False) |
667 ## \brief Update conetent of frameliens according layers. | 685 ## \brief Update conetent of frameliens according layers. |
668 # | 686 # |
669 def _update_framelines(self): | 687 def _update_framelines(self): |
670 for frameline in self._framelines: | 688 for frameline in self._framelines: |
671 layer = frameline.layer | 689 layer = frameline.layer |
672 if frameline.node.label()==None: | 690 if frameline.node.getAttribute("inkscape:label")==None: |
673 frameline.label.set_text('???') | 691 frameline.label.set_text('???') |
674 else: | 692 else: |
675 frameline.label.set_text(frameline.node.label()) | 693 frameline.label.set_text(frameline.node.getAttribute("inkscape:label")) |
676 for scene in layer.scenes: | 694 for scene in layer.scenes: |
677 frameline.add_keyframe(scene.start-1,scene.node) | 695 frameline.add_keyframe(scene.start-1,scene.node) |
678 if scene.start != scene.end: | 696 if scene.start != scene.end: |
679 frameline.add_keyframe(scene.end-1,scene.node) | 697 frameline.add_keyframe(scene.end-1,scene.node) |
680 frameline.tween(scene.start-1,scene.type) | 698 frameline.tween(scene.start-1,scene.type) |
701 if key.idx == self.last_frame: | 719 if key.idx == self.last_frame: |
702 if i == 0: | 720 if i == 0: |
703 # This is the first frame, we can not duplicate it | 721 # This is the first frame, we can not duplicate it |
704 self.last_line.rm_keyframe(self.last_frame) | 722 self.last_line.rm_keyframe(self.last_frame) |
705 return | 723 return |
706 node = self.duplicateSceneGroup(last_key.ref.attribute("id")) | 724 node = self.duplicateSceneGroup(last_key.ref.getAttribute("id")) |
707 key.ref = node | 725 key.ref = node |
708 self.update() | 726 self.update() |
709 self.show() | 727 self.show() |
710 self.doEditScene(None) | 728 self.doEditScene(None) |
711 return | 729 return |
718 orig = None | 736 orig = None |
719 for node in doc.childList(): | 737 for node in doc.childList(): |
720 if node.name() == 'svg:g': | 738 if node.name() == 'svg:g': |
721 for t in node.childList(): | 739 for t in node.childList(): |
722 if t.name() == "svg:g": | 740 if t.name() == "svg:g": |
723 if t.attribute("id") == gid: | 741 if t.getAttribute("id") == gid: |
724 orig = t | 742 orig = t |
725 break | 743 break |
726 if orig == None: | 744 if orig == None: |
727 return None | 745 return None |
728 ns = orig.duplicate(rdoc) | 746 ns = orig.duplicate(rdoc) |
855 if self.last_update!= None: | 873 if self.last_update!= None: |
856 glib.source_remove(self.last_update) | 874 glib.source_remove(self.last_update) |
857 self.last_update = glib.timeout_add(300,self.show) | 875 self.last_update = glib.timeout_add(300,self.show) |
858 def show(self): | 876 def show(self): |
859 self.OK = True | 877 self.OK = True |
860 self.dom = self.desktop.doc().root() | 878 self.dom = self.desktop.doc().root().repr |
861 self.document = self.desktop.doc().rdoc | 879 self.document = self.desktop.doc().rdoc |
862 self.tween = TweenObject(self.document,self.dom) | 880 self.tween = TweenObject(self.document,self.dom) |
863 self.parseScene() | 881 self.parseScene() |
864 self._create_framelines() | 882 self._create_framelines() |
865 self._update_framelines() | 883 self._update_framelines() |