Mercurial > MadButterfly
comparison inkscape/firefox/helper_mb.py @ 288:d5327265da1e
Revert the firefox integration to 276
author | wycc |
---|---|
date | Sat, 31 Jan 2009 17:35:27 +0800 |
parents | |
children | 63aaf96209cd |
comparison
equal
deleted
inserted
replaced
287:5c066380a84e | 288:d5327265da1e |
---|---|
1 #!/usr/bin/python | |
2 from twisted.web import server, resource,soap | |
3 from twisted.internet import reactor,defer | |
4 import os,time | |
5 import traceback | |
6 | |
7 | |
8 | |
9 | |
10 class Server(soap.SOAPPublisher): | |
11 """ | |
12 SOAP server for inkscape extension. | |
13 """ | |
14 def soap_PUBLISH(self): | |
15 if self.client == None: | |
16 os.kill(self.pid,12) | |
17 time.sleep(1) | |
18 self.client = Client() | |
19 d = defer.Deferred() | |
20 self.client.PUBLISH().addCallback(self.quit,d) | |
21 return d | |
22 | |
23 def quit(self,result,d): | |
24 print [result] | |
25 d.callback(result) | |
26 self.client = None | |
27 def soap_INSERTKEY(self,layer,n): | |
28 if self.client == None: | |
29 os.kill(self.pid,12) | |
30 time.sleep(1) | |
31 self.client = Client() | |
32 try: | |
33 n = int(n) | |
34 except: | |
35 n = 0 | |
36 d = defer.Deferred() | |
37 self.client.INSERTKEY(layer,n).addCallback(self.generic_return,d).addErrback(self.generic_error,d) | |
38 return d | |
39 def soap_EXTENDSCENE(self,layer,n): | |
40 if self.client == None: | |
41 os.kill(self.pid,12) | |
42 time.sleep(1) | |
43 self.client = Client() | |
44 try: | |
45 n = int(n) | |
46 except: | |
47 n = 0 | |
48 d = defer.Deferred() | |
49 self.client.EXTENDSCENE(layer,n).addCallback(self.generic_return,d).addErrback(self.generic_error,d) | |
50 return d | |
51 def soap_DELETESCENE(self,layer,n): | |
52 if self.client == None: | |
53 os.kill(self.pid,12) | |
54 time.sleep(1) | |
55 self.client = Client() | |
56 try: | |
57 n = int(n) | |
58 except: | |
59 n = 0 | |
60 d = defer.Deferred() | |
61 self.client.DELETESCENE(layer,n).addCallback(self.generic_return,d).addErrback(self.generic_error,d) | |
62 return d | |
63 | |
64 def soap_SCENE(self,n): | |
65 if self.client == None: | |
66 os.kill(self.pid,12) | |
67 time.sleep(1) | |
68 self.client = Client() | |
69 | |
70 d = defer.Deferred() | |
71 self.client.SCENE(n).addCallback(self.generic_return,d) | |
72 return d | |
73 def generic_return(self,result,d): | |
74 print [result] | |
75 d.callback(result) | |
76 def generic_error(self,result,d): | |
77 print [result] | |
78 d.errback(result) | |
79 def soap_START(self): | |
80 if self.client == None: | |
81 os.kill(self.pid,12) | |
82 time.sleep(1) | |
83 self.client = Client() | |
84 return "OK" | |
85 def soap_GETDOC(self): | |
86 try: | |
87 print "xxxxx" | |
88 if self.client == None: | |
89 os.kill(self.pid,12) | |
90 time.sleep(1) | |
91 self.client = Client() | |
92 d = defer.Deferred() | |
93 self.client.GETDOC().addCallback(self.generic_return,d) | |
94 print "yyy" | |
95 return d | |
96 except: | |
97 traceback.print_exc() | |
98 | |
99 | |
100 | |
101 | |
102 class Client(object): | |
103 def __init__(self): | |
104 self.proxy = soap.Proxy('http://localhost:8080') | |
105 def PUBLISH(self): | |
106 return self.proxy.callRemote('PUBLISH') | |
107 def SCENE(self,n): | |
108 return self.proxy.callRemote('SCENE',n) | |
109 def INSERTKEY(self,layer,n): | |
110 return self.proxy.callRemote('INSERTKEY',layer,n) | |
111 def GETDOC(self): | |
112 return self.proxy.callRemote('GETDOC') | |
113 def EXTENDSCENE(self,layer,n): | |
114 return self.proxy.callRemote('EXTENDSCENE',layer,n) | |
115 def DELETESCENE(self,layer,n): | |
116 return self.proxy.callRemote('DELETESCENE',layer,n) | |
117 | |
118 os.system("killall -9 inkscape-mb") | |
119 pid = os.fork() | |
120 if pid==0: | |
121 os.execvp("inkscape-mb",["inkscape-mb","/tmp/scene.mbsvg"]) | |
122 s = Server() | |
123 s.client = None | |
124 s.pid = pid | |
125 site = server.Site(s) | |
126 reactor.listenTCP(19192,site) | |
127 reactor.run() | |
128 | |
129 |