changeset 1195:cb2c611d1656

Fix bug of duplicating a keyframe
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 02 Jan 2011 20:05:05 +0800
parents 319414e4d87a
children 42f8cee2118b
files pyink/MBScene.py
diffstat 1 files changed, 23 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/pyink/MBScene.py	Sun Jan 02 18:50:55 2011 +0800
+++ b/pyink/MBScene.py	Sun Jan 02 20:05:05 2011 +0800
@@ -222,11 +222,11 @@
 	if name == 'id' and old_value != new_value:
 	    if old_value and (old_value not in self._id2node):
 		raise ValueError, \
-		    'old ID value of passed node is valid one (%s)' % \
+		    'old ID value of passed node is invalid one (%s)' % \
 		    (old_value)
 	    if (new_value in self._id2node):
 		raise ValueError, \
-		    'new ID value of passed node is valid one (%s)' % \
+		    'new ID value of passed node is invalid one (%s)' % \
 		    (new_value)
 	    
 	    if old_value:
@@ -914,26 +914,27 @@
 
     def duplicateKeyScene(self):
         # 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
-		    return
-		self.last_line.add_keyframe(self.last_frame)
-		last_scene_node = last_key.ref
-		last_scene_group_id = last_scene_node.getAttribute('ref')
-		scene_group = self.duplicateSceneGroup(last_scene_group_id)
-		scene_node = self._add_scene_node(self.last_frame,
-						  self.last_frame,
-						  ref=last_scene_group_id)
-	        key.ref = scene_node
-	        self.doEditScene(None)
-		return
-	    last_key = key
-	    i = i + 1
-	    pass
+	frameline = self.last_line
+	frame_idx = self.last_frame
+	
+	try:
+	    start, end, scene_type = frameline.get_frame_block_floor(frame_idx)
+	except:
+	    return
+	if end >= frame_idx:
+	    return
+
+	prev_scene_node = frameline.get_frame_data(start)
+	prev_scene_group_id = prev_scene_node.getAttribute('ref')
+	
+	scene_group = self.duplicateSceneGroup(prev_scene_group_id)
+	scene_group_id = scene_group.getAttribute('id')
+	scene_node = self._add_scene_node(frame_idx, frame_idx,
+					  ref=scene_group_id)
+
+	frameline.add_keyframe(frame_idx, scene_node)
+
+	self.setCurrentScene(frame_idx)
 	pass
 
     def duplicateSceneGroup(self,gid):
@@ -1068,10 +1069,6 @@
 	btn.connect('clicked', self.doDuplicateKeyScene)
 	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)
-
 	btn=gtk.Button('Insert')
 	btn.connect('clicked', self.doInsertScene)
 	hbox.pack_start(btn,expand=False,fill=False)