# HG changeset patch # User wycc # Date 1233239446 -28800 # Node ID 96aae15527c81610100fe953d55bcbc1933c4d7c # Parent 0cadeb9fdfc306595dbe78746dec2ba4e1c64143 Port all basic scene editor from pyGtk to the firefox diff -r 0cadeb9fdfc3 -r 96aae15527c8 inkscape/firefox/MBServer.py --- a/inkscape/firefox/MBServer.py Mon Jan 26 01:37:04 2009 +0800 +++ b/inkscape/firefox/MBServer.py Thu Jan 29 22:30:46 2009 +0800 @@ -6,6 +6,7 @@ from lxml import etree from twisted.web import server, resource,soap from twisted.internet import reactor +import traceback import random @@ -159,18 +160,16 @@ return None - def insertKeyScene(self): + def insertKeyScene(self,layer,nth): """ Insert a new key scene into the stage. If the nth is always a key scene, we will return without changing anything. If the nth is a filled scene, we will break the original scene into two parts. If the nth is out of any scene, we will append a 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 + + # Check if the nth is in the middle of any scene for i in range(0,len(layer.scene)): s = layer.scene[i] if nth >= s.start and nth <= s.end: @@ -179,26 +178,16 @@ newscene.node.set("id", self.newID()) layer.scene.insert(i+1,newscene) layer.scene[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 if len(layer.scene) > 0: + # extend the last scene befor eit automatically last = nth lastscene = None + # Find the last scene before it for s in layer.scene: if s.end < nth and last < s.end: last = s.end lastscene = s - for x in range(last+1, nth): - btn = self.newCell('fill.png') - btn.nScene = x - btn.layer = layer.node.get('id') - btn.nLayer = y - self.grid.attach(btn, x, x+1, y , y+1,0,0,0,0) if lastscene == None: node = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene') node.set("id", self.newID()) @@ -208,46 +197,19 @@ newscene = Scene(deepcopy(lastscene.node),nth,nth) newscene.node.set("id",self.newID()) layer.scene.append(newscene) - btn = self.newCell('start.png') - x = self.last_cell.nScene - y = self.last_cell.nLayer - btn.nScene = nth - btn.layer = layer.node.get('id') - 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('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene') node.set("id", self.newID()) newscene = Scene(node,nth,nth) layer.scene.append(newscene) - btn = self.newCell('start.png') - btn.nScene = nth - btn.layer = layer.node.get('id') - btn.nLayer = y - self.grid.attach(btn, x, x+1, y, y+1,0,0,0,0) - - - 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 + def deleteScene(self,layer,nth): for i in range(0,len(layer.scene)): s = layer.scene[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) layer.scene.remove(s) else: if s.start == layer.scene[i-1].end+1: @@ -255,33 +217,16 @@ # scene segmenet to the last one layer.scene[i-1].end = s.end layer.scene.remove(s) - btn = self.newCell('fill.png') - - btn.nScene = nth - btn.layer = layer - btn.nLayer = y - self.grid.attach(btn, x,x+1,y,y+1,0,0,0,0) else: # Convert all scenes into empty cell layer.scene.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) - return + pass + pass - def extendScene(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 + + def extendScene(self,layer,nth): if layer == None: return for i in range(0,len(layer.scene)-1): @@ -292,22 +237,11 @@ for i in range(0,len(layer.scene)-1): s = layer.scene[i] if nth >= layer.scene[i].start and nth < layer.scene[i+1].start: - for j in range(layer.scene[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.scene[i].end = nth return if len(layer.scene) > 0 and nth > layer.scene[len(layer.scene)-1].end: - for j in range(layer.scene[len(layer.scene)-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) layer.scene[len(layer.scene)-1].end = nth + def setCurrentScene(self,nth): self.current = nth for layer in self.layer: @@ -445,19 +379,11 @@ self.setCurrentScene(self.last_cell.nScene) self.generate() gtk.main_quit() - def doInsertKeyScene(self,w): - self.insertKeyScene() - self.grid.show_all() - self.generate() def doRemoveScene(self,w): self.removeKeyScene() self.grid.show_all() self.generate() - def doExtendScene(self,w): - self.extendScene() - self.grid.show_all() - self.generate() def addButtons(self,hbox): btn = gtk.Button('Edit') btn.connect('clicked', self.doEditScene) @@ -522,13 +448,34 @@ def soap_SCENE(self,n): self.target.setCurrentScene(int(n)) return "OK" - - - - - + def soap_INSERTKEY(self,layer,n): + try: + layer = self.target.getLayer(layer) + self.target.insertKeyScene(layer,int(n)) + return "OK" + except: + return traceback.format_exc() + def soap_EXTENDSCENE(self,layer,n): + try: + layer = self.target.getLayer(layer) + self.target.extendScene(layer,int(n)) + return "OK" + except: + return traceback.format_exc() + def soap_DELETESCENE(self,layer,n): + try: + layer = self.target.getLayer(layer) + self.target.deleteScene(layer,int(n)) + return "OK" + except: + return traceback.format_exc() + def soap_GETDOC(self): + try: + self.target.generate() + return etree.tostring(self.target.document) + except: + return traceback.format_exc() import os - os.chdir('/usr/share/inkscape/extensions') A = MBScene() diff -r 0cadeb9fdfc3 -r 96aae15527c8 inkscape/firefox/active-empty.png Binary file inkscape/firefox/active-empty.png has changed diff -r 0cadeb9fdfc3 -r 96aae15527c8 inkscape/firefox/active-empty.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inkscape/firefox/active-empty.svg Thu Jan 29 22:30:46 2009 +0800 @@ -0,0 +1,74 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + diff -r 0cadeb9fdfc3 -r 96aae15527c8 inkscape/firefox/active-fill.png Binary file inkscape/firefox/active-fill.png has changed diff -r 0cadeb9fdfc3 -r 96aae15527c8 inkscape/firefox/active-fill.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inkscape/firefox/active-fill.svg Thu Jan 29 22:30:46 2009 +0800 @@ -0,0 +1,81 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + + diff -r 0cadeb9fdfc3 -r 96aae15527c8 inkscape/firefox/active-start.png Binary file inkscape/firefox/active-start.png has changed diff -r 0cadeb9fdfc3 -r 96aae15527c8 inkscape/firefox/active-start.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inkscape/firefox/active-start.svg Thu Jan 29 22:30:46 2009 +0800 @@ -0,0 +1,91 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff -r 0cadeb9fdfc3 -r 96aae15527c8 inkscape/firefox/empty.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inkscape/firefox/empty.svg Thu Jan 29 22:30:46 2009 +0800 @@ -0,0 +1,74 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + diff -r 0cadeb9fdfc3 -r 96aae15527c8 inkscape/firefox/fill.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inkscape/firefox/fill.svg Thu Jan 29 22:30:46 2009 +0800 @@ -0,0 +1,81 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + + diff -r 0cadeb9fdfc3 -r 96aae15527c8 inkscape/firefox/helper_mb.py --- a/inkscape/firefox/helper_mb.py Mon Jan 26 01:37:04 2009 +0800 +++ b/inkscape/firefox/helper_mb.py Thu Jan 29 22:30:46 2009 +0800 @@ -2,6 +2,7 @@ from twisted.web import server, resource,soap from twisted.internet import reactor,defer import os,time +import traceback @@ -23,6 +24,43 @@ print [result] d.callback(result) self.client = None + def soap_INSERTKEY(self,layer,n): + if self.client == None: + os.kill(self.pid,12) + time.sleep(1) + self.client = Client() + try: + n = int(n) + except: + n = 0 + d = defer.Deferred() + self.client.INSERTKEY(layer,n).addCallback(self.generic_return,d).addErrback(self.generic_error,d) + return d + def soap_EXTENDSCENE(self,layer,n): + if self.client == None: + os.kill(self.pid,12) + time.sleep(1) + self.client = Client() + try: + n = int(n) + except: + n = 0 + d = defer.Deferred() + self.client.EXTENDSCENE(layer,n).addCallback(self.generic_return,d).addErrback(self.generic_error,d) + return d + def soap_DELETESCENE(self,layer,n): + if self.client == None: + os.kill(self.pid,12) + time.sleep(1) + self.client = Client() + try: + n = int(n) + except: + n = 0 + d = defer.Deferred() + self.client.DELETESCENE(layer,n).addCallback(self.generic_return,d).addErrback(self.generic_error,d) + return d + def soap_SCENE(self,n): if self.client == None: os.kill(self.pid,12) @@ -35,12 +73,28 @@ def generic_return(self,result,d): print [result] d.callback(result) + def generic_error(self,result,d): + print [result] + d.errback(result) def soap_START(self): if self.client == None: os.kill(self.pid,12) time.sleep(1) self.client = Client() return "OK" + def soap_GETDOC(self): + try: + print "xxxxx" + if self.client == None: + os.kill(self.pid,12) + time.sleep(1) + self.client = Client() + d = defer.Deferred() + self.client.GETDOC().addCallback(self.generic_return,d) + print "yyy" + return d + except: + traceback.print_exc() @@ -52,9 +106,19 @@ return self.proxy.callRemote('PUBLISH') def SCENE(self,n): return self.proxy.callRemote('SCENE',n) + def INSERTKEY(self,layer,n): + return self.proxy.callRemote('INSERTKEY',layer,n) + def GETDOC(self): + return self.proxy.callRemote('GETDOC') + def EXTENDSCENE(self,layer,n): + return self.proxy.callRemote('EXTENDSCENE',layer,n) + def DELETESCENE(self,layer,n): + return self.proxy.callRemote('DELETESCENE',layer,n) + +os.system("killall -9 inkscape-mb") pid = os.fork() if pid==0: - os.execvp("inkscape-mb",["inkscape-mb","scene.svg"]) + os.execvp("inkscape-mb",["inkscape-mb","/tmp/scene.mbsvg"]) s = Server() s.client = None s.pid = pid diff -r 0cadeb9fdfc3 -r 96aae15527c8 inkscape/firefox/inkscape.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inkscape/firefox/inkscape.js Thu Jan 29 22:30:46 2009 +0800 @@ -0,0 +1,382 @@ +var isInProgress=0; + +var MAX_DUMP_DEPTH = 10; +var mbsvg; + + + +function dumpObj(obj, name, indent, depth) { + if (depth > MAX_DUMP_DEPTH) { + return indent + name + ": \n"; + } + if (typeof obj == "object") { + var child = null; + var output = indent + name + "\n"; + indent += "\t"; + for (var item in obj) + { + try { + child = obj[item]; + } catch (e) { + child = ""; + } + if (typeof child == "object") { + output += dumpObj(child, item, indent, depth + 1); + } else { + output += indent + item + ": " + child + "\n"; + } + } + return output; + } else { + return obj; + } +} +function dumpObjItem(obj, name, indent, depth) { + if (depth > MAX_DUMP_DEPTH) { + return indent + name + ": \n"; + } + if (typeof obj == "object") { + var child = null; + var output = indent + name + "\n"; + indent += "\t"; + for (var item in obj) + { + try { + child = obj[item]; + } catch (e) { + child = ""; + } + if (typeof child == "object") { + output += dumpObjItem(child, item, indent, depth + 1); + } else { + output += indent + item + ":\n"; + } + } + return output; + } else { + return obj; + } +} + +function inkscape_load(file) +{ + var inkscape = document.getElementById('inkscape'); + inkscape.innerHTML = ""; +} + +function MBSVG(file) +{ + var xmlDoc=document.implementation.createDocument("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","",null); + xmlDoc.async=false; + xmlDoc.load(file); + MBSVG_loadFromDoc(this,xmlDoc); + +} +function MBSVGString(xml) +{ + var xmlParser = new DOMParser(); + var xmlDoc = xmlParser.parseFromString( xml, 'text/xml'); + MBSVG_loadFromDoc(this,xmlDoc); +} + + + +function MBSVG_loadFromDoc(self,xmlDoc) +{ + var scenesNode = xmlDoc.getElementsByTagNameNS("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","scene"); + if (scenesNode == null) { + alert('This is not a valid scene file'); + } + var len = scenesNode.length; + var i,j; + var max = 0; + var scenes = new Array(); + + // Get the length of scenes + for(i=0;i"; + for(var j=1;j<=max;j++) + cmd = cmd + ""+j+""; + + for(var i=layers.length-1;i>=0;i--) { + var l = layers[i]; + var id = l.getAttribute('id'); + var label = l.getAttribute('inkscape:label'); + cmd = cmd + ""+label+""; + for(j=0;j"; + empty = 0; + break; + } else if ((n>scenes[k].start)&&(n <= scenes[k].end)) { + cmd = cmd + ""; + empty = 0; + break; + } + } + if (empty) { + cmd = cmd + ""; + } + + } + cmd = cmd + "\n"; + } + cmd = cmd + "\n"; + var frame = document.getElementById('frame'); + frame.innerHTML=cmd; +} + +function selectCell(obj) +{ + var id = obj.getAttribute('id'); + var layer,n; + var f = id.split('#'); + layer=f[0]; + n = f[1]; + var img = obj.getAttribute('src'); + var f = img.split('-'); + + if (f[0] == 'active') + return; + else { + obj.setAttribute('src', 'active-'+img); + } + + if (last_select != null) { + f = last_select.getAttribute('src').split('-'); + last_select.setAttribute('src', f[1]); + } + last_select = obj; + currentScene = n; + currentLayer = layer; +} + + +function onButtonClick(obj) +{ + if (isInProgress != 0) return; + var id = obj.getAttribute('id'); + if (id == 'Jump') { + if (currentScene != 0) + gotoScene(currentScene); + } else if (id == 'InsertKey') { + InsertKey(currentScene); + } else if (id == 'ExtendScene') { + ExtendScene(currentScene); + } else if (id == 'DeleteScene') { + DeleteScene(currentScene); + } +} + +function gotoScene_cb(resObj) +{ + +} +var nextScene; +var currentScene = 0; +var currentLayer = ''; +function gotoScene(n) +{ + nextScene = n; + var soapBody = new SOAPObject("START"); + var sr = new SOAPRequest("START", soapBody); + SOAPClient.Proxy = "http://localhost:19192/"; + SOAPClient.SendRequest(sr, gotoScene1); + isInProgress++; +} +function gotoScene1(resp,n) +{ + var soapBody = new SOAPObject("SCENE"); + var v1 = new SOAPObject("v1"); + v1.val(nextScene); + soapBody.appendChild(v1); + var sr = new SOAPRequest("SCENE", soapBody); + SOAPClient.Proxy = "http://localhost:19192/"; + SOAPClient.SendRequest(sr, gotoScene2); +} +function gotoScene2(resp) +{ + var soapBody = new SOAPObject("PUBLISH"); + var sr = new SOAPRequest("PUBLISH", soapBody); + SOAPClient.Proxy = "http://localhost:19192/"; + SOAPClient.SendRequest(sr, gotoScene3); +} + +function gotoScene3(resp) +{ + isInProgress--; +} + + + +function InsertKey(n) +{ + nextScene = n; + var soapBody = new SOAPObject("START"); + var sr = new SOAPRequest("START", soapBody); + SOAPClient.Proxy = "http://localhost:19192/"; + SOAPClient.SendRequest(sr, InsertKey1); + isInProgress++; +} +function InsertKey1(resp) +{ + var soapBody = new SOAPObject("INSERTKEY"); + var v1 = new SOAPObject("v1"); + v1.attr('type','string'); + v1.val(currentLayer); + soapBody.appendChild(v1); + var v2 = new SOAPObject("v2"); + v2.val(nextScene); + soapBody.appendChild(v2); + var sr = new SOAPRequest("INSERTKEY", soapBody); + SOAPClient.Proxy = "http://localhost:19192/"; + SOAPClient.SendRequest(sr, RefreshDocument); +} +function PublishDocument(resp) +{ + mbsvg = new MBSVGString(resp.Body[0].GETDOCResponse[0].Result[0].Text); + renderUI(mbsvg); + + var soapBody = new SOAPObject("PUBLISH"); + var sr = new SOAPRequest("PUBLISH", soapBody); + SOAPClient.Proxy = "http://localhost:19192/"; + SOAPClient.SendRequest(sr, OperationDone); +} + +function RefreshDocument(resp) +{ + var soapBody = new SOAPObject("GETDOC"); + var sr = new SOAPRequest("GETDOC", soapBody); + SOAPClient.Proxy = "http://localhost:19192/"; + SOAPClient.SendRequest(sr, PublishDocument); +} + +function OperationDone(res) +{ + isInProgress--; +} + + +function ExtendScene() +{ + var soapBody = new SOAPObject("START"); + var sr = new SOAPRequest("START", soapBody); + SOAPClient.Proxy = "http://localhost:19192/"; + SOAPClient.SendRequest(sr,ExtendScene1); + isInProgress++; +} + + +function ExtendScene1(resp) +{ + var soapBody = new SOAPObject("EXTENDSCENE"); + var v1 = new SOAPObject("v1"); + v1.attr('type','string'); + v1.val(currentLayer); + soapBody.appendChild(v1); + var v2 = new SOAPObject("v2"); + v2.val(currentScene); + soapBody.appendChild(v2); + var sr = new SOAPRequest("EXTENDSCENE", soapBody); + SOAPClient.Proxy = "http://localhost:19192/"; + SOAPClient.SendRequest(sr, RefreshDocument); +} + + +function DeleteScene() +{ + var soapBody = new SOAPObject("START"); + var sr = new SOAPRequest("START", soapBody); + SOAPClient.Proxy = "http://localhost:19192/"; + SOAPClient.SendRequest(sr,DeleteScene1); + isInProgress++; +} + +function DeleteScene1(resp) +{ + var soapBody = new SOAPObject("DELETESCENE"); + var v1 = new SOAPObject("v1"); + v1.attr('type','string'); + v1.val(currentLayer); + soapBody.appendChild(v1); + var v2 = new SOAPObject("v2"); + v2.val(currentScene); + soapBody.appendChild(v2); + var sr = new SOAPRequest("EXTENDSCENE", soapBody); + SOAPClient.Proxy = "http://localhost:19192/"; + SOAPClient.SendRequest(sr, RefreshDocument); + +} + +function FetchDocument() +{ + var soapBody = new SOAPObject("START"); + var sr = new SOAPRequest("START", soapBody); + SOAPClient.Proxy = "http://localhost:19192/"; + SOAPClient.SendRequest(sr,RefreshDocument); + isInProgress++; +} + +var last_select = null; +inkscape_load("scene.mbsvg"); +setTimeout("FetchDocument()",4000); + +$('a.button').mouseover(function () { + if (isInProgress==0) + this.style.MozOpacity = 0.1; + }).mouseout(function () { + this.style.MozOpacity= 1; + }); + diff -r 0cadeb9fdfc3 -r 96aae15527c8 inkscape/firefox/install.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inkscape/firefox/install.sh Thu Jan 29 22:30:46 2009 +0800 @@ -0,0 +1,4 @@ +#!/bin/sh +cp inkscape.js madbuilder.html *.png /home/wycc/.mozilla/firefox/tmkakd0b.devel/extensions/madswatter@madswatter.branda.to/content/ +cp MBServer.py /usr/local/share/inkscape/extensions +cp helper_mb.py /usr/bin diff -r 0cadeb9fdfc3 -r 96aae15527c8 inkscape/firefox/madbuilder.html --- a/inkscape/firefox/madbuilder.html Mon Jan 26 01:37:04 2009 +0800 +++ b/inkscape/firefox/madbuilder.html Thu Jan 29 22:30:46 2009 +0800 @@ -3,12 +3,55 @@ + +
-
+ +
diff -r 0cadeb9fdfc3 -r 96aae15527c8 inkscape/firefox/start.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inkscape/firefox/start.svg Thu Jan 29 22:30:46 2009 +0800 @@ -0,0 +1,91 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff -r 0cadeb9fdfc3 -r 96aae15527c8 inkscape/firefox/testsoap.py --- a/inkscape/firefox/testsoap.py Mon Jan 26 01:37:04 2009 +0800 +++ b/inkscape/firefox/testsoap.py Thu Jan 29 22:30:46 2009 +0800 @@ -3,13 +3,19 @@ import sys,os class Inkscape(object): def __init__(self): - self.server = soap.Proxy('http://localhost:19192') + self.server = soap.Proxy('http://localhost:8080') def PUBLISH(self): return self.server.callRemote('PUBLISH') def SCENE(self,n): return self.server.callRemote('SCENE',n) def START(self): return self.server.callRemote('START') + def INSERTKEY(self,layer,n): + return self.server.callRemote('INSERTKEY',layer,n) + def EXTENDSCENE(self,layer,n): + return self.server.callRemote('EXTENDSCENE',layer,n) + def GETDOC(self): + return self.server.callRemote('GETDOC') def quitSession(result): @@ -29,6 +35,12 @@ d = ink.SCENE(sys.argv[2]) elif sys.argv[1] == 'START': d = ink.START() +elif sys.argv[1] == 'INSERTKEY': + d = ink.INSERTKEY(sys.argv[2], sys.argv[3]) +elif sys.argv[1] == 'GETDOC': + d = ink.GETDOC() +elif sys.argv[1] == 'EXTENDSCENE': + d = ink.EXTENDSCENE(sys.argv[2],sys.argv[3]) else: print 'Unknown command %s' % sys.argv[1] sys.exit(-1)