Mercurial > MadButterfly
comparison pyink/MBScene.py @ 955:53b0f8dc2284
Add tailing 'pass' commands to close indents
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 17 Nov 2010 13:30:32 +0800 |
parents | 82321f404b5f |
children | 167e359c9d5b |
comparison
equal
deleted
inserted
replaced
954:75bc6d9f4e0a | 955:53b0f8dc2284 |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # -*- indent-tabs-mode: t; tab-width: 8; python-indent: 4; -*- | |
3 # vim: sw=4:ts=8:sts=4 | |
2 import pygtk | 4 import pygtk |
3 import gtk | 5 import gtk |
4 from copy import deepcopy | 6 from copy import deepcopy |
5 from lxml import etree | 7 from lxml import etree |
6 import random | 8 import random |
9 # Please refer to http://www.assembla.com/wiki/show/MadButterfly/Inkscape_extention for the designed document. | 11 # Please refer to http://www.assembla.com/wiki/show/MadButterfly/Inkscape_extention for the designed document. |
10 | 12 |
11 | 13 |
12 # Algorithm: | 14 # Algorithm: |
13 # | 15 # |
14 # We will parse the first two level of the SVG DOM. collect a table of layer and scene. | 16 # We will parse the first two level of the SVG DOM. collect a table of |
15 # 1. Collect the layer table which will be displayed as the first column of the grid. | 17 # layer and scene. |
16 # 2. Get the maximum scene number. This will decide the size of the grid. | 18 # - 1. Collect the layer table which will be displayed as the first |
17 # 3. When F6 is pressed, we will check if this scene has been defined. This can be done by scan all second level group and check if the current scene number is within the | 19 # column of the grid. |
18 # range specified by scene field. The function IsSceneDefined(scene) can be used for this purpose. | 20 # - 2. Get the maximum scene number. This will decide the size of the |
19 # 4. If this is a new scene, we will append a new group which duplication the content of the last scene in the same group. The scene field will contain the number from the | 21 # grid. |
20 # last scene number of the last scene to the current scenen number. For example, if the last scene is from 4-7 and the new scene is 10, we will set the scene field as | 22 # - 3. When F6 is pressed, we will check if this scene has been |
21 # "8-10". | 23 # defined. This can be done by scan all second level group and |
22 # 5. If this scene are filled screne, we will split the existing scene into two scenes with the same content. | 24 # check if the current scene number is within the range specified |
25 # by scene field. The function IsSceneDefined(scene) can be used | |
26 # for this purpose. | |
27 # - 4. If this is a new scene, we will append a new group which | |
28 # duplication the content of the last scene in the same | |
29 # group. The scene field will contain the number from the last | |
30 # scene number of the last scene to the current scenen | |
31 # number. For example, if the last scene is from 4-7 and the new | |
32 # scene is 10, we will set the scene field as "8-10". | |
33 # - 5. If this scene are filled screne, we will split the existing | |
34 # scene into two scenes with the same content. | |
35 # | |
23 | 36 |
24 class Layer: | 37 class Layer: |
25 def __init__(self,node): | 38 def __init__(self,node): |
26 self.scene = [] | 39 self.scene = [] |
27 self.node = node | 40 self.node = node |
28 self.nodes=[] | 41 self.nodes=[] |
42 pass | |
43 pass | |
44 | |
29 class Scene: | 45 class Scene: |
30 def __init__(self, node, start,end): | 46 def __init__(self, node, start,end): |
31 self.node = node | 47 self.node = node |
32 self.start = int(start) | 48 self.start = int(start) |
33 self.end = int(end) | 49 self.end = int(end) |
50 pass | |
51 pass | |
34 | 52 |
35 | 53 |
36 class MBScene(): | 54 class MBScene(): |
37 def __init__(self,desktop,win): | 55 def __init__(self,desktop,win): |
38 self.desktop = desktop | 56 self.desktop = desktop |
39 self.window = win | 57 self.window = win |
40 self.layer = [] | 58 self.layer = [] |
41 self.layer.append(Layer(None)) | 59 self.layer.append(Layer(None)) |
42 self.scenemap = None | 60 self.scenemap = None |
61 pass | |
43 | 62 |
44 def confirm(self,msg): | 63 def confirm(self,msg): |
45 vbox = gtk.VBox() | 64 vbox = gtk.VBox() |
46 vbox.pack_start(gtk.Label(msg)) | 65 vbox.pack_start(gtk.Label(msg)) |
47 self.button = gtk.Button('OK') | 66 self.button = gtk.Button('OK') |
48 vbox.pack_start(self.button) | 67 vbox.pack_start(self.button) |
49 self.button.connect("clicked", self.onQuit) | 68 self.button.connect("clicked", self.onQuit) |
50 self.window.add(vbox) | 69 self.window.add(vbox) |
70 pass | |
71 | |
51 def dumpattr(self,n): | 72 def dumpattr(self,n): |
52 s = "" | 73 s = "" |
53 for a,v in n.attrib.items(): | 74 for a,v in n.attrib.items(): |
54 s = s + ("%s=%s" % (a,v)) | 75 s = s + ("%s=%s" % (a,v)) |
55 return s | 76 return s |
56 | 77 |
57 def dump(self,node,l=0): | 78 def dump(self,node,l=0): |
58 print " " * l*2,"<", node.tag, self.dumpattr(node),">" | 79 print " " * l*2,"<", node.tag, self.dumpattr(node),">" |
59 for n in node: | 80 for n in node: |
60 self.dump(n,l+1) | 81 self.dump(n,l+1) |
82 pass | |
61 print " " * l * 2,"/>" | 83 print " " * l * 2,"/>" |
84 pass | |
85 | |
62 def parseMetadata(self,node): | 86 def parseMetadata(self,node): |
63 self.current = 1 | 87 self.current = 1 |
64 for n in node.childList(): | 88 for n in node.childList(): |
65 if n.repr.name() == 'ns0:scenes': | 89 if n.repr.name() == 'ns0:scenes': |
66 self.scenemap={} | 90 self.scenemap={} |
79 end = s.repr.attribute("end") | 103 end = s.repr.attribute("end") |
80 if end == None: | 104 if end == None: |
81 end = start | 105 end = start |
82 except: | 106 except: |
83 end = start | 107 end = start |
108 pass | |
84 link = s.repr.attribute("ref") | 109 link = s.repr.attribute("ref") |
85 self.scenemap[link] = [int(start),int(end)] | 110 self.scenemap[link] = [int(start),int(end)] |
86 print "scene %d to %d" % (self.scenemap[link][0],self.scenemap[link][1]) | 111 print "scene %d to %d" % (self.scenemap[link][0],self.scenemap[link][1]) |
87 if cur >= start and cur <= end: | 112 if cur >= start and cur <= end: |
88 self.currentscene = link | 113 self.currentscene = link |
89 | 114 pass |
90 pass | 115 pass |
91 pass | 116 pass |
92 pass | 117 pass |
93 pass | 118 pass |
94 | 119 pass |
120 | |
95 | 121 |
96 def parseScene(self): | 122 def parseScene(self): |
97 """ | 123 """ |
98 In this function, we will collect all items for the current scene and then relocate them back to the appropriate scene object. | 124 In this function, we will collect all items for the current scene and then relocate them back to the appropriate scene object. |
99 """ | 125 """ |
102 doc = self.desktop.doc().root() | 128 doc = self.desktop.doc().root() |
103 | 129 |
104 for node in doc.childList(): | 130 for node in doc.childList(): |
105 if node.repr.name() == 'svg:metadata': | 131 if node.repr.name() == 'svg:metadata': |
106 self.parseMetadata(node) | 132 self.parseMetadata(node) |
133 pass | |
107 elif node.repr.name() == 'svg:g': | 134 elif node.repr.name() == 'svg:g': |
108 oldscene = None | 135 oldscene = None |
109 #print layer.attrib.get("id") | 136 #print layer.attrib.get("id") |
110 lyobj = Layer(node) | 137 lyobj = Layer(node) |
111 self.layer.append(lyobj) | 138 self.layer.append(lyobj) |
117 if scmap == None: | 144 if scmap == None: |
118 lyobj.current_scene.append(scene) | 145 lyobj.current_scene.append(scene) |
119 continue | 146 continue |
120 if self.current <= scmap[1] and self.current >= scmap[0]: | 147 if self.current <= scmap[1] and self.current >= scmap[0]: |
121 oldscene = scene | 148 oldscene = scene |
149 pass | |
122 except: | 150 except: |
123 lyobj.current_scene.append(scene) | 151 lyobj.current_scene.append(scene) |
124 continue | 152 continue |
125 | 153 |
126 lyobj.scene.append(Scene(scene,scmap[0],scmap[1])) | 154 lyobj.scene.append(Scene(scene,scmap[0],scmap[1])) |
155 pass | |
127 else: | 156 else: |
128 lyobj.current_scene.append(scene) | 157 lyobj.current_scene.append(scene) |
129 pass | 158 pass |
159 pass | |
130 | 160 |
131 if oldscene != None: | 161 if oldscene != None: |
132 # Put the objects back to the current scene | 162 # Put the objects back to the current scene |
133 #for o in lyobj.current_scene: | 163 #for o in lyobj.current_scene: |
134 #print o.tag | 164 #print o.tag |
135 #oldscene.append(o) | 165 #oldscene.append(o) |
136 pass | 166 pass |
137 pass | 167 pass |
138 pass | 168 pass |
139 | 169 |
140 self.collectID() | 170 self.collectID() |
141 self.dumpID() | 171 self.dumpID() |
172 pass | |
173 | |
142 def collectID(self): | 174 def collectID(self): |
143 self.ID = {} | 175 self.ID = {} |
144 root = self.desktop.doc().root() | 176 root = self.desktop.doc().root() |
145 for n in root.childList(): | 177 for n in root.childList(): |
146 self.collectID_recursive(n) | 178 self.collectID_recursive(n) |
179 pass | |
180 pass | |
181 | |
147 def collectID_recursive(self,node): | 182 def collectID_recursive(self,node): |
148 self.ID[node.getId()] = 1 | 183 self.ID[node.getId()] = 1 |
149 for n in node.childList(): | 184 for n in node.childList(): |
150 self.collectID_recursive(n) | 185 self.collectID_recursive(n) |
186 pass | |
187 pass | |
188 | |
151 def newID(self): | 189 def newID(self): |
152 while True: | 190 while True: |
153 n = 's%d' % int(random.random()*10000) | 191 n = 's%d' % int(random.random()*10000) |
154 #print "try %s" % n | 192 #print "try %s" % n |
155 if self.ID.has_key(n) == False: | 193 if self.ID.has_key(n) == False: |
156 return n | 194 return n |
195 pass | |
196 pass | |
197 | |
157 def dumpID(self): | 198 def dumpID(self): |
158 for a,v in self.ID.items(): | 199 for a,v in self.ID.items(): |
159 print a | 200 print a |
160 | 201 pass |
202 pass | |
161 | 203 |
162 def getLayer(self, layer): | 204 def getLayer(self, layer): |
163 for l in self.layer: | 205 for l in self.layer: |
164 if l.node.getId() == layer: | 206 if l.node.getId() == layer: |
165 return l | 207 return l |
208 pass | |
166 return None | 209 return None |
167 | 210 |
168 | 211 |
169 def insertKeyScene(self): | 212 def insertKeyScene(self): |
170 """ | 213 """ |
191 btn.layer = layer | 234 btn.layer = layer |
192 btn.nLayer = y | 235 btn.nLayer = y |
193 self.grid.remove(self.last_cell) | 236 self.grid.remove(self.last_cell) |
194 self.grid.attach(btn, x,x+1,y,y+1,0,0,0,0) | 237 self.grid.attach(btn, x,x+1,y,y+1,0,0,0,0) |
195 return | 238 return |
239 pass | |
240 | |
196 if len(layer.scene) > 0: | 241 if len(layer.scene) > 0: |
197 last = nth | 242 last = nth |
198 lastscene = None | 243 lastscene = None |
199 for s in layer.scene: | 244 for s in layer.scene: |
200 if s.end < nth and last < s.end: | 245 if s.end < nth and last < s.end: |
201 last = s.end | 246 last = s.end |
202 lastscene = s | 247 lastscene = s |
248 pass | |
249 pass | |
250 | |
203 for x in range(last+1, nth): | 251 for x in range(last+1, nth): |
204 btn = self.newCell('fill.png') | 252 btn = self.newCell('fill.png') |
205 btn.nScene = x | 253 btn.nScene = x |
206 btn.layer = layer.node.getId() | 254 btn.layer = layer.node.getId() |
207 btn.nLayer = y | 255 btn.nLayer = y |
208 self.grid.attach(btn, x, x+1, y , y+1,0,0,0,0) | 256 self.grid.attach(btn, x, x+1, y , y+1,0,0,0,0) |
257 pass | |
258 | |
209 if lastscene == None: | 259 if lastscene == None: |
210 node = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene') | 260 node = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene') |
211 node.setId(self.newID()) | 261 node.setId(self.newID()) |
212 newscene = Scene(node,nth,nth) | 262 newscene = Scene(node,nth,nth) |
213 else: | 263 else: |
214 lastscene.end = nth-1 | 264 lastscene.end = nth-1 |
215 newscene = Scene(DuplicateNode(lastscene.node),nth,nth) | 265 newscene = Scene(DuplicateNode(lastscene.node),nth,nth) |
216 newscene.node.setId(self.newID()) | 266 newscene.node.setId(self.newID()) |
267 pass | |
268 | |
217 layer.scene.append(newscene) | 269 layer.scene.append(newscene) |
218 btn = self.newCell('start.png') | 270 btn = self.newCell('start.png') |
219 x = self.last_cell.nScene | 271 x = self.last_cell.nScene |
220 y = self.last_cell.nLayer | 272 y = self.last_cell.nLayer |
221 btn.nScene = nth | 273 btn.nScene = nth |
231 btn = self.newCell('start.png') | 283 btn = self.newCell('start.png') |
232 btn.nScene = nth | 284 btn.nScene = nth |
233 btn.layer = layer.node.getId() | 285 btn.layer = layer.node.getId() |
234 btn.nLayer = y | 286 btn.nLayer = y |
235 self.grid.attach(btn, x, x+1, y, y+1,0,0,0,0) | 287 self.grid.attach(btn, x, x+1, y, y+1,0,0,0,0) |
236 | 288 pass |
237 | 289 pass |
238 | 290 |
239 | 291 |
240 def removeKeyScene(self): | 292 def removeKeyScene(self): |
241 nth = self.last_cell.nScene | 293 nth = self.last_cell.nScene |
242 try: | 294 try: |
243 layer = self.getLayer(self.last_cell.layer) | 295 layer = self.getLayer(self.last_cell.layer) |
253 btn = self.newCell('empty.png') | 305 btn = self.newCell('empty.png') |
254 btn.nScene = nth | 306 btn.nScene = nth |
255 btn.layer = layer | 307 btn.layer = layer |
256 btn.nLayer = y | 308 btn.nLayer = y |
257 self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0) | 309 self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0) |
310 pass | |
258 layer.scene.remove(s) | 311 layer.scene.remove(s) |
259 else: | 312 else: |
260 if s.start == layer.scene[i-1].end+1: | 313 if s.start == layer.scene[i-1].end+1: |
261 # If the start of the delete scene segment is the end of the last scene segmenet, convert all scenes in the deleted | 314 # If the start of the delete scene segment is the end of the last scene segmenet, convert all scenes in the deleted |
262 # scene segmenet to the last one | 315 # scene segmenet to the last one |
275 btn = self.newCell('empty.png') | 328 btn = self.newCell('empty.png') |
276 btn.nScene = nth | 329 btn.nScene = nth |
277 btn.layer = layer | 330 btn.layer = layer |
278 btn.nLayer = y | 331 btn.nLayer = y |
279 self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0) | 332 self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0) |
280 | 333 pass |
281 | 334 pass |
335 pass | |
282 return | 336 return |
337 pass | |
338 pass | |
283 | 339 |
284 def extendScene(self): | 340 def extendScene(self): |
285 nth = self.last_cell.nScene | 341 nth = self.last_cell.nScene |
286 try: | 342 try: |
287 layer = self.getLayer(self.last_cell.layer) | 343 layer = self.getLayer(self.last_cell.layer) |
288 except: | 344 except: |
289 traceback.print_exc() | 345 traceback.print_exc() |
290 return | 346 return |
291 x = self.last_cell.nScene | 347 x = self.last_cell.nScene |
292 y = self.last_cell.nLayer | 348 y = self.last_cell.nLayer |
293 if layer == None: return | 349 if layer == None: |
350 return | |
294 | 351 |
295 for i in range(0,len(layer.scene)-1): | 352 for i in range(0,len(layer.scene)-1): |
296 s = layer.scene[i] | 353 s = layer.scene[i] |
297 if nth >= layer.scene[i].start and nth <= layer.scene[i].end: | 354 if nth >= layer.scene[i].start and nth <= layer.scene[i].end: |
298 return | 355 return |
356 pass | |
299 | 357 |
300 for i in range(0,len(layer.scene)-1): | 358 for i in range(0,len(layer.scene)-1): |
301 s = layer.scene[i] | 359 s = layer.scene[i] |
302 if nth >= layer.scene[i].start and nth < layer.scene[i+1].start: | 360 if nth >= layer.scene[i].start and nth < layer.scene[i+1].start: |
303 for j in range(layer.scene[i].end+1, nth+1): | 361 for j in range(layer.scene[i].end+1, nth+1): |
306 btn.nLayer = y | 364 btn.nLayer = y |
307 btn.layer = self.last_cell.layer | 365 btn.layer = self.last_cell.layer |
308 self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0) | 366 self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0) |
309 layer.scene[i].end = nth | 367 layer.scene[i].end = nth |
310 return | 368 return |
369 pass | |
311 if len(layer.scene) > 0 and nth > layer.scene[len(layer.scene)-1].end: | 370 if len(layer.scene) > 0 and nth > layer.scene[len(layer.scene)-1].end: |
312 for j in range(layer.scene[len(layer.scene)-1].end+1, nth+1): | 371 for j in range(layer.scene[len(layer.scene)-1].end+1, nth+1): |
313 btn = self.newCell('fill.png') | 372 btn = self.newCell('fill.png') |
314 btn.nScene = nth | 373 btn.nScene = nth |
315 btn.nLayer = y | 374 btn.nLayer = y |
316 btn.layer = self.last_cell.layer | 375 btn.layer = self.last_cell.layer |
317 self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0) | 376 self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0) |
377 pass | |
318 layer.scene[len(layer.scene)-1].end = nth | 378 layer.scene[len(layer.scene)-1].end = nth |
379 pass | |
380 pass | |
381 | |
319 def setCurrentScene(self,nth): | 382 def setCurrentScene(self,nth): |
320 self.current = nth | 383 self.current = nth |
321 for layer in self.layer: | 384 for layer in self.layer: |
322 for s in layer.scene: | 385 for s in layer.scene: |
323 if nth >= s.start and nth <= s.end: | 386 if nth >= s.start and nth <= s.end: |
330 # layer.nodes.append(o) | 393 # layer.nodes.append(o) |
331 #for o in s.node: | 394 #for o in s.node: |
332 # s.node.remove(o) | 395 # s.node.remove(o) |
333 else: | 396 else: |
334 s.node.repr.setAttribute("style","display:none",True) | 397 s.node.repr.setAttribute("style","display:none",True) |
398 pass | |
399 pass | |
400 pass | |
401 pass | |
402 | |
335 def generate(self): | 403 def generate(self): |
336 newdoc = deepcopy(self.document) | 404 newdoc = deepcopy(self.document) |
337 root = newdoc.getroot() | 405 root = newdoc.getroot() |
338 has_scene = False | 406 has_scene = False |
339 for n in root: | 407 for n in root: |
351 if s.start == s.end: | 419 if s.start == s.end: |
352 scene.set("start", "%d" % s.start) | 420 scene.set("start", "%d" % s.start) |
353 else: | 421 else: |
354 scene.set("start", "%d" % s.start) | 422 scene.set("start", "%d" % s.start) |
355 scene.set("end", "%d" % s.end) | 423 scene.set("end", "%d" % s.end) |
424 pass | |
356 | 425 |
357 scenes.append(scene) | 426 scenes.append(scene) |
427 pass | |
428 pass | |
358 for s in scenes: | 429 for s in scenes: |
359 nn.append(s) | 430 nn.append(s) |
431 pass | |
360 has_scene = True | 432 has_scene = True |
433 pass | |
434 pass | |
361 if has_scene == False: | 435 if has_scene == False: |
362 scenes = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scenes') | 436 scenes = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scenes') |
363 scenes.set("current","%d" % self.current) | 437 scenes.set("current","%d" % self.current) |
364 for l in self.layer: | 438 for l in self.layer: |
365 for s in l.scene: | 439 for s in l.scene: |
368 if s.start == s.end: | 442 if s.start == s.end: |
369 scene.set("start", "%d" % s.start) | 443 scene.set("start", "%d" % s.start) |
370 else: | 444 else: |
371 scene.set("start", "%d" % s.start) | 445 scene.set("start", "%d" % s.start) |
372 scene.set("end", "%d" % s.end) | 446 scene.set("end", "%d" % s.end) |
447 pass | |
373 scenes.append(scene) | 448 scenes.append(scene) |
449 pass | |
450 pass | |
374 n.append(scenes) | 451 n.append(scenes) |
375 if n.tag == '{http://www.w3.org/2000/svg}g': | 452 if n.tag == '{http://www.w3.org/2000/svg}g': |
376 root.remove(n) | 453 root.remove(n) |
377 | 454 pass |
455 pass | |
456 | |
378 for l in self.layer: | 457 for l in self.layer: |
379 # Duplicate all attribute of the layer | 458 # Duplicate all attribute of the layer |
380 lnode = etree.Element("{http://www.w3.org/2000/svg}g") | 459 lnode = etree.Element("{http://www.w3.org/2000/svg}g") |
381 for a,v in l.node.attrib.items(): | 460 for a,v in l.node.attrib.items(): |
382 lnode.set(a,v) | 461 lnode.set(a,v) |
462 pass | |
383 for n in l.nodes: | 463 for n in l.nodes: |
384 lnode.append(n) | 464 lnode.append(n) |
465 pass | |
385 root.append(lnode) | 466 root.append(lnode) |
386 for s in l.scene: | 467 for s in l.scene: |
387 snode = etree.Element("{http://www.w3.org/2000/svg}g") | 468 snode = etree.Element("{http://www.w3.org/2000/svg}g") |
388 for a,v in s.node.attrib.items(): | 469 for a,v in s.node.attrib.items(): |
389 snode.set(a,v) | 470 snode.set(a,v) |
471 pass | |
390 for n in s.node: | 472 for n in s.node: |
391 snode.append(deepcopy(n)) | 473 snode.append(deepcopy(n)) |
474 pass | |
392 lnode.append(snode) | 475 lnode.append(snode) |
476 pass | |
477 pass | |
393 self.document = newdoc | 478 self.document = newdoc |
479 pass | |
480 | |
394 def newCell(self,file): | 481 def newCell(self,file): |
395 img = gtk.Image() | 482 img = gtk.Image() |
396 img.set_from_file(file) | 483 img.set_from_file(file) |
397 btn = gtk.EventBox() | 484 btn = gtk.EventBox() |
398 btn.add(img) | 485 btn.add(img) |
399 btn.connect("button_press_event", self.cellSelect) | 486 btn.connect("button_press_event", self.cellSelect) |
400 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray")) | 487 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray")) |
401 return btn | 488 return btn |
489 | |
402 def showGrid(self): | 490 def showGrid(self): |
403 max = 0 | 491 max = 0 |
404 for layer in self.layer: | 492 for layer in self.layer: |
405 for s in layer.scene: | 493 for s in layer.scene: |
406 if s.end > max: | 494 if s.end > max: |
407 max = s.end | 495 max = s.end |
496 pass | |
497 pass | |
498 pass | |
408 max = 50 | 499 max = 50 |
409 | 500 |
410 self.grid = gtk.Table(len(self.layer)+1, 50) | 501 self.grid = gtk.Table(len(self.layer)+1, 50) |
411 self.scrollwin = gtk.ScrolledWindow() | 502 self.scrollwin = gtk.ScrolledWindow() |
412 self.scrollwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) | 503 self.scrollwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) |
413 self.scrollwin.add_with_viewport(self.grid) | 504 self.scrollwin.add_with_viewport(self.grid) |
414 self.scrollwin.set_size_request(-1,150) | 505 self.scrollwin.set_size_request(-1,150) |
415 for i in range(1,max): | 506 for i in range(1,max): |
416 self.grid.attach(gtk.Label('%d'% i), i,i+1,0,1,0,0,0,0) | 507 self.grid.attach(gtk.Label('%d'% i), i,i+1,0,1,0,0,0,0) |
508 pass | |
417 for i in range(1,len(self.layer)+1): | 509 for i in range(1,len(self.layer)+1): |
418 print "Layer", i | 510 print "Layer", i |
419 l = self.layer[i-1] | 511 l = self.layer[i-1] |
420 #self.grid.attach(gtk.Label(l.node.get('{http://www.inkscape.org/namespaces/inkscape}label')), 0, 1, i, i+1,0,0,10,0) | 512 #self.grid.attach(gtk.Label(l.node.get('{http://www.inkscape.org/namespaces/inkscape}label')), 0, 1, i, i+1,0,0,10,0) |
421 for s in l.scene: | 513 for s in l.scene: |
430 self.grid.attach(btn, j, j+1, i , i+1,0,0,0,0) | 522 self.grid.attach(btn, j, j+1, i , i+1,0,0,0,0) |
431 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray")) | 523 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray")) |
432 btn.nScene = j | 524 btn.nScene = j |
433 btn.layer = l.node.getId() | 525 btn.layer = l.node.getId() |
434 btn.nLayer = i | 526 btn.nLayer = i |
527 pass | |
528 pass | |
435 if len(l.scene) == 0: | 529 if len(l.scene) == 0: |
436 start = 0 | 530 start = 0 |
437 else: | 531 else: |
438 start = l.scene[len(l.scene)-1].end | 532 start = l.scene[len(l.scene)-1].end |
533 pass | |
534 | |
439 for j in range(start,max): | 535 for j in range(start,max): |
440 btn = self.newCell('empty.png') | 536 btn = self.newCell('empty.png') |
441 self.grid.attach(btn, j+1, j+2,i,i+1,0,0,0,0) | 537 self.grid.attach(btn, j+1, j+2,i,i+1,0,0,0,0) |
442 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray")) | 538 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray")) |
443 btn.nScene = j+1 | 539 btn.nScene = j+1 |
444 btn.layer = l.node.getId() | 540 btn.layer = l.node.getId() |
445 btn.nLayer = i | 541 btn.nLayer = i |
542 pass | |
543 pass | |
446 self.last_cell = None | 544 self.last_cell = None |
545 pass | |
546 | |
447 def cellSelect(self, cell, data): | 547 def cellSelect(self, cell, data): |
448 if self.last_cell: | 548 if self.last_cell: |
449 self.last_cell.modify_bg(gtk.STATE_NORMAL, self.last_cell.get_colormap().alloc_color("gray")) | 549 self.last_cell.modify_bg(gtk.STATE_NORMAL, self.last_cell.get_colormap().alloc_color("gray")) |
550 pass | |
450 | 551 |
451 self.last_cell = cell | 552 self.last_cell = cell |
452 cell.modify_bg(gtk.STATE_NORMAL, cell.get_colormap().alloc_color("green")) | 553 cell.modify_bg(gtk.STATE_NORMAL, cell.get_colormap().alloc_color("green")) |
554 pass | |
453 | 555 |
454 def doEditScene(self,w): | 556 def doEditScene(self,w): |
455 self.setCurrentScene(self.last_cell.nScene) | 557 self.setCurrentScene(self.last_cell.nScene) |
558 pass | |
559 | |
456 def doInsertKeyScene(self,w): | 560 def doInsertKeyScene(self,w): |
561 #self.insertKeyScene() | |
562 #self.grid.show_all() | |
457 return | 563 return |
458 self.insertKeyScene() | |
459 self.grid.show_all() | |
460 | 564 |
461 def doRemoveScene(self,w): | 565 def doRemoveScene(self,w): |
462 return | 566 return |
463 self.removeKeyScene() | 567 self.removeKeyScene() |
464 self.grid.show_all() | 568 self.grid.show_all() |
465 self.generate() | 569 self.generate() |
570 pass | |
571 | |
466 def doExtendScene(self,w): | 572 def doExtendScene(self,w): |
467 self.extendScene() | 573 self.extendScene() |
468 self.grid.show_all() | 574 self.grid.show_all() |
575 pass | |
576 | |
469 def addButtons(self,hbox): | 577 def addButtons(self,hbox): |
470 btn = gtk.Button('Edit') | 578 btn = gtk.Button('Edit') |
471 btn.connect('clicked', self.doEditScene) | 579 btn.connect('clicked', self.doEditScene) |
472 hbox.pack_start(btn,expand=False,fill=False) | 580 hbox.pack_start(btn,expand=False,fill=False) |
473 btn = gtk.Button('Insert Key') | 581 btn = gtk.Button('Insert Key') |
477 btn.connect('clicked', self.doRemoveScene) | 585 btn.connect('clicked', self.doRemoveScene) |
478 hbox.pack_start(btn,expand=False,fill=False) | 586 hbox.pack_start(btn,expand=False,fill=False) |
479 btn=gtk.Button('Extend scene') | 587 btn=gtk.Button('Extend scene') |
480 btn.connect('clicked', self.doExtendScene) | 588 btn.connect('clicked', self.doExtendScene) |
481 hbox.pack_start(btn,expand=False,fill=False) | 589 hbox.pack_start(btn,expand=False,fill=False) |
590 pass | |
591 | |
482 def onQuit(self, event): | 592 def onQuit(self, event): |
483 self.OK = False | 593 self.OK = False |
484 gtk.main_quit() | 594 gtk.main_quit() |
595 pass | |
596 | |
485 def onOK(self,event): | 597 def onOK(self,event): |
486 self.OK = True | 598 self.OK = True |
487 gtk.main_quit() | 599 gtk.main_quit() |
600 pass | |
488 | 601 |
489 def onConfirmDelete(self): | 602 def onConfirmDelete(self): |
490 if self.scenemap == None: | 603 if self.scenemap == None: |
491 vbox = gtk.VBox(False,0) | 604 vbox = gtk.VBox(False,0) |
492 vbox.pack_start(gtk.Label('Convert the SVG into a MadButterfly SVG file. All current element will be delted')) | 605 vbox.pack_start(gtk.Label('Convert the SVG into a MadButterfly SVG file. All current element will be delted')) |
500 vbox.pack_start(hbox,expand=False,fill=False) | 613 vbox.pack_start(hbox,expand=False,fill=False) |
501 self.window.add(vbox) | 614 self.window.add(vbox) |
502 self.window.show_all() | 615 self.window.show_all() |
503 gtk.main() | 616 gtk.main() |
504 self.window.remove(vbox) | 617 self.window.remove(vbox) |
505 | 618 pass |
619 pass | |
506 | 620 |
507 def show(self): | 621 def show(self): |
508 self.OK = True | 622 self.OK = True |
509 self.parseScene() | 623 self.parseScene() |
510 self.showGrid() | 624 self.showGrid() |
514 #self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) | 628 #self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) |
515 #self.window.connect("destroy", gtk.main_quit) | 629 #self.window.connect("destroy", gtk.main_quit) |
516 #self.window.set_position(gtk.WIN_POS_MOUSE) | 630 #self.window.set_position(gtk.WIN_POS_MOUSE) |
517 if self.scenemap == None: | 631 if self.scenemap == None: |
518 self.onConfirmDelete() | 632 self.onConfirmDelete() |
633 pass | |
519 if self.OK: | 634 if self.OK: |
520 vbox = gtk.VBox(False,0) | 635 vbox = gtk.VBox(False,0) |
521 self.window.pack_start(vbox,expand=False) | 636 self.window.pack_start(vbox,expand=False) |
522 vbox.pack_start(self.scrollwin,expand=False) | 637 vbox.pack_start(self.scrollwin,expand=False) |
523 self.vbox = vbox | 638 self.vbox = vbox |
528 return | 643 return |
529 | 644 |
530 #self.window.set_size_request(600,200) | 645 #self.window.set_size_request(600,200) |
531 | 646 |
532 self.window.show_all() | 647 self.window.show_all() |
533 | 648 pass |
534 | 649 pass |