comparison inkscape/firefox/helper_mb.py @ 262:c39b24036a75

Add proxy daemon and extention for the firefox integration. We need to implement javascript web client to repalce the unite test program testsoap.py
author wycc@wycc-desktop
date Fri, 23 Jan 2009 23:15:04 +0800
parents
children 96aae15527c8
comparison
equal deleted inserted replaced
261:11017576328c 262:c39b24036a75
1 #!/usr/bin/python
2 from twisted.web import server, resource,soap
3 from twisted.internet import reactor,defer
4 import os,time
5
6
7
8
9 class Server(soap.SOAPPublisher):
10 """
11 SOAP server for inkscape extension.
12 """
13 def soap_PUBLISH(self):
14 if self.client == None:
15 os.kill(self.pid,12)
16 time.sleep(1)
17 self.client = Client()
18 d = defer.Deferred()
19 self.client.PUBLISH().addCallback(self.quit,d)
20 return d
21
22 def quit(self,result,d):
23 print [result]
24 d.callback(result)
25 self.client = None
26 def soap_SCENE(self,n):
27 if self.client == None:
28 os.kill(self.pid,12)
29 time.sleep(1)
30 self.client = Client()
31
32 d = defer.Deferred()
33 self.client.SCENE(n).addCallback(self.generic_return,d)
34 return d
35 def generic_return(self,result,d):
36 print [result]
37 d.callback(result)
38 def soap_START(self):
39 if self.client == None:
40 os.kill(self.pid,12)
41 time.sleep(1)
42 self.client = Client()
43 return "OK"
44
45
46
47
48 class Client(object):
49 def __init__(self):
50 self.proxy = soap.Proxy('http://localhost:8080')
51 def PUBLISH(self):
52 return self.proxy.callRemote('PUBLISH')
53 def SCENE(self,n):
54 return self.proxy.callRemote('SCENE',n)
55 pid = os.fork()
56 if pid==0:
57 os.execvp("inkscape-mb",["inkscape-mb","scene.svg"])
58 s = Server()
59 s.client = None
60 s.pid = pid
61 site = server.Site(s)
62 reactor.listenTCP(19192,site)
63 reactor.run()
64
65