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