comparison pyink/MBScene.py @ 1181:f14dbcf19e2b

Move MBScene.insertKeyScene() to MBScene_dom
author Thinker K.F. Li <thinker@codemud.net>
date Fri, 31 Dec 2010 12:21:27 +0800
parents bfd7d466a022
children 8b0e5e8a6b0c
comparison
equal deleted inserted replaced
1180:bfd7d466a022 1181:f14dbcf19e2b
151 pass 151 pass
152 yield node 152 yield node
153 pass 153 pass
154 pass 154 pass
155 155
156 ## \brief Layer of MBScene to manipulate DOM tree.
157 #
156 class MBScene_dom(object): 158 class MBScene_dom(object):
157 def dumpattr(self, n): 159 def dumpattr(self, n):
158 s = "" 160 s = ""
159 for a,v in n.attrib.items(): 161 for a,v in n.attrib.items():
160 s = s + ("%s=%s" % (a,v)) 162 s = s + ("%s=%s" % (a,v))
223 ns = "http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd" 225 ns = "http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd"
224 self.root.setAttribute("xmlns:ns0", ns) 226 self.root.setAttribute("xmlns:ns0", ns)
225 scenes = self.document.createElement("ns0:scenes") 227 scenes = self.document.createElement("ns0:scenes")
226 node.appendChild(scenes) 228 node.appendChild(scenes)
227 pass 229 pass
230 pass
231
232 def insertKeyScene(self, line, frame):
233 """
234 Insert a new key scene into the stage. If the nth is always a
235 key scene, we will return without changing anything. If the
236 nth is a filled scene, we will break the original scene into
237 two parts. If the nth is out of any scene, we will append a
238 new scene.
239
240 """
241 rdoc = self.document
242 ns = rdoc.createElement("svg:g")
243 found = False
244 for node in line.node.childList():
245 try:
246 label = node.getAttribute("inkscape:label")
247 except:
248 continue
249 if label == "dup":
250 #FIXME: The duplication here is not perfect. We should
251 # get the element inside the group and apply the
252 # transformation matrix to it directly.
253 for n in node.childList():
254 ns.appendChild(n.duplicate(self.document))
255 found = True
256 node.setAttribute("style","display:none")
257 break
258 pass
259 pass
260
261 if found == False:
262 txt = rdoc.createElement("svg:rect")
263 txt.setAttribute("x","0")
264 txt.setAttribute("y","0")
265 txt.setAttribute("width","100")
266 txt.setAttribute("height","100")
267 txt.setAttribute("style","fill:#ff00")
268 ns.appendChild(txt)
269
270 gid = line.node.getAttribute('inkscape:label')+self.newID()
271 self.ID[gid]=1
272 ns.setAttribute("id",gid)
273 ns.setAttribute("inkscape:groupmode","layer")
274 line.node.appendChild(ns)
275 line.add_keyframe(frame, ns)
276 self.update()
228 pass 277 pass
229 pass 278 pass
230 279
231 class MBScene(MBScene_dom): 280 class MBScene(MBScene_dom):
232 _frameline_tween_types = (frameline.TWEEN_TYPE_NONE, 281 _frameline_tween_types = (frameline.TWEEN_TYPE_NONE,
409 return l 458 return l
410 pass 459 pass
411 return None 460 return None
412 461
413 462
414 def insertKeyScene(self, line, frame):
415 """
416 Insert a new key scene into the stage. If the nth is always a
417 key scene, we will return without changing anything. If the
418 nth is a filled scene, we will break the original scene into
419 two parts. If the nth is out of any scene, we will append a
420 new scene.
421
422 """
423 rdoc = self.document
424 ns = rdoc.createElement("svg:g")
425 found = False
426 for node in line.node.childList():
427 try:
428 label = node.getAttribute("inkscape:label")
429 except:
430 continue
431 if label == "dup":
432 #FIXME: The duplication here is not perfect. We should
433 # get the element inside the group and apply the
434 # transformation matrix to it directly.
435 for n in node.childList():
436 ns.appendChild(n.duplicate(self.document))
437 found = True
438 node.setAttribute("style","display:none")
439 break
440 pass
441 pass
442
443 if found == False:
444 txt = rdoc.createElement("svg:rect")
445 txt.setAttribute("x","0")
446 txt.setAttribute("y","0")
447 txt.setAttribute("width","100")
448 txt.setAttribute("height","100")
449 txt.setAttribute("style","fill:#ff00")
450 ns.appendChild(txt)
451
452 gid = line.node.getAttribute('inkscape:label')+self.newID()
453 self.ID[gid]=1
454 ns.setAttribute("id",gid)
455 ns.setAttribute("inkscape:groupmode","layer")
456 line.node.appendChild(ns)
457 line.add_keyframe(frame, ns)
458 self.update()
459 pass
460
461 def removeKeyScene(self): 463 def removeKeyScene(self):
462 nth = self.last_frame 464 nth = self.last_frame
463 y = self.last_line 465 y = self.last_line
464 rdoc = self.document 466 rdoc = self.document
465 i = 0 467 i = 0