Mercurial > MadButterfly
annotate pyink/MBScene.py @ 973:84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
author | wycc |
---|---|
date | Sat, 20 Nov 2010 11:45:17 +0800 |
parents | 1028f6278ead |
children | ed7e8e309d55 |
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 |
973
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
10 import time |
941
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
11 |
957 | 12 # Please refer to |
13 # http://www.assembla.com/wiki/show/MadButterfly/Inkscape_extention | |
14 # 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
|
15 |
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
16 |
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
17 # Algorithm: |
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
18 # |
955
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
19 # 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
|
20 # layer and scene. |
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
21 # - 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
|
22 # column of the grid. |
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
23 # - 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
|
24 # grid. |
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
25 # - 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
|
26 # 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
|
27 # 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
|
28 # 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
|
29 # for this purpose. |
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
30 # - 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
|
31 # 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
|
32 # 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
|
33 # 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
|
34 # 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
|
35 # 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
|
36 # - 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
|
37 # 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
|
38 # |
941
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
39 |
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
40 class Layer: |
955
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
41 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
|
42 self.scenes = [] |
955
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
43 self.node = node |
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
44 self.nodes=[] |
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 pass |
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
47 |
941
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
48 class Scene: |
956 | 49 def __init__(self, node, start,end): |
50 self.node = node | |
51 self.start = int(start) | |
52 self.end = int(end) | |
955
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
53 pass |
956 | 54 pass |
941
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
55 |
957 | 56 _scenes = '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scenes' |
57 _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
|
58 |
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
59 class MBScene(): |
956 | 60 def __init__(self,desktop,win): |
61 self.desktop = desktop | |
62 self.window = win | |
961
b6375e74c69e
Rename MBScene.layer to MBScene.layers
Thinker K.F. Li <thinker@codemud.net>
parents:
960
diff
changeset
|
63 self.layers = [] |
b6375e74c69e
Rename MBScene.layer to MBScene.layers
Thinker K.F. Li <thinker@codemud.net>
parents:
960
diff
changeset
|
64 self.layers.append(Layer(None)) |
956 | 65 self.scenemap = None |
66 pass | |
941
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
67 |
956 | 68 def confirm(self,msg): |
69 vbox = gtk.VBox() | |
70 vbox.pack_start(gtk.Label(msg)) | |
71 self.button = gtk.Button('OK') | |
72 vbox.pack_start(self.button) | |
73 self.button.connect("clicked", self.onQuit) | |
74 self.window.add(vbox) | |
75 pass | |
76 | |
77 def dumpattr(self,n): | |
78 s = "" | |
79 for a,v in n.attrib.items(): | |
80 s = s + ("%s=%s" % (a,v)) | |
81 pass | |
82 return s | |
955
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
83 |
956 | 84 def dump(self,node,l=0): |
85 print " " * l*2,"<", node.tag, self.dumpattr(node),">" | |
86 for n in node: | |
87 self.dump(n,l+1) | |
88 pass | |
89 print " " * l * 2,"/>" | |
90 pass | |
91 | |
92 def parseMetadata(self,node): | |
93 self.current = 1 | |
94 for n in node.childList(): | |
95 if n.repr.name() == 'ns0:scenes': | |
96 self.scenemap={} | |
97 cur = int(n.repr.attribute("current")) | |
98 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
|
99 |
956 | 100 for s in n.childList(): |
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 | |
973
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
127 def update(self): |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
128 doc = self.desktop.doc().root() |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
129 rdoc = self.desktop.doc().rdoc |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
130 for node in doc.childList(): |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
131 if node.repr.name() == 'svg:metadata': |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
132 for t in node.childList(): |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
133 if t.repr.name() == "ns0:scenes": |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
134 node.repr.removeChild(t.repr) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
135 ns = rdoc.createElement("ns0:scenes") |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
136 node.repr.appendChild(ns) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
137 for layer in range(0,len(self._framelines)): |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
138 lobj = self._framelines[layer] |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
139 lobj.addScenes(rdoc,ns) |
956 | 140 |
141 | |
142 def parseScene(self): | |
143 """ | |
957 | 144 In this function, we will collect all items for the current |
145 scene and then relocate them back to the appropriate scene | |
146 object. | |
956 | 147 """ |
961
b6375e74c69e
Rename MBScene.layer to MBScene.layers
Thinker K.F. Li <thinker@codemud.net>
parents:
960
diff
changeset
|
148 self.layers = [] |
956 | 149 self.scenemap = None |
150 doc = self.desktop.doc().root() | |
151 | |
152 for node in doc.childList(): | |
153 if node.repr.name() == 'svg:metadata': | |
154 self.parseMetadata(node) | |
955
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
155 pass |
956 | 156 elif node.repr.name() == 'svg:g': |
157 oldscene = None | |
158 #print layer.attrib.get("id") | |
159 lyobj = Layer(node) | |
961
b6375e74c69e
Rename MBScene.layer to MBScene.layers
Thinker K.F. Li <thinker@codemud.net>
parents:
960
diff
changeset
|
160 self.layers.append(lyobj) |
956 | 161 lyobj.current_scene = [] |
162 for scene in node.childList(): | |
163 if scene.repr.name() == 'svg:g': | |
164 try: | |
165 scmap = self.scenemap[scene.getId()] | |
166 if scmap == None: | |
167 lyobj.current_scene.append(scene) | |
168 continue | |
957 | 169 if self.current <= scmap[1] and \ |
170 self.current >= scmap[0]: | |
956 | 171 oldscene = scene |
172 pass | |
173 except: | |
174 lyobj.current_scene.append(scene) | |
175 continue | |
176 | |
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
|
177 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
|
178 pass |
956 | 179 else: |
180 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
|
181 pass |
956 | 182 pass |
183 | |
184 if oldscene != None: | |
185 # Put the objects back to the current scene | |
186 # for o in lyobj.current_scene: | |
187 # print o.tag | |
188 # oldscene.append(o) | |
189 pass | |
955
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
190 pass |
956 | 191 pass |
192 | |
193 self.collectID() | |
194 self.dumpID() | |
195 pass | |
196 | |
197 def collectID(self): | |
198 self.ID = {} | |
199 root = self.desktop.doc().root() | |
200 for n in root.childList(): | |
201 self.collectID_recursive(n) | |
202 pass | |
203 pass | |
204 | |
205 def collectID_recursive(self,node): | |
206 self.ID[node.getId()] = 1 | |
207 for n in node.childList(): | |
208 self.collectID_recursive(n) | |
209 pass | |
210 pass | |
211 | |
212 def newID(self): | |
213 while True: | |
214 n = 's%d' % int(random.random()*10000) | |
215 #print "try %s" % n | |
216 if self.ID.has_key(n) == False: | |
217 return n | |
218 pass | |
219 pass | |
220 | |
221 def dumpID(self): | |
222 for a,v in self.ID.items(): | |
223 pass | |
224 pass | |
225 | |
226 def getLayer(self, layer): | |
961
b6375e74c69e
Rename MBScene.layer to MBScene.layers
Thinker K.F. Li <thinker@codemud.net>
parents:
960
diff
changeset
|
227 for l in self.layers: |
956 | 228 if l.node.getId() == layer: |
229 return l | |
230 pass | |
231 return None | |
232 | |
233 | |
234 def insertKeyScene(self): | |
235 """ | |
957 | 236 Insert a new key scene into the stage. If the nth is always a |
237 key scene, we will return without changing anything. If the | |
238 nth is a filled scene, we will break the original scene into | |
239 two parts. If the nth is out of any scene, we will append a | |
240 new scene. | |
941
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
241 |
956 | 242 """ |
973
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
243 x = self.last_frame |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
244 y = self.last_line |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
245 rdoc = self.desktop.doc().rdoc |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
246 ns = rdoc.createElement("svg:g") |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
247 txt = rdoc.createElement("svg:rect") |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
248 txt.setAttribute("x","0",True) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
249 txt.setAttribute("y","0",True) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
250 txt.setAttribute("width","100",True) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
251 txt.setAttribute("height","100",True) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
252 txt.setAttribute("style","fill:#ff00",True) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
253 ns.appendChild(txt) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
254 gid = self.newID() |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
255 ns.setAttribute("id",gid,True) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
256 self.last_line.node.repr.appendChild(ns) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
257 self.last_line.add_keyframe(x,ns) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
258 self.update() |
956 | 259 |
260 | |
261 def removeKeyScene(self): | |
973
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
262 nth = self.last_frame |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
263 y = self.last_line |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
264 rdoc = self.desktop.doc().rdoc |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
265 i = 0 |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
266 layer = self.last_line |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
267 while i < len(layer._keys): |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
268 s = layer._keys[i] |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
269 print "nth:%d idx %d" % (nth,s.idx) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
270 if nth > s.idx: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
271 if i == len(layer._keys)-1: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
272 return |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
273 if nth == s.idx: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
274 if s.left_tween: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
275 # This is left tween, we move the keyframe one frame ahead |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
276 if s.idx == layer._keys[i-1].idx: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
277 layer._keys[i].ref.parent().removeChild(layer._keys[i].ref) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
278 self.last_line.rm_keyframe(nth) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
279 self.last_line.rm_keyframe(nth-1) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
280 else: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
281 s.idx = s.idx-1 |
941
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
282 else: |
973
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
283 layer._keys[i].ref.parent().removeChild(layer._keys[i].ref) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
284 if s.right_tween: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
285 self.last_line.rm_keyframe(layer._keys[i+1].idx) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
286 self.last_line.rm_keyframe(nth) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
287 else: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
288 self.last_line.rm_keyframe(nth) |
941
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
289 |
973
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
290 self.update() |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
291 self.last_line._draw_all_frames() |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
292 return |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
293 i = i + 1 |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
294 def extendScene(self): |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
295 nth = self.last_frame |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
296 layer = self.last_line |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
297 i = 0 |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
298 while i < len(layer._keys): |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
299 s = layer._keys[i] |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
300 if s.right_tween: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
301 if nth > s.idx: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
302 if nth <= layer._keys[i+1].idx: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
303 return |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
304 try: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
305 if nth <= layer._keys[i+2].idx: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
306 layer._keys[i+1].idx = nth |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
307 layer.draw_all_frames() |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
308 self.update() |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
309 self.setCurrentScene(nth) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
310 return |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
311 else: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
312 # We may in the next scene |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
313 i = i + 2 |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
314 pass |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
315 except: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
316 # This is the last keyframe, extend the keyframe by |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
317 # relocate the location of the keyframe |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
318 layer._keys[i+1].idx = nth |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
319 layer._draw_all_frames() |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
320 self.update() |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
321 self.setCurrentScene(nth) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
322 return |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
323 else: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
324 # We are in the front of all keyframes |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
325 return |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
326 else: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
327 # This is a single keyframe |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
328 if nth < s.idx: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
329 return |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
330 if nth == s.idx: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
331 return |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
332 try: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
333 if nth < layer._keys[i+1].idx: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
334 # We are after a single keyframe and no scene is |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
335 # available here. Create a new tween here |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
336 idx = layer._keys[i].idx |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
337 layer.add_keyframe(nth,layer._keys[i].ref) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
338 layer.tween(idx) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
339 layer._draw_all_frames() |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
340 self.update() |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
341 self.setCurrentScene(nth) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
342 return |
956 | 343 else: |
973
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
344 # We may in the next scene |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
345 i = i + 1 |
956 | 346 pass |
347 pass | |
973
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
348 except: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
349 # This is the last scene, create a new one |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
350 idx = layer._keys[i].idx |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
351 layer.add_keyframe(nth,layer._keys[i].ref) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
352 layer.tween(idx) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
353 layer._draw_all_frames() |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
354 self.update() |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
355 self.setCurrentScene(nth) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
356 return |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
357 pass |
956 | 358 pass |
359 pass | |
941
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
360 |
956 | 361 |
362 def setCurrentScene(self,nth): | |
363 self.current = nth | |
973
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
364 for layer in self._framelines: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
365 i=0 |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
366 while i < len(layer._keys): |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
367 s = layer._keys[i] |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
368 print s.ref.attribute("id"),s.idx,s.left_tween,s.right_tween |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
369 if s.right_tween is False: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
370 if nth == s.idx: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
371 s.ref.setAttribute("style","",True) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
372 else: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
373 s.ref.setAttribute("style","display:none",True) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
374 i = i + 1 |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
375 continue |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
376 |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
377 if nth >= (s.idx+1) and nth <= (layer._keys[i+1].idx+1): |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
378 s.ref.setAttribute("style","",True) |
959
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
379 else: |
973
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
380 s.ref.setAttribute("style","display:none",True) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
381 i = i + 2 |
955
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
382 pass |
956 | 383 pass |
384 pass | |
955
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
385 |
956 | 386 def generate(self): |
387 newdoc = deepcopy(self.document) | |
388 root = newdoc.getroot() | |
389 has_scene = False | |
390 for n in root: | |
391 if n.tag == '{http://www.w3.org/2000/svg}metadata': | |
392 for nn in n: | |
957 | 393 if nn.tag == _scenes: |
956 | 394 nn.clear() |
395 nn.set("current", "%d" % self.current) | |
396 scenes = [] | |
961
b6375e74c69e
Rename MBScene.layer to MBScene.layers
Thinker K.F. Li <thinker@codemud.net>
parents:
960
diff
changeset
|
397 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
|
398 for s in l.scenes: |
956 | 399 id = s.node.get("id") |
957 | 400 scene = etree.Element(_scene) |
956 | 401 scene.set("ref", id) |
402 if s.start == s.end: | |
403 scene.set("start", "%d" % s.start) | |
404 else: | |
405 scene.set("start", "%d" % s.start) | |
406 scene.set("end", "%d" % s.end) | |
407 pass | |
941
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
408 |
956 | 409 scenes.append(scene) |
410 pass | |
411 pass | |
412 for s in scenes: | |
413 nn.append(s) | |
414 pass | |
415 has_scene = True | |
955
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
416 pass |
956 | 417 pass |
418 if has_scene == False: | |
957 | 419 scenes = etree.Element(_scenes) |
956 | 420 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
|
421 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
|
422 for s in l.scenes: |
957 | 423 scene = etree.Element(_scene) |
956 | 424 scene.set("ref", s.node.get("id")) |
425 if s.start == s.end: | |
426 scene.set("start", "%d" % s.start) | |
427 else: | |
428 scene.set("start", "%d" % s.start) | |
429 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
|
430 pass |
956 | 431 scenes.append(scene) |
432 pass | |
955
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
433 pass |
956 | 434 n.append(scenes) |
435 pass | |
955
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
436 pass |
956 | 437 if n.tag == '{http://www.w3.org/2000/svg}g': |
438 root.remove(n) | |
439 pass | |
440 pass | |
955
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
441 |
961
b6375e74c69e
Rename MBScene.layer to MBScene.layers
Thinker K.F. Li <thinker@codemud.net>
parents:
960
diff
changeset
|
442 for l in self.layers: |
956 | 443 # Duplicate all attribute of the layer |
444 lnode = etree.Element("{http://www.w3.org/2000/svg}g") | |
445 for a,v in l.node.attrib.items(): | |
446 lnode.set(a,v) | |
447 pass | |
448 for n in l.nodes: | |
449 lnode.append(n) | |
450 pass | |
451 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
|
452 for s in l.scenes: |
956 | 453 snode = etree.Element("{http://www.w3.org/2000/svg}g") |
454 for a,v in s.node.attrib.items(): | |
455 snode.set(a,v) | |
456 pass | |
457 for n in s.node: | |
458 snode.append(deepcopy(n)) | |
459 pass | |
460 lnode.append(snode) | |
955
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
461 pass |
956 | 462 pass |
463 self.document = newdoc | |
464 pass | |
955
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
465 |
956 | 466 def newCell(self,file): |
467 img = gtk.Image() | |
468 img.set_from_file(file) | |
469 btn = gtk.EventBox() | |
470 btn.add(img) | |
471 btn.connect("button_press_event", self.cellSelect) | |
472 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray")) | |
473 return btn | |
474 | |
973
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
475 def onCellClick(self,line,frame,but): |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
476 self.last_line = line |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
477 self.last_frame = frame |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
478 self.doEditScene(frame) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
479 |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
480 |
963
a05ec4fb1c20
update framelines according content 0f layers
Thinker K.F. Li <thinker@codemud.net>
parents:
962
diff
changeset
|
481 def _create_framelines(self): |
959
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
482 import frameline |
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
483 self.scrollwin = gtk.ScrolledWindow() |
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
484 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
|
485 self.scrollwin.set_size_request(-1,150) |
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
486 |
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
487 nframes = 100 |
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
488 |
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
489 vbox = gtk.VBox() |
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
490 vbox.show() |
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
491 self.scrollwin.add_with_viewport(vbox) |
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
492 |
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
493 ruler = frameline.frameruler(nframes) |
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
494 ruler.set_size_request(nframes * 10, 20) |
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
495 ruler.show() |
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
496 vbox.pack_start(ruler, False) |
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
497 |
960
8fd97e0becb3
Add a frameline for each layer
Thinker K.F. Li <thinker@codemud.net>
parents:
959
diff
changeset
|
498 # |
8fd97e0becb3
Add a frameline for each layer
Thinker K.F. Li <thinker@codemud.net>
parents:
959
diff
changeset
|
499 # Add a frameline for each layer |
8fd97e0becb3
Add a frameline for each layer
Thinker K.F. Li <thinker@codemud.net>
parents:
959
diff
changeset
|
500 # |
8fd97e0becb3
Add a frameline for each layer
Thinker K.F. Li <thinker@codemud.net>
parents:
959
diff
changeset
|
501 self._framelines = [] |
961
b6375e74c69e
Rename MBScene.layer to MBScene.layers
Thinker K.F. Li <thinker@codemud.net>
parents:
960
diff
changeset
|
502 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
|
503 line = frameline.frameline(nframes) |
8fd97e0becb3
Add a frameline for each layer
Thinker K.F. Li <thinker@codemud.net>
parents:
959
diff
changeset
|
504 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
|
505 vbox.pack_start(line, False) |
8fd97e0becb3
Add a frameline for each layer
Thinker K.F. Li <thinker@codemud.net>
parents:
959
diff
changeset
|
506 self._framelines.append(line) |
973
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
507 line.connect(line.FRAME_BUT_PRESS, self.onCellClick) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
508 line.nLayer = i |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
509 line.node = self.layers[i].node |
960
8fd97e0becb3
Add a frameline for each layer
Thinker K.F. Li <thinker@codemud.net>
parents:
959
diff
changeset
|
510 pass |
8fd97e0becb3
Add a frameline for each layer
Thinker K.F. Li <thinker@codemud.net>
parents:
959
diff
changeset
|
511 pass |
8fd97e0becb3
Add a frameline for each layer
Thinker K.F. Li <thinker@codemud.net>
parents:
959
diff
changeset
|
512 |
963
a05ec4fb1c20
update framelines according content 0f layers
Thinker K.F. Li <thinker@codemud.net>
parents:
962
diff
changeset
|
513 ## \brief Update conetent of frameliens according layers. |
a05ec4fb1c20
update framelines according content 0f layers
Thinker K.F. Li <thinker@codemud.net>
parents:
962
diff
changeset
|
514 # |
a05ec4fb1c20
update framelines according content 0f layers
Thinker K.F. Li <thinker@codemud.net>
parents:
962
diff
changeset
|
515 def _update_framelines(self): |
a05ec4fb1c20
update framelines according content 0f layers
Thinker K.F. Li <thinker@codemud.net>
parents:
962
diff
changeset
|
516 for layer_i, layer in enumerate(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
|
517 for scene in layer.scenes: |
963
a05ec4fb1c20
update framelines according content 0f layers
Thinker K.F. Li <thinker@codemud.net>
parents:
962
diff
changeset
|
518 frameline = self._framelines[layer_i] |
973
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
519 frameline.add_keyframe(scene.start-1,scene.node.repr) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
520 if scene.start != scene.end: |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
521 frameline.add_keyframe(scene.end-1,scene.node.repr) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
522 frameline.tween(scene.start-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
|
523 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
|
524 pass |
959
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
525 pass |
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
526 |
956 | 527 def cellSelect(self, cell, data): |
528 if self.last_cell: | |
957 | 529 color = self.last_cell.get_colormap().alloc_color("gray") |
530 self.last_cell.modify_bg(gtk.STATE_NORMAL, color) | |
956 | 531 pass |
955
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
532 |
956 | 533 self.last_cell = cell |
957 | 534 color = cell.get_colormap().alloc_color("green") |
535 cell.modify_bg(gtk.STATE_NORMAL, color) | |
956 | 536 pass |
537 | |
538 def doEditScene(self,w): | |
973
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
539 self.setCurrentScene(self.last_frame+1) |
956 | 540 pass |
541 | |
542 def doInsertKeyScene(self,w): | |
973
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
543 self.insertKeyScene() |
956 | 544 # self.grid.show_all() |
545 return | |
546 | |
547 def doRemoveScene(self,w): | |
973
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
548 self.removeKeyScene() |
956 | 549 # self.grid.show_all() |
550 # self.generate() | |
551 return | |
941
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
552 |
956 | 553 |
554 def doExtendScene(self,w): | |
555 self.extendScene() | |
973
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
556 #self.grid.show_all() |
956 | 557 pass |
558 | |
559 def addButtons(self,hbox): | |
973
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
560 #btn = gtk.Button('Edit') |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
561 #btn.connect('clicked', self.doEditScene) |
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
562 #hbox.pack_start(btn,expand=False,fill=False) |
956 | 563 btn = gtk.Button('Insert Key') |
564 btn.connect('clicked',self.doInsertKeyScene) | |
565 hbox.pack_start(btn,expand=False,fill=False) | |
566 btn=gtk.Button('Remove Key') | |
567 btn.connect('clicked', self.doRemoveScene) | |
568 hbox.pack_start(btn,expand=False,fill=False) | |
569 btn=gtk.Button('Extend scene') | |
570 btn.connect('clicked', self.doExtendScene) | |
571 hbox.pack_start(btn,expand=False,fill=False) | |
572 pass | |
573 | |
574 def onQuit(self, event): | |
575 self.OK = False | |
576 gtk.main_quit() | |
577 pass | |
578 | |
579 def onOK(self,event): | |
580 self.OK = True | |
581 gtk.main_quit() | |
582 pass | |
941
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
583 |
956 | 584 def onConfirmDelete(self): |
585 if self.scenemap == None: | |
586 vbox = gtk.VBox(False,0) | |
957 | 587 vbox.pack_start(gtk.Label('Convert the SVG into a MadButterfly' |
588 ' SVG file. All current element will' | |
589 ' be delted')) | |
956 | 590 hbox = gtk.HBox(False,0) |
591 self.button = gtk.Button('OK') | |
592 hbox.pack_start(self.button,expand=False,fill=False) | |
593 self.button.connect('clicked', self.onOK) | |
594 self.button = gtk.Button('Cancel') | |
595 hbox.pack_start(self.button,expand=False,fill=False) | |
596 self.button.connect("clicked", self.onQuit) | |
597 vbox.pack_start(hbox,expand=False,fill=False) | |
598 self.window.add(vbox) | |
599 self.window.show_all() | |
600 gtk.main() | |
601 self.window.remove(vbox) | |
602 pass | |
603 pass | |
941
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
604 |
956 | 605 def show(self): |
606 self.OK = True | |
607 self.parseScene() | |
963
a05ec4fb1c20
update framelines according content 0f layers
Thinker K.F. Li <thinker@codemud.net>
parents:
962
diff
changeset
|
608 self._create_framelines() |
a05ec4fb1c20
update framelines according content 0f layers
Thinker K.F. Li <thinker@codemud.net>
parents:
962
diff
changeset
|
609 self._update_framelines() |
956 | 610 vbox = gtk.VBox(False,0) |
611 self.desktop.getToplevel().child.child.pack_end(vbox,expand=False) | |
612 self.window = vbox | |
613 # self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) | |
614 # self.window.connect("destroy", gtk.main_quit) | |
615 # self.window.set_position(gtk.WIN_POS_MOUSE) | |
616 if self.scenemap == None: | |
617 self.onConfirmDelete() | |
618 pass | |
619 if self.OK: | |
620 vbox = gtk.VBox(False,0) | |
621 self.window.pack_start(vbox,expand=False) | |
622 vbox.pack_start(self.scrollwin,expand=False) | |
623 self.vbox = vbox | |
624 hbox=gtk.HBox(False,0) | |
625 self.addButtons(hbox) | |
626 vbox.pack_start(hbox,expand=False) | |
627 else: | |
628 return | |
941
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
629 |
956 | 630 # self.window.set_size_request(600,200) |
631 | |
632 self.window.show_all() | |
955
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
633 pass |
956 | 634 pass |