# HG changeset patch # User Thinker K.F. Li # Date 1290484684 -28800 # Node ID 5d4bc2a93c0969dec8f4daf5890d2d4fd42a8439 # Parent 18329b6f77a416199dd337af71117b682d856a8f# Parent 769921baf111381afb472390043c63027863c168 Merge from refine_backend_if branch diff -r 769921baf111 -r 5d4bc2a93c09 nodejs/examples/mce/background2.jpg Binary file nodejs/examples/mce/background2.jpg has changed diff -r 769921baf111 -r 5d4bc2a93c09 nodejs/examples/mce/epg.js --- a/nodejs/examples/mce/epg.js Tue Nov 23 11:55:12 2010 +0800 +++ b/nodejs/examples/mce/epg.js Tue Nov 23 11:58:04 2010 +0800 @@ -122,7 +122,8 @@ if (ext != "png") { fields.push("png"); newf = fields.join("."); - os.spawn("convert",[file,newf]); + sys.puts("cachepath="+cachepath+" newf="+newf); + os.spawn("convert",[cachepath,newf]); } else { newf = cachepath; } diff -r 769921baf111 -r 5d4bc2a93c09 nodejs/examples/mce/main.svg --- a/nodejs/examples/mce/main.svg Tue Nov 23 11:55:12 2010 +0800 +++ b/nodejs/examples/mce/main.svg Tue Nov 23 11:58:04 2010 +0800 @@ -14,8 +14,9 @@ height="1052.3622047" id="svg2" version="1.1" - inkscape:version="0.47 r22583" - sodipodi:docname="main.svg"> + inkscape:version="0.48+devel r9764 custom" + sodipodi:docname="main.svg" + xmlns:ns0="http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd"> + inkscape:window-width="1680" + inkscape:window-height="976" + inkscape:window-x="0" + inkscape:window-y="25" + inkscape:window-maximized="1" /> @@ -76,11 +77,19 @@ + + + + + id="layer2" + inkscape:label="Background"> + + - + - - - + + + - - - + + + - - - + + + - - - + + + - - - - - + + + + + - - - + + + - - - + + + + inkscape:label="cat6" + id="g2939" + transform="translate(661.14163,8.5714057)"> + + + + + + diff -r 769921baf111 -r 5d4bc2a93c09 nodejs/examples/mce/mainmenu.js --- a/nodejs/examples/mce/mainmenu.js Tue Nov 23 11:55:12 2010 +0800 +++ b/nodejs/examples/mce/mainmenu.js Tue Nov 23 11:58:04 2010 +0800 @@ -21,6 +21,7 @@ MainMenu.prototype.init=function() { app.loadSVG("main.svg"); + app.changeScene(1); var i; var self = this; @@ -150,7 +151,7 @@ } MainMenu.prototype.changePage=function() { - this.app.loadSVG("preview.svg"); + this.app.changeScene(2); } exports.MainMenu=MainMenu; diff -r 769921baf111 -r 5d4bc2a93c09 nodejs/examples/scene/mainmenu.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nodejs/examples/scene/mainmenu.js Tue Nov 23 11:58:04 2010 +0800 @@ -0,0 +1,60 @@ +// -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- +// vim: sw=4:ts=8:sts=4 +var svg = require("svg"); +var mbapp = require("mbapp"); +var sys=require("sys"); +var animate=require("animate"); +var fs = require("fs"); +/** + * We will fetch the EPG file from the server and fetch all images required for the main category from it. + * If these files are cached, we will not fetch it again. Otherwise, we will fetch them. The EPG class is + * responsible for the cache management. + */ +function MainMenu(app) +{ + var self = this; + this.n = 1; + this.app = app; + self.init(app); +} +MainMenu.prototype.init=function(app) +{ + var self = this; + app.loadSVG("mbtest.svg"); + + app.addKeyListener(mbapp.KEY_LEFT, function() { self.key_left();}); + app.addKeyListener(mbapp.KEY_RIGHT, function() { self.key_right();}); + app.addKeyListener(mbapp.KEY_UP, function() {self.key_up();}); + app.addKeyListener(mbapp.KEY_DOWN, function() {self.key_down();}); + app.addKeyListener(mbapp.KEY_ENTER, function() {self.key_enter();}); + app.changeScene(this.n); +} + +MainMenu.prototype.key_left=function () +{ + this.n = this.n - 1; + this.app.changeScene(this.n); + sys.puts("scene "+this.n); +} + +MainMenu.prototype.key_right=function() +{ + this.n = this.n + 1; + this.app.changeScene(this.n); + sys.puts("scene "+this.n); +} + +MainMenu.prototype.key_up=function() +{ +} + + +MainMenu.prototype.key_down=function () +{ +} + +MainMenu.prototype.key_enter=function() +{ +} + +exports.MainMenu=MainMenu; diff -r 769921baf111 -r 5d4bc2a93c09 nodejs/examples/scene/mbtest.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nodejs/examples/scene/mbtest.svg Tue Nov 23 11:58:04 2010 +0800 @@ -0,0 +1,374 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + Action + + + + Select + + + + + + + + + + + + diff -r 769921baf111 -r 5d4bc2a93c09 nodejs/examples/scene/scene.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nodejs/examples/scene/scene.js Tue Nov 23 11:58:04 2010 +0800 @@ -0,0 +1,11 @@ +// -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- +// vim: sw=4:ts=8:sts=4 +var svg = require("svg"); +var mbapp = require("mbapp"); +var sys=require("sys"); +var animate=require("animate"); +var fs = require("fs"); +var main=require("./mainmenu"); +app = new mbapp.app(":0.0",800,600); +scene=new main.MainMenu(app); +app.loop(); diff -r 769921baf111 -r 5d4bc2a93c09 nodejs/mbapp.js --- a/nodejs/mbapp.js Tue Nov 23 11:55:12 2010 +0800 +++ b/nodejs/mbapp.js Tue Nov 23 11:58:04 2010 +0800 @@ -145,6 +145,34 @@ } } + +app.prototype.changeScene=function(s) { + var nth; + if (typeof(s)=='number') { + var i; + nth = s; + } else { + nth = this.svg.getFrameNumber(s); + if (nth == -1) return; + } + var scenes = this.svg.scenes; + for(i=0;i=scenes[i].start && nth <=scenes[i].end) { + this.get(scenes[i].ref).show(); + } else { + this.get(scenes[i].ref).hide(); + } + } catch(e) { + sys.puts(e); + sys.puts(scenes[i].ref); + } + } +} +app.prototype.addSceneListener=function(n, cb) { + sys.puts("This is not implemented yet") +} + var app_with_win = function(display, win) { var self = this; var mb_rt; diff -r 769921baf111 -r 5d4bc2a93c09 nodejs/svg.js --- a/nodejs/svg.js Tue Nov 23 11:55:12 2010 +0800 +++ b/nodejs/svg.js Tue Nov 23 11:58:04 2010 +0800 @@ -72,12 +72,16 @@ var n = nodes[k].name(); if (n == "defs") { this.parseDefs(coord,nodes[k]); + } else if (n == "metadata") { + this.parseMetadata(coord,nodes[k]); } else if (n == "g") { this.parseGroup(accu,coord,'root_coord',nodes[k]); } } } + + loadSVG.prototype.leaveSVG=function() { var p = this.pgstack.pop(); @@ -104,6 +108,12 @@ name = mbname.value(); mb_rt.mbnames[name] = obj; } + try { + var gname = n.attr('id').value(); + sys.puts(gname); + mb_rt.mbnames[gname] = obj; + } catch(e) { + } } function getInteger(n,name) @@ -1117,7 +1127,8 @@ href = href.value(); var hrefid = href.substring(1); pstops = this.stop_ref[hrefid]; - stops = pstops.concat(stops); + if (pstops) + stops = pstops.concat(stops); var hrefgr = this.gradients[hrefid]; if(typeof x1 == "undefined") @@ -1191,6 +1202,44 @@ this.stop_ref[id] = stops; } +loadSVG.prototype.parseScenes=function(coord,node) { + var nodes = node.childNodes(); + + for(k in nodes) { + var name = nodes[k].name(); + if (name == 'scene') { + var node = nodes[k]; + + scene = new Object(); + scene.start = parseInt(node.attr('start').value()); + try { + scene.end = parseInt(node.attr('end').value()); + } catch(e) { + scene.end = scene.start; + } + scene.ref = node.attr('ref').value(); + + try { + this.scenenames[node.attr('name').value()] = scene.start; + } catch(e) { + } + this.scenes.push(scene); + } + } +} + +loadSVG.prototype.parseMetadata=function(coord,node) { + var nodes = node.childNodes(); + + for(k in nodes) { + var name = nodes[k].name(); + if (name == 'scenes') { + this.scenes=[]; + this.scenenames={}; + this.parseScenes(coord,nodes[k]); + } + } +} loadSVG.prototype.parseDefs=function(root,n) { var k; diff -r 769921baf111 -r 5d4bc2a93c09 pyink/MBScene.py --- a/pyink/MBScene.py Tue Nov 23 11:55:12 2010 +0800 +++ b/pyink/MBScene.py Tue Nov 23 11:58:04 2010 +0800 @@ -7,6 +7,7 @@ from lxml import etree import random import traceback +import time # Please refer to # http://www.assembla.com/wiki/show/MadButterfly/Inkscape_extention @@ -93,11 +94,13 @@ for n in node.childList(): if n.repr.name() == 'ns0:scenes': self.scenemap={} - cur = int(n.repr.attribute("current")) + try: + cur = int(n.repr.attribute("current")) + except: + cur = 1 self.current = cur for s in n.childList(): - print '--->',s.repr.name() if s.repr.name() == 'ns0:scene': try: start = int(s.repr.attribute("start")) @@ -124,6 +127,23 @@ pass pass pass + if self.scenemap==None: + self.desktop.doc().root().repr.setAttribute("xmlns:ns0","http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd",True) + scenes = self.desktop.doc().rdoc.createElement("ns0:scenes") + node.repr.appendChild(scenes) + def update(self): + doc = self.desktop.doc().root() + rdoc = self.desktop.doc().rdoc + for node in doc.childList(): + if node.repr.name() == 'svg:metadata': + for t in node.childList(): + if t.repr.name() == "ns0:scenes": + node.repr.removeChild(t.repr) + ns = rdoc.createElement("ns0:scenes") + node.repr.appendChild(ns) + for layer in range(0,len(self._framelines)): + lobj = self._framelines[layer] + lobj.addScenes(rdoc,ns) def parseScene(self): @@ -153,10 +173,6 @@ if scmap == None: lyobj.current_scene.append(scene) continue - if self.current <= scmap[1] and \ - self.current >= scmap[0]: - oldscene = scene - pass except: lyobj.current_scene.append(scene) continue @@ -167,16 +183,10 @@ lyobj.current_scene.append(scene) pass pass - - if oldscene != None: - # Put the objects back to the current scene - # for o in lyobj.current_scene: - # print o.tag - # oldscene.append(o) - pass pass pass + self.collectID() self.dumpID() pass @@ -207,7 +217,6 @@ def dumpID(self): for a,v in self.ID.items(): - print a pass pass @@ -228,273 +237,158 @@ new scene. """ - nth = self.last_cell.nScene - layer = self.getLayer(self.last_cell.layer) - x = self.last_cell.nScene - y = self.last_cell.nLayer - if layer == None: return - for i in range(0,len(layer.scenes)): - s = layer.scenes[i] - if nth >= s.start and nth <= s.end: - if nth == s.start: return - newscene = Scene(DuplicateNode(s.node),nth,s.end) - newscene.node.setId(self.newID()) - layer.scenes.insert(i+1,newscene) - layer.scenes[i].end = nth-1 - btn = self.newCell('start.png') - btn.nScene = nth - btn.layer = layer - btn.nLayer = y - self.grid.remove(self.last_cell) - self.grid.attach(btn, x,x+1,y,y+1,0,0,0,0) - return - pass - - if len(layer.scenes) > 0: - last = nth - lastscene = None - for s in layer.scenes: - if s.end < nth and last < s.end: - last = s.end - lastscene = s - pass - pass - - for x in range(last+1, nth): - btn = self.newCell('fill.png') - btn.nScene = x - btn.layer = layer.node.getId() - btn.nLayer = y - self.grid.attach(btn, x, x+1, y , y+1,0,0,0,0) - pass - - if lastscene == None: - node = etree.Element(_scene) - node.setId(self.newID()) - newscene = Scene(node,nth,nth) - else: - lastscene.end = nth-1 - newscene = Scene(DuplicateNode(lastscene.node),nth,nth) - newscene.node.setId(self.newID()) - pass - - layer.scenes.append(newscene) - btn = self.newCell('start.png') - x = self.last_cell.nScene - y = self.last_cell.nLayer - btn.nScene = nth - btn.layer = layer.node.getId() - btn.nLayer = y - self.grid.attach(btn, x, x+1, y, y+1,0,0,0,0) - else: - # This is the first scene in the layer - node = etree.Element(_scene) - node.repr.setId(self.newID()) - newscene = Scene(node,nth,nth) - layer.scenes.append(newscene) - btn = self.newCell('start.png') - btn.nScene = nth - btn.layer = layer.node.getId() - btn.nLayer = y - self.grid.attach(btn, x, x+1, y, y+1,0,0,0,0) - pass - pass + x = self.last_frame + y = self.last_line + rdoc = self.desktop.doc().rdoc + ns = rdoc.createElement("svg:g") + txt = rdoc.createElement("svg:rect") + txt.setAttribute("x","0",True) + txt.setAttribute("y","0",True) + txt.setAttribute("width","100",True) + txt.setAttribute("height","100",True) + txt.setAttribute("style","fill:#ff00",True) + ns.appendChild(txt) + gid = self.last_line.node.label()+self.newID() + self.ID[gid]=1 + ns.setAttribute("id",gid,True) + ns.setAttribute("inkscape:groupmode","layer",True) + self.last_line.node.repr.appendChild(ns) + print 'Add key ', x + self.last_line.add_keyframe(x,ns) + self.update() + self.last_line.update() def removeKeyScene(self): - nth = self.last_cell.nScene - try: - layer = self.getLayer(self.last_cell.layer) - except: - return - x = self.last_cell.nScene - y = self.last_cell.nLayer - for i in range(0,len(layer.scenes)): - s = layer.scenes[i] - if nth == s.start: - if i == 0: - for j in range(s.start,s.end+1): - btn = self.newCell('empty.png') - btn.nScene = nth - btn.layer = layer - btn.nLayer = y - self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0) - pass - layer.scenes.remove(s) + nth = self.last_frame + y = self.last_line + rdoc = self.desktop.doc().rdoc + i = 0 + layer = self.last_line + while i < len(layer._keys): + s = layer._keys[i] + print "nth:%d idx %d" % (nth,s.idx) + if nth > s.idx: + if i == len(layer._keys)-1: + return + if nth == s.idx: + if s.left_tween: + # This is left tween, we move the keyframe one frame ahead + if s.idx == layer._keys[i-1].idx: + layer._keys[i].ref.parent().removeChild(layer._keys[i].ref) + self.last_line.rm_keyframe(nth) + self.last_line.rm_keyframe(nth-1) + else: + s.idx = s.idx-1 else: - if s.start == layer.scenes[i-1].end+1: - # If the start of the delete scene segment is - # the end of the last scene segmenet, convert - # all scenes in the deleted scene segmenet to - # the last one - layer.scenes[i-1].end = s.end - layer.scenes.remove(s) - btn = self.newCell('fill.png') + layer._keys[i].ref.parent().removeChild(layer._keys[i].ref) + if s.right_tween: + self.last_line.rm_keyframe(layer._keys[i+1].idx) + self.last_line.rm_keyframe(nth) + else: + self.last_line.rm_keyframe(nth) - btn.nScene = nth - btn.layer = layer - btn.nLayer = y - self.grid.attach(btn, x,x+1,y,y+1,0,0,0,0) + self.update() + self.last_line._draw_all_frames() + self.last_line.update() + return + i = i + 1 + def extendScene(self): + nth = self.last_frame + layer = self.last_line + i = 0 + while i < len(layer._keys): + s = layer._keys[i] + if s.right_tween: + if nth > s.idx: + if nth <= layer._keys[i+1].idx: + return + try: + if nth <= layer._keys[i+2].idx: + layer._keys[i+1].idx = nth + layer.draw_all_frames() + self.update() + self.setCurrentScene(nth) + self.last_line.update() + return + else: + # We may in the next scene + i = i + 2 + pass + except: + # This is the last keyframe, extend the keyframe by + # relocate the location of the keyframe + layer._keys[i+1].idx = nth + layer._draw_all_frames() + self.update() + self.last_line.update() + self.setCurrentScene(nth) + return + else: + # We are in the front of all keyframes + return + else: + # This is a single keyframe + if nth < s.idx: + return + if nth == s.idx: + return + try: + if nth < layer._keys[i+1].idx: + # We are after a single keyframe and no scene is + # available here. Create a new tween here + idx = layer._keys[i].idx + layer.add_keyframe(nth,layer._keys[i].ref) + layer.tween(idx) + layer._draw_all_frames() + self.update() + self.setCurrentScene(nth) + self.last_line.update() + return else: - # Convert all scenes into empty cell - layer.scenes.remove(s) - for j in range(s.start,s.end+1): - btn = self.newCell('empty.png') - btn.nScene = nth - btn.layer = layer - btn.nLayer = y - self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0) - pass + # We may in the next scene + i = i + 1 pass pass - return + except: + # This is the last scene, create a new one + idx = layer._keys[i].idx + layer.add_keyframe(nth,layer._keys[i].ref) + layer.tween(idx) + layer._draw_all_frames() + self.update() + self.setCurrentScene(nth) + self.last_line.update() + return + pass pass pass - def extendScene(self): - nth = self.last_cell.nScene - try: - layer = self.getLayer(self.last_cell.layer) - except: - traceback.print_exc() - return - x = self.last_cell.nScene - y = self.last_cell.nLayer - if layer == None: - return - - for i in range(0,len(layer.scenes)-1): - s = layer.scenes[i] - if nth >= layer.scenes[i].start and nth <= layer.scenes[i].end: - return - pass - - for i in range(0,len(layer.scenes)-1): - s = layer.scenes[i] - if nth >= layer.scenes[i].start and nth < layer.scenes[i+1].start: - for j in range(layer.scenes[i].end+1, nth+1): - btn = self.newCell('fill.png') - btn.nScene = nth - btn.nLayer = y - btn.layer = self.last_cell.layer - self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0) - layer.scenes[i].end = nth - return - pass - if len(layer.scenes) > 0 and \ - nth > layer.scenes[len(layer.scenes)-1].end: - for j in range(layer.scenes[len(layer.scenes)-1].end+1, nth+1): - btn = self.newCell('fill.png') - btn.nScene = nth - btn.nLayer = y - btn.layer = self.last_cell.layer - self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0) - pass - layer.scenes[len(layer.scenes)-1].end = nth - pass - pass - pass def setCurrentScene(self,nth): self.current = nth - for layer in self.layers: - for s in layer.scenes: - if nth >= s.start and nth <= s.end: - s.node.repr.setAttribute("style","",True) - # print "Put the elemenets out" - layer.nodes = [] - - # for o in s.node: - # print " ",o.tag - # layer.nodes.append(o) - # for o in s.node: - # s.node.remove(o) + for layer in self._framelines: + i=0 + while i < len(layer._keys): + s = layer._keys[i] + print s.ref.attribute("id"),s.idx,s.left_tween,s.right_tween + if s.right_tween is False: + if nth == s.idx+1: + s.ref.setAttribute("style","",True) + else: + s.ref.setAttribute("style","display:none",True) + i = i + 1 + continue + + if nth >= (s.idx+1) and nth <= (layer._keys[i+1].idx+1): + s.ref.setAttribute("style","",True) else: - s.node.repr.setAttribute("style","display:none",True) - pass + s.ref.setAttribute("style","display:none",True) + i = i + 2 pass pass pass - def generate(self): - newdoc = deepcopy(self.document) - root = newdoc.getroot() - has_scene = False - for n in root: - if n.tag == '{http://www.w3.org/2000/svg}metadata': - for nn in n: - if nn.tag == _scenes: - nn.clear() - nn.set("current", "%d" % self.current) - scenes = [] - for l in self.layers: - for s in l.scenes: - id = s.node.get("id") - scene = etree.Element(_scene) - scene.set("ref", id) - if s.start == s.end: - scene.set("start", "%d" % s.start) - else: - scene.set("start", "%d" % s.start) - scene.set("end", "%d" % s.end) - pass - - scenes.append(scene) - pass - pass - for s in scenes: - nn.append(s) - pass - has_scene = True - pass - pass - if has_scene == False: - scenes = etree.Element(_scenes) - scenes.set("current","%d" % self.current) - for l in self.layers: - for s in l.scenes: - scene = etree.Element(_scene) - scene.set("ref", s.node.get("id")) - if s.start == s.end: - scene.set("start", "%d" % s.start) - else: - scene.set("start", "%d" % s.start) - scene.set("end", "%d" % s.end) - pass - scenes.append(scene) - pass - pass - n.append(scenes) - pass - pass - if n.tag == '{http://www.w3.org/2000/svg}g': - root.remove(n) - pass - pass - - for l in self.layers: - # Duplicate all attribute of the layer - lnode = etree.Element("{http://www.w3.org/2000/svg}g") - for a,v in l.node.attrib.items(): - lnode.set(a,v) - pass - for n in l.nodes: - lnode.append(n) - pass - root.append(lnode) - for s in l.scenes: - snode = etree.Element("{http://www.w3.org/2000/svg}g") - for a,v in s.node.attrib.items(): - snode.set(a,v) - pass - for n in s.node: - snode.append(deepcopy(n)) - pass - lnode.append(snode) - pass - pass - self.document = newdoc - pass def newCell(self,file): img = gtk.Image() @@ -505,6 +399,22 @@ btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray")) return btn + def onCellClick(self,line,frame,but): + self.last_line = line + self.last_frame = frame + self.last_line.active_frame(frame) + self.doEditScene(frame) + + + def _remove_active_frame(self,widget,event): + """ + Hide all hover frames. This is a hack. We should use the lost focus event + instead in the future to reduce the overhead. + """ + for f in self._framelines: + if f != widget: + f.hide_hover() + def _create_framelines(self): import frameline self.scrollwin = gtk.ScrolledWindow() @@ -520,29 +430,47 @@ ruler = frameline.frameruler(nframes) ruler.set_size_request(nframes * 10, 20) ruler.show() - vbox.pack_start(ruler, False) + hbox = gtk.HBox() + label=gtk.Label('') + label.set_size_request(100,0) + hbox.pack_start(label,expand=False,fill=True) + hbox.pack_start(ruler) + vbox.pack_start(hbox, False) # # Add a frameline for each layer # self._framelines = [] - for i in range(len(self.layers)): + 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.set_size_request(100,0) + hbox.pack_start(label,expand=False,fill=True) + hbox.pack_start(line) line.set_size_request(nframes * 10, 20) - vbox.pack_start(line, False) + vbox.pack_start(hbox, False) + line.label = label self._framelines.append(line) + line.connect(line.FRAME_BUT_PRESS, self.onCellClick) + line.nLayer = i + line.node = self.layers[i].node + line.layer = self.layers[i] + line.connect('motion-notify-event', self._remove_active_frame) pass pass ## \brief Update conetent of frameliens according layers. # def _update_framelines(self): - for layer_i, layer in enumerate(self.layers): + for frameline in self._framelines: + layer = frameline.layer + frameline.label.set_text(frameline.node.label()) for scene in layer.scenes: - frameline = self._framelines[layer_i] - for scene_i in range(scene.start, scene.stop + 1): - frameline.add_keyframe(scene_i) - pass + frameline.add_keyframe(scene.start-1,scene.node.repr) + if scene.start != scene.end: + frameline.add_keyframe(scene.end-1,scene.node.repr) + frameline.tween(scene.start-1) pass pass pass @@ -559,30 +487,28 @@ pass def doEditScene(self,w): - self.setCurrentScene(self.last_cell.nScene) + self.setCurrentScene(self.last_frame+1) pass def doInsertKeyScene(self,w): - # self.insertKeyScene() + self.insertKeyScene() # self.grid.show_all() return def doRemoveScene(self,w): - # self.removeKeyScene() - # self.grid.show_all() - # self.generate() + self.removeKeyScene() return def doExtendScene(self,w): self.extendScene() - self.grid.show_all() + #self.grid.show_all() pass def addButtons(self,hbox): - btn = gtk.Button('Edit') - btn.connect('clicked', self.doEditScene) - hbox.pack_start(btn,expand=False,fill=False) + #btn = gtk.Button('Edit') + #btn.connect('clicked', self.doEditScene) + #hbox.pack_start(btn,expand=False,fill=False) btn = gtk.Button('Insert Key') btn.connect('clicked',self.doInsertKeyScene) hbox.pack_start(btn,expand=False,fill=False) @@ -604,26 +530,6 @@ gtk.main_quit() pass - def onConfirmDelete(self): - if self.scenemap == None: - vbox = gtk.VBox(False,0) - vbox.pack_start(gtk.Label('Convert the SVG into a MadButterfly' - ' SVG file. All current element will' - ' be delted')) - hbox = gtk.HBox(False,0) - self.button = gtk.Button('OK') - hbox.pack_start(self.button,expand=False,fill=False) - self.button.connect('clicked', self.onOK) - self.button = gtk.Button('Cancel') - hbox.pack_start(self.button,expand=False,fill=False) - self.button.connect("clicked", self.onQuit) - vbox.pack_start(hbox,expand=False,fill=False) - self.window.add(vbox) - self.window.show_all() - gtk.main() - self.window.remove(vbox) - pass - pass def show(self): self.OK = True @@ -633,24 +539,17 @@ vbox = gtk.VBox(False,0) self.desktop.getToplevel().child.child.pack_end(vbox,expand=False) self.window = vbox + vbox = gtk.VBox(False,0) + self.window.pack_start(vbox,expand=False) + vbox.pack_start(self.scrollwin,expand=False) + self.vbox = vbox + hbox=gtk.HBox(False,0) + self.addButtons(hbox) + vbox.pack_start(hbox,expand=False) + # self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) # self.window.connect("destroy", gtk.main_quit) # self.window.set_position(gtk.WIN_POS_MOUSE) - if self.scenemap == None: - self.onConfirmDelete() - pass - if self.OK: - vbox = gtk.VBox(False,0) - self.window.pack_start(vbox,expand=False) - vbox.pack_start(self.scrollwin,expand=False) - self.vbox = vbox - hbox=gtk.HBox(False,0) - self.addButtons(hbox) - vbox.pack_start(hbox,expand=False) - else: - return - - # self.window.set_size_request(600,200) self.window.show_all() pass diff -r 769921baf111 -r 5d4bc2a93c09 pyink/frameline.py --- a/pyink/frameline.py Tue Nov 23 11:55:12 2010 +0800 +++ b/pyink/frameline.py Tue Nov 23 11:58:04 2010 +0800 @@ -16,6 +16,7 @@ self.left_tween = False self.right_tween = False self.right_tween_type = 0 + self.ref='' pass pass @@ -121,6 +122,10 @@ _normal_border = 0xaaaaaa # border color of normal frames. _active_border = 0xff3030 # border color of an active frame _hover_border_color = 0xa0a0a0 # border when the pointer over a frame + # tween types + _tween_type_none=0 + _tween_type_shape=3 + FRAME_BUT_PRESS = 'frame-button-press' @@ -154,9 +159,13 @@ but = event.button self.emit(frameline.FRAME_BUT_PRESS, frame, but) pass + def hide_hover(self): + if self._active_frame != self._last_hover: + self._draw_normal_frame(self._last_hover) def _motion_hdl(self, widget, event): frame = int(event.x / self._frame_width) + if frame < self._num_frames and frame >= 0: self._draw_hover(frame) pass @@ -299,6 +308,12 @@ i = last_tween_key.idx + 1 pass else: + if key.idx == i: + key_i=key_i+1 + try: + key = self._keys[key_i] + except: + key = keyframe(self._num_frames) self._draw_normal_frame(i) i = i + 1 pass @@ -343,11 +358,15 @@ gc.set_rgb_fg_color(color) for key in self._keys: + if key.left_tween is True and lastkey.right_tween_type == frameline._tween_type_none: + continue + mark_sz = self._key_mark_sz mark_x = int((key.idx + 0.5) * self._frame_width - mark_sz / 2) mark_y = w_h * 2 / 3 - mark_sz / 2 win.draw_rectangle(gc, True, mark_x, mark_y, mark_sz, mark_sz) + lastkey = key pass pass @@ -393,7 +412,7 @@ last_pos = last_pos + 1 pass - return first_pox, last_pos + return first_pos, last_pos ## \brief Redraw a frame specified by an index. # @@ -432,7 +451,9 @@ for i in range(first_pos, last_pos + 1): key = self._keys[i] - self._draw_keyframe(key.idx) + if key.left_tween is False or lastkey.right_tween_type != frameline._tween_type_none: + self._draw_keyframe(key.idx) + lastkey = key pass pass else: # not in tween @@ -481,7 +502,6 @@ win = self.window x, y, w, h, depth = win.get_geometry() - self._draw_all_frames() self._draw_keyframes() if self._active_frame != -1: @@ -493,7 +513,7 @@ # # A key frame is the frame that user specify actions. For # example, move a object or add new objects at the frame. - def add_keyframe(self, idx): + def add_keyframe(self, idx,ref=None): key_indic = [key.idx for key in self._keys] if idx in key_indic: return @@ -503,6 +523,7 @@ insert_pos = key_indic.index(idx) key = keyframe(idx) + key.ref = ref self._keys[insert_pos:insert_pos] = [key] if insert_pos > 0 and self._keys[insert_pos - 1].right_tween: key.left_tween = True @@ -516,8 +537,14 @@ pass def rm_keyframe(self, idx): + found=False + for i in range(0,len(self._keys)): + if self._keys[i].idx == idx: + idx = i + found = True + break + if not found: return key = self._keys[idx] - del self._keys[idx] if key.right_tween ^ key.left_tween: # @@ -526,13 +553,12 @@ if key.right_tween: right_key = self._keys[idx] right_key.left_tween = False - rdraw_range = (right_key.idx, idx + 1) + redraw_range = (right_key.idx, idx + 1) else: left_key = self._keys[idx - 1] left_key.right_key = False redraw_range = (idx, left_key.idx + 1) pass - for i in range(*redraw_range): self._redraw_frame(i) pass @@ -540,6 +566,7 @@ self._redraw_frame(idx) pass + del self._keys[idx] self._draw_active() pass @@ -589,6 +616,23 @@ self._keys = [] pass + def addScenes(self,rdoc,node): + for i in range(0,len(self._keys)): + key = self._keys[i] + if key.left_tween is True: continue + if key.right_tween is True: + ss = rdoc.createElement("ns0:scene") + node.appendChild(ss) + ss.setAttribute("start", str(key.idx+1),True) + ss.setAttribute("ref",key.ref.attribute("id"),True) + ss.setAttribute("end", str(self._keys[i+1].idx+1),True) + else: + ss = rdoc.createElement("ns0:scene") + node.appendChild(ss) + ss.setAttribute("start", str(key.idx+1),True) + ss.setAttribute("ref",key.ref.attribute("id"),True) + + ## \brief Start future drawing actions # def start_drawing(self): @@ -616,13 +660,14 @@ fl = frameline(40) fl.set_size_request(300, 20) + fl.add_keyframe(15) fl.add_keyframe(3) + fl.tween(3) fl.add_keyframe(9) - fl.add_keyframe(15) fl.add_keyframe(20) - fl.tween(3) - fl.tween(15, 1) - fl.active_frame(15) + fl.tween(9) + fl.active_frame(1) + fl.rm_keyframe(15) print 'num of frames: %d' % (len(fl)) def press_sig(fl, frame, but): diff -r 769921baf111 -r 5d4bc2a93c09 pyink/mbtest.svg --- a/pyink/mbtest.svg Tue Nov 23 11:55:12 2010 +0800 +++ b/pyink/mbtest.svg Tue Nov 23 11:58:04 2010 +0800 @@ -15,7 +15,7 @@ height="480px" id="svg2383" sodipodi:version="0.32" - inkscape:version="0.48+devel r9760 custom" + inkscape:version="0.48+devel r9764 custom" sodipodi:docname="mbtest.svg" inkscape:output_extension="org.inkscape.output.svg.inkscape" version="1.1"> @@ -27,14 +27,14 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="1.6029106" - inkscape:cx="229.53957" - inkscape:cy="240.5" - inkscape:current-layer="g3380" + inkscape:cx="69.206233" + inkscape:cy="290.40921" + inkscape:current-layer="layer2" inkscape:document-units="px" showgrid="false" inkscape:window-width="1400" inkscape:window-height="974" - inkscape:window-x="0" + inkscape:window-x="271" inkscape:window-y="25" inkscape:window-maximized="0" /> - - - - - - + + + + + + + + + + @@ -164,97 +191,100 @@ rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - + + ref="g3189" + end="15" /> + +