# HG changeset patch # User wycc # Date 1293033646 -28800 # Node ID 8f0ee167c5b2f04186ef1f6b4cd76768deac0bf3 # Parent d4dbcb93aee0ab91252afaf06fa01c2d84437ceb# Parent a2b0685944122ba28cf257f34ba08a7243819712 Fix the issue of the new DOM implementation diff -r d4dbcb93aee0 -r 8f0ee167c5b2 pyink/MBScene.py --- a/pyink/MBScene.py Wed Dec 22 23:02:46 2010 +0800 +++ b/pyink/MBScene.py Thu Dec 23 00:00:46 2010 +0800 @@ -151,7 +151,7 @@ return self.last_select = o try: - self.nameEditor.set_text(o.repr.attribute("inkscape:label")) + self.nameEditor.set_text(o.getAttribute("inkscape:label")) except: self.nameEditor.set_text('') pass @@ -186,7 +186,7 @@ if n.name() == 'ns0:scenes': self.scenemap={} try: - cur = int(n.attribute("current")) + cur = int(n.getAttribute("current")) except: cur = 1 self.current = cur @@ -194,12 +194,12 @@ for s in n.childList(): if s.name() == 'ns0:scene': try: - start = int(s.attribute("start")) + start = int(s.getAttribute("start")) except: traceback.print_exc() continue try: - end = s.attribute("end") + end = s.getAttribute("end") if end == None: end = start pass @@ -207,13 +207,13 @@ end = start pass try: - typ = s.attribute('type') + typ = s.getAttribute('type') if typ == None: typ = 'normal' except: traceback.print_exc() typ = 'normal' - link = s.attribute("ref") + link = s.getAttribute("ref") self.scenemap[link] = [int(start),int(end),typ] if cur >= start and cur <= end: self.currentscene = link @@ -260,8 +260,8 @@ addEventListener(doc,'DOMNodeRemoved',self.updateUI,None) doc.childList() try: - self.width = float(doc.attribute("width")) - self.height= float(doc.attribute("height")) + self.width = float(doc.getAttribute("width")) + self.height= float(doc.getAttribute("height")) except: self.width = 640 self.height=480 @@ -283,14 +283,14 @@ print scene.getCenter() if scene.name() == 'svg:g': try: - label = scene.attribute('inkscape:label') + label = scene.getAttribute('inkscape:label') if label == 'dup': node.removeChild(scene) except: pass try: - scmap = self.scenemap[scene.getId()] + scmap = self.scenemap[scene.getAttribute('id')] if scmap == None: lyobj.current_scene.append(scene) continue @@ -321,7 +321,10 @@ pass def collectID_recursive(self,node): - self.ID[node.getId()] = 1 + try: + self.ID[node.getAttribute('id')] = 1 + except: + pass for n in node.childList(): self.collectID_recursive(n) pass @@ -343,7 +346,7 @@ def getLayer(self, layer): for l in self.layers: - if l.node.getId() == layer: + if l.node.getAttribute('id') == layer: return l pass return None @@ -520,7 +523,7 @@ while i < len(layer._keys): s = layer._keys[i] - print s.ref.attribute("id"),s.idx,s.left_tween,s.right_tween + print s.ref.getAttribute("id"),s.idx,s.left_tween,s.right_tween if s.right_tween is False: if nth == s.idx+1: s.ref.setAttribute("style","") @@ -553,11 +556,26 @@ pass pass + def DOMtoItem(self,obj): + """ + Find the corresponding PYSPObject object for a DOM object. + """ + return self.DOMtoItem_recursive(self.desktop.doc().root(),obj) + + def DOMtoItem_recursive(self,tree,obj): + nodes = tree.childList() + for s in nodes: + if s.getId() == obj.getAttribute('id'): + return s + d = self.DOMtoItem_recursive(s,obj) + if d != None: return d + + def enterGroup(self,obj): for l in self.layers: for s in l.node.childList(): - if s.getId() == obj.attribute("id"): - self.desktop.setCurrentLayer(s) + if s.getAttribute('id') == obj.getAttribute("id"): + self.desktop.setCurrentLayer(self.DOMtoItem(s)) def selectSceneObject(self,frameline, nth): i = 0 @@ -648,7 +666,7 @@ for i in range(len(self.layers)-1,-1,-1): line = frameline.frameline(nframes) hbox = gtk.HBox() - label = gtk.Label(self.layers[i].node.label()) + label = gtk.Label(self.layers[i].node.getAttribute("inkscape:label")) label.set_size_request(100,0) hbox.pack_start(label,expand=False,fill=True) hbox.pack_start(line) @@ -669,10 +687,10 @@ def _update_framelines(self): for frameline in self._framelines: layer = frameline.layer - if frameline.node.label()==None: + if frameline.node.getAttribute("inkscape:label")==None: frameline.label.set_text('???') else: - frameline.label.set_text(frameline.node.label()) + frameline.label.set_text(frameline.node.getAttribute("inkscape:label")) for scene in layer.scenes: frameline.add_keyframe(scene.start-1,scene.node) if scene.start != scene.end: @@ -703,7 +721,7 @@ # This is the first frame, we can not duplicate it self.last_line.rm_keyframe(self.last_frame) return - node = self.duplicateSceneGroup(last_key.ref.attribute("id")) + node = self.duplicateSceneGroup(last_key.ref.getAttribute("id")) key.ref = node self.update() self.show() @@ -720,7 +738,7 @@ if node.name() == 'svg:g': for t in node.childList(): if t.name() == "svg:g": - if t.attribute("id") == gid: + if t.getAttribute("id") == gid: orig = t break if orig == None: @@ -857,7 +875,7 @@ self.last_update = glib.timeout_add(300,self.show) def show(self): self.OK = True - self.dom = self.desktop.doc().root() + self.dom = self.desktop.doc().root().repr self.document = self.desktop.doc().rdoc self.tween = TweenObject(self.document,self.dom) self.parseScene() diff -r d4dbcb93aee0 -r 8f0ee167c5b2 pyink/tween.py --- a/pyink/tween.py Wed Dec 22 23:02:46 2010 +0800 +++ b/pyink/tween.py Thu Dec 23 00:00:46 2010 +0800 @@ -6,8 +6,12 @@ def __init__(self,doc,dom): self.document = doc self.dom = dom - self.width = float(dom.attribute("width")) - self.height = float(dom.attribute("height")) + try: + self.width = float(dom.getAttribute("width")) + self.height = float(dom.getAttribute("height")) + except: + self.width = 640 + self.height = 480 def updateMapping(self): self.nodeToItem={} @@ -16,7 +20,10 @@ def updateMappingNode(self,node): for c in node.childList(): self.updateMappingNode(c) - self.nodeToItem[c.getId()] = c + try: + self.nodeToItem[c.getAttribute("id")] = c + except: + pass def updateTweenContent(self,obj, typ, source,dest,cur): """ Update the content of the duplicate scene group. We will use the (start,end) and cur to calculate the percentage of @@ -36,48 +43,48 @@ # Collect all objects while d: try: - label = d.attribute("inkscape:label") + label = d.getAttribute("inkscape:label") except: - d = d.getNext() + d = d.next() continue dests[label] = d - d = d.getNext() + d = d.next() # Check if the object in the source exists in the destination s = source.ref.firstChild() d = dest.ref.firstChild() while s: print s,d try: - label = s.attribute("inkscape:label") + label = s.getAttribute("inkscape:label") # Use i8nkscape:label to identidy the equipvalent objects if label: if dests.hasattr(label.value()): self.updateTweenObject(obj,typ,s,dests[label.value()],percent) - s = s.getNext() + s = s.next() continue except: pass # Search obejcts in the destination while d: try: - d.attribute("inkscape:label") - d = d.getNext() + d.getAttribute("inkscape:label") + d = d.next() continue except: pass if s.name() == d.name(): self.updateTweenObject(obj,typ,s,d,percent) - d = d.getNext() + d = d.next() break - d = d.getNext() - s = s.getNext() + d = d.next() + s = s.next() def parseTransform(self,obj): """ Return the transform matrix of an object """ try: - t = obj.attribute("transform") + t = obj.getAttribute("transform") print t if t[0:9] == 'translate': print "translate" @@ -145,7 +152,7 @@ """ if typ == 'relocate': newobj = s.duplicate(self.document) - newobj.setAttribute("ref", s.getId()) + newobj.setAttribute("ref", s.getAttribute("id")) top = self.document.createElement("svg:g") top.appendChild(newobj) obj.appendChild(top) @@ -156,10 +163,10 @@ top.setAttribute("transform","translate(%g,%g)" % ((dm[2]-sm[2])*p,(dm[5]-sm[5])*p)) else: try: - sx = float(s.attribute("x")) - sy = float(s.attribute("y")) - dx = float(d.attribute("x")) - dy = float(d.attribute("y")) + sx = float(s.getAttribute("x")) + sy = float(s.getAttribute("y")) + dx = float(d.getAttribute("x")) + dy = float(d.getAttribute("y")) tx = (dx-sx)*p ty = (dy-sy)*p print tx,ty @@ -173,7 +180,7 @@ pass elif typ == 'normal': newobj = s.duplicate(self.document) - newobj.setAttribute("ref", s.getId()) + newobj.setAttribute("ref", s.getAttribute("id")) top = self.document.createElement("svg:g") top.appendChild(newobj) obj.appendChild(top) @@ -198,13 +205,13 @@ # # D = B inv(A) try: - item = self.nodeToItem[s.attribute("id")] + item = self.nodeToItem[s.getAttribute("id")] (ox,oy) = item.getCenter() except: ox = 0 oy = 0 try: - item = self.nodeToItem[d.attribute("id")] + item = self.nodeToItem[d.getAttribute("id")] (dx,dy) = item.getCenter() except: dx = 0 @@ -227,18 +234,18 @@ top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5])) else: try: - sw = float(s.attribute("width")) - sh = float(s.attribute("height")) - dw = float(d.attribute("width")) - dh = float(d.attribute("height")) + sw = float(s.getAttribute("width")) + sh = float(s.getAttribute("height")) + dw = float(d.getAttribute("width")) + dh = float(d.getAttribute("height")) try: - item = self.nodeToItem[s.attribute("id")] + item = self.nodeToItem[s.getAttribute("id")] (ox,oy) = item.getCenter() except: ox = 0 oy = 0 try: - item = self.nodeToItem[d.attribute("id")] + item = self.nodeToItem[d.getAttribute("id")] (dx,dy) = item.getCenter() except: dx = 0