comparison pyink/MBScene.py @ 1219:b5e648a317eb

Add insert and remove frame function.
author wycc
date Wed, 05 Jan 2011 22:57:10 +0800
parents 93acb8568ad3
children 9425733a677e
comparison
equal deleted inserted replaced
1217:93acb8568ad3 1219:b5e648a317eb
791 except: 791 except:
792 print "*" * 40 792 print "*" * 40
793 layer_idx = frameline.layer_idx 793 layer_idx = frameline.layer_idx
794 layer = self._layers[layer_idx] 794 layer = self._layers[layer_idx]
795 for child in layer.group.childList(): 795 for child in layer.group.childList():
796 label = child.getAttribute('inkscape:label') 796 try:
797 if label == 'dup': 797 label = child.getAttribute('inkscape:label')
798 frameline.duplicateGroup = child 798 if label == 'dup':
799 break 799 frameline.duplicateGroup = child
800 break
801 except:
802 pass
800 pass 803 pass
801 else: 804 else:
802 duplicateGroup = self.document.createElement("svg:g") 805 duplicateGroup = self.document.createElement("svg:g")
803 duplicateGroup.setAttribute("inkscape:label","dup") 806 duplicateGroup.setAttribute("inkscape:label","dup")
804 duplicateGroup.setAttribute("sodipodi:insensitive","1") 807 duplicateGroup.setAttribute("sodipodi:insensitive","1")
1170 self.current = self.current + 1 1173 self.current = self.current + 1
1171 tmout = 1000 / self.framerate 1174 tmout = 1000 / self.framerate
1172 self.last_update = glib.timeout_add(tmout, self.doRunNext) 1175 self.last_update = glib.timeout_add(tmout, self.doRunNext)
1173 pass 1176 pass
1174 1177
1178 def remove_frame(self,line,frame):
1179 for start, end, tween_type in line.get_frame_blocks():
1180 if frame > end:
1181 # Don't change the tween before the select frame
1182 continue
1183 elif frame == start:
1184 # Please use remove key frame ro remove the key frame instead
1185 return
1186 elif frame < start:
1187 # For all tweens after the frame, shift both key frames by one
1188 scene_node = line.get_frame_data(start)
1189 self.chg_scene_node(scene_node, start=start-1,end=end-1)
1190 line.rm_keyframe(start)
1191
1192 if start != end:
1193 line.rm_keyframe(end)
1194 line.add_keyframe(start-1)
1195 line.set_frame_data(start-1,scene_node)
1196 if start != end:
1197 line.add_keyframe(end-1)
1198 line.tween(start-1,tween_type)
1199 pass
1200 else:
1201 # For the tween contain the frame, remove the end keyframe
1202 # and put it back one frame before. The tween is removed
1203 # if the tween has one frame only. In this case, keep only
1204 # the start key frame and remove the second one.
1205 scene_node = line.get_frame_data(start)
1206 self.chg_scene_node(scene_node,end=end-1)
1207 line.rm_keyframe(end)
1208 if start != end-1:
1209 line.add_keyframe(end-1)
1210 line.tween(start,tween_type)
1211 pass
1212 pass
1213 pass
1214
1215 def insert_frame(self,line,frame):
1216 for start, end, tween_type in line.get_frame_blocks():
1217 print "start=",start
1218 print "end=",end
1219 if frame > end:
1220 # Don't change the tween before the select frame
1221 continue
1222 elif frame <= start:
1223 # For all tweens after the frame, shift both key frames by one
1224 scene_node = line.get_frame_data(start)
1225 if scene_node==None: continue
1226 self.chg_scene_node(scene_node,start=start+1,end=end+1)
1227 line.rm_keyframe(start)
1228 if start != end:
1229 line.rm_keyframe(end)
1230 line.add_keyframe(start+1)
1231 line.set_frame_data(start+1,scene_node)
1232 if start != end:
1233 line.add_keyframe(end+1)
1234 line.tween(start+1,tween_type)
1235 pass
1236 else:
1237 # For the tween contain the frame, remove the end keyframe
1238 # and put it back one frame before. The tween is removed
1239 # if the tween has one frame only. In this case, keep only
1240 # the start key frame and remove the second one.
1241 scene_node = line.get_frame_data(start)
1242 self.chg_scene_node(scene_node,end=end+1)
1243 line.rm_keyframe(end)
1244 line.add_keyframe(end+1)
1245 line.tween(start,tween_type)
1246 pass
1247 pass
1248 pass
1249
1250
1251 def doInsertFrame(self,w):
1252 self.lockui=True
1253 self.insert_frame(self.last_line,self.last_frame)
1254 self.lockui=False
1255
1256 def doRemoveFrame(self,w):
1257 self.lockui=True
1258 self.remove_frame(self.last_line,self.last_frame)
1259 self.lockui=False
1260
1175 def addButtons(self,hbox): 1261 def addButtons(self,hbox):
1176 btn = gtk.Button('Insert Key') 1262 btn = gtk.Button('Insert Key')
1177 btn.connect('clicked',self.doInsertKeyScene) 1263 btn.connect('clicked',self.doInsertKeyScene)
1178 hbox.pack_start(btn,expand=False,fill=False) 1264 hbox.pack_start(btn,expand=False,fill=False)
1179 1265
1187 1273
1188 btn=gtk.Button('Duplicate Key') 1274 btn=gtk.Button('Duplicate Key')
1189 btn.connect('clicked', self.doDuplicateKeyScene) 1275 btn.connect('clicked', self.doDuplicateKeyScene)
1190 hbox.pack_start(btn,expand=False,fill=False) 1276 hbox.pack_start(btn,expand=False,fill=False)
1191 1277
1278 btn=gtk.Button('insert')
1279 btn.connect('clicked', self.doInsertFrame)
1280 hbox.pack_start(btn,expand=False,fill=False)
1281
1282 btn=gtk.Button('remove')
1283 btn.connect('clicked', self.doRemoveFrame)
1284 hbox.pack_start(btn,expand=False,fill=False)
1285
1192 btn=gtk.Button('Run') 1286 btn=gtk.Button('Run')
1193 btn.connect('clicked', self.doRun) 1287 btn.connect('clicked', self.doRun)
1194 self.btnRun = btn 1288 self.btnRun = btn
1195 hbox.pack_start(btn,expand=False,fill=False) 1289 hbox.pack_start(btn,expand=False,fill=False)
1196 1290