Mercurial > MadButterfly
comparison pyink/MBScene.py @ 1222:03daff2d939c
Add a space after every comma in an argument list
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Thu, 06 Jan 2011 09:37:24 +0800 |
parents | 9425733a677e |
children | ec964cf4c993 |
comparison
equal
deleted
inserted
replaced
1220:9425733a677e | 1222:03daff2d939c |
---|---|
41 # - 5. If this scene are filled screne, we will split the existing | 41 # - 5. If this scene are filled screne, we will split the existing |
42 # scene into two scenes with the same content. | 42 # scene into two scenes with the same content. |
43 # | 43 # |
44 | 44 |
45 class Layer: | 45 class Layer: |
46 def __init__(self,node): | 46 def __init__(self, node): |
47 self.scenes = [] | 47 self.scenes = [] |
48 self.group = node | 48 self.group = node |
49 pass | 49 pass |
50 pass | 50 pass |
51 | 51 |
52 class ObjectWatcher(pybInkscape.PYNodeObserver): | 52 class ObjectWatcher(pybInkscape.PYNodeObserver): |
53 def __init__(self,obj,type,func,arg): | 53 def __init__(self, obj, type, func, arg): |
54 self.obj = obj | 54 self.obj = obj |
55 self.type = type | 55 self.type = type |
56 self.func = func | 56 self.func = func |
57 self.arg = arg | 57 self.arg = arg |
58 | 58 |
69 self.func(node) | 69 self.func(node) |
70 def notifyAttributeChanged(self,node, name, old_value, new_value): | 70 def notifyAttributeChanged(self,node, name, old_value, new_value): |
71 if self.type == 'DOMAttrModified': | 71 if self.type == 'DOMAttrModified': |
72 self.func(node, name, old_value, new_value) | 72 self.func(node, name, old_value, new_value) |
73 | 73 |
74 def addEventListener(obj, type, func,arg): | 74 def addEventListener(obj, type, func, arg): |
75 obs = ObjectWatcher(obj,type,func,arg) | 75 obs = ObjectWatcher(obj, type, func, arg) |
76 obj.addSubtreeObserver(obs) | 76 obj.addSubtreeObserver(obs) |
77 | 77 pass |
78 | 78 |
79 def _travel_DOM(node): | 79 def _travel_DOM(node): |
80 nodes = [node] | 80 nodes = [node] |
81 while nodes: | 81 while nodes: |
82 node = nodes.pop(0) | 82 node = nodes.pop(0) |
106 def _start_monitor(self): | 106 def _start_monitor(self): |
107 self._collect_node_ids() | 107 self._collect_node_ids() |
108 self._collect_all_scenes() | 108 self._collect_all_scenes() |
109 | 109 |
110 doc = self._doc | 110 doc = self._doc |
111 addEventListener(doc,'DOMNodeInserted', self._on_insert_node, None) | 111 addEventListener(doc, 'DOMNodeInserted', self._on_insert_node, None) |
112 addEventListener(doc,'DOMNodeRemoved', self._on_remove_node, None) | 112 addEventListener(doc, 'DOMNodeRemoved', self._on_remove_node, None) |
113 addEventListener(doc, 'DOMAttrModified', self._on_attr_modified, None) | 113 addEventListener(doc, 'DOMAttrModified', self._on_attr_modified, None) |
114 pass | 114 pass |
115 | 115 |
116 def _on_insert_node(self, node, child): | 116 def _on_insert_node(self, node, child): |
117 try: | 117 try: |
1170 self.current = self.current + 1 | 1170 self.current = self.current + 1 |
1171 tmout = 1000 / self.framerate | 1171 tmout = 1000 / self.framerate |
1172 self.last_update = glib.timeout_add(tmout, self.doRunNext) | 1172 self.last_update = glib.timeout_add(tmout, self.doRunNext) |
1173 pass | 1173 pass |
1174 | 1174 |
1175 def remove_frame(self,line,frame): | 1175 def remove_frame(self, line, frame): |
1176 for start, end, tween_type in line.get_frame_blocks(): | 1176 for start, end, tween_type in line.get_frame_blocks(): |
1177 if frame > end: | 1177 if frame > end: |
1178 # Don't change the tween before the select frame | 1178 # Don't change the tween before the select frame |
1179 continue | 1179 continue |
1180 elif frame == start: | 1180 elif frame == start: |
1181 # Please use remove key frame ro remove the key frame instead | 1181 # Please use remove key frame ro remove the key frame instead |
1182 return | 1182 return |
1183 elif frame < start: | 1183 elif frame < start: |
1184 # For all tweens after the frame, shift both key frames by one | 1184 # For all tweens after the frame, shift both key frames by one |
1185 scene_node = line.get_frame_data(start) | 1185 scene_node = line.get_frame_data(start) |
1186 self.chg_scene_node(scene_node, start=start-1,end=end-1) | 1186 self.chg_scene_node(scene_node, start=start-1, end=end-1) |
1187 line.rm_keyframe(start) | 1187 line.rm_keyframe(start) |
1188 | 1188 |
1189 if start != end: | 1189 if start != end: |
1190 line.rm_keyframe(end) | 1190 line.rm_keyframe(end) |
1191 line.add_keyframe(start-1) | 1191 line.add_keyframe(start-1) |
1192 line.set_frame_data(start-1,scene_node) | 1192 line.set_frame_data(start-1, scene_node) |
1193 if start != end: | 1193 if start != end: |
1194 line.add_keyframe(end-1) | 1194 line.add_keyframe(end-1) |
1195 line.tween(start-1,tween_type) | 1195 line.tween(start-1, tween_type) |
1196 pass | 1196 pass |
1197 else: | 1197 else: |
1198 # For the tween contain the frame, remove the end keyframe | 1198 # For the tween contain the frame, remove the end keyframe |
1199 # and put it back one frame before. The tween is removed | 1199 # and put it back one frame before. The tween is removed |
1200 # if the tween has one frame only. In this case, keep only | 1200 # if the tween has one frame only. In this case, keep only |
1201 # the start key frame and remove the second one. | 1201 # the start key frame and remove the second one. |
1202 scene_node = line.get_frame_data(start) | 1202 scene_node = line.get_frame_data(start) |
1203 self.chg_scene_node(scene_node,end=end-1) | 1203 self.chg_scene_node(scene_node, end=end-1) |
1204 line.rm_keyframe(end) | 1204 line.rm_keyframe(end) |
1205 if start != end-1: | 1205 if start != end-1: |
1206 line.add_keyframe(end-1) | 1206 line.add_keyframe(end-1) |
1207 line.tween(start,tween_type) | 1207 line.tween(start, tween_type) |
1208 pass | 1208 pass |
1209 pass | 1209 pass |
1210 pass | 1210 pass |
1211 | 1211 |
1212 def insert_frame(self,line,frame): | 1212 def insert_frame(self, line, frame): |
1213 for start, end, tween_type in line.get_frame_blocks(): | 1213 for start, end, tween_type in line.get_frame_blocks(): |
1214 print "start=",start | 1214 print "start=",start |
1215 print "end=",end | 1215 print "end=",end |
1216 if frame > end: | 1216 if frame > end: |
1217 # Don't change the tween before the select frame | 1217 # Don't change the tween before the select frame |
1218 continue | 1218 continue |
1219 elif frame <= start: | 1219 elif frame <= start: |
1220 # For all tweens after the frame, shift both key frames by one | 1220 # For all tweens after the frame, shift both key frames by one |
1221 scene_node = line.get_frame_data(start) | 1221 scene_node = line.get_frame_data(start) |
1222 if scene_node==None: continue | 1222 if scene_node==None: continue |
1223 self.chg_scene_node(scene_node,start=start+1,end=end+1) | 1223 self.chg_scene_node(scene_node, start=start+1, end=end+1) |
1224 line.rm_keyframe(start) | 1224 line.rm_keyframe(start) |
1225 if start != end: | 1225 if start != end: |
1226 line.rm_keyframe(end) | 1226 line.rm_keyframe(end) |
1227 line.add_keyframe(start+1) | 1227 line.add_keyframe(start+1) |
1228 line.set_frame_data(start+1,scene_node) | 1228 line.set_frame_data(start+1,scene_node) |
1234 # For the tween contain the frame, remove the end keyframe | 1234 # For the tween contain the frame, remove the end keyframe |
1235 # and put it back one frame before. The tween is removed | 1235 # and put it back one frame before. The tween is removed |
1236 # if the tween has one frame only. In this case, keep only | 1236 # if the tween has one frame only. In this case, keep only |
1237 # the start key frame and remove the second one. | 1237 # the start key frame and remove the second one. |
1238 scene_node = line.get_frame_data(start) | 1238 scene_node = line.get_frame_data(start) |
1239 self.chg_scene_node(scene_node,end=end+1) | 1239 self.chg_scene_node(scene_node, end=end+1) |
1240 line.rm_keyframe(end) | 1240 line.rm_keyframe(end) |
1241 line.add_keyframe(end+1) | 1241 line.add_keyframe(end+1) |
1242 line.tween(start,tween_type) | 1242 line.tween(start, tween_type) |
1243 pass | 1243 pass |
1244 pass | 1244 pass |
1245 pass | 1245 pass |
1246 | 1246 |
1247 | 1247 |
1248 def doInsertFrame(self,w): | 1248 def doInsertFrame(self, w): |
1249 self.lockui=True | 1249 self.lockui=True |
1250 self.insert_frame(self.last_line,self.last_frame) | 1250 self.insert_frame(self.last_line, self.last_frame) |
1251 self.lockui=False | 1251 self.lockui=False |
1252 | 1252 |
1253 def doRemoveFrame(self,w): | 1253 def doRemoveFrame(self, w): |
1254 self.lockui=True | 1254 self.lockui=True |
1255 self.remove_frame(self.last_line,self.last_frame) | 1255 self.remove_frame(self.last_line, self.last_frame) |
1256 self.lockui=False | 1256 self.lockui=False |
1257 | 1257 |
1258 def addButtons(self,hbox): | 1258 def addButtons(self, hbox): |
1259 btn = gtk.Button('Insert Key') | 1259 btn = gtk.Button('Insert Key') |
1260 btn.connect('clicked',self.doInsertKeyScene) | 1260 btn.connect('clicked', self.doInsertKeyScene) |
1261 hbox.pack_start(btn,expand=False,fill=False) | 1261 hbox.pack_start(btn, expand=False, fill=False) |
1262 | 1262 |
1263 btn=gtk.Button('Remove Key') | 1263 btn=gtk.Button('Remove Key') |
1264 btn.connect('clicked', self.doRemoveScene) | 1264 btn.connect('clicked', self.doRemoveScene) |
1265 hbox.pack_start(btn,expand=False,fill=False) | 1265 hbox.pack_start(btn, expand=False, fill=False) |
1266 | 1266 |
1267 btn=gtk.Button('Extend scene') | 1267 btn=gtk.Button('Extend scene') |
1268 btn.connect('clicked', self.doExtendScene) | 1268 btn.connect('clicked', self.doExtendScene) |
1269 hbox.pack_start(btn,expand=False,fill=False) | 1269 hbox.pack_start(btn, expand=False, fill=False) |
1270 | 1270 |
1271 btn=gtk.Button('Duplicate Key') | 1271 btn=gtk.Button('Duplicate Key') |
1272 btn.connect('clicked', self.doDuplicateKeyScene) | 1272 btn.connect('clicked', self.doDuplicateKeyScene) |
1273 hbox.pack_start(btn,expand=False,fill=False) | 1273 hbox.pack_start(btn, expand=False, fill=False) |
1274 | 1274 |
1275 btn=gtk.Button('insert') | 1275 btn=gtk.Button('insert') |
1276 btn.connect('clicked', self.doInsertFrame) | 1276 btn.connect('clicked', self.doInsertFrame) |
1277 hbox.pack_start(btn,expand=False,fill=False) | 1277 hbox.pack_start(btn, expand=False, fill=False) |
1278 | 1278 |
1279 btn=gtk.Button('remove') | 1279 btn=gtk.Button('remove') |
1280 btn.connect('clicked', self.doRemoveFrame) | 1280 btn.connect('clicked', self.doRemoveFrame) |
1281 hbox.pack_start(btn,expand=False,fill=False) | 1281 hbox.pack_start(btn, expand=False, fill=False) |
1282 | 1282 |
1283 btn=gtk.Button('Run') | 1283 btn=gtk.Button('Run') |
1284 btn.connect('clicked', self.doRun) | 1284 btn.connect('clicked', self.doRun) |
1285 self.btnRun = btn | 1285 self.btnRun = btn |
1286 hbox.pack_start(btn,expand=False,fill=False) | 1286 hbox.pack_start(btn, expand=False, fill=False) |
1287 | 1287 |
1288 self.addNameEditor(hbox) | 1288 self.addNameEditor(hbox) |
1289 self.addTweenTypeSelector(hbox) | 1289 self.addTweenTypeSelector(hbox) |
1290 pass | 1290 pass |
1291 | 1291 |
1306 | 1306 |
1307 scene_node = frameline.get_frame_data(start) | 1307 scene_node = frameline.get_frame_data(start) |
1308 self.chg_scene_node(scene_node, tween_type=type_name) | 1308 self.chg_scene_node(scene_node, tween_type=type_name) |
1309 pass | 1309 pass |
1310 | 1310 |
1311 def addTweenTypeSelector(self,hbox): | 1311 def addTweenTypeSelector(self, hbox): |
1312 tweenbox = gtk.HBox() | 1312 tweenbox = gtk.HBox() |
1313 label = gtk.Label('Tween Type') | 1313 label = gtk.Label('Tween Type') |
1314 tweenbox.pack_start(label) | 1314 tweenbox.pack_start(label) |
1315 | 1315 |
1316 self.tweenTypeSelector = gtk.combo_box_new_text() | 1316 self.tweenTypeSelector = gtk.combo_box_new_text() |
1317 self.tweenTypeSelector.append_text('normal') | 1317 self.tweenTypeSelector.append_text('normal') |
1318 #self.tweenTypeSelector.append_text('relocate') | 1318 #self.tweenTypeSelector.append_text('relocate') |
1319 self.tweenTypeSelector.append_text('scale') | 1319 self.tweenTypeSelector.append_text('scale') |
1320 self.tweenTypeSelector.set_active(0) | 1320 self.tweenTypeSelector.set_active(0) |
1321 tweenbox.pack_start(self.tweenTypeSelector, expand=False,fill=False) | 1321 tweenbox.pack_start(self.tweenTypeSelector, expand=False, fill=False) |
1322 hbox.pack_start(tweenbox,expand=False,fill=False) | 1322 hbox.pack_start(tweenbox, expand=False, fill=False) |
1323 self.tweenTypeSelector.connect('changed', self.onTweenTypeChange) | 1323 self.tweenTypeSelector.connect('changed', self.onTweenTypeChange) |
1324 pass | 1324 pass |
1325 | 1325 |
1326 def onQuit(self, event): | 1326 def onQuit(self, event): |
1327 self.OK = False | 1327 self.OK = False |
1328 gtk.main_quit() | 1328 gtk.main_quit() |
1329 pass | 1329 pass |
1330 | 1330 |
1331 def onOK(self,event): | 1331 def onOK(self, event): |
1332 self.OK = True | 1332 self.OK = True |
1333 gtk.main_quit() | 1333 gtk.main_quit() |
1334 pass | 1334 pass |
1335 | 1335 |
1336 def show(self): | 1336 def show(self): |
1345 self._init_framelines() | 1345 self._init_framelines() |
1346 self._add_frameline_for_every_layer() | 1346 self._add_frameline_for_every_layer() |
1347 self._show_framelines() | 1347 self._show_framelines() |
1348 | 1348 |
1349 if self.top == None: | 1349 if self.top == None: |
1350 self.top = gtk.VBox(False,0) | 1350 self.top = gtk.VBox(False, 0) |
1351 toplevel = self.desktop.getToplevel() | 1351 toplevel = self.desktop.getToplevel() |
1352 toplevel.child.child.pack_end(self.top,expand=False) | 1352 toplevel.child.child.pack_end(self.top, expand=False) |
1353 else: | 1353 else: |
1354 self.top.remove(self.startWindow) | 1354 self.top.remove(self.startWindow) |
1355 pass | 1355 pass |
1356 | 1356 |
1357 vbox = gtk.VBox(False,0) | 1357 vbox = gtk.VBox(False, 0) |
1358 self.startWindow = vbox | 1358 self.startWindow = vbox |
1359 self.top.pack_start(vbox,expand=False) | 1359 self.top.pack_start(vbox, expand=False) |
1360 vbox.pack_start(self._frameline_box,expand=False) | 1360 vbox.pack_start(self._frameline_box, expand=False) |
1361 hbox=gtk.HBox(False,0) | 1361 hbox=gtk.HBox(False, 0) |
1362 self.addButtons(hbox) | 1362 self.addButtons(hbox) |
1363 vbox.pack_start(hbox,expand=False) | 1363 vbox.pack_start(hbox, expand=False) |
1364 | 1364 |
1365 doc = self.document | 1365 doc = self.document |
1366 addEventListener(doc,'DOMNodeInserted', self.updateUI, None) | 1366 addEventListener(doc,'DOMNodeInserted', self.updateUI, None) |
1367 addEventListener(doc,'DOMNodeRemoved', self.updateUI, None) | 1367 addEventListener(doc,'DOMNodeRemoved', self.updateUI, None) |
1368 | 1368 |