Mercurial > MadButterfly
changeset 274:96aae15527c8
Port all basic scene editor from pyGtk to the firefox
author | wycc |
---|---|
date | Thu, 29 Jan 2009 22:30:46 +0800 |
parents | 0cadeb9fdfc3 |
children | 40c0c907c6dd |
files | inkscape/firefox/MBServer.py inkscape/firefox/active-empty.png inkscape/firefox/active-empty.svg inkscape/firefox/active-fill.png inkscape/firefox/active-fill.svg inkscape/firefox/active-start.png inkscape/firefox/active-start.svg inkscape/firefox/empty.svg inkscape/firefox/fill.svg inkscape/firefox/helper_mb.py inkscape/firefox/inkscape.js inkscape/firefox/install.sh inkscape/firefox/madbuilder.html inkscape/firefox/start.svg inkscape/firefox/testsoap.py |
diffstat | 15 files changed, 1039 insertions(+), 95 deletions(-) [+] |
line wrap: on
line diff
--- 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()
--- /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 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="744.09448819" + height="1052.3622047" + id="svg2" + sodipodi:version="0.32" + inkscape:version="0.46" + sodipodi:docname="active-empty.svg" + inkscape:output_extension="org.inkscape.output.svg.inkscape" + inkscape:export-filename="active-empty.png" + inkscape:export-xdpi="86.949997" + inkscape:export-ydpi="86.949997"> + <defs + id="defs4"> + <inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 526.18109 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="744.09448 : 526.18109 : 1" + inkscape:persp3d-origin="372.04724 : 350.78739 : 1" + id="perspective10" /> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + gridtolerance="10000" + guidetolerance="10" + objecttolerance="10" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="3.959798" + inkscape:cx="41.651785" + inkscape:cy="934.16255" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="false" + inkscape:window-width="1400" + inkscape:window-height="978" + inkscape:window-x="0" + inkscape:window-y="25" /> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1"> + <rect + style="fill:none;stroke:#00d300;stroke-opacity:1" + id="rect2380" + width="30" + height="30" + x="79.802048" + y="67.262962" /> + </g> +</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 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="744.09448819" + height="1052.3622047" + id="svg2" + sodipodi:version="0.32" + inkscape:version="0.46" + sodipodi:docname="active-fill.svg" + inkscape:output_extension="org.inkscape.output.svg.inkscape" + inkscape:export-filename="active-fill.png" + inkscape:export-xdpi="86.949997" + inkscape:export-ydpi="86.949997"> + <defs + id="defs4"> + <inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 526.18109 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="744.09448 : 526.18109 : 1" + inkscape:persp3d-origin="372.04724 : 350.78739 : 1" + id="perspective10" /> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + gridtolerance="10000" + guidetolerance="10" + objecttolerance="10" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="3.959798" + inkscape:cx="1.3719525" + inkscape:cy="934.16255" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="false" + inkscape:window-width="1400" + inkscape:window-height="978" + inkscape:window-x="0" + inkscape:window-y="25" /> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1"> + <rect + style="fill:none;stroke:#000000;stroke-opacity:1" + id="rect2380" + width="30" + height="30" + x="79.802048" + y="67.262962" /> + <rect + style="fill:#00d300;fill-opacity:1;stroke:#00d300;stroke-width:1.90641569999999994;stroke-opacity:1" + id="rect3154" + width="28.388008" + height="2.6291182" + x="81.012871" + y="80.543571" /> + </g> +</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 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="744.09448819" + height="1052.3622047" + id="svg2" + sodipodi:version="0.32" + inkscape:version="0.46" + sodipodi:docname="active-start.svg" + inkscape:output_extension="org.inkscape.output.svg.inkscape" + inkscape:export-filename="active-start.png" + inkscape:export-xdpi="86.949997" + inkscape:export-ydpi="86.949997"> + <defs + id="defs4"> + <inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 526.18109 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="744.09448 : 526.18109 : 1" + inkscape:persp3d-origin="372.04724 : 350.78739 : 1" + id="perspective10" /> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + gridtolerance="10000" + guidetolerance="10" + objecttolerance="10" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="3.959798" + inkscape:cx="1.3719525" + inkscape:cy="913.9595" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="false" + inkscape:window-width="1400" + inkscape:window-height="978" + inkscape:window-x="0" + inkscape:window-y="25" /> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1"> + <path + sodipodi:type="arc" + style="fill:#00d300;fill-opacity:1" + id="path2383" + sodipodi:cx="114.28571" + sodipodi:cy="123.79076" + sodipodi:rx="14.285714" + sodipodi:ry="14.285714" + d="M 128.57143,123.79076 A 14.285714,14.285714 0 1 1 99.999999,123.79076 A 14.285714,14.285714 0 1 1 128.57143,123.79076 z" + transform="matrix(0.7,0,0,0.7,14.342634,-4.5390011)" /> + <rect + style="fill:none;stroke:#000000;stroke-opacity:1" + id="rect2380" + width="30" + height="30" + x="79.802048" + y="67.262962" /> + <rect + style="fill:#00d300;stroke:#00d300;stroke-opacity:1;fill-opacity:1" + id="rect3154" + width="5.8083773" + height="3.5355339" + x="104.04571" + y="80.090363" /> + </g> +</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 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="744.09448819" + height="1052.3622047" + id="svg2" + sodipodi:version="0.32" + inkscape:version="0.46" + sodipodi:docname="empty.svg" + inkscape:output_extension="org.inkscape.output.svg.inkscape" + inkscape:export-filename="/home/wycc/devel/test/MadButterfly/inkscape/empty.png" + inkscape:export-xdpi="86.949997" + inkscape:export-ydpi="86.949997"> + <defs + id="defs4"> + <inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 526.18109 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="744.09448 : 526.18109 : 1" + inkscape:persp3d-origin="372.04724 : 350.78739 : 1" + id="perspective10" /> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + gridtolerance="10000" + guidetolerance="10" + objecttolerance="10" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="3.959798" + inkscape:cx="41.651785" + inkscape:cy="934.16255" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="false" + inkscape:window-width="1400" + inkscape:window-height="978" + inkscape:window-x="0" + inkscape:window-y="25" /> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1"> + <rect + style="fill:none;stroke:#000000;stroke-opacity:1" + id="rect2380" + width="30" + height="30" + x="79.802048" + y="67.262962" /> + </g> +</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 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="744.09448819" + height="1052.3622047" + id="svg2" + sodipodi:version="0.32" + inkscape:version="0.46" + sodipodi:docname="fill.svg" + inkscape:output_extension="org.inkscape.output.svg.inkscape" + inkscape:export-filename="/home/wycc/devel/test/MadButterfly/inkscape/fill.png" + inkscape:export-xdpi="86.949997" + inkscape:export-ydpi="86.949997"> + <defs + id="defs4"> + <inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 526.18109 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="744.09448 : 526.18109 : 1" + inkscape:persp3d-origin="372.04724 : 350.78739 : 1" + id="perspective10" /> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + gridtolerance="10000" + guidetolerance="10" + objecttolerance="10" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="3.959798" + inkscape:cx="41.651785" + inkscape:cy="934.16255" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="false" + inkscape:window-width="1400" + inkscape:window-height="978" + inkscape:window-x="0" + inkscape:window-y="25" /> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1"> + <rect + style="fill:none;stroke:#000000;stroke-opacity:1" + id="rect2380" + width="30" + height="30" + x="79.802048" + y="67.262962" /> + <rect + style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:1.9064157;stroke-opacity:1" + id="rect3154" + width="28.388008" + height="2.6291182" + x="81.012871" + y="80.543571" /> + </g> +</svg>
--- 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
--- /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 + ": <Maximum Depth Reached>\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 = "<Unable to Evaluate>"; + } + 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 + ": <Maximum Depth Reached>\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 = "<Unable to Evaluate>"; + } + 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 = "<embed src="+file+" width=1000 height=800 />"; +} + +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<len;i++) { + var s = scenesNode[i]; + var start = s.getAttribute("start"); + var end = s.getAttribute("end"); + var ref = s.getAttribute("ref"); + var ss = new Object(); + + if (end == null) end = start + if (max <end) max = end; + ss.node = s; + ss.start = start; + ss.end = end; + ss.ref = ref; + ss.layer = null; + scenes.push(ss); + } + if (max < 20) max = 20; + // Collect all layers + var nodes = xmlDoc.getElementsByTagNameNS("http://www.w3.org/2000/svg","svg")[0].childNodes; + var layers = new Array(); + len = nodes.length; + for(i=0;i<len;i++) { + if (nodes[i].localName == 'g') { + var subnodes = nodes[i].childNodes; + for(j=0;j<subnodes.length;j++) { + if (subnodes[j].localName == 'g') { + for(var k=0;k<scenes.length;k++) { + if (scenes[k].ref == subnodes[j].getAttribute('id')) { + scenes[k].layer = nodes[i].getAttribute('id'); + break; + } + } + } + } + layers.push(nodes[i]); + } + } + self.layers = layers; + self.scenes = scenes; + self.maxframe = max; +} + +function renderUI(mbsvg) +{ + var layers = mbsvg.layers; + var scenes = mbsvg.scenes; + var max = mbsvg.maxframe; + var cmd = "<table border=1>\n"; + cmd = cmd + "<tr><td></td>"; + for(var j=1;j<=max;j++) + cmd = cmd + "<td>"+j+"</td>"; + + 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 + "<tr><td>"+label+"</td>"; + for(j=0;j<max;j++) { + var empty = 1; + var n = j +1; + var id_str = id+"#"+n + for(var k=0;k<scenes.length;k++) { + if (id != scenes[k].layer) continue; + if (n == scenes[k].start) { + cmd = cmd + "<td><img class='normal' src=start.png id='"+id_str+"' onClick='selectCell(this)' /></td>"; + empty = 0; + break; + } else if ((n>scenes[k].start)&&(n <= scenes[k].end)) { + cmd = cmd + "<td><img class='normal' src=fill.png id='"+id_str+"' onClick='selectCell(this)' /></td>"; + empty = 0; + break; + } + } + if (empty) { + cmd = cmd + "<td><img class='normal' src=empty.png id='"+id_str+"'onClick='selectCell(this)' /></td>"; + } + + } + cmd = cmd + "</tr>\n"; + } + cmd = cmd + "</table>\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; + }); +
--- /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
--- 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 @@ <script language="javascript" src="jquery-1.3.1.js"></script> <script language="javascript" src="jqXMLUtils.js"></script> <script language="javascript" src="jqSOAPClient.js"></script> + <style type="text/css"> + .normal { + background-color:write + } + .active { + background-color: yellow + } + a.button { + background:#0ff ; + color : # 444 ; + display : block ; + float : left ; + font : normal 12px arial, sans-serif ; + height : 24px; + margin-right : 6px; + padding-right : 18px; + text-decoration : none ; + } + a.button span { + background : transparent url ( 'bg_button_div.gif' ) no-repeat ; + display : block ; + line- height : 14px; line- height : 14px; + padding : 5px 0 5px 18px; padding : 5px 0 5px 18px; + } + a.button :active { + background-position : bottom right ; + color : # 000 ; + outline : none ; + } + a.button :active span { + background-position : bottom left ; + padding : 6px 0 4px 18px; + } + </style> + </style> </head> <body> <div id='frame' width=800 height=200> </div> -<div id='inkscape' width=1200 height=600> +<div id='btns'> + <a class='button' href='#'> <span id='Jump' onClick='onButtonClick(this)'>Jump</span></a> + <a class='button' href='#'> <span id='InsertKey' onClick='onButtonClick(this)'>Insert</span></a> + <a class='button' href='#'> <span id='ExtendScene' onClick='onButtonClick(this)'>Extend</span></a> + <a class='button' href='#'> <span id='DeleteScene' onClick='onButtonClick(this)'>Delete</span></a> + <br/> + <br/> +</div> +<div id='inkscape' width=1000 height=700> </div> <script type="text/javascript" src="inkscape.js" > </script>
--- /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 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="744.09448819" + height="1052.3622047" + id="svg2" + sodipodi:version="0.32" + inkscape:version="0.46" + sodipodi:docname="start.svg" + inkscape:output_extension="org.inkscape.output.svg.inkscape" + inkscape:export-filename="/home/wycc/devel/test/MadButterfly/inkscape/start.png" + inkscape:export-xdpi="86.949997" + inkscape:export-ydpi="86.949997"> + <defs + id="defs4"> + <inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 526.18109 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="744.09448 : 526.18109 : 1" + inkscape:persp3d-origin="372.04724 : 350.78739 : 1" + id="perspective10" /> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + gridtolerance="10000" + guidetolerance="10" + objecttolerance="10" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="3.959798" + inkscape:cx="41.651785" + inkscape:cy="934.16255" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="false" + inkscape:window-width="1400" + inkscape:window-height="978" + inkscape:window-x="0" + inkscape:window-y="25" /> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1"> + <path + sodipodi:type="arc" + style="fill:#000000" + id="path2383" + sodipodi:cx="114.28571" + sodipodi:cy="123.79076" + sodipodi:rx="14.285714" + sodipodi:ry="14.285714" + d="M 128.57143,123.79076 A 14.285714,14.285714 0 1 1 99.999999,123.79076 A 14.285714,14.285714 0 1 1 128.57143,123.79076 z" + transform="matrix(0.7,0,0,0.7,14.342634,-4.5390011)" /> + <rect + style="fill:none;stroke:#000000;stroke-opacity:1" + id="rect2380" + width="30" + height="30" + x="79.802048" + y="67.262962" /> + <rect + style="fill:#000000;stroke:#000000;stroke-opacity:1;fill-opacity:1" + id="rect3154" + width="5.8083773" + height="3.5355339" + x="104.04571" + y="80.090363" /> + </g> +</svg>
--- 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)