Mercurial > MadButterfly
comparison pyink/MBScene.py @ 1139:a2b068594412
Use pybind with new DOM API (at PYNode).
- MBScene.document is a PYDocument instead of PYSPDocument.
- MBScene.root is a PYNode isntead of PYSPItem.
- getNext() was replaced by next().
- attribute() was replaced by getAttribute().
- getID() was removed, use setAttribute() instead.
- MBScene.dom was removed, use MBScene.document.root() instead.
- MBScene.nodeToItem was removed, use PYNode.spitem instead.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 22 Dec 2010 13:27:37 +0800 |
parents | 950076863b7e |
children | 8f0ee167c5b2 |
comparison
equal
deleted
inserted
replaced
1138:593a418ed8bf | 1139:a2b068594412 |
---|---|
148 if o == self.last_select: | 148 if o == self.last_select: |
149 glib.timeout_add(500,self.startPolling) | 149 glib.timeout_add(500,self.startPolling) |
150 return | 150 return |
151 self.last_select = o | 151 self.last_select = o |
152 try: | 152 try: |
153 self.nameEditor.set_text(o.repr.attribute("inkscape:label")) | 153 self.nameEditor.set_text(o.getAttribute("inkscape:label")) |
154 except: | 154 except: |
155 self.nameEditor.set_text('') | 155 self.nameEditor.set_text('') |
156 pass | 156 pass |
157 glib.timeout_add(500,self.startPolling) | 157 glib.timeout_add(500,self.startPolling) |
158 def show_selection(self,w,obj): | 158 def show_selection(self,w,obj): |
159 objs = self.desktop.selection.list() | 159 objs = self.desktop.selection.list() |
160 try: | 160 try: |
161 o = objs[0] | 161 o = objs[0].repr |
162 print o.getCenter() | 162 print o.getCenter() |
163 if o == self.last_select: | 163 if o == self.last_select: |
164 return | 164 return |
165 except: | 165 except: |
166 self.nameEditor.set_text('') | 166 self.nameEditor.set_text('') |
167 self.last_select = None | 167 self.last_select = None |
168 return | 168 return |
169 self.last_select = o | 169 self.last_select = o |
170 try: | 170 try: |
171 self.nameEditor.set_text(o.repr.attribute("inkscape:label")) | 171 self.nameEditor.set_text(o.getAttribute("inkscape:label")) |
172 except: | 172 except: |
173 self.nameEditor.set_text('') | 173 self.nameEditor.set_text('') |
174 pass | 174 pass |
175 | 175 |
176 def confirm(self,msg): | 176 def confirm(self,msg): |
201 self.current = 1 | 201 self.current = 1 |
202 for n in node.childList(): | 202 for n in node.childList(): |
203 if n.name() == 'ns0:scenes': | 203 if n.name() == 'ns0:scenes': |
204 self.scenemap={} | 204 self.scenemap={} |
205 try: | 205 try: |
206 cur = int(n.attribute("current")) | 206 cur = int(n.getAttribute("current")) |
207 except: | 207 except: |
208 cur = 1 | 208 cur = 1 |
209 self.current = cur | 209 self.current = cur |
210 | 210 |
211 for s in n.childList(): | 211 for s in n.childList(): |
212 if s.name() == 'ns0:scene': | 212 if s.name() == 'ns0:scene': |
213 try: | 213 try: |
214 start = int(s.attribute("start")) | 214 start = int(s.getAttribute("start")) |
215 except: | 215 except: |
216 traceback.print_exc() | 216 traceback.print_exc() |
217 continue | 217 continue |
218 try: | 218 try: |
219 end = s.attribute("end") | 219 end = s.getAttribute("end") |
220 if end == None: | 220 if end == None: |
221 end = start | 221 end = start |
222 pass | 222 pass |
223 except: | 223 except: |
224 end = start | 224 end = start |
225 pass | 225 pass |
226 try: | 226 try: |
227 typ = s.attribute('type') | 227 typ = s.getAttribute('type') |
228 if typ == None: | 228 if typ == None: |
229 typ = 'normal' | 229 typ = 'normal' |
230 except: | 230 except: |
231 traceback.print_exc() | 231 traceback.print_exc() |
232 typ = 'normal' | 232 typ = 'normal' |
233 link = s.attribute("ref") | 233 link = s.getAttribute("ref") |
234 self.scenemap[link] = [int(start),int(end),typ] | 234 self.scenemap[link] = [int(start),int(end),typ] |
235 if cur >= start and cur <= end: | 235 if cur >= start and cur <= end: |
236 self.currentscene = link | 236 self.currentscene = link |
237 pass | 237 pass |
238 pass | 238 pass |
239 pass | 239 pass |
240 pass | 240 pass |
241 pass | 241 pass |
242 pass | 242 pass |
243 if self.scenemap==None: | 243 if self.scenemap==None: |
244 #self.desktop.doc().root().repr.setAttribute("xmlns:ns0","http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd") | 244 self.document.root().setAttribute("xmlns:ns0","http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd") |
245 self.dom.setAttribute("xmlns:ns0","http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd") | |
246 scenes = self.document.createElement("ns0:scenes") | 245 scenes = self.document.createElement("ns0:scenes") |
247 node.appendChild(scenes) | 246 node.appendChild(scenes) |
248 def update(self): | 247 def update(self): |
249 doc = self.dom | 248 root = self.document.root() |
250 rdoc = self.document | 249 rdoc = self.document |
251 for node in doc.childList(): | 250 for node in root.childList(): |
252 if node.name() == 'svg:metadata': | 251 if node.name() == 'svg:metadata': |
253 for t in node.childList(): | 252 for t in node.childList(): |
254 if t.name() == "ns0:scenes": | 253 if t.name() == "ns0:scenes": |
255 node.removeChild(t) | 254 node.removeChild(t) |
256 ns = rdoc.createElement("ns0:scenes") | 255 ns = rdoc.createElement("ns0:scenes") |
266 scene and then relocate them back to the appropriate scene | 265 scene and then relocate them back to the appropriate scene |
267 object. | 266 object. |
268 """ | 267 """ |
269 self.layers = [] | 268 self.layers = [] |
270 self.scenemap = None | 269 self.scenemap = None |
271 doc = self.dom | 270 root = self.document.root() |
272 | 271 |
273 #obs = pybInkscape.PYNodeObserver() | 272 #obs = pybInkscape.PYNodeObserver() |
274 #obs = LayerAddRemoveWatcher(self) | 273 #obs = LayerAddRemoveWatcher(self) |
275 #doc.addObserver(obs) | 274 #root.addObserver(obs) |
276 addEventListener(doc,'DOMNodeInserted',self.updateUI,None) | 275 addEventListener(root,'DOMNodeInserted',self.updateUI,None) |
277 addEventListener(doc,'DOMNodeRemoved',self.updateUI,None) | 276 addEventListener(root,'DOMNodeRemoved',self.updateUI,None) |
278 doc.childList() | 277 root.childList() |
279 try: | 278 try: |
280 self.width = float(doc.attribute("width")) | 279 self.width = float(root.getAttribute("width")) |
281 self.height= float(doc.attribute("height")) | 280 self.height= float(root.getAttribute("height")) |
282 except: | 281 except: |
283 self.width = 640 | 282 self.width = 640 |
284 self.height=480 | 283 self.height=480 |
285 | 284 |
286 for node in doc.childList(): | 285 for node in root.childList(): |
287 print node.name() | 286 print node.name() |
288 if node.name() == 'svg:metadata': | 287 if node.name() == 'svg:metadata': |
289 self.parseMetadata(node) | 288 self.parseMetadata(node) |
290 pass | 289 pass |
291 elif node.name() == 'svg:g': | 290 elif node.name() == 'svg:g': |
298 lyobj.current_scene = [] | 297 lyobj.current_scene = [] |
299 for scene in node.childList(): | 298 for scene in node.childList(): |
300 print scene.getCenter() | 299 print scene.getCenter() |
301 if scene.name() == 'svg:g': | 300 if scene.name() == 'svg:g': |
302 try: | 301 try: |
303 label = scene.attribute('inkscape:label') | 302 label = scene.getAttribute('inkscape:label') |
304 if label == 'dup': | 303 if label == 'dup': |
305 node.removeChild(scene) | 304 node.removeChild(scene) |
306 except: | 305 except: |
307 pass | 306 pass |
308 | 307 |
309 try: | 308 try: |
310 scmap = self.scenemap[scene.getId()] | 309 scmap = self.scenemap[scene.getAttribute('id')] |
311 if scmap == None: | 310 if scmap == None: |
312 lyobj.current_scene.append(scene) | 311 lyobj.current_scene.append(scene) |
313 continue | 312 continue |
314 except: | 313 except: |
315 lyobj.current_scene.append(scene) | 314 lyobj.current_scene.append(scene) |
329 self.dumpID() | 328 self.dumpID() |
330 pass | 329 pass |
331 | 330 |
332 def collectID(self): | 331 def collectID(self): |
333 self.ID = {} | 332 self.ID = {} |
334 root = self.dom | 333 root = self.document.root() |
335 for n in root.childList(): | 334 for n in root.childList(): |
336 self.collectID_recursive(n) | 335 self.collectID_recursive(n) |
337 pass | 336 pass |
338 pass | 337 pass |
339 | 338 |
340 def collectID_recursive(self,node): | 339 def collectID_recursive(self,node): |
341 self.ID[node.getId()] = 1 | 340 try: |
341 self.ID[node.getAttribute('id')] = 1 | |
342 except KeyError: | |
343 pass | |
342 for n in node.childList(): | 344 for n in node.childList(): |
343 self.collectID_recursive(n) | 345 self.collectID_recursive(n) |
344 pass | 346 pass |
345 pass | 347 pass |
346 | 348 |
358 pass | 360 pass |
359 pass | 361 pass |
360 | 362 |
361 def getLayer(self, layer): | 363 def getLayer(self, layer): |
362 for l in self.layers: | 364 for l in self.layers: |
363 if l.node.getId() == layer: | 365 if l.node.getAttribute('id') == layer: |
364 return l | 366 return l |
365 pass | 367 pass |
366 return None | 368 return None |
367 | 369 |
368 | 370 |
384 txt.setAttribute("y","0") | 386 txt.setAttribute("y","0") |
385 txt.setAttribute("width","100") | 387 txt.setAttribute("width","100") |
386 txt.setAttribute("height","100") | 388 txt.setAttribute("height","100") |
387 txt.setAttribute("style","fill:#ff00") | 389 txt.setAttribute("style","fill:#ff00") |
388 ns.appendChild(txt) | 390 ns.appendChild(txt) |
389 gid = self.last_line.node.label()+self.newID() | 391 try: |
392 gid = self.last_line.node.getAttribute('inkscape:label') + \ | |
393 self.newID() | |
394 except KeyError: | |
395 gid = self.newID() | |
396 pass | |
390 self.ID[gid]=1 | 397 self.ID[gid]=1 |
391 ns.setAttribute("id",gid) | 398 ns.setAttribute("id",gid) |
392 ns.setAttribute("inkscape:groupmode","layer") | 399 ns.setAttribute("inkscape:groupmode","layer") |
393 self.last_line.node.appendChild(ns) | 400 self.last_line.node.appendChild(ns) |
394 print 'Add key ', x | 401 print 'Add key ', x |
500 return | 507 return |
501 pass | 508 pass |
502 pass | 509 pass |
503 pass | 510 pass |
504 | 511 |
505 def updateMapping(self): | |
506 self.nodeToItem={} | |
507 root = self.dom | |
508 self.updateMappingNode(root) | |
509 def updateMappingNode(self,node): | |
510 for c in node.childList(): | |
511 self.updateMappingNode(c) | |
512 self.nodeToItem[c.getId()] = c | |
513 print "Add",c.getId() | |
514 | |
515 | |
516 def setCurrentScene(self,nth): | 512 def setCurrentScene(self,nth): |
517 """ | 513 """ |
518 Update the scene group according to the curretn scene data. There are a couple of cases. | 514 Update the scene group according to the curretn scene data. There are a couple of cases. |
519 1. If the type of the scene is normal, we display it when it contains the current | 515 1. If the type of the scene is normal, we display it when it contains the current |
520 frame. Otherwise hide it. | 516 frame. Otherwise hide it. |
526 For each layer, we will always use the duplicated scene group whose name as dup. | 522 For each layer, we will always use the duplicated scene group whose name as dup. |
527 We will put the duplicated scene group inside it. We will create this group if it is not | 523 We will put the duplicated scene group inside it. We will create this group if it is not |
528 available. | 524 available. |
529 """ | 525 """ |
530 self.current = nth | 526 self.current = nth |
531 self.updateMapping() | |
532 for layer in self._framelines: | 527 for layer in self._framelines: |
533 i=0 | 528 i=0 |
534 | 529 |
535 # Check the duplicated scene group and create it if it is not available | 530 # Check the duplicated scene group and create it if it is not available |
536 try: | 531 try: |
544 layer.duplicateGroup = None | 539 layer.duplicateGroup = None |
545 | 540 |
546 | 541 |
547 while i < len(layer._keys): | 542 while i < len(layer._keys): |
548 s = layer._keys[i] | 543 s = layer._keys[i] |
549 print s.ref.attribute("id"),s.idx,s.left_tween,s.right_tween | 544 print s.ref.getAttribute("id"),s.idx,s.left_tween,s.right_tween |
550 if s.right_tween is False: | 545 if s.right_tween is False: |
551 if nth == s.idx+1: | 546 if nth == s.idx+1: |
552 s.ref.setAttribute("style","") | 547 s.ref.setAttribute("style","") |
553 else: | 548 else: |
554 s.ref.setAttribute("style","display:none") | 549 s.ref.setAttribute("style","display:none") |
587 dests={} | 582 dests={} |
588 | 583 |
589 # Collect all objects | 584 # Collect all objects |
590 while d: | 585 while d: |
591 try: | 586 try: |
592 label = d.attribute("inkscape:label") | 587 label = d.getAttribute("inkscape:label") |
593 except: | 588 except KeyError: |
594 d = d.getNext() | 589 d = d.next() |
595 continue | 590 continue |
596 dests[label] = d | 591 dests[label] = d |
597 d = d.getNext() | 592 d = d.next() |
598 # Check if the object in the source exists in the destination | 593 # Check if the object in the source exists in the destination |
599 s = source.ref.firstChild() | 594 s = source.ref.firstChild() |
600 d = dest.ref.firstChild() | 595 d = dest.ref.firstChild() |
601 while s: | 596 while s: |
602 print s,d | 597 print s,d |
603 try: | 598 try: |
604 label = s.attribute("inkscape:label") | 599 label = s.getAttribute("inkscape:label") |
605 # Use i8nkscape:label to identidy the equipvalent objects | 600 # Use i8nkscape:label to identidy the equipvalent objects |
606 if label: | 601 if label: |
607 if dests.hasattr(label.value()): | 602 if dests.hasattr(label.value()): |
608 self.updateTweenObject(obj,typ,s,dests[label.value()],percent) | 603 self.updateTweenObject(obj,typ,s,dests[label.value()],percent) |
609 s = s.getNext() | 604 s = s.next() |
610 continue | 605 continue |
611 except: | 606 except: |
612 pass | 607 pass |
613 # Search obejcts in the destination | 608 # Search obejcts in the destination |
614 while d: | 609 while d: |
615 try: | 610 try: |
616 d.attribute("inkscape:label") | 611 d.getAttribute("inkscape:label") |
617 d = d.getNext() | 612 d = d.next() |
618 continue | 613 continue |
619 except: | 614 except: |
620 pass | 615 pass |
621 if s.name() == d.name(): | 616 if s.name() == d.name(): |
622 self.updateTweenObject(obj,typ,s,d,percent) | 617 self.updateTweenObject(obj,typ,s,d,percent) |
623 d = d.getNext() | 618 d = d.next() |
624 break | 619 break |
625 d = d.getNext() | 620 d = d.next() |
626 s = s.getNext() | 621 s = s.next() |
627 def parseTransform(self,obj): | 622 def parseTransform(self,obj): |
628 """ | 623 """ |
629 Return the transform matrix of an object | 624 Return the transform matrix of an object |
630 """ | 625 """ |
631 try: | 626 try: |
632 t = obj.attribute("transform") | 627 t = obj.getAttribute("transform") |
633 print t | 628 print t |
634 if t[0:9] == 'translate': | 629 if t[0:9] == 'translate': |
635 print "translate" | 630 print "translate" |
636 fields = t[10:].split(',') | 631 fields = t[10:].split(',') |
637 x = float(fields[0]) | 632 x = float(fields[0]) |
702 """ | 697 """ |
703 print 'compare',s,d | 698 print 'compare',s,d |
704 if typ == 'relocate': | 699 if typ == 'relocate': |
705 print "percent",p | 700 print "percent",p |
706 newobj = s.duplicate(self.document) | 701 newobj = s.duplicate(self.document) |
707 newobj.setAttribute("ref", s.getId()) | 702 newobj.setAttribute("ref", s.getAttribute('id')) |
708 top = self.document.createElement("svg:g") | 703 top = self.document.createElement("svg:g") |
709 top.appendChild(newobj) | 704 top.appendChild(newobj) |
710 obj.appendChild(top) | 705 obj.appendChild(top) |
711 print s.name() | 706 print s.name() |
712 if s.name() == 'svg:g': | 707 if s.name() == 'svg:g': |
714 sm = self.parseTransform(s) | 709 sm = self.parseTransform(s) |
715 dm = self.parseTransform(d) | 710 dm = self.parseTransform(d) |
716 top.setAttribute("transform","translate(%g,%g)" % ((dm[2]-sm[2])*p,(dm[5]-sm[5])*p)) | 711 top.setAttribute("transform","translate(%g,%g)" % ((dm[2]-sm[2])*p,(dm[5]-sm[5])*p)) |
717 else: | 712 else: |
718 try: | 713 try: |
719 sx = float(s.attribute("x")) | 714 sx = float(s.getAttribute("x")) |
720 sy = float(s.attribute("y")) | 715 sy = float(s.getAttribute("y")) |
721 dx = float(d.attribute("x")) | 716 dx = float(d.getAttribute("x")) |
722 dy = float(d.attribute("y")) | 717 dy = float(d.getAttribute("y")) |
723 tx = (dx-sx)*p | 718 tx = (dx-sx)*p |
724 ty = (dy-sy)*p | 719 ty = (dy-sy)*p |
725 print tx,ty | 720 print tx,ty |
726 top.setAttribute("transform","translate(%g,%g)" % (tx,ty)) | 721 top.setAttribute("transform","translate(%g,%g)" % (tx,ty)) |
727 except: | 722 except: |
737 print s,d | 732 print s,d |
738 if s.name() == 'svg:g': | 733 if s.name() == 'svg:g': |
739 # Parse the translate or matrix | 734 # Parse the translate or matrix |
740 # | 735 # |
741 # D = B inv(A) | 736 # D = B inv(A) |
742 try: | 737 item = s.spitem |
743 item = self.nodeToItem[s.attribute("id")] | 738 (ox,oy) = item.getCenter() |
744 (ox,oy) = item.getCenter() | 739 item = d.spitem |
745 except: | 740 (dx,dy) = item.getCenter() |
746 ox = 0 | |
747 oy = 0 | |
748 try: | |
749 item = self.nodeToItem[d.attribute("id")] | |
750 (dx,dy) = item.getCenter() | |
751 except: | |
752 dx = 0 | |
753 dy = 0 | |
754 | 741 |
755 sm = self.parseTransform(s) | 742 sm = self.parseTransform(s) |
756 ss = self.decomposition(sm) | 743 ss = self.decomposition(sm) |
757 dm = self.parseTransform(d) | 744 dm = self.parseTransform(d) |
758 dd = self.decomposition(dm) | 745 dd = self.decomposition(dm) |
767 m = self.mulA([1,0,0,1,tx,self.height-ty],m) | 754 m = self.mulA([1,0,0,1,tx,self.height-ty],m) |
768 | 755 |
769 top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5])) | 756 top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5])) |
770 else: | 757 else: |
771 try: | 758 try: |
772 sw = float(s.attribute("width")) | 759 sw = float(s.getAttribute("width")) |
773 sh = float(s.attribute("height")) | 760 sh = float(s.getAttribute("height")) |
774 dw = float(d.attribute("width")) | 761 dw = float(d.getAttribute("width")) |
775 dh = float(d.attribute("height")) | 762 dh = float(d.getAttribute("height")) |
776 try: | 763 try: |
777 item = self.nodeToItem[s.attribute("id")] | 764 item = self.nodeToItem[s.attribute("id")] |
778 (ox,oy) = item.getCenter() | 765 (ox,oy) = item.getCenter() |
779 except: | 766 except: |
780 ox = 0 | 767 ox = 0 |
817 | 804 |
818 pass | 805 pass |
819 def enterGroup(self,obj): | 806 def enterGroup(self,obj): |
820 for l in self.layers: | 807 for l in self.layers: |
821 for s in l.node.childList(): | 808 for s in l.node.childList(): |
822 if s.getId() == obj.attribute("id"): | 809 if s.getAttribute('id') == obj.getAttribute("id"): |
823 self.desktop.setCurrentLayer(s) | 810 self.desktop.setCurrentLayer(s.spitem) |
824 | 811 |
825 def selectSceneObject(self,frameline, nth): | 812 def selectSceneObject(self,frameline, nth): |
826 i = 0 | 813 i = 0 |
827 while i < len(frameline._keys): | 814 while i < len(frameline._keys): |
828 s = frameline._keys[i] | 815 s = frameline._keys[i] |
909 # | 896 # |
910 self._framelines = [] | 897 self._framelines = [] |
911 for i in range(len(self.layers)-1,-1,-1): | 898 for i in range(len(self.layers)-1,-1,-1): |
912 line = frameline.frameline(nframes) | 899 line = frameline.frameline(nframes) |
913 hbox = gtk.HBox() | 900 hbox = gtk.HBox() |
914 label = gtk.Label(self.layers[i].node.label()) | 901 label = gtk.Label(self.layers[i].node.getAttribute('inkscape:label')) |
915 label.set_size_request(100,0) | 902 label.set_size_request(100,0) |
916 hbox.pack_start(label,expand=False,fill=True) | 903 hbox.pack_start(label,expand=False,fill=True) |
917 hbox.pack_start(line) | 904 hbox.pack_start(line) |
918 line.set_size_request(nframes * 10, 20) | 905 line.set_size_request(nframes * 10, 20) |
919 vbox.pack_start(hbox, False) | 906 vbox.pack_start(hbox, False) |
930 ## \brief Update conetent of frameliens according layers. | 917 ## \brief Update conetent of frameliens according layers. |
931 # | 918 # |
932 def _update_framelines(self): | 919 def _update_framelines(self): |
933 for frameline in self._framelines: | 920 for frameline in self._framelines: |
934 layer = frameline.layer | 921 layer = frameline.layer |
935 if frameline.node.label()==None: | 922 try: |
936 frameline.label.set_text('???') | 923 frameline.label.set_text(frameline.node.getAttribute('inkscape:label')) |
937 else: | 924 except KeyError: |
938 frameline.label.set_text(frameline.node.label()) | 925 frameline.label.set_text('???') |
926 pass | |
939 for scene in layer.scenes: | 927 for scene in layer.scenes: |
940 frameline.add_keyframe(scene.start-1,scene.node) | 928 frameline.add_keyframe(scene.start-1,scene.node) |
941 if scene.start != scene.end: | 929 if scene.start != scene.end: |
942 frameline.add_keyframe(scene.end-1,scene.node) | 930 frameline.add_keyframe(scene.end-1,scene.node) |
943 frameline.tween(scene.start-1,scene.type) | 931 frameline.tween(scene.start-1,scene.type) |
964 if key.idx == self.last_frame: | 952 if key.idx == self.last_frame: |
965 if i == 0: | 953 if i == 0: |
966 # This is the first frame, we can not duplicate it | 954 # This is the first frame, we can not duplicate it |
967 self.last_line.rm_keyframe(self.last_frame) | 955 self.last_line.rm_keyframe(self.last_frame) |
968 return | 956 return |
969 node = self.duplicateSceneGroup(last_key.ref.attribute("id")) | 957 node = self.duplicateSceneGroup(last_key.ref.getAttribute("id")) |
970 key.ref = node | 958 key.ref = node |
971 self.update() | 959 self.update() |
972 self.show() | 960 self.show() |
973 self.doEditScene(None) | 961 self.doEditScene(None) |
974 return | 962 return |
975 last_key = key | 963 last_key = key |
976 i = i + 1 | 964 i = i + 1 |
977 def duplicateSceneGroup(self,gid): | 965 def duplicateSceneGroup(self,gid): |
978 # Search for the duplicated group | 966 # Search for the duplicated group |
979 doc = self.dom | 967 root = self.document.root() |
980 rdoc = self.document | 968 rdoc = self.document |
981 orig = None | 969 orig = None |
982 for node in doc.childList(): | 970 for node in root.childList(): |
983 if node.name() == 'svg:g': | 971 if node.name() == 'svg:g': |
984 for t in node.childList(): | 972 for t in node.childList(): |
985 if t.name() == "svg:g": | 973 if t.name() == "svg:g": |
986 if t.attribute("id") == gid: | 974 if t.getAttribute("id") == gid: |
987 orig = t | 975 orig = t |
988 break | 976 break |
989 if orig == None: | 977 if orig == None: |
990 return None | 978 return None |
991 ns = orig.duplicate(rdoc) | 979 ns = orig.duplicate(rdoc) |
992 gid = self.last_line.node.label()+self.newID() | 980 try: |
981 gid = self.last_line.node.getAttribute('inkscape:label') + \ | |
982 self.newID() | |
983 except KeyError: | |
984 gid = self.newID() | |
985 pass | |
993 self.ID[gid]=1 | 986 self.ID[gid]=1 |
994 ns.setAttribute("id",gid) | 987 ns.setAttribute("id",gid) |
995 ns.setAttribute("inkscape:groupmode","layer") | 988 ns.setAttribute("inkscape:groupmode","layer") |
996 self.last_line.node.appendChild(ns) | 989 self.last_line.node.appendChild(ns) |
997 return ns | 990 return ns |
1118 if self.last_update!= None: | 1111 if self.last_update!= None: |
1119 glib.source_remove(self.last_update) | 1112 glib.source_remove(self.last_update) |
1120 self.last_update = glib.timeout_add(300,self.show) | 1113 self.last_update = glib.timeout_add(300,self.show) |
1121 def show(self): | 1114 def show(self): |
1122 self.OK = True | 1115 self.OK = True |
1123 self.dom = self.desktop.doc().root() | |
1124 self.document = self.desktop.doc().rdoc | 1116 self.document = self.desktop.doc().rdoc |
1125 self.parseScene() | 1117 self.parseScene() |
1126 self._create_framelines() | 1118 self._create_framelines() |
1127 self._update_framelines() | 1119 self._update_framelines() |
1128 if self.top == None: | 1120 if self.top == None: |