Mercurial > MadButterfly
comparison pyink/MBScene.py @ 1183:e8446e138427
Move update_scenes_of_dom() to MBScene_dom
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Fri, 31 Dec 2010 12:37:30 +0800 |
parents | 8b0e5e8a6b0c |
children | 05d33f0fbc76 |
comparison
equal
deleted
inserted
replaced
1182:8b0e5e8a6b0c | 1183:e8446e138427 |
---|---|
154 pass | 154 pass |
155 | 155 |
156 ## \brief Layer of MBScene to manipulate DOM tree. | 156 ## \brief Layer of MBScene to manipulate DOM tree. |
157 # | 157 # |
158 class MBScene_dom(object): | 158 class MBScene_dom(object): |
159 def newID(self): | |
160 while True: | |
161 n = 's%d' % int(random.random()*10000) | |
162 #print "try %s" % n | |
163 if self.ID.has_key(n) == False: | |
164 return n | |
165 pass | |
166 pass | |
167 | |
168 def dumpID(self): | |
169 for a,v in self.ID.items(): | |
170 pass | |
171 pass | |
172 | |
159 def dumpattr(self, n): | 173 def dumpattr(self, n): |
160 s = "" | 174 s = "" |
161 for a,v in n.attrib.items(): | 175 for a,v in n.attrib.items(): |
162 s = s + ("%s=%s" % (a,v)) | 176 s = s + ("%s=%s" % (a,v)) |
163 pass | 177 pass |
273 ns.setAttribute("inkscape:groupmode","layer") | 287 ns.setAttribute("inkscape:groupmode","layer") |
274 line.node.appendChild(ns) | 288 line.node.appendChild(ns) |
275 line.add_keyframe(frame, ns) | 289 line.add_keyframe(frame, ns) |
276 self.update_scenes_of_dom() | 290 self.update_scenes_of_dom() |
277 pass | 291 pass |
292 | |
293 def add_scene_on_dom(self, frameline, scenes_node): | |
294 doc = self.document | |
295 for start_idx, stop_idx, tween_type in frameline.get_frame_blocks(): | |
296 ref = frameline.get_frame_data(start_idx) | |
297 tween_type_idx = self._frameline_tween_types.index(tween_type) | |
298 tween_type_name = self._tween_type_names[tween_type_idx] | |
299 | |
300 scene_node = doc.createElement("ns0:scene") | |
301 scenes_node.appendChild(scene_node) | |
302 scene_node.setAttribute("start", str(start_idx + 1)) | |
303 if start_idx != stop_idx: | |
304 scene_node.setAttribute("end", str(stop_idx + 1)) | |
305 pass | |
306 scene_node.setAttribute("ref", ref.attribute("id")) | |
307 scene_node.setAttribute("type", tween_type_name) | |
308 pass | |
309 pass | |
310 | |
311 def update_scenes_of_dom(self): | |
312 doc = self.root | |
313 rdoc = self.document | |
314 for node in doc.childList(): | |
315 if node.name() == 'svg:metadata': | |
316 for t in node.childList(): | |
317 if t.name() == "ns0:scenes": | |
318 node.removeChild(t) | |
319 scenes = rdoc.createElement("ns0:scenes") | |
320 node.appendChild(scenes) | |
321 for layer in range(0, len(self._framelines)): | |
322 lobj = self._framelines[layer] | |
323 self.add_scene_on_dom(lobj, scenes) | |
324 pass | |
325 pass | |
326 pass | |
327 pass | |
328 pass | |
329 pass | |
278 pass | 330 pass |
279 | 331 |
280 class MBScene(MBScene_dom): | 332 class MBScene(MBScene_dom): |
281 _frameline_tween_types = (frameline.TWEEN_TYPE_NONE, | 333 _frameline_tween_types = (frameline.TWEEN_TYPE_NONE, |
282 frameline.TWEEN_TYPE_SHAPE) | 334 frameline.TWEEN_TYPE_SHAPE) |
327 vbox.pack_start(gtk.Label(msg)) | 379 vbox.pack_start(gtk.Label(msg)) |
328 self.button = gtk.Button('OK') | 380 self.button = gtk.Button('OK') |
329 vbox.pack_start(self.button) | 381 vbox.pack_start(self.button) |
330 self.button.connect("clicked", self.onQuit) | 382 self.button.connect("clicked", self.onQuit) |
331 self.window.add(vbox) | 383 self.window.add(vbox) |
332 pass | |
333 | |
334 def update_scenes_of_dom(self): | |
335 doc = self.root | |
336 rdoc = self.document | |
337 for node in doc.childList(): | |
338 if node.name() == 'svg:metadata': | |
339 for t in node.childList(): | |
340 if t.name() == "ns0:scenes": | |
341 node.removeChild(t) | |
342 scenes = rdoc.createElement("ns0:scenes") | |
343 node.appendChild(scenes) | |
344 for layer in range(0, len(self._framelines)): | |
345 lobj = self._framelines[layer] | |
346 self.add_scene_on_dom(lobj, scenes) | |
347 pass | |
348 pass | |
349 pass | |
350 pass | |
351 pass | |
352 pass | 384 pass |
353 | 385 |
354 def parseScene(self): | 386 def parseScene(self): |
355 """ | 387 """ |
356 In this function, we will collect all items for the current | 388 In this function, we will collect all items for the current |
433 self.ID[node.getAttribute('id')] = 1 | 465 self.ID[node.getAttribute('id')] = 1 |
434 except: | 466 except: |
435 pass | 467 pass |
436 for n in node.childList(): | 468 for n in node.childList(): |
437 self.collectID_recursive(n) | 469 self.collectID_recursive(n) |
438 pass | |
439 pass | |
440 | |
441 def newID(self): | |
442 while True: | |
443 n = 's%d' % int(random.random()*10000) | |
444 #print "try %s" % n | |
445 if self.ID.has_key(n) == False: | |
446 return n | |
447 pass | |
448 pass | |
449 | |
450 def dumpID(self): | |
451 for a,v in self.ID.items(): | |
452 pass | 470 pass |
453 pass | 471 pass |
454 | 472 |
455 def getLayer(self, layer): | 473 def getLayer(self, layer): |
456 for l in self.layers: | 474 for l in self.layers: |
1018 def onOK(self,event): | 1036 def onOK(self,event): |
1019 self.OK = True | 1037 self.OK = True |
1020 gtk.main_quit() | 1038 gtk.main_quit() |
1021 pass | 1039 pass |
1022 | 1040 |
1023 def add_scene_on_dom(self, frameline, scenes_node): | |
1024 doc = self.document | |
1025 for start_idx, stop_idx, tween_type in frameline.get_frame_blocks(): | |
1026 ref = frameline.get_frame_data(start_idx) | |
1027 tween_type_idx = self._frameline_tween_types.index(tween_type) | |
1028 tween_type_name = self._tween_type_names[tween_type_idx] | |
1029 | |
1030 scene_node = doc.createElement("ns0:scene") | |
1031 scenes_node.appendChild(scene_node) | |
1032 scene_node.setAttribute("start", str(start_idx + 1)) | |
1033 if start_idx != stop_idx: | |
1034 scene_node.setAttribute("end", str(stop_idx + 1)) | |
1035 pass | |
1036 scene_node.setAttribute("ref", ref.attribute("id")) | |
1037 scene_node.setAttribute("type", tween_type_name) | |
1038 pass | |
1039 pass | |
1040 | |
1041 def updateUI(self,node=None,arg=None): | 1041 def updateUI(self,node=None,arg=None): |
1042 if self.lockui: return | 1042 if self.lockui: return |
1043 | 1043 |
1044 if self.last_update!= None: | 1044 if self.last_update!= None: |
1045 glib.source_remove(self.last_update) | 1045 glib.source_remove(self.last_update) |