comparison pyink/MBScene.py @ 1194:319414e4d87a

Fix the issue that is fault to switch scenes
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 02 Jan 2011 18:50:55 +0800
parents 0e3a65b7b00c
children cb2c611d1656
comparison
equal deleted inserted replaced
1193:0e3a65b7b00c 1194:319414e4d87a
344 def _parse_one_scenes(self, scenes_node): 344 def _parse_one_scenes(self, scenes_node):
345 self.scenemap = {} 345 self.scenemap = {}
346 try: 346 try:
347 cur = int(n.getAttribute("current")) 347 cur = int(n.getAttribute("current"))
348 except: 348 except:
349 cur = 1 349 cur = 0
350 pass 350 pass
351 self.current = cur 351 self.current = cur
352 352
353 for scene_node in scenes_node.childList(): 353 for scene_node in scenes_node.childList():
354 if scene_node.name() != 'ns0:scene': 354 if scene_node.name() != 'ns0:scene':
672 scene_node.setAttribute('end', str(frame_idx)) 672 scene_node.setAttribute('end', str(frame_idx))
673 frameline.add_keyframe(frame_idx) 673 frameline.add_keyframe(frame_idx)
674 frameline.tween(start, scene_type) 674 frameline.tween(start, scene_type)
675 pass 675 pass
676 676
677 def setCurrentScene(self,nth): 677 def setCurrentScene(self, idx):
678 """ 678 """
679 Update the scene group according to the curretn scene 679 Update the scene group according to the curretn scene
680 data. There are a couple of cases. 680 data. There are a couple of cases.
681 1. If the type of the scene is normal, we display it when 681 1. If the type of the scene is normal, we display it when
682 it contains the current frame. Otherwise hide it. 682 it contains the current frame. Otherwise hide it.
691 group whose name as dup. 691 group whose name as dup.
692 We will put the duplicated scene group inside it. We will 692 We will put the duplicated scene group inside it. We will
693 create this group if it is not 693 create this group if it is not
694 available. 694 available.
695 """ 695 """
696 self.current = nth 696 self.current = idx
697 self.tween.updateMapping() 697 self.tween.updateMapping()
698 idx = nth - 1
699 for frameline in self._framelines: 698 for frameline in self._framelines:
700 i=0 699 i=0
701 700
702 # Check the duplicated scene group and create it if it is not available 701 # Check the duplicated scene group and create it if it is not available
703 try: 702 try:
712 pass 711 pass
713 # Create a new group 712 # Create a new group
714 for start_idx, stop_idx, tween_type in frameline.get_frame_blocks(): 713 for start_idx, stop_idx, tween_type in frameline.get_frame_blocks():
715 if start_idx == stop_idx: 714 if start_idx == stop_idx:
716 scene_node = frameline.get_frame_data(start_idx) 715 scene_node = frameline.get_frame_data(start_idx)
716 scene_group_id = scene_node.getAttribute('ref')
717 scene_group = self.get_node(scene_group_id)
717 if idx == start_idx: 718 if idx == start_idx:
718 scene_node.setAttribute('style', '') 719 scene_group.setAttribute('style', '')
719 else: 720 else:
720 scene_node.setAttribute('style', 'display: none') 721 scene_group.setAttribute('style', 'display: none')
721 pass 722 pass
722 elif idx == start_idx: 723 elif idx == start_idx:
723 frameline.duplicateGroup.setAttribute("style","display:none") 724 frameline.duplicateGroup.setAttribute("style","display:none")
724 scene_node = frameline.get_frame_data(start_idx) 725 scene_node = frameline.get_frame_data(start_idx)
725 scene_node.setAttribute("style","") 726 scene_node.setAttribute("style","")
726 elif start_idx <= idx and stop_idx >= idx: 727 elif start_idx <= idx and stop_idx >= idx:
727 scene_node = frameline.get_frame_data(start_idx) 728 scene_node = frameline.get_frame_data(start_idx)
728 scene_node.setAttribute("style","display:none") 729 scene_group_id = scene_node.getAttribute('ref')
730 scene_group = self.get_node(scene_group_id)
731 scene_group.setAttribute("style","display:none")
729 frameline.duplicateGroup.setAttribute("style","") 732 frameline.duplicateGroup.setAttribute("style","")
730 tween_type_idx = \ 733 tween_type_idx = \
731 self._frameline_tween_types.index(tween_type) 734 self._frameline_tween_types.index(tween_type)
732 tween_obj_tween_type = \ 735 tween_obj_tween_type = \
733 self._tween_obj_tween_types[tween_type_idx] 736 self._tween_obj_tween_types[tween_type_idx]
738 except: 741 except:
739 next_scene_node = scene_node 742 next_scene_node = scene_node
740 else: 743 else:
741 next_scene_node = frameline.get_frame_data(next_idx) 744 next_scene_node = frameline.get_frame_data(next_idx)
742 pass 745 pass
746
747 next_scene_group_id = next_scene_node.getAttribute('ref')
748 next_scene_group = self.get_node(next_scene_group_id)
743 749
744 nframes = stop_idx - start_idx + 1 750 nframes = stop_idx - start_idx + 1
745 percent = float(idx - start_idx) / nframes 751 percent = float(idx - start_idx) / nframes
746 self.tween.updateTweenContent(frameline.duplicateGroup, 752 self.tween.updateTweenContent(frameline.duplicateGroup,
747 tween_obj_tween_type, 753 tween_obj_tween_type,
748 scene_node, 754 scene_group,
749 next_scene_node, 755 next_scene_node,
750 percent) 756 percent)
751 else: 757 else:
752 scene_node = frameline.get_frame_data(start_idx) 758 scene_node = frameline.get_frame_data(start_idx)
753 scene_node.setAttribute("style","display:none") 759 scene_group_id = scene_node.getAttribute('ref')
760 scene_group = self.get_node(scene_group_id)
761 scene_group.setAttribute("style","display:none")
754 pass 762 pass
755 pass 763 pass
756 pass 764 pass
757 pass 765 pass
758 766
962 scene_group.setAttribute("inkscape:groupmode","layer") 970 scene_group.setAttribute("inkscape:groupmode","layer")
963 self.last_line.layer_group.appendChild(scene_group) 971 self.last_line.layer_group.appendChild(scene_group)
964 return scene_group 972 return scene_group
965 973
966 def doEditScene(self, w): 974 def doEditScene(self, w):
967 self.setCurrentScene(self.last_frame+1) 975 self.setCurrentScene(self.last_frame)
968 self.selectSceneObject(self.last_line, self.last_frame) 976 self.selectSceneObject(self.last_line, self.last_frame)
969 pass 977 pass
970 978
971 def doInsertKeyScene(self,w): 979 def doInsertKeyScene(self,w):
972 self._lockui=True 980 self._lockui=True
1023 1031
1024 def doRunNext(self): 1032 def doRunNext(self):
1025 if self.current >= self.maxframe: 1033 if self.current >= self.maxframe:
1026 self.current = 0 1034 self.current = 0
1027 try: 1035 try:
1028 self.setCurrentScene(self.current+1) 1036 self.setCurrentScene(self.current)
1029 except: 1037 except:
1030 traceback.print_exc() 1038 traceback.print_exc()
1031 raise 1039 raise
1032 self.last_update = glib.timeout_add(1000/self.framerate,self.doRunNext) 1040 self.last_update = glib.timeout_add(1000/self.framerate,self.doRunNext)
1033 1041