Mercurial > MadButterfly
comparison pyink/MBScene.py @ 1235:84e7b1c1892b
Remove updateUI
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 10 Jan 2011 11:45:12 +0800 |
parents | 0f597a2073eb |
children | 2eeac97853eb |
comparison
equal
deleted
inserted
replaced
1234:0f597a2073eb | 1235:84e7b1c1892b |
---|---|
964 | 964 |
965 ## \brief Update content of a frameline from scenes of respective layer. | 965 ## \brief Update content of a frameline from scenes of respective layer. |
966 # | 966 # |
967 def _update_frameline_content(self, layer_idx): | 967 def _update_frameline_content(self, layer_idx): |
968 fl_mgr = self._fl_mgr | 968 fl_mgr = self._fl_mgr |
969 scene_nodes = self._fl_mgr.get_all_scene_node_of_layer(layer_idx): | 969 scene_nodes = fl_mgr.get_all_scene_node_of_layer(layer_idx) |
970 for scene_node in scene_nodes: | 970 for scene_node in scene_nodes: |
971 start, end, tween_name = self._parse_one_scene(scene_node) | 971 start, end, tween_name = self._parse_one_scene(scene_node) |
972 | 972 |
973 fl_mgr.add_keyframe(layer_idx, start) | 973 fl_mgr.add_keyframe(layer_idx, start) |
974 fl_mgr.set_keyframe_data(layer_idx, start, scene_node) | 974 fl_mgr.set_keyframe_data(layer_idx, start, scene_node) |
1340 scene_group = self._dom.get_keyframe_group(layer_idx, start) | 1340 scene_group = self._dom.get_keyframe_group(layer_idx, start) |
1341 self._enterGroup(scene_group) | 1341 self._enterGroup(scene_group) |
1342 self.setTweenType(tween_type) | 1342 self.setTweenType(tween_type) |
1343 pass | 1343 pass |
1344 | 1344 |
1345 ## \brief Remove the layer that lost the layer group. | |
1346 # | |
1347 # This function is called when a layer group being removed from the | |
1348 # DOM-tree. | |
1349 def _remove_lost_group_layer(self, layer_idx): | |
1350 layer = self._layers[layer_idx] | |
1351 frameline = self._framelines[layer_idx] | |
1352 for start, end, tween_type in frameline.get_frame_blocks(): | |
1353 scene_node = frameline.get_frame_data(start) | |
1354 self.rm_scene_node(scene_node) | |
1355 pass | |
1356 | |
1357 self._remove_frameline(layer_idx) # TODO | |
1358 self._show_framelines() | |
1359 del self._layers[layer_idx] | |
1360 pass | |
1361 | |
1362 ## \brief Make status of layers is updated when DOM is changed. | |
1363 # | |
1364 # When DOM-tree is changed, this function make sure layer information is up | |
1365 # to date. | |
1366 # | |
1367 # TODO: move this to somewhere | |
1368 # | |
1369 def _make_layers_integral(self): | |
1370 root = self._root | |
1371 root_id = root.getAttribute('id') | |
1372 | |
1373 # Remove group of removed layers | |
1374 layer_idx = 0 | |
1375 while layer_idx < len(self._layers): | |
1376 layer = self._layers[layer_idx] | |
1377 | |
1378 if layer.group.name() != 'svg:g': | |
1379 self._remove_lost_group_layer(layer_idx) # TODO | |
1380 continue | |
1381 | |
1382 parent = layer.group.parent() | |
1383 | |
1384 if not parent: # parent is None when a node being removed from | |
1385 # DOM-tree. | |
1386 self._remove_lost_group_layer(layer_idx) | |
1387 continue | |
1388 | |
1389 if parent.name() != 'svg:svg': | |
1390 self._remove_lost_group_layer(layer_idx) | |
1391 continue | |
1392 | |
1393 if parent.getAttribute('id') != root_id: | |
1394 self._remove_lost_group_layer(layer_idx) | |
1395 continue | |
1396 | |
1397 layer_idx = layer_idx + 1 | |
1398 pass | |
1399 | |
1400 # Add new layers | |
1401 layer_idx = 0 | |
1402 for child in root.childList(): | |
1403 if child.name() != 'svg:g': | |
1404 continue | |
1405 | |
1406 try: | |
1407 layer = self._layers[layer_idx] | |
1408 except IndexError: | |
1409 layer = None | |
1410 else: | |
1411 layer_group_id = layer.group.getAttribute('id') | |
1412 pass | |
1413 | |
1414 child_id = child.getAttribute('id') | |
1415 if (not layer) or layer_group_id != child_id: | |
1416 self.add_layer(layer_idx, child) | |
1417 self.parse_layer(layer_idx) | |
1418 self._add_frameline(layer_idx) | |
1419 | |
1420 layer = self._layers[layer_idx] | |
1421 frameline = self._framelines[layer_idx] | |
1422 try: | |
1423 label = layer.group.getAttribute('inkscape:label') | |
1424 except: | |
1425 label = layer.group.getAttribute('id') | |
1426 pass | |
1427 frameline.label.set_text(label) | |
1428 | |
1429 self._show_framelines() | |
1430 pass | |
1431 | |
1432 layer_idx = layer_idx + 1 | |
1433 pass | |
1434 pass | |
1435 | |
1436 def duplicateKeyScene(self): | 1345 def duplicateKeyScene(self): |
1437 # Search for the current scene | 1346 # Search for the current scene |
1438 layer_idx, frame_idx = self._dom.get_active_layer_frame() | 1347 layer_idx, frame_idx = self._dom.get_active_layer_frame() |
1439 | 1348 |
1440 try: | 1349 try: |
1491 self.editDone = gtk.Button('Set') | 1400 self.editDone = gtk.Button('Set') |
1492 hbox.pack_start(self.editDone,expand=False,fill=False) | 1401 hbox.pack_start(self.editDone,expand=False,fill=False) |
1493 self.editDone.connect('clicked', self.changeObjectLabel) | 1402 self.editDone.connect('clicked', self.changeObjectLabel) |
1494 pass | 1403 pass |
1495 | 1404 |
1496 def updateUI(self, *args): | |
1497 if self._lockui: return | |
1498 | |
1499 if self.last_update!= None: | |
1500 glib.source_remove(self.last_update) | |
1501 self.last_update = glib.timeout_add(300,self._updateUI) | |
1502 | |
1503 pass | |
1504 | |
1505 def _updateUI(self,node=None,arg=None): | |
1506 self._lockui = True | |
1507 self._make_layers_integral() | |
1508 self._lockui = False | |
1509 pass | |
1510 | |
1511 def addTweenTypeSelector(self, hbox): | 1405 def addTweenTypeSelector(self, hbox): |
1512 tweenbox = gtk.HBox() | 1406 tweenbox = gtk.HBox() |
1513 label = gtk.Label('Tween Type') | 1407 label = gtk.Label('Tween Type') |
1514 tweenbox.pack_start(label) | 1408 tweenbox.pack_start(label) |
1515 | 1409 |
1707 vbox.pack_start(frame_ui, expand=False) | 1601 vbox.pack_start(frame_ui, expand=False) |
1708 hbox=gtk.HBox(False, 0) | 1602 hbox=gtk.HBox(False, 0) |
1709 self._add_buttons(hbox) | 1603 self._add_buttons(hbox) |
1710 vbox.pack_start(hbox, expand=False) | 1604 vbox.pack_start(hbox, expand=False) |
1711 | 1605 |
1712 doc = self.document | |
1713 addEventListener(doc,'DOMNodeInserted', self.updateUI, None) | |
1714 addEventListener(doc,'DOMNodeRemoved', self.updateUI, None) | |
1715 | |
1716 self.top.show_all() | 1606 self.top.show_all() |
1717 self.last_update = None | 1607 self.last_update = None |
1718 return False | 1608 return False |
1719 pass | 1609 pass |