diff pyink/domview.py @ 1431:60f2c9a24cdb

Keep the same active layer and frame when switching back a timeline. - Add functions to remember frame and layer for timeline at domview. - Recall active frame and layer when calling switch_component() and switch_timeline().
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 11 Apr 2011 00:05:25 +0800
parents bf405cb2d7cb
children 8e8c9ab3818f
line wrap: on
line diff
--- a/pyink/domview.py	Sun Apr 10 20:30:06 2011 +0800
+++ b/pyink/domview.py	Mon Apr 11 00:05:25 2011 +0800
@@ -664,6 +664,40 @@
         parent_group.appendChild(use_node)
         
         return use_node
+
+    def remember_current_frame(self, layer_idx, frame_idx):
+        if not isinstance(layer_idx, int):
+            raise TypeError, 'layer index should be a integer'
+        if not isinstance(frame_idx, int):
+            raise TypeError, 'frame index should be a integer'
+        
+        timeline_name = self.get_current_timeline()
+        timeline = self._cur_comp.get_timeline(timeline_name)
+        timeline_scenes = timeline.scenes_node
+        timeline_scenes.setAttribute('cur_layer', str(layer_idx))
+        timeline_scenes.setAttribute('cur_frame', str(frame_idx))
+        pass
+
+    def get_current_frame(self):
+        timeline_name = self.get_current_timeline()
+        timeline = self._cur_comp.get_timeline(timeline_name)
+        timeline_scenes = timeline.scenes_node
+        try:
+            cur_layer = timeline_scenes.getAttribute('cur_layer')
+        except KeyError:
+            cur_layer_idx = 0
+        else:
+            cur_layer_idx = int(cur_layer)
+            pass
+        try:
+            cur_frame = timeline_scenes.getAttribute('cur_frame')
+        except KeyError:
+            cur_frame_idx = 0
+        else:
+            cur_frame_idx = int(cur_frame)
+            pass
+
+        return cur_layer_idx, cur_frame_idx
     pass