comparison pyink/MBScene.py @ 961:b6375e74c69e

Rename MBScene.layer to MBScene.layers
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 17 Nov 2010 17:10:07 +0800
parents 8fd97e0becb3
children 6612fd386ea9
comparison
equal deleted inserted replaced
960:8fd97e0becb3 961:b6375e74c69e
57 57
58 class MBScene(): 58 class MBScene():
59 def __init__(self,desktop,win): 59 def __init__(self,desktop,win):
60 self.desktop = desktop 60 self.desktop = desktop
61 self.window = win 61 self.window = win
62 self.layer = [] 62 self.layers = []
63 self.layer.append(Layer(None)) 63 self.layers.append(Layer(None))
64 self.scenemap = None 64 self.scenemap = None
65 pass 65 pass
66 66
67 def confirm(self,msg): 67 def confirm(self,msg):
68 vbox = gtk.VBox() 68 vbox = gtk.VBox()
130 """ 130 """
131 In this function, we will collect all items for the current 131 In this function, we will collect all items for the current
132 scene and then relocate them back to the appropriate scene 132 scene and then relocate them back to the appropriate scene
133 object. 133 object.
134 """ 134 """
135 self.layer = [] 135 self.layers = []
136 self.scenemap = None 136 self.scenemap = None
137 doc = self.desktop.doc().root() 137 doc = self.desktop.doc().root()
138 138
139 for node in doc.childList(): 139 for node in doc.childList():
140 if node.repr.name() == 'svg:metadata': 140 if node.repr.name() == 'svg:metadata':
142 pass 142 pass
143 elif node.repr.name() == 'svg:g': 143 elif node.repr.name() == 'svg:g':
144 oldscene = None 144 oldscene = None
145 #print layer.attrib.get("id") 145 #print layer.attrib.get("id")
146 lyobj = Layer(node) 146 lyobj = Layer(node)
147 self.layer.append(lyobj) 147 self.layers.append(lyobj)
148 lyobj.current_scene = [] 148 lyobj.current_scene = []
149 for scene in node.childList(): 149 for scene in node.childList():
150 if scene.repr.name() == 'svg:g': 150 if scene.repr.name() == 'svg:g':
151 try: 151 try:
152 scmap = self.scenemap[scene.getId()] 152 scmap = self.scenemap[scene.getId()]
210 print a 210 print a
211 pass 211 pass
212 pass 212 pass
213 213
214 def getLayer(self, layer): 214 def getLayer(self, layer):
215 for l in self.layer: 215 for l in self.layers:
216 if l.node.getId() == layer: 216 if l.node.getId() == layer:
217 return l 217 return l
218 pass 218 pass
219 return None 219 return None
220 220
395 pass 395 pass
396 pass 396 pass
397 397
398 def setCurrentScene(self,nth): 398 def setCurrentScene(self,nth):
399 self.current = nth 399 self.current = nth
400 for layer in self.layer: 400 for layer in self.layers:
401 for s in layer.scene: 401 for s in layer.scene:
402 if nth >= s.start and nth <= s.end: 402 if nth >= s.start and nth <= s.end:
403 s.node.repr.setAttribute("style","",True) 403 s.node.repr.setAttribute("style","",True)
404 # print "Put the elemenets out" 404 # print "Put the elemenets out"
405 layer.nodes = [] 405 layer.nodes = []
425 for nn in n: 425 for nn in n:
426 if nn.tag == _scenes: 426 if nn.tag == _scenes:
427 nn.clear() 427 nn.clear()
428 nn.set("current", "%d" % self.current) 428 nn.set("current", "%d" % self.current)
429 scenes = [] 429 scenes = []
430 for l in self.layer: 430 for l in self.layers:
431 for s in l.scene: 431 for s in l.scene:
432 id = s.node.get("id") 432 id = s.node.get("id")
433 scene = etree.Element(_scene) 433 scene = etree.Element(_scene)
434 scene.set("ref", id) 434 scene.set("ref", id)
435 if s.start == s.end: 435 if s.start == s.end:
449 pass 449 pass
450 pass 450 pass
451 if has_scene == False: 451 if has_scene == False:
452 scenes = etree.Element(_scenes) 452 scenes = etree.Element(_scenes)
453 scenes.set("current","%d" % self.current) 453 scenes.set("current","%d" % self.current)
454 for l in self.layer: 454 for l in self.layers:
455 for s in l.scene: 455 for s in l.scene:
456 scene = etree.Element(_scene) 456 scene = etree.Element(_scene)
457 scene.set("ref", s.node.get("id")) 457 scene.set("ref", s.node.get("id"))
458 if s.start == s.end: 458 if s.start == s.end:
459 scene.set("start", "%d" % s.start) 459 scene.set("start", "%d" % s.start)
470 if n.tag == '{http://www.w3.org/2000/svg}g': 470 if n.tag == '{http://www.w3.org/2000/svg}g':
471 root.remove(n) 471 root.remove(n)
472 pass 472 pass
473 pass 473 pass
474 474
475 for l in self.layer: 475 for l in self.layers:
476 # Duplicate all attribute of the layer 476 # Duplicate all attribute of the layer
477 lnode = etree.Element("{http://www.w3.org/2000/svg}g") 477 lnode = etree.Element("{http://www.w3.org/2000/svg}g")
478 for a,v in l.node.attrib.items(): 478 for a,v in l.node.attrib.items():
479 lnode.set(a,v) 479 lnode.set(a,v)
480 pass 480 pass
524 524
525 # 525 #
526 # Add a frameline for each layer 526 # Add a frameline for each layer
527 # 527 #
528 self._framelines = [] 528 self._framelines = []
529 for i in range(len(self.layer)): 529 for i in range(len(self.layers)):
530 line = frameline.frameline(nframes) 530 line = frameline.frameline(nframes)
531 line.set_size_request(nframes * 10, 20) 531 line.set_size_request(nframes * 10, 20)
532 vbox.pack_start(line, False) 532 vbox.pack_start(line, False)
533 self._framelines.append(line) 533 self._framelines.append(line)
534 pass 534 pass
537 def update_framelines(self): 537 def update_framelines(self):
538 pass 538 pass
539 539
540 def showGrid(self): 540 def showGrid(self):
541 max = 0 541 max = 0
542 for layer in self.layer: 542 for layer in self.layers:
543 for s in layer.scene: 543 for s in layer.scene:
544 if s.end > max: 544 if s.end > max:
545 max = s.end 545 max = s.end
546 pass 546 pass
547 pass 547 pass
548 pass 548 pass
549 max = 50 549 max = 50
550 550
551 self.grid = gtk.Table(len(self.layer)+1, 50) 551 self.grid = gtk.Table(len(self.layers)+1, 50)
552 self.scrollwin = gtk.ScrolledWindow() 552 self.scrollwin = gtk.ScrolledWindow()
553 self.scrollwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) 553 self.scrollwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
554 self.scrollwin.add_with_viewport(self.grid) 554 self.scrollwin.add_with_viewport(self.grid)
555 self.scrollwin.set_size_request(-1,150) 555 self.scrollwin.set_size_request(-1,150)
556 for i in range(1,max): 556 for i in range(1,max):
557 self.grid.attach(gtk.Label('%d'% i), i,i+1,0,1,0,0,0,0) 557 self.grid.attach(gtk.Label('%d'% i), i,i+1,0,1,0,0,0,0)
558 pass 558 pass
559 for i in range(1,len(self.layer)+1): 559 for i in range(1,len(self.layers)+1):
560 print "Layer", i 560 print "Layer", i
561 l = self.layer[i-1] 561 l = self.layers[i-1]
562 for s in l.scene: 562 for s in l.scene:
563 btn = self.newCell('start.png') 563 btn = self.newCell('start.png')
564 btn.nScene = s.start 564 btn.nScene = s.start
565 btn.layer = l.node.getId() 565 btn.layer = l.node.getId()
566 btn.nLayer = i 566 btn.nLayer = i