comparison pyink/MBScene.py @ 1232:6d4de488389e

Change setCurrentScene
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 10 Jan 2011 11:45:12 +0800
parents d28b1b840bfc
children 7f17a7e70d82
comparison
equal deleted inserted replaced
1231:d28b1b840bfc 1232:6d4de488389e
567 567
568 def get_all_scene_node_of_layer(self, layer_idx): 568 def get_all_scene_node_of_layer(self, layer_idx):
569 layer = self._layers[layer_idx] 569 layer = self._layers[layer_idx]
570 return layer.scenes 570 return layer.scenes
571 571
572 def get_layer_data(self, layer_idx):
573 layer = self._layers[layer_idx]
574 try:
575 data = layer.data
576 except:
577 return None
578 return data
579
580 def set_layer_data(self, layer_idx, data):
581 layer = self._layers[layer_idx]
582 layer.data = data
583 pass
584
585 def add_layer_dup_group(self, layer_idx):
586 layer = self._layers[layer_idx]
587
588 dup_group = self._doc.createElement('svg:g')
589 gid = self.new_id()
590 dup_group.setAttribute('id', gid)
591 dup_group.setAttribute('inkscape:label', 'dup')
592 dup_group.setAttribute('sodipodi:insensitive', '1')
593 dup_group.setAttribute('style', '')
594
595 layer.group.appendChild(dup_group)
596
597 return dup_group
598
572 def add_frames(self, layer_idx, frame_idx, num): 599 def add_frames(self, layer_idx, frame_idx, num):
573 layer = self._layers[layer_idx] 600 layer = self._layers[layer_idx]
574 for scene_node in layer.scenes: 601 for scene_node in layer.scenes:
575 start, end, tween_type = self._parse_one_scene(scene_node) 602 start, end, tween_type = self._parse_one_scene(scene_node)
576 if start >= frame_idx: 603 if start >= frame_idx:
1108 pass 1135 pass
1109 1136
1110 def set_layer_label(self, txt): 1137 def set_layer_label(self, txt):
1111 self._fl_mgr.set_layer_label(txt) 1138 self._fl_mgr.set_layer_label(txt)
1112 pass 1139 pass
1140
1141 ## \brief Get duplicate group of a layer.
1142 #
1143 def get_layer_dup_group(self, layer_idx):
1144 data = self._dom.get_layer_data(layer_idx)
1145 if not data:
1146 data = object()
1147 self._dom.set_layer_data(layer_idx, data)
1148 pass
1149
1150 if hasattr(data, 'dup_group_id'):
1151 try:
1152 dup_group = self._dom.get_node(data.dup_group_id)
1153 except KeyError:
1154 dup_group = None
1155 pass
1156 pass
1157
1158 if not dup_group:
1159 dup_group = self._dom.add_layer_dup_group(layer_idx)
1160 data.dup_group_id = dup_group.getAttribute('id')
1161 pass
1162
1163 return dup_group
1113 pass 1164 pass
1114 1165
1115 ## \brief MBScene connect GUI and DOM-tree 1166 ## \brief MBScene connect GUI and DOM-tree
1116 # 1167 #
1117 # This class connect behavior of GUI to the DOM-tree. All about GUI is 1168 # This class connect behavior of GUI to the DOM-tree. All about GUI is
1217 create this group if it is not 1268 create this group if it is not
1218 available. 1269 available.
1219 """ 1270 """
1220 self.current = idx 1271 self.current = idx
1221 self.tween.updateMapping() 1272 self.tween.updateMapping()
1222 for frameline in self._framelines: 1273 for layer_idx in range(self._dom.get_layer_num()):
1223 i=0 1274 dup_group = self._dom.get_layer_dup_group(layer_idx)
1224 1275
1225 # Check the duplicated scene group and create it if it is not 1276 all_key_tweens = self._dom.get_all_key_tween_of_layer(layer_idx)
1226 # available 1277 for start, stop, tween_type in all_key_tweens:
1227 try: 1278 if start == idx: # at key frame
1228 frameline.duplicateGroup.setAttribute("style","display:none") 1279 dup_group.setAttribute('style', 'display: none')
1229 except: 1280 scene_group = \
1230 print "*" * 40 1281 self._dom.get_keyframe_group(layer_idx, idx)
1231 layer_idx = frameline.layer_idx 1282 scene_group.setAttribute('style', '')
1232 layer = self._layers[layer_idx] 1283 elif start < idx and end >= idx: # in Tween
1233 for child in layer.group.childList(): 1284 scene_group = \
1234 try: 1285 self._dom.get_keyframe_group(layer_idx, idx)
1235 label = child.getAttribute('inkscape:label')
1236 if label == 'dup':
1237 frameline.duplicateGroup = child
1238 break
1239 except:
1240 pass
1241 pass
1242 else:
1243 duplicateGroup = self.document.createElement("svg:g")
1244 duplicateGroup.setAttribute("inkscape:label","dup")
1245 duplicateGroup.setAttribute("sodipodi:insensitive","1")
1246 duplicateGroup.setAttribute("style","")
1247
1248 layer.group.appendChild(duplicateGroup)
1249 frameline.duplicateGroup = duplicateGroup
1250 pass
1251 pass
1252
1253 # Create a new group
1254 for start_idx, stop_idx, tween_type in frameline.get_frame_blocks():
1255 if start_idx == stop_idx:
1256 scene_node = frameline.get_frame_data(start_idx)
1257 scene_group_id = scene_node.getAttribute('ref')
1258 scene_group = self.get_node(scene_group_id)
1259 if idx == start_idx:
1260 scene_group.setAttribute('style', '')
1261 else:
1262 scene_group.setAttribute('style', 'display: none')
1263 pass
1264 elif idx == start_idx:
1265 frameline.duplicateGroup.setAttribute("style","display:none")
1266 scene_node = frameline.get_frame_data(start_idx)
1267 scene_group_id = scene_node.getAttribute('ref')
1268 scene_group = self.get_node(scene_group_id)
1269 scene_group.setAttribute("style","")
1270 elif start_idx < idx and stop_idx >= idx:
1271 scene_node = frameline.get_frame_data(start_idx)
1272 scene_group_id = scene_node.getAttribute('ref')
1273 scene_group = self.get_node(scene_group_id)
1274 scene_group.setAttribute("style","display:none")
1275 frameline.duplicateGroup.setAttribute("style","")
1276 tween_type_idx = \
1277 self._frameline_tween_types.index(tween_type)
1278 tween_obj_tween_type = \
1279 self._tween_obj_tween_types[tween_type_idx]
1280 1286
1281 try: 1287 try:
1282 next_idx, next_stop_idx, next_tween_type = \ 1288 next_scene_group = \
1283 frameline.get_frame_block(stop_idx + 1) 1289 self._dom.get_keyframe_group(layer_idx, end + 1)
1284 except: 1290 except: # no next key frame
1285 next_scene_node = scene_node 1291 next_scene_group = scene_group
1286 else:
1287 next_scene_node = frameline.get_frame_data(next_idx)
1288 pass 1292 pass
1289 1293
1290 next_scene_group_id = next_scene_node.getAttribute('ref') 1294 tween_obj_type = self._tween_obj_tween_types[tween_type]
1291 next_scene_group = self.get_node(next_scene_group_id) 1295 nframes = stop - start + 1
1292 1296 percent = float(idx - start) / nframes
1293 nframes = stop_idx - start_idx + 1 1297 self.tween.updateTweenContent(dup_group,
1294 percent = float(idx - start_idx) / nframes 1298 tween_obj_type,
1295 self.tween.updateTweenContent(frameline.duplicateGroup,
1296 tween_obj_tween_type,
1297 scene_group, 1299 scene_group,
1298 next_scene_group, 1300 next_scene_group,
1299 percent) 1301 percent)
1300 else:
1301 scene_node = frameline.get_frame_data(start_idx)
1302 scene_group_id = scene_node.getAttribute('ref')
1303 scene_group = self.get_node(scene_group_id)
1304 scene_group.setAttribute("style","display:none")
1305 pass 1302 pass
1306 pass 1303 else: # this scene should not be showed.
1307 pass 1304 scene_group = \
1308 pass 1305 self._dom.get_keyframe_group(layer_idx, idx)
1309 1306 scene_group.setAttribute('style', '')
1307 pass
1308 pass
1309 pass
1310 pass
1311
1310 def enterGroup(self, obj): 1312 def enterGroup(self, obj):
1311 for l in self._layers: 1313 for l in self._layers:
1312 for s in l.group.childList(): 1314 for s in l.group.childList():
1313 if s.getAttribute('id') == obj.getAttribute("id"): 1315 if s.getAttribute('id') == obj.getAttribute("id"):
1314 self.desktop.setCurrentLayer(s.spitem) 1316 self.desktop.setCurrentLayer(s.spitem)
1355 1357
1356 ## \brief Make status of layers is updated when DOM is changed. 1358 ## \brief Make status of layers is updated when DOM is changed.
1357 # 1359 #
1358 # When DOM-tree is changed, this function make sure layer information is up 1360 # When DOM-tree is changed, this function make sure layer information is up
1359 # to date. 1361 # to date.
1362 #
1363 # TODO: move this to somewhere
1364 #
1360 def _make_layers_integral(self): 1365 def _make_layers_integral(self):
1361 root = self._root 1366 root = self._root
1362 root_id = root.getAttribute('id') 1367 root_id = root.getAttribute('id')
1363 1368
1364 # Remove group of removed layers 1369 # Remove group of removed layers