Mercurial > MadButterfly
comparison pyink/MBScene.py @ 1224:5d731460b32c
Remove search_by_id() from frameline.
- frameline is only responsible for drawing a row of frames.
- layers and scenes are managed by MBScene_dom. So, function of
search_by_id() must move to MBScene_dom class.
- onCellClick() and _change_active_frame() are responsible for
handling GUI event.
- It should not be used with workaround to implement some function.
- Solutions
- MBScene_dom.find_layer_n_scene_of_nod() is used to replace
search_by_id().
- MBScene_framelines.active_frame() is used to replace the
workaround.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Thu, 06 Jan 2011 11:11:27 +0800 |
parents | ec964cf4c993 |
children | 027187a21117 |
comparison
equal
deleted
inserted
replaced
1223:ec964cf4c993 | 1224:5d731460b32c |
---|---|
523 | 523 |
524 for idx in range(layer_idx, len(layers)): | 524 for idx in range(layer_idx, len(layers)): |
525 layers[idx].idx = idx | 525 layers[idx].idx = idx |
526 pass | 526 pass |
527 pass | 527 pass |
528 | |
529 def find_layer_n_scene_of_node(self, node_id): | |
530 for layer_idx, layer in enumerate(self._layers): | |
531 for scene_node in layer.scenes: | |
532 scene_group_id = scene_node.getAttribute('ref') | |
533 if scene_group_id == node_id: | |
534 return layer_idx, scene_node | |
535 pass | |
536 pass | |
537 pass | |
528 pass | 538 pass |
529 | 539 |
530 ## \brief Maintain frameline list for MBScene. | 540 ## \brief Maintain frameline list for MBScene. |
531 # | 541 # |
532 class MBScene_framelines(object): | 542 class MBScene_framelines(object): |
540 | 550 |
541 self._last_mouse_over_frameline = None | 551 self._last_mouse_over_frameline = None |
542 self._last_active_frameline = None | 552 self._last_active_frameline = None |
543 pass | 553 pass |
544 | 554 |
545 def search_frameline_by_id(self, id): | |
546 """ | |
547 Search the frameline whose layer is id | |
548 """ | |
549 | |
550 for f in self._framelines: | |
551 idx = f.search_by_id(id) | |
552 if idx != -1: | |
553 return (f,idx) | |
554 pass | |
555 return (None,-1) | |
556 | |
557 def _change_hover_frameline(self, widget, event): | 555 def _change_hover_frameline(self, widget, event): |
558 """ | 556 """ |
559 Hide all hover frames. This is a hack. We should use the lost focus | 557 Hide all hover frames. This is a hack. We should use the lost focus |
560 event instead in the future to reduce the overhead. | 558 event instead in the future to reduce the overhead. |
561 """ | 559 """ |
564 self._last_mouse_over_frameline.mouse_leave() | 562 self._last_mouse_over_frameline.mouse_leave() |
565 pass | 563 pass |
566 self._last_mouse_over_frameline = widget | 564 self._last_mouse_over_frameline = widget |
567 pass | 565 pass |
568 | 566 |
567 def _active_frameline(self, frameline): | |
568 last = self._last_active_frameline | |
569 | |
570 if last and last != frameline: | |
571 last.deactive() | |
572 pass | |
573 | |
574 self._last_active_frameline = frameline | |
575 pass | |
576 | |
569 ## \brief Called for changing of active frame. | 577 ## \brief Called for changing of active frame. |
570 # | 578 # |
571 # This handle deactive previous frameline that owns an active frame when a | 579 # This handle deactive previous frameline that owns an active frame when a |
572 # frame in another frameline is activated. | 580 # frame in another frameline is activated. |
573 def _change_active_frame(self, widget, frame, button): | 581 def _change_active_frame(self, widget, frame, button): |
574 if self._last_active_frameline and \ | 582 self._active_frameline(widget) |
575 self._last_active_frameline != widget: | |
576 self._last_active_frameline.deactive() | |
577 pass | |
578 self._last_active_frameline = widget | |
579 pass | 583 pass |
580 | 584 |
581 ## \brief Add a frameline into the frameline box for the given layer. | 585 ## \brief Add a frameline into the frameline box for the given layer. |
582 # | 586 # |
583 def _add_frameline(self, layer_idx): | 587 def _add_frameline(self, layer_idx): |
602 | 606 |
603 self._framelines[layer_idx: layer_idx] = [line] | 607 self._framelines[layer_idx: layer_idx] = [line] |
604 | 608 |
605 line.label = label | 609 line.label = label |
606 line.layer_idx = layer_idx | 610 line.layer_idx = layer_idx |
611 # TODO: The following line of code should be moved to MBScene. | |
607 line.connect(line.FRAME_BUT_PRESS, self.onCellClick) | 612 line.connect(line.FRAME_BUT_PRESS, self.onCellClick) |
608 line.connect('motion-notify-event', self._change_hover_frameline) | 613 line.connect('motion-notify-event', self._change_hover_frameline) |
609 line.connect(frameline.FRAME_BUT_PRESS, self._change_active_frame) | 614 line.connect(frameline.FRAME_BUT_PRESS, self._change_active_frame) |
610 pass | 615 pass |
611 | 616 |
652 # When a frameline was inserted or removed, it would not be showed | 657 # When a frameline was inserted or removed, it would not be showed |
653 # immediately. This function is used to notify toolkit to update the | 658 # immediately. This function is used to notify toolkit to update the |
654 # screen and drawing framelines. | 659 # screen and drawing framelines. |
655 def _show_framelines(self): | 660 def _show_framelines(self): |
656 self._frameline_vbox.show_all() | 661 self._frameline_vbox.show_all() |
662 pass | |
663 | |
664 def active_frame(self, layer_idx, frame_idx): | |
665 frameline = self._framelines[layer_idx] | |
666 self._active_frameline(frameline) | |
667 frameline.active_frame(frame_idx) | |
657 pass | 668 pass |
658 pass | 669 pass |
659 | 670 |
660 ## \brief MBScene connect GUI and DOM-tree | 671 ## \brief MBScene connect GUI and DOM-tree |
661 # | 672 # |
707 | 718 |
708 # The selection is a PYSPObject. Convert it to be PYNode | 719 # The selection is a PYSPObject. Convert it to be PYNode |
709 self.change_active_frame(self.last_select.repr.parent()) | 720 self.change_active_frame(self.last_select.repr.parent()) |
710 pass | 721 pass |
711 | 722 |
712 def change_active_frame(self, obj): | 723 def change_active_frame(self, node): |
713 """ | 724 """ |
714 Change the active frame to the current selected object. This will | 725 Change the active frame to the current selected node. This will |
715 tell users where the current object is. | 726 tell users where the current node is. |
716 """ | 727 """ |
717 | 728 |
718 while obj: | 729 while node: |
719 id = obj.getAttribute('id') | |
720 try: | 730 try: |
721 # Search for the frameline which use @obj as one of its scene | 731 node_id = node.getAttribute('id') |
732 except: | |
733 node = node.parent() | |
734 continue | |
735 | |
736 try: | |
737 # Search for the frameline which use @node as one of its scene | |
722 # group. | 738 # group. |
723 (frameline, frame) = self.search_frameline_by_id(id) | 739 try: |
724 if frameline == None: | 740 layer_idx, scene_node = \ |
725 print "Error: internal structure error %s not found" % id | 741 self.find_layer_n_scene_of_node(node_id) |
742 except: | |
743 pass | |
726 else: | 744 else: |
727 self._change_active_frame(frameline, 0, 0) | 745 start, end, tween_type_name = \ |
728 self.onCellClick(frameline, frame, 0) | 746 self._parse_one_scene(scene_node) |
747 self.active_frame(layer_idx, start) | |
729 return | 748 return |
730 except: | 749 except: |
731 traceback.print_exc() | 750 traceback.print_exc() |
732 pass | 751 pass |
733 obj = obj.parent() | 752 node = node.parent() |
734 pass | 753 pass |
735 pass | 754 pass |
736 | 755 |
737 def insertKeyScene(self, line, frame): | 756 def insertKeyScene(self, line, frame): |
738 """ | 757 """ |