Mercurial > MadButterfly
comparison pyink/MBScene.py @ 1242:1b1eb8f9a866
Rename *_dom to *_domview and *_framelines to *_frameline_stack
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 10 Jan 2011 16:09:18 +0800 |
parents | e64f5bd2270c |
children | d5f70928e9f1 |
comparison
equal
deleted
inserted
replaced
1241:e64f5bd2270c | 1242:1b1eb8f9a866 |
---|---|
94 | 94 |
95 ## \brief Monitor changes of DOM-tree. | 95 ## \brief Monitor changes of DOM-tree. |
96 # | 96 # |
97 # This class monitors DOM-tree to maintain _maxframe and maps for node ID to | 97 # This class monitors DOM-tree to maintain _maxframe and maps for node ID to |
98 # node and scene group ID to scene node. | 98 # node and scene group ID to scene node. |
99 class MBScene_dom_monitor(object): | 99 class MBScene_domview_monitor(object): |
100 def __init__(self, *args, **kws): | 100 def __init__(self, *args, **kws): |
101 super(MBScene_dom_monitor, self).__init__() | 101 super(MBScene_domview_monitor, self).__init__() |
102 | 102 |
103 self._maxframe = 0 | 103 self._maxframe = 0 |
104 self._id2node = {} # map ID to the node in the DOM tree. | 104 self._id2node = {} # map ID to the node in the DOM tree. |
105 self._group2scene = {} # map ID of a group to associated scene node. | 105 self._group2scene = {} # map ID of a group to associated scene node. |
106 pass | 106 pass |
346 pass | 346 pass |
347 pass | 347 pass |
348 pass | 348 pass |
349 | 349 |
350 | 350 |
351 ## \brief Layer of MBScene to manipulate DOM tree. | 351 ## \brief This layer provide a data view to the DOM-tree. |
352 # | 352 # |
353 # This class maintains layers information, and provides functions to create, | 353 # This class maintains layers information, and provides functions to create, |
354 # change and destroy scene node and scene group. A scene node is a 'ns0:scene' | 354 # change and destroy scene node and scene group. A scene node is a 'ns0:scene' |
355 # in 'ns0:scenes' tag. A scene group is respective 'svg:g' for a scene. | 355 # in 'ns0:scenes' tag. A scene group is respective 'svg:g' for a scene. |
356 # | 356 # |
357 class MBScene_dom(MBScene_dom_monitor): | 357 class MBScene_domview(MBScene_domview_monitor): |
358 # Declare variables, here, for keeping tracking | 358 # Declare variables, here, for keeping tracking |
359 _doc = None | 359 _doc = None |
360 _root = None | 360 _root = None |
361 | 361 |
362 def __init__(self, *args, **kws): | 362 def __init__(self, *args, **kws): |
363 super(MBScene_dom, self).__init__() | 363 super(MBScene_domview, self).__init__() |
364 pass | 364 pass |
365 | 365 |
366 ## \brief Create a scenes node if not existed. | 366 ## \brief Create a scenes node if not existed. |
367 # | 367 # |
368 def _init_metadata(self): | 368 def _init_metadata(self): |
407 def handle_doc_root(self, doc, root): | 407 def handle_doc_root(self, doc, root): |
408 self._doc = doc | 408 self._doc = doc |
409 self._root = root | 409 self._root = root |
410 self._layers = [] | 410 self._layers = [] |
411 | 411 |
412 self._start_monitor() # start MBScene_dom_monitor | 412 self._start_monitor() # start MBScene_domview_monitor |
413 self._init_metadata() | 413 self._init_metadata() |
414 self._parse_all_layers() | 414 self._parse_all_layers() |
415 pass | 415 pass |
416 | 416 |
417 def dumpattr(self, n): | 417 def dumpattr(self, n): |
645 | 645 |
646 def get_max_frame(self): | 646 def get_max_frame(self): |
647 return self._maxframe | 647 return self._maxframe |
648 pass | 648 pass |
649 | 649 |
650 ## \brief Maintain frameline list for MBScene. | 650 ## \brief Maintain a stack of frameline UI component. |
651 # | 651 # |
652 class MBScene_framelines(object): | 652 # Every layer is assocated with a frameline. Framelines are showed/stacked in |
653 # virtical. Framelines of lower layers are placed at lower position on the | |
654 # screen. This class provide a set of API to access framelines with layer and | |
655 # frame index number. You access/set content of frameline by specifing layer | |
656 # index and frame index. | |
657 # | |
658 class MBScene_frameline_stack(object): | |
653 _frameline_tween_types = (frameline.TWEEN_TYPE_NONE, | 659 _frameline_tween_types = (frameline.TWEEN_TYPE_NONE, |
654 frameline.TWEEN_TYPE_SHAPE) | 660 frameline.TWEEN_TYPE_SHAPE) |
655 _num_frames_of_line = 100 | 661 _num_frames_of_line = 100 |
656 | 662 |
657 _framelines = None | 663 _framelines = None |
658 | 664 |
659 def __init__(self, *args, **kws): | 665 def __init__(self, *args, **kws): |
660 super(MBScene_framelines, self).__init__(*args, **kws) | 666 super(MBScene_frameline_stack, self).__init__(*args, **kws) |
661 | 667 |
662 self._last_mouse_over_frameline = None | 668 self._last_mouse_over_frameline = None |
663 self._last_active_frameline = None | 669 self._last_active_frameline = None |
664 self._active_frame_callback = None | 670 self._active_frame_callback = None |
665 pass | 671 pass |
986 pass | 992 pass |
987 | 993 |
988 ## \brief Bridge of DOM-tree to syncrhonize data-model and UI. | 994 ## \brief Bridge of DOM-tree to syncrhonize data-model and UI. |
989 # | 995 # |
990 # This class is a wrapper | 996 # This class is a wrapper |
991 class MBDOM_UI(object): | 997 class MBScene_domview_ui(object): |
992 _tween_type_names = ('normal', 'scale') | 998 _tween_type_names = ('normal', 'scale') |
993 | 999 |
994 def __init__(self): | 1000 def __init__(self): |
995 super(MBDOM_UI, self).__init__() | 1001 super(MBScene_domview_ui, self).__init__() |
996 self._fl_mgr = MBScene_framelines() | 1002 self._fl_stack = MBScene_frameline_stack() |
997 self._dom = MBScene_dom() | 1003 self._dom = MBScene_domview() |
998 pass | 1004 pass |
999 | 1005 |
1000 ## \brief Update content of a frameline from scenes of respective layer. | 1006 ## \brief Update content of a frameline from scenes of respective layer. |
1001 # | 1007 # |
1002 def _update_frameline_content(self, layer_idx): | 1008 def _update_frameline_content(self, layer_idx): |
1003 fl_mgr = self._fl_mgr | 1009 fl_stack = self._fl_stack |
1004 scene_nodes = self._dom.get_all_scene_node_of_layer(layer_idx) | 1010 scene_nodes = self._dom.get_all_scene_node_of_layer(layer_idx) |
1005 for scene_node in scene_nodes: | 1011 for scene_node in scene_nodes: |
1006 start, end, tween_name = self._dom._parse_one_scene(scene_node) | 1012 start, end, tween_name = self._dom._parse_one_scene(scene_node) |
1007 | 1013 |
1008 fl_mgr.mark_keyframe(layer_idx, start) | 1014 fl_stack.mark_keyframe(layer_idx, start) |
1009 fl_mgr.set_keyframe_data(layer_idx, start, scene_node) | 1015 fl_stack.set_keyframe_data(layer_idx, start, scene_node) |
1010 if start != end: | 1016 if start != end: |
1011 tween_type = self._tween_type_names.index(tween_name) | 1017 tween_type = self._tween_type_names.index(tween_name) |
1012 tween_len = end - start + 1 | 1018 tween_len = end - start + 1 |
1013 fl_mgr.tween(layer_idx, start, tween_len, tween_type) | 1019 fl_stack.tween(layer_idx, start, tween_len, tween_type) |
1014 pass | 1020 pass |
1015 pass | 1021 pass |
1016 pass | 1022 pass |
1017 | 1023 |
1018 ## \brief Add a frameline for every found layer. | 1024 ## \brief Add a frameline for every found layer. |
1023 def _add_frameline_for_every_layer(self): | 1029 def _add_frameline_for_every_layer(self): |
1024 for layer_idx in range(self._dom.get_layer_num()): | 1030 for layer_idx in range(self._dom.get_layer_num()): |
1025 layer_group_node = self._dom.get_layer_group(layer_idx) | 1031 layer_group_node = self._dom.get_layer_group(layer_idx) |
1026 label = layer_group_node.getAttribute('inkscape:label') | 1032 label = layer_group_node.getAttribute('inkscape:label') |
1027 | 1033 |
1028 self._fl_mgr._add_frameline(layer_idx) | 1034 self._fl_stack._add_frameline(layer_idx) |
1029 self._fl_mgr.set_layer_label(layer_idx, label) | 1035 self._fl_stack.set_layer_label(layer_idx, label) |
1030 | 1036 |
1031 self._update_frameline_content(layer_idx) | 1037 self._update_frameline_content(layer_idx) |
1032 pass | 1038 pass |
1033 pass | 1039 pass |
1034 | 1040 |
1035 ## \brief This method is called to handle a new document. | 1041 ## \brief This method is called to handle a new document. |
1036 # | 1042 # |
1037 def handle_doc_root(self, doc, root): | 1043 def handle_doc_root(self, doc, root): |
1038 self._dom.handle_doc_root(doc, root) | 1044 self._dom.handle_doc_root(doc, root) |
1039 self._fl_mgr._init_framelines() | 1045 self._fl_stack._init_framelines() |
1040 self._add_frameline_for_every_layer() | 1046 self._add_frameline_for_every_layer() |
1041 self._fl_mgr._show_framelines() | 1047 self._fl_stack._show_framelines() |
1042 pass | 1048 pass |
1043 | 1049 |
1044 ## \brief Mark given frame as a key frame. | 1050 ## \brief Mark given frame as a key frame. |
1045 # | 1051 # |
1046 def mark_key(self, layer_idx, key_idx): | 1052 def mark_key(self, layer_idx, key_idx): |
1048 scene_group_id = scene_group.getAttribute('id') | 1054 scene_group_id = scene_group.getAttribute('id') |
1049 | 1055 |
1050 scene_node = self._dom.add_scene_node(key_idx, key_idx) | 1056 scene_node = self._dom.add_scene_node(key_idx, key_idx) |
1051 self._dom.chg_scene_node(scene_node, ref=scene_group_id) | 1057 self._dom.chg_scene_node(scene_node, ref=scene_group_id) |
1052 | 1058 |
1053 self._fl_mgr.mark_keyframe(layer_idx, key_idx) | 1059 self._fl_stack.mark_keyframe(layer_idx, key_idx) |
1054 self._fl_mgr.set_keyframe_data(layer_idx, key_idx, scene_node) | 1060 self._fl_stack.set_keyframe_data(layer_idx, key_idx, scene_node) |
1055 pass | 1061 pass |
1056 | 1062 |
1057 ## \brief Tweening a key frame. | 1063 ## \brief Tweening a key frame. |
1058 # | 1064 # |
1059 # To tween a key spanning several frames at right-side. | 1065 # To tween a key spanning several frames at right-side. |
1060 # The tween of a key frame can be changed by tweening it again. | 1066 # The tween of a key frame can be changed by tweening it again. |
1061 # | 1067 # |
1062 def tween(self, layer_idx, key_frame_idx, tween_len, | 1068 def tween(self, layer_idx, key_frame_idx, tween_len, |
1063 tween_type=TweenObject.TWEEN_TYPE_NORMAL): | 1069 tween_type=TweenObject.TWEEN_TYPE_NORMAL): |
1064 self._fl_mgr.tween(layer_idx, key_frame_idx, tween_len, tween_type) | 1070 self._fl_stack.tween(layer_idx, key_frame_idx, tween_len, tween_type) |
1065 | 1071 |
1066 end_frame_idx = key_frame_idx + tween_len - 1 | 1072 end_frame_idx = key_frame_idx + tween_len - 1 |
1067 scene_node = self._fl_mgr.get_keyframe_data(layer_idx, key_frame_idx) | 1073 scene_node = self._fl_stack.get_keyframe_data(layer_idx, key_frame_idx) |
1068 tween_name = self._tween_type_names[tween_type] | 1074 tween_name = self._tween_type_names[tween_type] |
1069 self._dom.chg_scene_node(scene_node, end=end_frame_idx, | 1075 self._dom.chg_scene_node(scene_node, end=end_frame_idx, |
1070 tween_type=tween_name) | 1076 tween_type=tween_name) |
1071 pass | 1077 pass |
1072 | 1078 |
1073 ## \brief Change tween info of a key frame | 1079 ## \brief Change tween info of a key frame |
1074 # | 1080 # |
1075 def chg_tween(self, layer_idx, key_frame_idx, | 1081 def chg_tween(self, layer_idx, key_frame_idx, |
1076 tween_len=None, tween_type=None): | 1082 tween_len=None, tween_type=None): |
1077 scene_node = self._fl_mgr.get_keyframe_data(layer_idx, key_frame_idx) | 1083 scene_node = self._fl_stack.get_keyframe_data(layer_idx, key_frame_idx) |
1078 start, end, old_tween_type = \ | 1084 start, end, old_tween_type = \ |
1079 self._fl_mgr.get_key_tween(layer_idx, key_frame_idx) | 1085 self._fl_stack.get_key_tween(layer_idx, key_frame_idx) |
1080 | 1086 |
1081 if tween_len is not None: | 1087 if tween_len is not None: |
1082 end = start + tween_len - 1 | 1088 end = start + tween_len - 1 |
1083 self._dom.chg_scene_node(scene_node, end=end) | 1089 self._dom.chg_scene_node(scene_node, end=end) |
1084 pass | 1090 pass |
1090 if tween_type is None: | 1096 if tween_type is None: |
1091 tween_type = old_tween_type | 1097 tween_type = old_tween_type |
1092 pass | 1098 pass |
1093 | 1099 |
1094 tween_len = end - start + 1 | 1100 tween_len = end - start + 1 |
1095 self._fl_mgr.tween(layer_idx, start, tween_len, tween_type) | 1101 self._fl_stack.tween(layer_idx, start, tween_len, tween_type) |
1096 pass | 1102 pass |
1097 | 1103 |
1098 ## \brief Unmark a frame from a key frame. | 1104 ## \brief Unmark a frame from a key frame. |
1099 # | 1105 # |
1100 def unmark_key(self, layer_idx, key_frame_idx): | 1106 def unmark_key(self, layer_idx, key_frame_idx): |
1101 scene_node = self._fl_mgr.get_keyframe_data(layer_idx, key_frame_idx) | 1107 scene_node = self._fl_stack.get_keyframe_data(layer_idx, key_frame_idx) |
1102 self._dom.rm_scene_node_n_group(scene_node) | 1108 self._dom.rm_scene_node_n_group(scene_node) |
1103 | 1109 |
1104 self._fl_mgr.unmark_keyframe(layer_idx, key_frame_idx) | 1110 self._fl_stack.unmark_keyframe(layer_idx, key_frame_idx) |
1105 pass | 1111 pass |
1106 | 1112 |
1107 ## \brief Insert frames at specified position. | 1113 ## \brief Insert frames at specified position. |
1108 # | 1114 # |
1109 # All frame at and after given position will shift right. | 1115 # All frame at and after given position will shift right. |
1110 # | 1116 # |
1111 def insert_frames(self, layer_idx, frame_idx, num): | 1117 def insert_frames(self, layer_idx, frame_idx, num): |
1112 self._fl_mgr.insert_frames(layer_idx, frame_idx, num) | 1118 self._fl_stack.insert_frames(layer_idx, frame_idx, num) |
1113 self._dom.insert_frames(layer_idx, frame_idx, num) | 1119 self._dom.insert_frames(layer_idx, frame_idx, num) |
1114 pass | 1120 pass |
1115 | 1121 |
1116 ## \brief Insert frames at specified position. | 1122 ## \brief Insert frames at specified position. |
1117 # | 1123 # |
1118 # All frame at and after given position will shift left, except nearest | 1124 # All frame at and after given position will shift left, except nearest |
1119 # \ref num frames are removed. | 1125 # \ref num frames are removed. |
1120 # | 1126 # |
1121 def rm_frames(self, layer_idx, frame_idx, num): | 1127 def rm_frames(self, layer_idx, frame_idx, num): |
1122 self._fl_mgr.insert_frames(layer_idx, frame_idx, num) | 1128 self._fl_stack.insert_frames(layer_idx, frame_idx, num) |
1123 self._dom.rm_frames(layer_idx, frame_idx, num) | 1129 self._dom.rm_frames(layer_idx, frame_idx, num) |
1124 pass | 1130 pass |
1125 | 1131 |
1126 ## \brief Insert a layer at given position. | 1132 ## \brief Insert a layer at given position. |
1127 # | 1133 # |
1128 # Original layer \ref layer_idx and later ones would be shifted to make a | 1134 # Original layer \ref layer_idx and later ones would be shifted to make a |
1129 # space for the new layer. | 1135 # space for the new layer. |
1130 # | 1136 # |
1131 def insert_layer(self, layer_idx): | 1137 def insert_layer(self, layer_idx): |
1132 self._dom.insert_layer(layer_idx) | 1138 self._dom.insert_layer(layer_idx) |
1133 self._fl_mgr._add_frameline(layer_idx) | 1139 self._fl_stack._add_frameline(layer_idx) |
1134 self._fl_mgr._show_framelines() | 1140 self._fl_stack._show_framelines() |
1135 pass | 1141 pass |
1136 | 1142 |
1137 ## \brief Remove given layer. | 1143 ## \brief Remove given layer. |
1138 # | 1144 # |
1139 def rm_layer(self, layer_idx): | 1145 def rm_layer(self, layer_idx): |
1140 self._dom.rm_layer(layer_idx) | 1146 self._dom.rm_layer(layer_idx) |
1141 self._fl_mgr._remove_frameline(layer_idx) | 1147 self._fl_stack._remove_frameline(layer_idx) |
1142 self._fl_mgr._show_framelines() | 1148 self._fl_stack._show_framelines() |
1143 pass | 1149 pass |
1144 | 1150 |
1145 def set_active_layer_frame(self, layer_idx, frame_idx): | 1151 def set_active_layer_frame(self, layer_idx, frame_idx): |
1146 self._fl_mgr.active_frame(layer_idx, frame_idx) | 1152 self._fl_stack.active_frame(layer_idx, frame_idx) |
1147 pass | 1153 pass |
1148 | 1154 |
1149 ## \bref Return current active frame and its layer. | 1155 ## \bref Return current active frame and its layer. |
1150 # | 1156 # |
1151 # \return (layer_idx, frame_idx) of active frame, or (-1, -1) when no | 1157 # \return (layer_idx, frame_idx) of active frame, or (-1, -1) when no |
1152 # active one. | 1158 # active one. |
1153 def get_active_layer_frame(self): | 1159 def get_active_layer_frame(self): |
1154 layer_idx, frame_idx = self._fl_mgr.get_active_layer_frame() | 1160 layer_idx, frame_idx = self._fl_stack.get_active_layer_frame() |
1155 return layer_idx, frame_idx | 1161 return layer_idx, frame_idx |
1156 | 1162 |
1157 def get_layer_num(self): | 1163 def get_layer_num(self): |
1158 return self._dom.get_layer_num() | 1164 return self._dom.get_layer_num() |
1159 | 1165 |
1160 ## \brief Return associated group node for a key frame. | 1166 ## \brief Return associated group node for a key frame. |
1161 # | 1167 # |
1162 # The given frame index must be exactly a key frame. | 1168 # The given frame index must be exactly a key frame. |
1163 # | 1169 # |
1164 def get_key_group(self, layer_idx, frame_idx): | 1170 def get_key_group(self, layer_idx, frame_idx): |
1165 scene_node = self._fl_mgr.get_keyframe_data(layer_idx, frame_idx) | 1171 scene_node = self._fl_stack.get_keyframe_data(layer_idx, frame_idx) |
1166 scene_group_id = scene_node.getAttribute('ref') | 1172 scene_group_id = scene_node.getAttribute('ref') |
1167 scene_group_node = self._dom.get_node(scene_group_id) | 1173 scene_group_node = self._dom.get_node(scene_group_id) |
1168 return scene_group_node | 1174 return scene_group_node |
1169 | 1175 |
1170 ## \brief Find an associated key frame and tween info for a group ID. | 1176 ## \brief Find an associated key frame and tween info for a group ID. |
1180 # | 1186 # |
1181 # The return key is at given frame, or its tween covers given frame. | 1187 # The return key is at given frame, or its tween covers given frame. |
1182 # | 1188 # |
1183 def get_key(self, layer_idx, frame_idx): | 1189 def get_key(self, layer_idx, frame_idx): |
1184 start, end, tween_type = \ | 1190 start, end, tween_type = \ |
1185 self._fl_mgr.get_key_tween(layer_idx, frame_idx) | 1191 self._fl_stack.get_key_tween(layer_idx, frame_idx) |
1186 return start, end, tween_type | 1192 return start, end, tween_type |
1187 | 1193 |
1188 def get_left_key(self, layer_idx, frame_idx): | 1194 def get_left_key(self, layer_idx, frame_idx): |
1189 start, end, tween_type = \ | 1195 start, end, tween_type = \ |
1190 self._fl_mgr.get_left_key_tween(layer_idx, frame_idx) | 1196 self._fl_stack.get_left_key_tween(layer_idx, frame_idx) |
1191 return start, end, tween_type | 1197 return start, end, tween_type |
1192 | 1198 |
1193 ## \brief Return information of key frames in the given layer. | 1199 ## \brief Return information of key frames in the given layer. |
1194 # | 1200 # |
1195 def get_layer_keys(self, layer_idx): | 1201 def get_layer_keys(self, layer_idx): |
1196 key_tweens = self._fl_mgr.get_all_key_tween_of_layer(layer_idx) | 1202 key_tweens = self._fl_stack.get_all_key_tween_of_layer(layer_idx) |
1197 return key_tweens | 1203 return key_tweens |
1198 | 1204 |
1199 ## \brief Return widget showing frames and layers. | 1205 ## \brief Return widget showing frames and layers. |
1200 # | 1206 # |
1201 def get_frame_ui_widget(self): | 1207 def get_frame_ui_widget(self): |
1202 return self._fl_mgr._frameline_box | 1208 return self._fl_stack._frameline_box |
1203 | 1209 |
1204 ## \brief Register a callback for activating a frame event. | 1210 ## \brief Register a callback for activating a frame event. |
1205 # | 1211 # |
1206 # The callback function is called when a frame is activated. | 1212 # The callback function is called when a frame is activated. |
1207 # | 1213 # |
1208 def register_active_frame_callback(self, cb): | 1214 def register_active_frame_callback(self, cb): |
1209 self._fl_mgr.register_active_frame_callback(cb) | 1215 self._fl_stack.register_active_frame_callback(cb) |
1210 pass | 1216 pass |
1211 | 1217 |
1212 ## \brief Get duplicate group of a layer. | 1218 ## \brief Get duplicate group of a layer. |
1213 # | 1219 # |
1214 def get_layer_dup_group(self, layer_idx): | 1220 def get_layer_dup_group(self, layer_idx): |
1253 return max_frame | 1259 return max_frame |
1254 pass | 1260 pass |
1255 | 1261 |
1256 ## \brief MBScene connect GUI and DOM-tree | 1262 ## \brief MBScene connect GUI and DOM-tree |
1257 # | 1263 # |
1258 # This class connect behavior of GUI to the DOM-tree. All about GUI is | 1264 # This method accepts user actions and involves MBScene_domview_ui to update |
1259 # implemented by this class. It use API provided by MBScene_dom to reflect | 1265 # data on the document. |
1260 # actions to the DOM-tree. | |
1261 # | 1266 # |
1262 class MBScene(object): | 1267 class MBScene(object): |
1263 _tween_obj_tween_types = (TweenObject.TWEEN_TYPE_NORMAL, | 1268 _tween_obj_tween_types = (TweenObject.TWEEN_TYPE_NORMAL, |
1264 TweenObject.TWEEN_TYPE_SCALE) | 1269 TweenObject.TWEEN_TYPE_SCALE) |
1265 _tween_type_names = ('normal', 'scale') | 1270 _tween_type_names = ('normal', 'scale') |
1281 self._root = root | 1286 self._root = root |
1282 self.framerate = 12 | 1287 self.framerate = 12 |
1283 self._disable_tween_type_selector = False | 1288 self._disable_tween_type_selector = False |
1284 self.current = 0 | 1289 self.current = 0 |
1285 | 1290 |
1286 self._dom = MBDOM_UI() | 1291 self._domview = MBScene_domview_ui() |
1287 pass | 1292 pass |
1288 | 1293 |
1289 def change_active_frame(self, node): | 1294 def change_active_frame(self, node): |
1290 """ | 1295 """ |
1291 Change the active frame to the current selected node. This will | 1296 Change the active frame to the current selected node. This will |
1298 node = node.parent() | 1303 node = node.parent() |
1299 continue | 1304 continue |
1300 | 1305 |
1301 try: | 1306 try: |
1302 layer_idx, (start, end, tween_type) = \ | 1307 layer_idx, (start, end, tween_type) = \ |
1303 self._dom.find_key_from_group(node_id) | 1308 self._domview.find_key_from_group(node_id) |
1304 except: | 1309 except: |
1305 pass | 1310 pass |
1306 else: | 1311 else: |
1307 self._dom.set_active_layer_frame(layer_idx, start) | 1312 self._domview.set_active_layer_frame(layer_idx, start) |
1308 break | 1313 break |
1309 | 1314 |
1310 node = node.parent() | 1315 node = node.parent() |
1311 pass | 1316 pass |
1312 pass | 1317 pass |
1319 two parts. If the nth is out of any scene, we will append a | 1324 two parts. If the nth is out of any scene, we will append a |
1320 new scene. | 1325 new scene. |
1321 | 1326 |
1322 """ | 1327 """ |
1323 try: | 1328 try: |
1324 self._dom.mark_key(layer_idx, frame_idx) | 1329 self._domview.mark_key(layer_idx, frame_idx) |
1325 except ValueError: # existed key frame | 1330 except ValueError: # existed key frame |
1326 pass | 1331 pass |
1327 pass | 1332 pass |
1328 | 1333 |
1329 def removeKeyScene(self, layer_idx, frame_idx): | 1334 def removeKeyScene(self, layer_idx, frame_idx): |
1330 self._dom.unmark_key(layer_idx, frame_idx) | 1335 self._domview.unmark_key(layer_idx, frame_idx) |
1331 self.setCurrentScene(frame_idx) | 1336 self.setCurrentScene(frame_idx) |
1332 pass | 1337 pass |
1333 | 1338 |
1334 def extendScene(self): | 1339 def extendScene(self): |
1335 layer_idx, frame_idx = self._dom.get_active_layer_frame() | 1340 layer_idx, frame_idx = self._domview.get_active_layer_frame() |
1336 start, end, tween_type = \ | 1341 start, end, tween_type = \ |
1337 self._dom.get_left_key(layer_idx, frame_idx) | 1342 self._domview.get_left_key(layer_idx, frame_idx) |
1338 tween_len = frame_idx - start + 1 | 1343 tween_len = frame_idx - start + 1 |
1339 self._dom.tween(layer_idx, start, tween_len, tween_type) | 1344 self._domview.tween(layer_idx, start, tween_len, tween_type) |
1340 | 1345 |
1341 scene_group = self._dom.get_key_group(layer_idx, start) | 1346 scene_group = self._domview.get_key_group(layer_idx, start) |
1342 self._enterGroup(scene_group) | 1347 self._enterGroup(scene_group) |
1343 pass | 1348 pass |
1344 | 1349 |
1345 def setCurrentScene(self, idx): | 1350 def setCurrentScene(self, idx): |
1346 """ | 1351 """ |
1361 create this group if it is not | 1366 create this group if it is not |
1362 available. | 1367 available. |
1363 """ | 1368 """ |
1364 self.current = idx | 1369 self.current = idx |
1365 self.tween.updateMapping() | 1370 self.tween.updateMapping() |
1366 for layer_idx in range(self._dom.get_layer_num()): | 1371 for layer_idx in range(self._domview.get_layer_num()): |
1367 dup_group = self._dom.get_layer_dup_group(layer_idx) | 1372 dup_group = self._domview.get_layer_dup_group(layer_idx) |
1368 dup_group.setAttribute('style', 'display: none') | 1373 dup_group.setAttribute('style', 'display: none') |
1369 | 1374 |
1370 all_key_tweens = self._dom.get_layer_keys(layer_idx) | 1375 all_key_tweens = self._domview.get_layer_keys(layer_idx) |
1371 for start, end, tween_type in all_key_tweens: | 1376 for start, end, tween_type in all_key_tweens: |
1372 if start == idx: # at key frame | 1377 if start == idx: # at key frame |
1373 scene_group = \ | 1378 scene_group = \ |
1374 self._dom.get_key_group(layer_idx, start) | 1379 self._domview.get_key_group(layer_idx, start) |
1375 scene_group.setAttribute('style', '') | 1380 scene_group.setAttribute('style', '') |
1376 elif start < idx and end >= idx: # in Tween | 1381 elif start < idx and end >= idx: # in Tween |
1377 dup_group.setAttribute('style', '') | 1382 dup_group.setAttribute('style', '') |
1378 scene_group = \ | 1383 scene_group = \ |
1379 self._dom.get_key_group(layer_idx, start) | 1384 self._domview.get_key_group(layer_idx, start) |
1380 scene_group.setAttribute('style', 'display: none') | 1385 scene_group.setAttribute('style', 'display: none') |
1381 | 1386 |
1382 try: | 1387 try: |
1383 next_scene_group = \ | 1388 next_scene_group = \ |
1384 self._dom.get_key_group(layer_idx, end + 1) | 1389 self._domview.get_key_group(layer_idx, end + 1) |
1385 except: # no next key frame | 1390 except: # no next key frame |
1386 next_scene_group = scene_group | 1391 next_scene_group = scene_group |
1387 pass | 1392 pass |
1388 | 1393 |
1389 tween_obj_type = self._tween_obj_tween_types[tween_type] | 1394 tween_obj_type = self._tween_obj_tween_types[tween_type] |
1395 next_scene_group, | 1400 next_scene_group, |
1396 percent) | 1401 percent) |
1397 pass | 1402 pass |
1398 else: # this scene should not be showed. | 1403 else: # this scene should not be showed. |
1399 scene_group = \ | 1404 scene_group = \ |
1400 self._dom.get_key_group(layer_idx, start) | 1405 self._domview.get_key_group(layer_idx, start) |
1401 scene_group.setAttribute('style', 'display: none') | 1406 scene_group.setAttribute('style', 'display: none') |
1402 pass | 1407 pass |
1403 pass | 1408 pass |
1404 pass | 1409 pass |
1405 pass | 1410 pass |
1414 self._disable_tween_type_selector = False | 1419 self._disable_tween_type_selector = False |
1415 pass | 1420 pass |
1416 | 1421 |
1417 def selectSceneObject(self, layer_idx, frame_idx): | 1422 def selectSceneObject(self, layer_idx, frame_idx): |
1418 try: | 1423 try: |
1419 start, stop, tween_type = self._dom.get_key(layer_idx, frame_idx) | 1424 start, stop, tween_type = \ |
1425 self._domview.get_key(layer_idx, frame_idx) | |
1420 except: | 1426 except: |
1421 return | 1427 return |
1422 | 1428 |
1423 scene_group = self._dom.get_key_group(layer_idx, start) | 1429 scene_group = self._domview.get_key_group(layer_idx, start) |
1424 self._enterGroup(scene_group) | 1430 self._enterGroup(scene_group) |
1425 self.setTweenType(tween_type) | 1431 self.setTweenType(tween_type) |
1426 pass | 1432 pass |
1427 | 1433 |
1428 def duplicateKeyScene(self): | 1434 def duplicateKeyScene(self): |
1429 # Search for the current scene | 1435 # Search for the current scene |
1430 layer_idx, frame_idx = self._dom.get_active_layer_frame() | 1436 layer_idx, frame_idx = self._domview.get_active_layer_frame() |
1431 | 1437 |
1432 try: | 1438 try: |
1433 left_start, left_end, left_tween_type = \ | 1439 left_start, left_end, left_tween_type = \ |
1434 self._dom.get_left_key(layer_idx, frame_idx) | 1440 self._domview.get_left_key(layer_idx, frame_idx) |
1435 except: | 1441 except: |
1436 return | 1442 return |
1437 if left_end >= frame_idx: | 1443 if left_end >= frame_idx: |
1438 return | 1444 return |
1439 | 1445 |
1440 self._dom.mark_key(layer_idx, frame_idx) | 1446 self._domview.mark_key(layer_idx, frame_idx) |
1441 | 1447 |
1442 scene_group = self._dom.get_key_group(layer_idx, frame_idx) | 1448 scene_group = self._domview.get_key_group(layer_idx, frame_idx) |
1443 left_scene_group = \ | 1449 left_scene_group = \ |
1444 self._dom.get_key_group(layer_idx, left_start) | 1450 self._domview.get_key_group(layer_idx, left_start) |
1445 | 1451 |
1446 dup_group = self._duplicate_group(left_scene_group, scene_group) | 1452 dup_group = self._duplicate_group(left_scene_group, scene_group) |
1447 | 1453 |
1448 self.setCurrentScene(frame_idx) | 1454 self.setCurrentScene(frame_idx) |
1449 pass | 1455 pass |
1530 self._lockui = False | 1536 self._lockui = False |
1531 pass | 1537 pass |
1532 | 1538 |
1533 def doInsertKeyScene(self,w): | 1539 def doInsertKeyScene(self,w): |
1534 self._lockui=True | 1540 self._lockui=True |
1535 layer_idx, frame_idx = self._dom.get_active_layer_frame() | 1541 layer_idx, frame_idx = self._domview.get_active_layer_frame() |
1536 self.insertKeyScene(layer_idx, frame_idx) | 1542 self.insertKeyScene(layer_idx, frame_idx) |
1537 self.selectSceneObject(layer_idx, frame_idx) | 1543 self.selectSceneObject(layer_idx, frame_idx) |
1538 self._lockui=False | 1544 self._lockui=False |
1539 return | 1545 return |
1540 | 1546 |
1543 self.duplicateKeyScene() | 1549 self.duplicateKeyScene() |
1544 self._lockui = False | 1550 self._lockui = False |
1545 | 1551 |
1546 def doRemoveScene(self,w): | 1552 def doRemoveScene(self,w): |
1547 self._lockui = True | 1553 self._lockui = True |
1548 layer_idx, frame_idx = self._dom.get_active_layer_frame() | 1554 layer_idx, frame_idx = self._domview.get_active_layer_frame() |
1549 self.removeKeyScene(layer_idx, frame_idx) | 1555 self.removeKeyScene(layer_idx, frame_idx) |
1550 self._lockui = False | 1556 self._lockui = False |
1551 return | 1557 return |
1552 | 1558 |
1553 | 1559 |
1572 self._lockui = False | 1578 self._lockui = False |
1573 pass | 1579 pass |
1574 pass | 1580 pass |
1575 | 1581 |
1576 def doRunNext(self): | 1582 def doRunNext(self): |
1577 if self.current > self._dom.get_max_frame(): | 1583 if self.current > self._domview.get_max_frame(): |
1578 self.current = 0 | 1584 self.current = 0 |
1579 pass | 1585 pass |
1580 try: | 1586 try: |
1581 self.setCurrentScene(self.current) | 1587 self.setCurrentScene(self.current) |
1582 except: | 1588 except: |
1587 self.last_update = glib.timeout_add(tmout, self.doRunNext) | 1593 self.last_update = glib.timeout_add(tmout, self.doRunNext) |
1588 pass | 1594 pass |
1589 | 1595 |
1590 def doInsertFrame(self, w): | 1596 def doInsertFrame(self, w): |
1591 self.lockui=True | 1597 self.lockui=True |
1592 layer_idx, frame_idx = self._dom.get_active_layer_frame() | 1598 layer_idx, frame_idx = self._domview.get_active_layer_frame() |
1593 self._dom.insert_frames(layer_idx, frame_idx, 1) | 1599 self._domview.insert_frames(layer_idx, frame_idx, 1) |
1594 self.lockui=False | 1600 self.lockui=False |
1595 | 1601 |
1596 def doRemoveFrame(self, w): | 1602 def doRemoveFrame(self, w): |
1597 self.lockui=True | 1603 self.lockui=True |
1598 layer_idx, frame_idx = self._dom.get_active_layer_frame() | 1604 layer_idx, frame_idx = self._domview.get_active_layer_frame() |
1599 self._dom.rm_frames(layer_idx, frame_idx, 1) | 1605 self._domview.rm_frames(layer_idx, frame_idx, 1) |
1600 self.lockui=False | 1606 self.lockui=False |
1601 | 1607 |
1602 def onTweenTypeChange(self, w): | 1608 def onTweenTypeChange(self, w): |
1603 if self._disable_tween_type_selector: | 1609 if self._disable_tween_type_selector: |
1604 return | 1610 return |
1605 | 1611 |
1606 layer_idx, frame_idx = self._dom.get_active_layer_frame() | 1612 layer_idx, frame_idx = self._domview.get_active_layer_frame() |
1607 tween_type = self.tweenTypeSelector.get_active() | 1613 tween_type = self.tweenTypeSelector.get_active() |
1608 | 1614 |
1609 start, end, old_tween_type = \ | 1615 start, end, old_tween_type = \ |
1610 self._dom.get_left_key(layer_idx, frame_idx) | 1616 self._domview.get_left_key(layer_idx, frame_idx) |
1611 if end >= frame_idx and start != end: | 1617 if end >= frame_idx and start != end: |
1612 # Length of tween > 1 and cover this frame | 1618 # Length of tween > 1 and cover this frame |
1613 self._dom.chg_tween(layer_idx, start, tween_type=tween_type) | 1619 self._domview.chg_tween(layer_idx, start, tween_type=tween_type) |
1614 pass | 1620 pass |
1615 pass | 1621 pass |
1616 | 1622 |
1617 def onQuit(self, event): | 1623 def onQuit(self, event): |
1618 self.OK = False | 1624 self.OK = False |
1665 pass | 1671 pass |
1666 | 1672 |
1667 self.document = self.desktop.doc().rdoc | 1673 self.document = self.desktop.doc().rdoc |
1668 | 1674 |
1669 self.tween = TweenObject(self.document, self._root) | 1675 self.tween = TweenObject(self.document, self._root) |
1670 self._dom.handle_doc_root(self.document, self._root) | 1676 self._domview.handle_doc_root(self.document, self._root) |
1671 self._dom.register_active_frame_callback(self.onCellClick) | 1677 self._domview.register_active_frame_callback(self.onCellClick) |
1672 | 1678 |
1673 if self.top == None: | 1679 if self.top == None: |
1674 self.top = gtk.VBox(False, 0) | 1680 self.top = gtk.VBox(False, 0) |
1675 toplevel = self.desktop.getToplevel() | 1681 toplevel = self.desktop.getToplevel() |
1676 toplevel.child.child.pack_end(self.top, expand=False) | 1682 toplevel.child.child.pack_end(self.top, expand=False) |
1679 pass | 1685 pass |
1680 | 1686 |
1681 vbox = gtk.VBox(False, 0) | 1687 vbox = gtk.VBox(False, 0) |
1682 self.startWindow = vbox | 1688 self.startWindow = vbox |
1683 self.top.pack_start(vbox, expand=False) | 1689 self.top.pack_start(vbox, expand=False) |
1684 frame_ui = self._dom.get_frame_ui_widget() | 1690 frame_ui = self._domview.get_frame_ui_widget() |
1685 vbox.pack_start(frame_ui, expand=False) | 1691 vbox.pack_start(frame_ui, expand=False) |
1686 hbox=gtk.HBox(False, 0) | 1692 hbox=gtk.HBox(False, 0) |
1687 self._add_buttons(hbox) | 1693 self._add_buttons(hbox) |
1688 vbox.pack_start(hbox, expand=False) | 1694 vbox.pack_start(hbox, expand=False) |
1689 | 1695 |