comparison pyink/MBScene.py @ 1199:25e1579ed3d1

Fix bug of running animation - Animation can not be played correctly. - It needs the group of a scene, but it passes the scene node. - fixed by passing scene group.
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 03 Jan 2011 12:23:36 +0800
parents 164076156e04
children 213f03dbfc41
comparison
equal deleted inserted replaced
1198:164076156e04 1199:25e1579ed3d1
404 doc = self._doc 404 doc = self._doc
405 405
406 scene_node = doc.createElement('ns0:scene') 406 scene_node = doc.createElement('ns0:scene')
407 scene_node.setAttribute('start', str(start)) 407 scene_node.setAttribute('start', str(start))
408 if start != end: 408 if start != end:
409 scene_node.setAttribute('end', str(end)) 409 self._chg_scene_node(scene_node, end=end)
410 pass 410 pass
411 type_name = type_names[frame_type] 411 type_name = type_names[frame_type]
412 scene_node.setAttribute('type', type_name) 412 scene_node.setAttribute('type', type_name)
413 if ref: 413 if ref:
414 scene_node.setAttribute('ref', ref) 414 scene_node.setAttribute('ref', ref)
415 pass 415 pass
416 416
417 scenes_node.appendChild(scene_node) 417 scenes_node.appendChild(scene_node)
418 418
419 return scene_node 419 return scene_node
420
421 def _chg_scene_node(self, scene_node, start=None, end=None,
422 tween_type=None, ref=None):
423 if start:
424 scene_node.setAttribute('start', str(start))
425 pass
426 if end:
427 scene_node.setAttribute('end', str(end))
428 if int(end) > self.maxframe:
429 self.maxframe = int(end)
430 pass
431 pass
432 if tween_type:
433 scene_node.setAttribute('type', tween_type)
434 pass
435 if ref:
436 scene_node.setAttribute('ref', ref)
437 pass
438 pass
420 439
421 ## \brief Create and add a svg:g for a scene under a group for a layer. 440 ## \brief Create and add a svg:g for a scene under a group for a layer.
422 # 441 #
423 def _add_scene_group(self, layer_idx): 442 def _add_scene_group(self, layer_idx):
424 layer = self.layers[layer_idx] 443 layer = self.layers[layer_idx]
533 continue 552 continue
534 553
535 try: 554 try:
536 label = scene_group.getAttribute('inkscape:label') 555 label = scene_group.getAttribute('inkscape:label')
537 if label == 'dup': 556 if label == 'dup':
538 # TODO: remove this since this functio is for
539 # parsing. Why do this here?
540 node.removeChild(scene_group)
541 continue 557 continue
542 except: 558 except:
543 pass 559 pass
544 560
545 try: 561 try:
668 if start < end: 684 if start < end:
669 frameline.rm_keyframe(end) 685 frameline.rm_keyframe(end)
670 pass 686 pass
671 687
672 scene_node = frameline.get_frame_data(start) 688 scene_node = frameline.get_frame_data(start)
673 scene_node.setAttribute('end', str(frame_idx)) 689 self._chg_scene_node(scene_node, end=frame_idx)
674 frameline.add_keyframe(frame_idx) 690 frameline.add_keyframe(frame_idx)
675 frameline.tween(start, scene_type) 691 frameline.tween(start, scene_type)
676 pass 692 pass
677 693
678 def setCurrentScene(self, idx): 694 def setCurrentScene(self, idx):
701 717
702 # Check the duplicated scene group and create it if it is not available 718 # Check the duplicated scene group and create it if it is not available
703 try: 719 try:
704 frameline.duplicateGroup.setAttribute("style","display:none") 720 frameline.duplicateGroup.setAttribute("style","display:none")
705 except: 721 except:
706 print "*"*40 722 print "*" * 40
707 frameline.duplicateGroup = self.document.createElement("svg:g") 723 layer_idx = frameline.layer_idx
708 frameline.duplicateGroup.setAttribute("inkscape:label","dup") 724 layer = self.layers[layer_idx]
709 frameline.duplicateGroup.setAttribute("sodipodi:insensitive","1") 725 for child in layer.group.childList():
710 frameline.duplicateGroup.setAttribute("style","") 726 label = child.getAttribute('inkscape:label')
711 frameline.layer.group.appendChild(frameline.duplicateGroup) 727 if label == 'dup':
728 frameline.duplicateGroup = child
729 break
730 pass
731 else:
732 duplicateGroup = self.document.createElement("svg:g")
733 duplicateGroup.setAttribute("inkscape:label","dup")
734 duplicateGroup.setAttribute("sodipodi:insensitive","1")
735 duplicateGroup.setAttribute("style","")
736 frameline.layer.group.appendChild(duplicateGroup)
737 frameline.duplicateGroup = duplicateGroup
738 pass
712 pass 739 pass
740
713 # Create a new group 741 # Create a new group
714 for start_idx, stop_idx, tween_type in frameline.get_frame_blocks(): 742 for start_idx, stop_idx, tween_type in frameline.get_frame_blocks():
715 if start_idx == stop_idx: 743 if start_idx == stop_idx:
716 scene_node = frameline.get_frame_data(start_idx) 744 scene_node = frameline.get_frame_data(start_idx)
717 scene_group_id = scene_node.getAttribute('ref') 745 scene_group_id = scene_node.getAttribute('ref')
725 frameline.duplicateGroup.setAttribute("style","display:none") 753 frameline.duplicateGroup.setAttribute("style","display:none")
726 scene_node = frameline.get_frame_data(start_idx) 754 scene_node = frameline.get_frame_data(start_idx)
727 scene_group_id = scene_node.getAttribute('ref') 755 scene_group_id = scene_node.getAttribute('ref')
728 scene_group = self.get_node(scene_group_id) 756 scene_group = self.get_node(scene_group_id)
729 scene_group.setAttribute("style","") 757 scene_group.setAttribute("style","")
730 elif start_idx <= idx and stop_idx >= idx: 758 elif start_idx < idx and stop_idx >= idx:
731 scene_node = frameline.get_frame_data(start_idx) 759 scene_node = frameline.get_frame_data(start_idx)
732 scene_group_id = scene_node.getAttribute('ref') 760 scene_group_id = scene_node.getAttribute('ref')
733 scene_group = self.get_node(scene_group_id) 761 scene_group = self.get_node(scene_group_id)
734 scene_group.setAttribute("style","display:none") 762 scene_group.setAttribute("style","display:none")
735 frameline.duplicateGroup.setAttribute("style","") 763 frameline.duplicateGroup.setAttribute("style","")
750 next_scene_group_id = next_scene_node.getAttribute('ref') 778 next_scene_group_id = next_scene_node.getAttribute('ref')
751 next_scene_group = self.get_node(next_scene_group_id) 779 next_scene_group = self.get_node(next_scene_group_id)
752 780
753 nframes = stop_idx - start_idx + 1 781 nframes = stop_idx - start_idx + 1
754 percent = float(idx - start_idx) / nframes 782 percent = float(idx - start_idx) / nframes
783 print tween_obj_tween_type
755 self.tween.updateTweenContent(frameline.duplicateGroup, 784 self.tween.updateTweenContent(frameline.duplicateGroup,
756 tween_obj_tween_type, 785 tween_obj_tween_type,
757 scene_group, 786 scene_group,
758 next_scene_node, 787 next_scene_group,
759 percent) 788 percent)
760 else: 789 else:
761 scene_node = frameline.get_frame_data(start_idx) 790 scene_node = frameline.get_frame_data(start_idx)
762 scene_group_id = scene_node.getAttribute('ref') 791 scene_group_id = scene_node.getAttribute('ref')
763 scene_group = self.get_node(scene_group_id) 792 scene_group = self.get_node(scene_group_id)
869 line.set_size_request(nframes * 10, 20) 898 line.set_size_request(nframes * 10, 20)
870 vbox.pack_start(hbox, False) 899 vbox.pack_start(hbox, False)
871 line.label = label 900 line.label = label
872 self._framelines.append(line) 901 self._framelines.append(line)
873 line.connect(line.FRAME_BUT_PRESS, self.onCellClick) 902 line.connect(line.FRAME_BUT_PRESS, self.onCellClick)
874 line.nLayer = i 903 line.layer_idx = i
875 line.layer_group = self.layers[i].group 904 line.layer_group = self.layers[i].group
876 line.layer = self.layers[i] 905 line.layer = self.layers[i]
877 line.connect('motion-notify-event', self._remove_active_frame) 906 line.connect('motion-notify-event', self._remove_active_frame)
878 pass 907 pass
879 vbox.show_all() 908 vbox.show_all()
1032 glib.source_remove(self.last_update) 1061 glib.source_remove(self.last_update)
1033 self._lockui = False 1062 self._lockui = False
1034 pass 1063 pass
1035 1064
1036 def doRunNext(self): 1065 def doRunNext(self):
1037 if self.current >= self.maxframe: 1066 if self.current > self.maxframe:
1038 self.current = 0 1067 self.current = 0
1039 try: 1068 try:
1040 self.setCurrentScene(self.current) 1069 self.setCurrentScene(self.current)
1041 except: 1070 except:
1042 traceback.print_exc() 1071 traceback.print_exc()
1043 raise 1072 raise
1073 self.current = self.current + 1
1044 self.last_update = glib.timeout_add(1000/self.framerate,self.doRunNext) 1074 self.last_update = glib.timeout_add(1000/self.framerate,self.doRunNext)
1045 1075
1046 def doInsertScene(self,w): 1076 def doInsertScene(self,w):
1047 self._lockui=True 1077 self._lockui=True
1048 self.last_line.insert_frame(self.last_frame) 1078 self.last_line.insert_frame(self.last_frame)
1103 type_name = self._tween_type_names[type_idx] 1133 type_name = self._tween_type_names[type_idx]
1104 1134
1105 frameline.tween(start, tween_type) 1135 frameline.tween(start, tween_type)
1106 1136
1107 scene_node = frameline.get_frame_data(start) 1137 scene_node = frameline.get_frame_data(start)
1108 scene_node.setAttribute('type', type_name) 1138 self._chg_scene_node(scene_node, tween_type=type_name)
1109 pass 1139 pass
1110 1140
1111 def addTweenTypeSelector(self,hbox): 1141 def addTweenTypeSelector(self,hbox):
1112 tweenbox = gtk.HBox() 1142 tweenbox = gtk.HBox()
1113 label = gtk.Label('Tween Type') 1143 label = gtk.Label('Tween Type')