comparison pyink/MBScene.py @ 962:6612fd386ea9

Rename Layer.scene to Layer.scenes since it is a list of scenes
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 17 Nov 2010 17:14:22 +0800
parents b6375e74c69e
children a05ec4fb1c20
comparison
equal deleted inserted replaced
961:b6375e74c69e 962:6612fd386ea9
36 # scene into two scenes with the same content. 36 # scene into two scenes with the same content.
37 # 37 #
38 38
39 class Layer: 39 class Layer:
40 def __init__(self,node): 40 def __init__(self,node):
41 self.scene = [] 41 self.scenes = []
42 self.node = node 42 self.node = node
43 self.nodes=[] 43 self.nodes=[]
44 pass 44 pass
45 pass 45 pass
46 46
159 pass 159 pass
160 except: 160 except:
161 lyobj.current_scene.append(scene) 161 lyobj.current_scene.append(scene)
162 continue 162 continue
163 163
164 lyobj.scene.append(Scene(scene,scmap[0],scmap[1])) 164 lyobj.scenes.append(Scene(scene,scmap[0],scmap[1]))
165 pass 165 pass
166 else: 166 else:
167 lyobj.current_scene.append(scene) 167 lyobj.current_scene.append(scene)
168 pass 168 pass
169 pass 169 pass
231 nth = self.last_cell.nScene 231 nth = self.last_cell.nScene
232 layer = self.getLayer(self.last_cell.layer) 232 layer = self.getLayer(self.last_cell.layer)
233 x = self.last_cell.nScene 233 x = self.last_cell.nScene
234 y = self.last_cell.nLayer 234 y = self.last_cell.nLayer
235 if layer == None: return 235 if layer == None: return
236 for i in range(0,len(layer.scene)): 236 for i in range(0,len(layer.scenes)):
237 s = layer.scene[i] 237 s = layer.scenes[i]
238 if nth >= s.start and nth <= s.end: 238 if nth >= s.start and nth <= s.end:
239 if nth == s.start: return 239 if nth == s.start: return
240 newscene = Scene(DuplicateNode(s.node),nth,s.end) 240 newscene = Scene(DuplicateNode(s.node),nth,s.end)
241 newscene.node.setId(self.newID()) 241 newscene.node.setId(self.newID())
242 layer.scene.insert(i+1,newscene) 242 layer.scenes.insert(i+1,newscene)
243 layer.scene[i].end = nth-1 243 layer.scenes[i].end = nth-1
244 btn = self.newCell('start.png') 244 btn = self.newCell('start.png')
245 btn.nScene = nth 245 btn.nScene = nth
246 btn.layer = layer 246 btn.layer = layer
247 btn.nLayer = y 247 btn.nLayer = y
248 self.grid.remove(self.last_cell) 248 self.grid.remove(self.last_cell)
249 self.grid.attach(btn, x,x+1,y,y+1,0,0,0,0) 249 self.grid.attach(btn, x,x+1,y,y+1,0,0,0,0)
250 return 250 return
251 pass 251 pass
252 252
253 if len(layer.scene) > 0: 253 if len(layer.scenes) > 0:
254 last = nth 254 last = nth
255 lastscene = None 255 lastscene = None
256 for s in layer.scene: 256 for s in layer.scenes:
257 if s.end < nth and last < s.end: 257 if s.end < nth and last < s.end:
258 last = s.end 258 last = s.end
259 lastscene = s 259 lastscene = s
260 pass 260 pass
261 pass 261 pass
276 lastscene.end = nth-1 276 lastscene.end = nth-1
277 newscene = Scene(DuplicateNode(lastscene.node),nth,nth) 277 newscene = Scene(DuplicateNode(lastscene.node),nth,nth)
278 newscene.node.setId(self.newID()) 278 newscene.node.setId(self.newID())
279 pass 279 pass
280 280
281 layer.scene.append(newscene) 281 layer.scenes.append(newscene)
282 btn = self.newCell('start.png') 282 btn = self.newCell('start.png')
283 x = self.last_cell.nScene 283 x = self.last_cell.nScene
284 y = self.last_cell.nLayer 284 y = self.last_cell.nLayer
285 btn.nScene = nth 285 btn.nScene = nth
286 btn.layer = layer.node.getId() 286 btn.layer = layer.node.getId()
289 else: 289 else:
290 # This is the first scene in the layer 290 # This is the first scene in the layer
291 node = etree.Element(_scene) 291 node = etree.Element(_scene)
292 node.repr.setId(self.newID()) 292 node.repr.setId(self.newID())
293 newscene = Scene(node,nth,nth) 293 newscene = Scene(node,nth,nth)
294 layer.scene.append(newscene) 294 layer.scenes.append(newscene)
295 btn = self.newCell('start.png') 295 btn = self.newCell('start.png')
296 btn.nScene = nth 296 btn.nScene = nth
297 btn.layer = layer.node.getId() 297 btn.layer = layer.node.getId()
298 btn.nLayer = y 298 btn.nLayer = y
299 self.grid.attach(btn, x, x+1, y, y+1,0,0,0,0) 299 self.grid.attach(btn, x, x+1, y, y+1,0,0,0,0)
307 layer = self.getLayer(self.last_cell.layer) 307 layer = self.getLayer(self.last_cell.layer)
308 except: 308 except:
309 return 309 return
310 x = self.last_cell.nScene 310 x = self.last_cell.nScene
311 y = self.last_cell.nLayer 311 y = self.last_cell.nLayer
312 for i in range(0,len(layer.scene)): 312 for i in range(0,len(layer.scenes)):
313 s = layer.scene[i] 313 s = layer.scenes[i]
314 if nth == s.start: 314 if nth == s.start:
315 if i == 0: 315 if i == 0:
316 for j in range(s.start,s.end+1): 316 for j in range(s.start,s.end+1):
317 btn = self.newCell('empty.png') 317 btn = self.newCell('empty.png')
318 btn.nScene = nth 318 btn.nScene = nth
319 btn.layer = layer 319 btn.layer = layer
320 btn.nLayer = y 320 btn.nLayer = y
321 self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0) 321 self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0)
322 pass 322 pass
323 layer.scene.remove(s) 323 layer.scenes.remove(s)
324 else: 324 else:
325 if s.start == layer.scene[i-1].end+1: 325 if s.start == layer.scenes[i-1].end+1:
326 # If the start of the delete scene segment is 326 # If the start of the delete scene segment is
327 # the end of the last scene segmenet, convert 327 # the end of the last scene segmenet, convert
328 # all scenes in the deleted scene segmenet to 328 # all scenes in the deleted scene segmenet to
329 # the last one 329 # the last one
330 layer.scene[i-1].end = s.end 330 layer.scenes[i-1].end = s.end
331 layer.scene.remove(s) 331 layer.scenes.remove(s)
332 btn = self.newCell('fill.png') 332 btn = self.newCell('fill.png')
333 333
334 btn.nScene = nth 334 btn.nScene = nth
335 btn.layer = layer 335 btn.layer = layer
336 btn.nLayer = y 336 btn.nLayer = y
337 self.grid.attach(btn, x,x+1,y,y+1,0,0,0,0) 337 self.grid.attach(btn, x,x+1,y,y+1,0,0,0,0)
338 else: 338 else:
339 # Convert all scenes into empty cell 339 # Convert all scenes into empty cell
340 layer.scene.remove(s) 340 layer.scenes.remove(s)
341 for j in range(s.start,s.end+1): 341 for j in range(s.start,s.end+1):
342 btn = self.newCell('empty.png') 342 btn = self.newCell('empty.png')
343 btn.nScene = nth 343 btn.nScene = nth
344 btn.layer = layer 344 btn.layer = layer
345 btn.nLayer = y 345 btn.nLayer = y
361 x = self.last_cell.nScene 361 x = self.last_cell.nScene
362 y = self.last_cell.nLayer 362 y = self.last_cell.nLayer
363 if layer == None: 363 if layer == None:
364 return 364 return
365 365
366 for i in range(0,len(layer.scene)-1): 366 for i in range(0,len(layer.scenes)-1):
367 s = layer.scene[i] 367 s = layer.scenes[i]
368 if nth >= layer.scene[i].start and nth <= layer.scene[i].end: 368 if nth >= layer.scenes[i].start and nth <= layer.scenes[i].end:
369 return 369 return
370 pass 370 pass
371 371
372 for i in range(0,len(layer.scene)-1): 372 for i in range(0,len(layer.scenes)-1):
373 s = layer.scene[i] 373 s = layer.scenes[i]
374 if nth >= layer.scene[i].start and nth < layer.scene[i+1].start: 374 if nth >= layer.scenes[i].start and nth < layer.scenes[i+1].start:
375 for j in range(layer.scene[i].end+1, nth+1): 375 for j in range(layer.scenes[i].end+1, nth+1):
376 btn = self.newCell('fill.png') 376 btn = self.newCell('fill.png')
377 btn.nScene = nth 377 btn.nScene = nth
378 btn.nLayer = y 378 btn.nLayer = y
379 btn.layer = self.last_cell.layer 379 btn.layer = self.last_cell.layer
380 self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0) 380 self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0)
381 layer.scene[i].end = nth 381 layer.scenes[i].end = nth
382 return 382 return
383 pass 383 pass
384 if len(layer.scene) > 0 and \ 384 if len(layer.scenes) > 0 and \
385 nth > layer.scene[len(layer.scene)-1].end: 385 nth > layer.scenes[len(layer.scenes)-1].end:
386 for j in range(layer.scene[len(layer.scene)-1].end+1, nth+1): 386 for j in range(layer.scenes[len(layer.scenes)-1].end+1, nth+1):
387 btn = self.newCell('fill.png') 387 btn = self.newCell('fill.png')
388 btn.nScene = nth 388 btn.nScene = nth
389 btn.nLayer = y 389 btn.nLayer = y
390 btn.layer = self.last_cell.layer 390 btn.layer = self.last_cell.layer
391 self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0) 391 self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0)
392 pass 392 pass
393 layer.scene[len(layer.scene)-1].end = nth 393 layer.scenes[len(layer.scenes)-1].end = nth
394 pass 394 pass
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.layers: 400 for layer in self.layers:
401 for s in layer.scene: 401 for s in layer.scenes:
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 = []
406 406
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.layers: 430 for l in self.layers:
431 for s in l.scene: 431 for s in l.scenes:
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:
436 scene.set("start", "%d" % s.start) 436 scene.set("start", "%d" % s.start)
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.layers: 454 for l in self.layers:
455 for s in l.scene: 455 for s in l.scenes:
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)
460 else: 460 else:
480 pass 480 pass
481 for n in l.nodes: 481 for n in l.nodes:
482 lnode.append(n) 482 lnode.append(n)
483 pass 483 pass
484 root.append(lnode) 484 root.append(lnode)
485 for s in l.scene: 485 for s in l.scenes:
486 snode = etree.Element("{http://www.w3.org/2000/svg}g") 486 snode = etree.Element("{http://www.w3.org/2000/svg}g")
487 for a,v in s.node.attrib.items(): 487 for a,v in s.node.attrib.items():
488 snode.set(a,v) 488 snode.set(a,v)
489 pass 489 pass
490 for n in s.node: 490 for n in s.node:
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
535 pass 535 pass
536 536
537 def update_framelines(self): 537 def update_all_framelines(self):
538 for layer in self.layers:
539 for scene in layer.scenes:
540 pass
541 pass
538 pass 542 pass
539 543
540 def showGrid(self): 544 def showGrid(self):
541 max = 0 545 max = 0
542 for layer in self.layers: 546 for layer in self.layers:
543 for s in layer.scene: 547 for s in layer.scenes:
544 if s.end > max: 548 if s.end > max:
545 max = s.end 549 max = s.end
546 pass 550 pass
547 pass 551 pass
548 pass 552 pass
557 self.grid.attach(gtk.Label('%d'% i), i,i+1,0,1,0,0,0,0) 561 self.grid.attach(gtk.Label('%d'% i), i,i+1,0,1,0,0,0,0)
558 pass 562 pass
559 for i in range(1,len(self.layers)+1): 563 for i in range(1,len(self.layers)+1):
560 print "Layer", i 564 print "Layer", i
561 l = self.layers[i-1] 565 l = self.layers[i-1]
562 for s in l.scene: 566 for s in l.scenes:
563 btn = self.newCell('start.png') 567 btn = self.newCell('start.png')
564 btn.nScene = s.start 568 btn.nScene = s.start
565 btn.layer = l.node.getId() 569 btn.layer = l.node.getId()
566 btn.nLayer = i 570 btn.nLayer = i
567 571
574 btn.nScene = j 578 btn.nScene = j
575 btn.layer = l.node.getId() 579 btn.layer = l.node.getId()
576 btn.nLayer = i 580 btn.nLayer = i
577 pass 581 pass
578 pass 582 pass
579 if len(l.scene) == 0: 583 if len(l.scenes) == 0:
580 start = 0 584 start = 0
581 else: 585 else:
582 start = l.scene[len(l.scene)-1].end 586 start = l.scenes[len(l.scenes)-1].end
583 pass 587 pass
584 588
585 for j in range(start,max): 589 for j in range(start,max):
586 btn = self.newCell('empty.png') 590 btn = self.newCell('empty.png')
587 self.grid.attach(btn, j+1, j+2,i,i+1,0,0,0,0) 591 self.grid.attach(btn, j+1, j+2,i,i+1,0,0,0,0)