Mercurial > MadButterfly
comparison pyink/domview.py @ 1247:45e9566ea5c0
Fix bugs of inserting/removing frames.
- tracking layer.scenes when add/remove scene nodes.
- fix buggy add_frame()/rm_frame() of frameline.
- change ID of nodes before inserting when copy nodes from another
group.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 10 Jan 2011 22:15:16 +0800 |
parents | 42c4874c8d1e |
children | 07e0cb1e051d |
comparison
equal
deleted
inserted
replaced
1246:42c4874c8d1e | 1247:45e9566ea5c0 |
---|---|
390 print " " * l * 2,"/>" | 390 print " " * l * 2,"/>" |
391 pass | 391 pass |
392 | 392 |
393 ## \brief Create and add a ns0:scene node under ns0:scenes subtree. | 393 ## \brief Create and add a ns0:scene node under ns0:scenes subtree. |
394 # | 394 # |
395 def add_scene_node(self, start, end, | 395 def add_scene_node(self, layer_idx, start, end, |
396 frame_type=TweenObject.TWEEN_TYPE_NORMAL, | 396 frame_type=TweenObject.TWEEN_TYPE_NORMAL, |
397 ref=None): | 397 ref=None): |
398 type_names = ('normal', 'scale') | 398 type_names = ('normal', 'scale') |
399 scenes_node = self._scenes_node | 399 scenes_node = self._scenes_node |
400 doc = self._doc | 400 doc = self._doc |
409 if ref: | 409 if ref: |
410 self.chg_scene_node(scene_node, ref=ref) | 410 self.chg_scene_node(scene_node, ref=ref) |
411 pass | 411 pass |
412 | 412 |
413 scenes_node.appendChild(scene_node) | 413 scenes_node.appendChild(scene_node) |
414 | |
415 self._layers[layer_idx].scenes.append(scene_node) | |
414 | 416 |
415 return scene_node | 417 return scene_node |
416 | 418 |
417 ## \brief Change attributes of a scene node. | 419 ## \brief Change attributes of a scene node. |
418 # | 420 # |
433 pass | 435 pass |
434 pass | 436 pass |
435 | 437 |
436 def rm_scene_node(self, scene_node): | 438 def rm_scene_node(self, scene_node): |
437 self._scenes_node.removeChild(scene_node) | 439 self._scenes_node.removeChild(scene_node) |
440 for layer in self._layers: | |
441 try: | |
442 layer.scenes.remove(scene_node) | |
443 except ValueError: # not in the list | |
444 pass | |
445 else: | |
446 break | |
447 pass | |
438 pass | 448 pass |
439 | 449 |
440 def rm_scene_node_n_group(self, scene_node): | 450 def rm_scene_node_n_group(self, scene_node): |
441 scene_group_id = scene_node.getAttribute('ref') | 451 scene_group_id = scene_node.getAttribute('ref') |
442 scene_group_node = self.get_node(scene_group_id) | 452 scene_group_node = self.get_node(scene_group_id) |
443 scene_group_node.parent().removeChild(scene_group_node) | 453 scene_group_node.parent().removeChild(scene_group_node) |
444 | 454 |
445 self._scenes_node.removeChild(scene_node) | 455 self.rm_scene_node(scene_node) |
446 pass | 456 pass |
447 | 457 |
448 ## \brief Create and add a svg:g for a scene under a group for a layer. | 458 ## \brief Create and add a svg:g for a scene under a group for a layer. |
449 # | 459 # |
450 def add_scene_group(self, layer_idx): | 460 def add_scene_group(self, layer_idx): |
587 layer = self._layers[layer_idx] | 597 layer = self._layers[layer_idx] |
588 | 598 |
589 last_rm = frame_idx + num - 1 # last removed frame | 599 last_rm = frame_idx + num - 1 # last removed frame |
590 for scene_node in layer.scenes: | 600 for scene_node in layer.scenes: |
591 start, end, tween_type = \ | 601 start, end, tween_type = \ |
592 self._dom._parse_one_scene(scene_node) | 602 self._parse_one_scene(scene_node) |
593 | 603 |
594 if end < frame_idx: | 604 if end < frame_idx: |
595 continue | 605 continue |
596 | 606 |
597 if start > last_rm: # this scene is at right side | 607 if start > last_rm: # this scene is at right side |
612 # Duplicate children of a group, and append them to another group. | 622 # Duplicate children of a group, and append them to another group. |
613 # | 623 # |
614 def copy_group_children(self, src_group, dst_group): | 624 def copy_group_children(self, src_group, dst_group): |
615 # Search for the duplicated group | 625 # Search for the duplicated group |
616 doc = self._doc | 626 doc = self._doc |
617 | 627 |
618 dup_group = src_group.duplicate(doc) | 628 dup_group = src_group.duplicate(doc) |
619 for child in dup_group.childList(): | 629 |
620 dup_group.removeChild(child) # prvent from crash | |
621 dst_group.appendChild(child) | |
622 pass | |
623 | |
624 old_nodes = _DOM_iterator(src_group) | 630 old_nodes = _DOM_iterator(src_group) |
625 new_nodes = _DOM_iterator(dst_group) | 631 new_nodes = _DOM_iterator(dup_group) |
632 new_gids = set() | |
626 for old_node in old_nodes: | 633 for old_node in old_nodes: |
627 old_node_id = old_node.getAttribute('id') | 634 old_node_id = old_node.getAttribute('id') |
628 new_node = new_nodes.next() | 635 new_node = new_nodes.next() |
629 new_node.setAttribute('ns0:duplicate-src', old_node_id) | 636 new_node.setAttribute('ns0:duplicate-src', old_node_id) |
637 | |
638 # | |
639 # Change ID here, or inkscape would insert the node with | |
640 # the same ID, and change it later to avoid duplication. | |
641 # But, our event handler would be called before changing | |
642 # ID. It would confuse our code. We change ID of nodes | |
643 # before inserting them into the DOM-tree. | |
644 # | |
645 gid = self.new_id() | |
646 while gid in new_gids: | |
647 gid = self.new_id() | |
648 pass | |
649 new_gids.add(gid) | |
650 new_node.setAttribute('id', gid) | |
651 pass | |
652 | |
653 for child in dup_group.childList(): | |
654 dup_group.removeChild(child) # prvent from crash | |
655 dst_group.appendChild(child) | |
630 pass | 656 pass |
631 pass | 657 pass |
632 pass | 658 pass |
633 | 659 |