changeset 1104:9d52dda8d49f

merge from head
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 05 Dec 2010 14:27:17 +0800
parents 2b8b6deb35c8 (current diff) 5ba2cab1d505 (diff)
children 1b3e295f3acb 214e1f628d63
files
diffstat 1 files changed, 79 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/pyink/MBScene.py	Sun Dec 05 14:26:19 2010 +0800
+++ b/pyink/MBScene.py	Sun Dec 05 14:27:17 2010 +0800
@@ -92,8 +92,32 @@
 	self.scenemap = None
 	self.top = None
 	self.last_update = None
+	self.startPolling()
+	self.last_select = None
 	pass
 
+    def startPolling(self):
+	objs =  self.desktop.selection.list()
+	if len(objs) != 1: 
+	    glib.timeout_add(500,self.startPolling)
+	    try:
+		self.nameEditor.set_text('')
+	    except:
+		traceback.print_exc()
+		pass
+	    return
+	o = objs[0]
+	if o == self.last_select: 
+            glib.timeout_add(500,self.startPolling)
+	    return
+	self.last_select = o
+	try:
+	    self.nameEditor.set_text(o.repr.attribute("inkscape:label"))
+	except:
+	    self.nameEditor.set_text('')
+	    pass
+        glib.timeout_add(500,self.startPolling)
+
     def confirm(self,msg):
 	vbox = gtk.VBox()
 	vbox.pack_start(gtk.Label(msg))
@@ -549,7 +573,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 +623,8 @@
 	self.insertKeyScene()
 	# self.grid.show_all()
 	return
+    def doDuplicateKeyScene(self,w):
+        self.duplicateKeyScene()
 
     def doRemoveScene(self,w):
 	self.removeKeyScene()
@@ -570,6 +635,15 @@
 	self.extendScene()
 	#self.grid.show_all()
 	pass
+    def changeObjectLabel(self,w):
+	o = self.desktop.selection.list()[0]
+	o.repr.setAttribute("inkscape:label", self.nameEditor.get_text(), True)
+    def addNameEditor(self,hbox):
+	self.nameEditor = gtk.Entry(max=40)
+	hbox.pack_start(self.nameEditor,expand=False,fill=False)
+	self.editDone = gtk.Button('Set')
+	hbox.pack_start(self.editDone,expand=False,fill=False)
+	self.editDone.connect('clicked', self.changeObjectLabel)
     
     def addButtons(self,hbox):
 	#btn = gtk.Button('Edit')
@@ -584,6 +658,10 @@
 	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)
+	self.addNameEditor(hbox)
 	pass
     
     def onQuit(self, event):