annotate inkscape/firefox/helper_mb.py @ 356:3e84458968ec

Move mb_img_data_t out from argument list of rdman_shape_image_new(). - Application should specify content of sh_image_t by fill the shape with a paint_image_t.
author Thinker K.F. Li <thinker@branda.to>
date Mon, 09 Mar 2009 23:05:57 +0800
parents 3d03451be435
children 50d33c3987ba
rev   line source
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
1 #!/usr/bin/python
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
2 from twisted.web import server, resource,soap
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
3 from twisted.internet import reactor,defer
353
3d03451be435 Import the file specified in the mozplugger helper. This is the first step to handle the same file between inkscape and helper
wycc
parents: 339
diff changeset
4 import os,time,sys
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
5 import traceback
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
6
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
7
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
8
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
9
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
10 class Server(soap.SOAPPublisher):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
11 """
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
12 SOAP server for inkscape extension.
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
13 """
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
14 def soap_PUBLISH(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
15 if self.client == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
16 os.kill(self.pid,12)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
17 time.sleep(1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
18 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
19 d = defer.Deferred()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
20 self.client.PUBLISH().addCallback(self.quit,d)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
21 return d
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
22
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
23 def quit(self,result,d):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
24 print [result]
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
25 d.callback(result)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
26 self.client = None
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
27 def soap_INSERTKEY(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
28 if self.client == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
29 os.kill(self.pid,12)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
30 time.sleep(1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
31 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
32 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
33 n = int(n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
34 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
35 n = 0
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
36 d = defer.Deferred()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
37 self.client.INSERTKEY(layer,n).addCallback(self.generic_return,d).addErrback(self.generic_error,d)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
38 return d
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
39 def soap_EXTENDSCENE(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
40 if self.client == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
41 os.kill(self.pid,12)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
42 time.sleep(1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
43 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
44 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
45 n = int(n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
46 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
47 n = 0
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
48 d = defer.Deferred()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
49 self.client.EXTENDSCENE(layer,n).addCallback(self.generic_return,d).addErrback(self.generic_error,d)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
50 return d
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
51 def soap_DELETESCENE(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
52 if self.client == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
53 os.kill(self.pid,12)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
54 time.sleep(1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
55 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
56 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
57 n = int(n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
58 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
59 n = 0
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
60 d = defer.Deferred()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
61 self.client.DELETESCENE(layer,n).addCallback(self.generic_return,d).addErrback(self.generic_error,d)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
62 return d
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
63
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
64 def soap_SCENE(self,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
65 if self.client == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
66 os.kill(self.pid,12)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
67 time.sleep(1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
68 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
69
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
70 d = defer.Deferred()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
71 self.client.SCENE(n).addCallback(self.generic_return,d)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
72 return d
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
73 def generic_return(self,result,d):
339
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
74 print "Get result:"
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
75 print [result]
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
76 d.callback(result)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
77 def generic_error(self,result,d):
339
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
78 print "Error:"
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
79 print [result]
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
80 d.errback(result)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
81 def soap_START(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
82 if self.client == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
83 os.kill(self.pid,12)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
84 time.sleep(1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
85 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
86 return "OK"
339
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
87 def getdoc_error(self,result,d):
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
88 try:
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
89 print "reconnect"
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
90 time.sleep(1)
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
91 os.kill(self.pid,12)
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
92 op = self.client.GETDOC()
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
93 op.addCallback(self.generic_return,d)
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
94 op.addErrback(self.getdoc_error,d)
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
95 except:
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
96 traceback.print_exc()
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
97 def soap_GETDOC(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
98 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
99 print "xxxxx"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
100 if self.client == None:
339
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
101 while os.kill(self.pid,12)<0:
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
102 time.sleep(1)
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
103
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
104 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
105 d = defer.Deferred()
339
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
106 op = self.client.GETDOC()
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
107 op.addCallback(self.generic_return,d)
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
108 op.addErrback(self.getdoc_error,d)
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
109 print "yyy"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
110 return d
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
111 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
112 traceback.print_exc()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
113
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
114
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
115
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
116
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
117 class Client(object):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
118 def __init__(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
119 self.proxy = soap.Proxy('http://localhost:8080')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
120 def PUBLISH(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
121 return self.proxy.callRemote('PUBLISH')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
122 def SCENE(self,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
123 return self.proxy.callRemote('SCENE',n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
124 def INSERTKEY(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
125 return self.proxy.callRemote('INSERTKEY',layer,n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
126 def GETDOC(self):
339
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
127 doc = self.proxy.callRemote('GETDOC')
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
128 return doc
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
129 def EXTENDSCENE(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
130 return self.proxy.callRemote('EXTENDSCENE',layer,n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
131 def DELETESCENE(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
132 return self.proxy.callRemote('DELETESCENE',layer,n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
133
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
134 os.system("killall -9 inkscape-mb")
339
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
135 try:
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
136 f = open("/tmp/madbuilder.pid","r")
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
137 pid = int(f.read())
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
138 f.close()
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
139 os.system("kill -9 %d" % pid)
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
140 f = open("/tmp/madbuilder.pid","w")
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
141 f.write("%d\n" % os.getpid())
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
142 f.close()
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
143 except:
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
144 traceback.print_exc()
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
145
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
146 pid = os.fork()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
147 if pid==0:
353
3d03451be435 Import the file specified in the mozplugger helper. This is the first step to handle the same file between inkscape and helper
wycc
parents: 339
diff changeset
148 os.execvp("inkscape-mb",["inkscape-mb",sys.argv[1]])
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
149 s = Server()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
150 s.client = None
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
151 s.pid = pid
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
152 site = server.Site(s)
339
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
153 # Sleep for two seconds to wait for the inkscape become ready. It seems that our inkscape modification has
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
154 # semaphore issue so that it will be blocked if we connect to it in early stage. We need to check it and
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
155 # remove the following wait in the future.
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
156 reactor.listenTCP(19192,site)
339
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
157 time.sleep(5)
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
158 reactor.run()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
159
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
160