# HG changeset patch # User Thinker K.F. Li # Date 1293963990 -28800 # Node ID 0e3a65b7b00cbe9631da3e49e2851ea2365c5573 # Parent 79a3f82edaac4b8bf1693a2de9e92efb5d352a25 Simplify extendScened() diff -r 79a3f82edaac -r 0e3a65b7b00c pyink/MBScene.py --- a/pyink/MBScene.py Sun Jan 02 14:18:48 2011 +0800 +++ b/pyink/MBScene.py Sun Jan 02 18:26:30 2011 +0800 @@ -474,7 +474,7 @@ if start_idx != stop_idx: scene_node.setAttribute("end", str(stop_idx + 1)) pass - scene_node.setAttribute("ref", scene_node.getAttribute("id")) + scene_node.setAttribute("ref", scene_node.getAttribute("ref")) scene_node.setAttribute("type", tween_type_name) pass pass @@ -659,74 +659,19 @@ def extendScene(self): frame_idx = self.last_frame frameline = self.last_line - i = 0 - while i < len(frameline._keys): - s = frameline._keys[i] - if s.right_tween: - if frame_idx > s.idx: - if frame_idx <= frameline._keys[i+1].idx: - return - try: - if frame_idx <= frameline._keys[i+2].idx: - frameline._keys[i+1].idx = frame_idx - frameline.draw_all_frames() - self.update_scenes_of_dom() - self.setCurrentScene(frame_idx) - self.last_line.update() - return - else: - # We may in the next scene - i = i + 2 - pass - except: - # This is the last keyframe, extend the keyframe by - # relocate the location of the keyframe - frameline._keys[i+1].idx = frame_idx - frameline._draw_all_frames() - self.update_scenes_of_dom() - self.last_line.update() - self.setCurrentScene(frame_idx) - return - else: - # We are in the front of all keyframes - return - else: - # This is a single keyframe - if frame_idx < s.idx: - return - if frame_idx == s.idx: - return - try: - if frame_idx < frameline._keys[i+1].idx: - # We are after a single keyframe and no scene is - # available here. Create a new tween here - idx = frameline._keys[i].idx - scene_node = frameline._keys[i].ref - frameline.add_keyframe(frame_idx, scene_node) - frameline.tween(idx) - frameline._draw_all_frames() - self.update_scenes_of_dom() - self.setCurrentScene(frame_idx) - self.last_line.update() - return - else: - # We may in the next scene - i = i + 1 - pass - pass - except: - # This is the last scene, create a new one - idx = frameline._keys[i].idx - scene_node = frameline._keys[i].ref - frameline.add_keyframe(frame_idx, scene_node) - frameline.tween(idx) - frameline._draw_all_frames() - self.update_scenes_of_dom() - self.setCurrentScene(frame_idx) - self.last_line.update() - return - pass + + start, end, scene_type = frameline.get_frame_block_floor(frame_idx) + if frame_idx <= end: + return + + if start < end: + frameline.rm_keyframe(end) pass + + scene_node = frameline.get_frame_data(start) + scene_node.setAttribute('end', str(frame_idx)) + frameline.add_keyframe(frame_idx) + frameline.tween(start, scene_type) pass def setCurrentScene(self,nth): @@ -937,10 +882,10 @@ if last_scene and last_scene.end == scene.start: frameline.setRightTween(last_scene.end) else: - frameline.add_keyframe(scene.start-1, scene.node) + frameline.add_keyframe(scene.start, scene.node) last_scene = scene if scene.start != scene.end: - frameline.add_keyframe(scene.end-1, scene.node) + frameline.add_keyframe(scene.end, scene.node) tween_type_idx = self._tween_type_names.index(scene.type) tween_type = self._frameline_tween_types[tween_type_idx] frameline.tween(scene.start-1, tween_type) @@ -960,7 +905,6 @@ 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): @@ -968,12 +912,15 @@ 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.getAttribute("id")) - key.ref = node - self.update_scenes_of_dom() - self.updateUI() + 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 @@ -1014,7 +961,7 @@ scene_group.setAttribute("id",gid) scene_group.setAttribute("inkscape:groupmode","layer") self.last_line.layer_group.appendChild(scene_group) - return ns + return scene_group def doEditScene(self, w): self.setCurrentScene(self.last_frame+1) @@ -1045,7 +992,6 @@ self._lockui = True self.extendScene() self._lockui = False - #self.grid.show_all() pass def changeObjectLabel(self,w): diff -r 79a3f82edaac -r 0e3a65b7b00c pyink/frameline.py --- a/pyink/frameline.py Sun Jan 02 14:18:48 2011 +0800 +++ b/pyink/frameline.py Sun Jan 02 18:26:30 2011 +0800 @@ -790,23 +790,46 @@ # - If the indexed frame is a key frame with no right_tween, returns the # range that start and stop are both equivalent to idx. # + # - If both earlier two are not meat, the previesou keyframe or tween is + # returned. + # + # - Otherwise, raise an exception. + # + # \param idx is the index number of a frame. + # \return A tuple of (start, stop, tween_type) + # + def get_frame_block_floor(self, idx): + pos = self._find_keyframe_floor(idx) + if pos != -1: + key = self._keys[pos] + if key.right_tween: + next_key = self._keys[pos + 1] + return key.idx, next_key.idx, key.right_tween_type + if key.left_tween: + prev_key = self._keys[pos - 1] + return prev_key.idx, key.idx, prev_key.right_tween_type + return key.idx, key.idx, 0 + raise ValueError, \ + 'the frame specified by idx is not in any tween or a key frame' + + ## \brief Return the range of a block of consequence frames (tween). + # + # - If the index frame is in a tween, it returns the range of the tween. + # + # - If the indexed frame is a key frame with no right_tween, returns the + # range that start and stop are both equivalent to idx. + # # - Otherwise, raise an exception. # # \param idx is the index number of a frame. # \return A tuple of (start, stop, tween_type) # def get_frame_block(self, idx): - pos = self._find_keyframe_floor(idx) - if pos != -1: - key = self._keys[pos] - if key.right_tween: - next_key = self._keys[pos + 1] - return key.idx, next_key.idx, key.right_tween_type - elif key.idx == idx: - return key.idx, key.idx, 0 - pass - raise ValueError, \ - 'the frame specified by idx is not in any tween or a key frame' + start, stop, tween_type = self.get_frame_block_floor(idx) + if stop < idx: + raise ValueError, \ + 'the frame specified by idx is not in any tween or a key frame' + return start, stop, tween_type def get_frame_data(self, idx): pos = self._find_keyframe(idx)