# HG changeset patch # User wycc # Date 1291419831 -28800 # Node ID 52d8bf5d12b4c049752efaaaa98af0a267a74fe7 # Parent afa42d5836ccb6499e2c92735261d0282d2310f9 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node diff -r afa42d5836cc -r 52d8bf5d12b4 pyink/MBScene.py --- a/pyink/MBScene.py Thu Dec 02 08:23:08 2010 +0800 +++ b/pyink/MBScene.py Sat Dec 04 07:43:51 2010 +0800 @@ -549,7 +549,46 @@ color = cell.get_colormap().alloc_color("green") cell.modify_bg(gtk.STATE_NORMAL, color) pass - + def duplicateKeyScene(self): + self.last_line.add_keyframe(self.last_frame) + # Search for the current scene + i = 0 + while i < len(self.last_line._keys): + key = self.last_line._keys[i] + if key.idx == self.last_frame: + if i == 0: + # This is the first frame, we can not duplicate it + self.last_line.rm_keyframe(self.last_frame) + return + node = self.duplicateSceneGroup(last_key.ref.attribute("id")) + key.ref = node + self.update() + self.show() + self.doEditScene(None) + return + last_key = key + i = i + 1 + def duplicateSceneGroup(self,gid): + # Search for the duplicated group + doc = self.desktop.doc().root() + rdoc = self.desktop.doc().rdoc + orig = None + for node in doc.childList(): + if node.repr.name() == 'svg:g': + for t in node.childList(): + if t.repr.name() == "svg:g": + if t.repr.attribute("id") == gid: + orig = t.repr + break + if orig == None: + return None + ns = orig.duplicate(rdoc) + gid = self.last_line.node.label()+self.newID() + self.ID[gid]=1 + ns.setAttribute("id",gid,True) + ns.setAttribute("inkscape:groupmode","layer",True) + self.last_line.node.repr.appendChild(ns) + return ns def doEditScene(self,w): self.setCurrentScene(self.last_frame+1) @@ -560,6 +599,8 @@ self.insertKeyScene() # self.grid.show_all() return + def doDuplicateKeyScene(self,w): + self.duplicateKeyScene() def doRemoveScene(self,w): self.removeKeyScene() @@ -584,6 +625,9 @@ btn=gtk.Button('Extend scene') btn.connect('clicked', self.doExtendScene) hbox.pack_start(btn,expand=False,fill=False) + btn=gtk.Button('Duplicate Key') + btn.connect('clicked', self.doDuplicateKeyScene) + hbox.pack_start(btn,expand=False,fill=False) pass def onQuit(self, event):