comparison pyink/MBScene.py @ 1176:0c1ceecb8ddb

Move parseMetadata to MBScene_dom
author Thinker K.F. Li <thinker@codemud.net>
date Fri, 31 Dec 2010 10:12:44 +0800
parents 96a7abce774a
children ec1ea8555911
comparison
equal deleted inserted replaced
1175:c8c94ce92645 1176:0c1ceecb8ddb
151 pass 151 pass
152 yield node 152 yield node
153 pass 153 pass
154 pass 154 pass
155 155
156 class MBScene(): 156 class MBScene_dom(object):
157 def dumpattr(self, n):
158 s = ""
159 for a,v in n.attrib.items():
160 s = s + ("%s=%s" % (a,v))
161 pass
162 return s
163
164 def dump(self, node, l=0):
165 print " " * l*2,"<", node.tag, self.dumpattr(node),">"
166 for n in node:
167 self.dump(n, l+1)
168 pass
169 print " " * l * 2,"/>"
170 pass
171
172 def _parse_one_scenes(self, scenes):
173 self.scenemap = {}
174 try:
175 cur = int(n.getAttribute("current"))
176 except:
177 cur = 1
178 pass
179 self.current = cur
180
181 for scene in scenes.childList():
182 if scene.name() != 'ns0:scene':
183 continue
184
185 try:
186 start = int(scene.getAttribute("start"))
187 except:
188 traceback.print_exc()
189 continue
190 try:
191 end = int(scene.getAttribute("end"))
192 except:
193 end = start
194 pass
195
196 if end > self.maxframe:
197 self.maxframe = end
198 pass
199 try:
200 scene_type = scene.getAttribute('type')
201 if scene_type == None:
202 scene_type = 'normal'
203 pass
204 except:
205 traceback.print_exc()
206 scene_type = 'normal'
207 pass
208 link = scene.getAttribute("ref")
209 self.scenemap[link] = [int(start), int(end), scene_type]
210 if cur >= start and cur <= end:
211 self.currentscene = link
212 pass
213 pass
214 pass
215
216 def parseMetadata(self, node):
217 for n in node.childList():
218 if n.name() == 'ns0:scenes':
219 self._parse_one_scenes(n)
220 break
221 pass
222 else:
223 ns = "http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd"
224 self.root.setAttribute("xmlns:ns0", ns)
225 scenes = self.document.createElement("ns0:scenes")
226 node.appendChild(scenes)
227 pass
228 pass
229 pass
230
231 class MBScene(MBScene_dom):
157 _frameline_tween_types = (frameline.TWEEN_TYPE_NONE, 232 _frameline_tween_types = (frameline.TWEEN_TYPE_NONE,
158 frameline.TWEEN_TYPE_SHAPE) 233 frameline.TWEEN_TYPE_SHAPE)
159 _tween_obj_tween_types = (TweenObject.TWEEN_TYPE_NORMAL, 234 _tween_obj_tween_types = (TweenObject.TWEEN_TYPE_NORMAL,
160 TweenObject.TWEEN_TYPE_SCALE) 235 TweenObject.TWEEN_TYPE_SCALE)
161 _tween_type_names = ('normal', 'scale') 236 _tween_type_names = ('normal', 'scale')
203 vbox.pack_start(gtk.Label(msg)) 278 vbox.pack_start(gtk.Label(msg))
204 self.button = gtk.Button('OK') 279 self.button = gtk.Button('OK')
205 vbox.pack_start(self.button) 280 vbox.pack_start(self.button)
206 self.button.connect("clicked", self.onQuit) 281 self.button.connect("clicked", self.onQuit)
207 self.window.add(vbox) 282 self.window.add(vbox)
208 pass
209
210 def dumpattr(self,n):
211 s = ""
212 for a,v in n.attrib.items():
213 s = s + ("%s=%s" % (a,v))
214 pass
215 return s
216
217 def dump(self,node,l=0):
218 print " " * l*2,"<", node.tag, self.dumpattr(node),">"
219 for n in node:
220 self.dump(n,l+1)
221 pass
222 print " " * l * 2,"/>"
223 pass
224
225 def parseMetadata(self,node):
226 self.current = 1
227 for n in node.childList():
228 if n.name() == 'ns0:scenes':
229 self.scenemap={}
230 try:
231 cur = int(n.getAttribute("current"))
232 except:
233 cur = 1
234 self.current = cur
235
236 for s in n.childList():
237 if s.name() == 'ns0:scene':
238 try:
239 start = int(s.getAttribute("start"))
240 except:
241 traceback.print_exc()
242 continue
243 try:
244 end = int(s.getAttribute("end"))
245 if end == None:
246 end = start
247 pass
248 except:
249 end = start
250 pass
251 if end > self.maxframe:
252 self.maxframe = end
253 try:
254 typ = s.getAttribute('type')
255 if typ == None:
256 typ = 'normal'
257 except:
258 traceback.print_exc()
259 typ = 'normal'
260 link = s.getAttribute("ref")
261 self.scenemap[link] = [int(start),int(end),typ]
262 if cur >= start and cur <= end:
263 self.currentscene = link
264 pass
265 pass
266 pass
267 pass
268 pass
269 pass
270 if self.scenemap==None:
271 #self.desktop.doc().root().repr.setAttribute("xmlns:ns0","http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd")
272 self.root.setAttribute("xmlns:ns0","http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd")
273 scenes = self.document.createElement("ns0:scenes")
274 node.appendChild(scenes)
275 pass
276 pass 283 pass
277 284
278 def update(self): 285 def update(self):
279 doc = self.root 286 doc = self.root
280 rdoc = self.document 287 rdoc = self.document