Mercurial > MadButterfly
annotate inkscape/MB_Frame.py @ 653:34710e86b4a2
Remove cairo-directfb.h but it will be needed at graphic layer initialization of SMP8654.
author | Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com> |
---|---|
date | Sat, 31 Jul 2010 16:36:53 +0800 |
parents | a90fd749af82 |
children |
rev | line source |
---|---|
233 | 1 #!/usr/bin/python |
2 import inkex | |
3 import pygtk | |
4 import gtk | |
5 from copy import deepcopy | |
6 from lxml import etree | |
7 import random | |
8 | |
236 | 9 # Please refer to http://www.assembla.com/wiki/show/MadButterfly/Inkscape_extention for the designed document. |
233 | 10 |
11 | |
12 # Algorithm: | |
13 # | |
14 # We will parse the first two level of the SVG DOM. collect a table of layer and scene. | |
15 # 1. Collect the layer table which will be displayed as the first column of the grid. | |
16 # 2. Get the maximum scene number. This will decide the size of the grid. | |
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 | |
18 # range specified by scene field. The function IsSceneDefined(scene) can be used for this purpose. | |
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 | |
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 | |
21 # "8-10". | |
22 # 5. If this scene are filled screne, we will split the existing scene into two scenes with the same content. | |
23 | |
24 class Layer: | |
25 def __init__(self,node): | |
26 self.scene = [] | |
27 self.node = node | |
234
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
28 self.nodes=[] |
233 | 29 class Scene: |
30 def __init__(self, node, start,end): | |
31 self.node = node | |
32 self.start = int(start) | |
33 self.end = int(end) | |
34 | |
35 | |
36 class MBScene(inkex.Effect): | |
37 def confirm(self,msg): | |
38 vbox = gtk.VBox() | |
39 vbox.pack_start(gtk.Label(msg)) | |
40 self.button = gtk.Button('OK') | |
41 vbox.pack_start(self.button) | |
42 self.button.connect("clicked", self.onQuit) | |
43 self.window.add(vbox) | |
44 def dumpattr(self,n): | |
45 s = "" | |
46 for a,v in n.attrib.items(): | |
47 s = s + ("%s=%s" % (a,v)) | |
48 return s | |
49 | |
50 def dump(self,node,l=0): | |
51 print " " * l*2,"<", node.tag, self.dumpattr(node),">" | |
52 for n in node: | |
53 self.dump(n,l+1) | |
54 print " " * l * 2,"/>" | |
236 | 55 def parseMetadata(self,node): |
238 | 56 self.current = 1 |
236 | 57 for n in node: |
58 if n.tag == '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scenes': | |
59 self.scenemap={} | |
60 cur = int(n.get("current")) | |
61 self.current = cur | |
62 | |
63 for s in n: | |
64 if s.tag == '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene': | |
65 try: | |
66 start = int(s.get("start")) | |
67 except: | |
68 continue | |
69 try: | |
70 end = s.get("end") | |
71 if end == None: | |
72 end = start | |
73 except: | |
74 end = start | |
75 link = s.get("ref") | |
76 self.scenemap[link] = [int(start),int(end)] | |
77 if cur >= start and cur <= end: | |
78 self.currentscene = link | |
79 | |
80 pass | |
81 pass | |
82 pass | |
83 pass | |
84 | |
85 | |
233 | 86 def parseScene(self): |
234
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
87 """ |
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
88 In this function, we will collect all items for the current scene and then relocate them back to the appropriate scene object. |
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
89 """ |
233 | 90 self.layer = [] |
248
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
91 self.scenemap = None |
234
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
92 for node in self.document.getroot(): |
236 | 93 if node.tag == '{http://www.w3.org/2000/svg}metadata': |
94 self.parseMetadata(node) | |
95 elif node.tag == '{http://www.w3.org/2000/svg}g': | |
96 oldscene = None | |
233 | 97 #print layer.attrib.get("id") |
234
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
98 lyobj = Layer(node) |
233 | 99 self.layer.append(lyobj) |
236 | 100 lyobj.current_scene = [] |
234
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
101 for scene in node: |
233 | 102 if scene.tag == '{http://www.w3.org/2000/svg}g': |
236 | 103 try: |
104 scmap = self.scenemap[scene.get("id")] | |
105 if scmap == None: | |
106 lyobj.current_scene.append(scene) | |
107 continue | |
108 if self.current <= scmap[1] and self.current >= scmap[0]: | |
109 oldscene = scene | |
110 except: | |
111 lyobj.current_scene.append(scene) | |
234
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
112 continue |
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
113 |
236 | 114 lyobj.scene.append(Scene(scene,scmap[0],scmap[1])) |
234
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
115 else: |
236 | 116 lyobj.current_scene.append(scene) |
117 pass | |
118 pass | |
119 | |
120 if oldscene != None: | |
121 # Put the objects back to the current scene | |
122 for o in lyobj.current_scene: | |
123 #print o.tag | |
124 oldscene.append(o) | |
234
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
125 pass |
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
126 pass |
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
127 pass |
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
128 pass |
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
129 |
233 | 130 self.collectID() |
131 #self.dumpID() | |
132 def collectID(self): | |
133 self.ID = {} | |
134 root = self.document.getroot() | |
135 for n in root: | |
136 self.collectID_recursive(n) | |
137 def collectID_recursive(self,node): | |
138 self.ID[node.get("id")] = 1 | |
139 for n in node: | |
140 self.collectID_recursive(n) | |
141 def newID(self): | |
142 while True: | |
143 n = 's%d' % int(random.random()*10000) | |
144 #print "try %s" % n | |
145 if self.ID.has_key(n) == False: | |
146 return n | |
147 def dumpID(self): | |
148 for a,v in self.ID.items(): | |
149 print a | |
150 | |
151 | |
152 def getLayer(self, layer): | |
153 for l in self.layer: | |
154 if l.node.attrib.get("id") == layer: | |
155 return l | |
156 return None | |
157 | |
158 | |
159 def insertKeyScene(self): | |
160 """ | |
161 Insert a new key scene into the stage. If the nth is always a key scene, we will return without changing anything. | |
162 If the nth is a filled scene, we will break the original scene into two parts. If the nth is out of any scene, we will | |
163 append a new scene. | |
164 | |
165 """ | |
166 nth = self.last_cell.nScene | |
167 layer = self.getLayer(self.last_cell.layer) | |
168 x = self.last_cell.nScene | |
169 y = self.last_cell.nLayer | |
170 if layer == None: return | |
171 for i in range(0,len(layer.scene)): | |
172 s = layer.scene[i] | |
173 if nth >= s.start and nth <= s.end: | |
174 if nth == s.start: return | |
175 newscene = Scene(deepcopy(s.node),nth,s.end) | |
176 newscene.node.set("id", self.newID()) | |
177 layer.scene.insert(i+1,newscene) | |
178 layer.scene[i].end = nth-1 | |
179 btn = self.newCell('start.png') | |
180 btn.nScene = nth | |
181 btn.layer = layer | |
182 btn.nLayer = y | |
183 self.grid.remove(self.last_cell) | |
184 self.grid.attach(btn, x,x+1,y,y+1,0,0,0,0) | |
185 return | |
186 if len(layer.scene) > 0: | |
236 | 187 last = nth |
188 lastscene = None | |
189 for s in layer.scene: | |
190 if s.end < nth and last < s.end: | |
191 last = s.end | |
192 lastscene = s | |
193 for x in range(last+1, nth): | |
233 | 194 btn = self.newCell('fill.png') |
195 btn.nScene = x | |
236 | 196 btn.layer = layer.node.get('id') |
233 | 197 btn.nLayer = y |
198 self.grid.attach(btn, x, x+1, y , y+1,0,0,0,0) | |
236 | 199 if lastscene == None: |
200 node = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene') | |
201 node.set("id", self.newID()) | |
202 newscene = Scene(node,nth,nth) | |
203 else: | |
204 lastscene.end = nth-1 | |
205 newscene = Scene(deepcopy(lastscene.node),nth,nth) | |
206 newscene.node.set("id",self.newID()) | |
233 | 207 layer.scene.append(newscene) |
208 btn = self.newCell('start.png') | |
209 x = self.last_cell.nScene | |
210 y = self.last_cell.nLayer | |
211 btn.nScene = nth | |
236 | 212 btn.layer = layer.node.get('id') |
213 btn.nLayer = y | |
214 self.grid.attach(btn, x, x+1, y, y+1,0,0,0,0) | |
215 else: | |
216 # This is the first scene in the layer | |
217 node = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene') | |
218 node.set("id", self.newID()) | |
219 newscene = Scene(node,nth,nth) | |
220 layer.scene.append(newscene) | |
221 btn = self.newCell('start.png') | |
222 btn.nScene = nth | |
238 | 223 btn.layer = layer.node.get('id') |
233 | 224 btn.nLayer = y |
225 self.grid.attach(btn, x, x+1, y, y+1,0,0,0,0) | |
226 | |
227 | |
236 | 228 |
229 | |
233 | 230 def removeKeyScene(self): |
231 nth = self.last_cell.nScene | |
236 | 232 try: |
238 | 233 layer = self.getLayer(self.last_cell.layer) |
236 | 234 except: |
235 return | |
233 | 236 x = self.last_cell.nScene |
237 y = self.last_cell.nLayer | |
238 for i in range(0,len(layer.scene)): | |
239 s = layer.scene[i] | |
240 if nth == s.start: | |
236 | 241 if i == 0: |
242 for j in range(s.start,s.end+1): | |
243 btn = self.newCell('empty.png') | |
244 btn.nScene = nth | |
245 btn.layer = layer | |
246 btn.nLayer = y | |
247 self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0) | |
248 layer.scene.remove(s) | |
249 else: | |
250 if s.start == layer.scene[i-1].end+1: | |
251 # If the start of the delete scene segment is the end of the last scene segmenet, convert all scenes in the deleted | |
252 # scene segmenet to the last one | |
253 layer.scene[i-1].end = s.end | |
254 layer.scene.remove(s) | |
255 btn = self.newCell('fill.png') | |
256 | |
257 btn.nScene = nth | |
258 btn.layer = layer | |
259 btn.nLayer = y | |
260 self.grid.attach(btn, x,x+1,y,y+1,0,0,0,0) | |
261 else: | |
262 # Convert all scenes into empty cell | |
263 layer.scene.remove(s) | |
264 for j in range(s.start,s.end+1): | |
265 btn = self.newCell('empty.png') | |
266 btn.nScene = nth | |
267 btn.layer = layer | |
268 btn.nLayer = y | |
269 self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0) | |
270 | |
271 | |
233 | 272 return |
273 | |
238 | 274 def extendScene(self): |
275 nth = self.last_cell.nScene | |
276 try: | |
277 layer = self.getLayer(self.last_cell.layer) | |
278 except: | |
279 return | |
280 x = self.last_cell.nScene | |
281 y = self.last_cell.nLayer | |
233 | 282 if layer == None: return |
238 | 283 |
284 for i in range(0,len(layer.scene)-1): | |
285 s = layer.scene[i] | |
286 if nth >= layer.scene[i].start and nth <= layer.scene[i].end: | |
287 return | |
288 | |
233 | 289 for i in range(0,len(layer.scene)-1): |
290 s = layer.scene[i] | |
291 if nth >= layer.scene[i].start and nth < layer.scene[i+1].start: | |
238 | 292 for j in range(layer.scene[i].end+1, nth+1): |
293 btn = self.newCell('fill.png') | |
294 btn.nScene = nth | |
295 btn.nLayer = y | |
296 btn.layer = self.last_cell.layer | |
297 self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0) | |
233 | 298 layer.scene[i].end = nth |
238 | 299 return |
300 if len(layer.scene) > 0 and nth > layer.scene[len(layer.scene)-1].end: | |
301 for j in range(layer.scene[len(layer.scene)-1].end+1, nth+1): | |
302 btn = self.newCell('fill.png') | |
303 btn.nScene = nth | |
304 btn.nLayer = y | |
305 btn.layer = self.last_cell.layer | |
306 self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0) | |
233 | 307 layer.scene[len(layer.scene)-1].end = nth |
308 def setCurrentScene(self,nth): | |
236 | 309 self.current = nth |
233 | 310 for layer in self.layer: |
311 for s in layer.scene: | |
312 if nth >= s.start and nth <= s.end: | |
313 s.node.set("style","") | |
234
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
314 #print "Put the elemenets out" |
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
315 layer.nodes = [] |
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
316 |
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
317 for o in s.node: |
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
318 #print " ",o.tag |
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
319 layer.nodes.append(o) |
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
320 for o in s.node: |
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
321 s.node.remove(o) |
233 | 322 else: |
323 s.node.set("style","display:none") | |
324 def generate(self): | |
325 newdoc = deepcopy(self.document) | |
326 root = newdoc.getroot() | |
236 | 327 has_scene = False |
233 | 328 for n in root: |
236 | 329 if n.tag == '{http://www.w3.org/2000/svg}metadata': |
330 for nn in n: | |
331 if nn.tag == '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scenes': | |
332 nn.clear() | |
333 nn.set("current", "%d" % self.current) | |
334 scenes = [] | |
335 for l in self.layer: | |
336 for s in l.scene: | |
337 id = s.node.get("id") | |
338 scene = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene') | |
339 scene.set("ref", id) | |
340 if s.start == s.end: | |
341 scene.set("start", "%d" % s.start) | |
342 else: | |
343 scene.set("start", "%d" % s.start) | |
344 scene.set("end", "%d" % s.end) | |
345 | |
346 scenes.append(scene) | |
347 for s in scenes: | |
348 nn.append(s) | |
349 has_scene = True | |
350 if has_scene == False: | |
351 scenes = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scenes') | |
352 scenes.set("current","%d" % self.current) | |
353 for l in self.layer: | |
354 for s in l.scene: | |
355 scene = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene') | |
356 scene.set("ref", s.node.get("id")) | |
357 if s.start == s.end: | |
358 scene.set("start", "%d" % s.start) | |
359 else: | |
360 scene.set("start", "%d" % s.start) | |
361 scene.set("end", "%d" % s.end) | |
362 scenes.append(scene) | |
363 n.append(scenes) | |
233 | 364 if n.tag == '{http://www.w3.org/2000/svg}g': |
365 root.remove(n) | |
366 | |
367 for l in self.layer: | |
368 # Duplicate all attribute of the layer | |
369 lnode = etree.Element("{http://www.w3.org/2000/svg}g") | |
370 for a,v in l.node.attrib.items(): | |
371 lnode.set(a,v) | |
234
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
372 for n in l.nodes: |
889cdc5f23c5
When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure.
wycc
parents:
233
diff
changeset
|
373 lnode.append(n) |
233 | 374 root.append(lnode) |
375 for s in l.scene: | |
376 snode = etree.Element("{http://www.w3.org/2000/svg}g") | |
377 for a,v in s.node.attrib.items(): | |
378 snode.set(a,v) | |
379 for n in s.node: | |
380 snode.append(deepcopy(n)) | |
381 lnode.append(snode) | |
382 self.document = newdoc | |
383 def newCell(self,file): | |
384 img = gtk.Image() | |
385 img.set_from_file(file) | |
386 btn = gtk.EventBox() | |
387 btn.add(img) | |
388 btn.connect("button_press_event", self.cellSelect) | |
389 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray")) | |
390 return btn | |
391 def showGrid(self): | |
392 max = 0 | |
393 for layer in self.layer: | |
394 for s in layer.scene: | |
395 if s.end > max: | |
396 max = s.end | |
397 max = 50 | |
398 | |
399 self.grid = gtk.Table(len(self.layer)+1, 50) | |
400 self.scrollwin = gtk.ScrolledWindow() | |
401 self.scrollwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) | |
402 self.scrollwin.add_with_viewport(self.grid) | |
403 for i in range(1,max): | |
404 self.grid.attach(gtk.Label('%d'% i), i,i+1,0,1,0,0,0,0) | |
405 for i in range(1,len(self.layer)+1): | |
406 l = self.layer[i-1] | |
238 | 407 self.grid.attach(gtk.Label(l.node.get('{http://www.inkscape.org/namespaces/inkscape}label')), 0, 1, i, i+1,0,0,10,0) |
233 | 408 for s in l.scene: |
409 btn = self.newCell('start.png') | |
410 btn.nScene = s.start | |
411 btn.layer = l.node.get('id') | |
412 btn.nLayer = i | |
413 | |
414 self.grid.attach(btn, s.start, s.start+1, i, i+1,0,0,0,0) | |
415 for j in range(s.start+1,s.end+1): | |
416 btn = self.newCell('fill.png') | |
417 self.grid.attach(btn, j, j+1, i , i+1,0,0,0,0) | |
418 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray")) | |
419 btn.nScene = j | |
420 btn.layer = l.node.get('id') | |
421 btn.nLayer = i | |
422 if len(l.scene) == 0: | |
423 start = 0 | |
424 else: | |
425 start = l.scene[len(l.scene)-1].end | |
426 for j in range(start,max): | |
427 btn = self.newCell('empty.png') | |
428 self.grid.attach(btn, j+1, j+2,i,i+1,0,0,0,0) | |
429 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray")) | |
430 btn.nScene = j+1 | |
431 btn.layer = l.node.get('id') | |
432 btn.nLayer = i | |
433 self.last_cell = None | |
434 def cellSelect(self, cell, data): | |
435 if self.last_cell: | |
436 self.last_cell.modify_bg(gtk.STATE_NORMAL, self.last_cell.get_colormap().alloc_color("gray")) | |
437 | |
438 self.last_cell = cell | |
439 cell.modify_bg(gtk.STATE_NORMAL, cell.get_colormap().alloc_color("green")) | |
440 | |
441 def doEditScene(self,w): | |
442 self.setCurrentScene(self.last_cell.nScene) | |
443 self.generate() | |
444 gtk.main_quit() | |
445 def doInsertKeyScene(self,w): | |
446 self.insertKeyScene() | |
447 self.grid.show_all() | |
448 self.generate() | |
449 | |
450 def doRemoveScene(self,w): | |
451 self.removeKeyScene() | |
452 self.grid.show_all() | |
453 self.generate() | |
238 | 454 def doExtendScene(self,w): |
455 self.extendScene() | |
456 self.grid.show_all() | |
457 self.generate() | |
233 | 458 def addButtons(self,hbox): |
459 btn = gtk.Button('Edit') | |
460 btn.connect('clicked', self.doEditScene) | |
461 hbox.pack_start(btn) | |
462 btn = gtk.Button('Insert Key') | |
463 btn.connect('clicked',self.doInsertKeyScene) | |
464 hbox.pack_start(btn) | |
465 btn=gtk.Button('Remove Key') | |
466 btn.connect('clicked', self.doRemoveScene) | |
467 hbox.pack_start(btn) | |
238 | 468 btn=gtk.Button('Extend scene') |
469 btn.connect('clicked', self.doExtendScene) | |
470 hbox.pack_start(btn) | |
248
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
471 def onQuit(self, event): |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
472 self.OK = False |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
473 gtk.main_quit() |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
474 def onOK(self,event): |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
475 self.OK = True |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
476 gtk.main_quit() |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
477 |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
478 def onConfirmDelete(self): |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
479 if self.scenemap == None: |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
480 vbox = gtk.VBox() |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
481 vbox.pack_start(gtk.Label('Convert the SVG into a MadButterfly SVG file. All current element will be delted')) |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
482 hbox = gtk.HBox() |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
483 self.button = gtk.Button('OK') |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
484 hbox.pack_start(self.button) |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
485 self.button.connect('clicked', self.onOK) |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
486 self.button = gtk.Button('Cancel') |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
487 hbox.pack_start(self.button) |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
488 self.button.connect("clicked", self.onQuit) |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
489 vbox.pack_start(hbox) |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
490 self.window.add(vbox) |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
491 self.window.show_all() |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
492 gtk.main() |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
493 self.window.remove(vbox) |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
494 |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
495 |
233 | 496 def effect(self): |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
248
diff
changeset
|
497 self.OK = True |
233 | 498 self.parseScene() |
499 self.showGrid() | |
500 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) | |
501 self.window.connect("destroy", gtk.main_quit) | |
502 self.window.set_position(gtk.WIN_POS_MOUSE) | |
248
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
503 if self.scenemap == None: |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
504 self.onConfirmDelete() |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
505 if self.OK: |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
506 vbox = gtk.VBox() |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
507 self.window.add(vbox) |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
508 vbox.add(self.scrollwin) |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
509 self.vbox = vbox |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
510 hbox=gtk.HBox() |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
511 self.addButtons(hbox) |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
512 vbox.add(hbox) |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
513 else: |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
514 return |
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
515 |
233 | 516 self.window.set_size_request(600,200) |
248
1958bb2a87a2
* Check if the selected element is a group ot not. A symbol or button must be a group.
wycc
parents:
242
diff
changeset
|
517 |
233 | 518 self.window.show_all() |
519 gtk.main() | |
520 | |
521 | |
522 | |
242
d3fe0a0f3a8b
Implement MBApp API and modify the dynamic example to use this API.
wycc
parents:
238
diff
changeset
|
523 import os |
233 | 524 |
242
d3fe0a0f3a8b
Implement MBApp API and modify the dynamic example to use this API.
wycc
parents:
238
diff
changeset
|
525 os.chdir('/usr/share/inkscape/extensions') |
233 | 526 |
527 A = MBScene() | |
528 A.affect() | |
529 | |
530 |