annotate inkscape/firefox/helper_mb.py @ 948:518c61784355

Add frameruler to show ruler for framelines
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 17 Nov 2010 01:46:10 +0800
parents 29145d2affdb
children
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 d.callback(result)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
25 self.client = None
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
26 def soap_INSERTKEY(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
27 if self.client == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
28 os.kill(self.pid,12)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
29 time.sleep(1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
30 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
31 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
32 n = int(n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
33 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
34 n = 0
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
35 d = defer.Deferred()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
36 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
37 return d
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
38 def soap_EXTENDSCENE(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
39 if self.client == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
40 os.kill(self.pid,12)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
41 time.sleep(1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
42 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
43 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
44 n = int(n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
45 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
46 n = 0
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
47 d = defer.Deferred()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
48 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
49 return d
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
50 def soap_DELETESCENE(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
51 if self.client == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
52 os.kill(self.pid,12)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
53 time.sleep(1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
54 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
55 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
56 n = int(n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
57 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
58 n = 0
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
59 d = defer.Deferred()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
60 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
61 return d
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
62
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
63 def soap_SCENE(self,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
64 if self.client == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
65 os.kill(self.pid,12)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
66 time.sleep(1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
67 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
68
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
69 d = defer.Deferred()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
70 self.client.SCENE(n).addCallback(self.generic_return,d)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
71 return d
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
72 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
73 print "Get result:"
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
74 print [result]
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
75 d.callback(result)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
76 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
77 print "Error:"
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
78 print [result]
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
79 d.errback(result)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
80 def soap_START(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
81 if self.client == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
82 os.kill(self.pid,12)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
83 time.sleep(1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
84 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
85 return "OK"
339
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
86 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
87 try:
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
88 print "reconnect"
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
89 time.sleep(1)
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
90 os.kill(self.pid,12)
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
91 op = self.client.GETDOC()
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
92 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
93 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
94 except:
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
95 traceback.print_exc()
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
96 def soap_GETDOC(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
97 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
98 print "xxxxx"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
99 if self.client == None:
339
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
100 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
101 time.sleep(1)
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
102
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
103 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
104 d = defer.Deferred()
339
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
105 op = self.client.GETDOC()
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
106 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
107 op.addErrback(self.getdoc_error,d)
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
108 print "yyy"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
109 return d
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
110 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
111 traceback.print_exc()
358
50d33c3987ba Add loader for project file.
wycc
parents: 353
diff changeset
112 def soap_GETPRJ(self,prj):
50d33c3987ba Add loader for project file.
wycc
parents: 353
diff changeset
113 try:
50d33c3987ba Add loader for project file.
wycc
parents: 353
diff changeset
114 f = open(prj,"r")
50d33c3987ba Add loader for project file.
wycc
parents: 353
diff changeset
115 l = f.read()
50d33c3987ba Add loader for project file.
wycc
parents: 353
diff changeset
116 f.close()
50d33c3987ba Add loader for project file.
wycc
parents: 353
diff changeset
117 return l
50d33c3987ba Add loader for project file.
wycc
parents: 353
diff changeset
118 except:
50d33c3987ba Add loader for project file.
wycc
parents: 353
diff changeset
119 traceback.print_exc()
50d33c3987ba Add loader for project file.
wycc
parents: 353
diff changeset
120
381
29145d2affdb Add function to change the name of the symbol
wycc
parents: 358
diff changeset
121 def soap_CHANGESYMBOL(self,id,name):
29145d2affdb Add function to change the name of the symbol
wycc
parents: 358
diff changeset
122 if self.client == None:
29145d2affdb Add function to change the name of the symbol
wycc
parents: 358
diff changeset
123 os.kill(self.pid,12)
29145d2affdb Add function to change the name of the symbol
wycc
parents: 358
diff changeset
124 time.sleep(1)
29145d2affdb Add function to change the name of the symbol
wycc
parents: 358
diff changeset
125 self.client = Client()
29145d2affdb Add function to change the name of the symbol
wycc
parents: 358
diff changeset
126 d = defer.Deferred()
29145d2affdb Add function to change the name of the symbol
wycc
parents: 358
diff changeset
127 print "send changesymbol"
29145d2affdb Add function to change the name of the symbol
wycc
parents: 358
diff changeset
128 self.client.CHANGESYMBOL(id,name).addCallback(self.generic_return,d).addErrback(self.generic_error,d)
29145d2affdb Add function to change the name of the symbol
wycc
parents: 358
diff changeset
129 return d
29145d2affdb Add function to change the name of the symbol
wycc
parents: 358
diff changeset
130
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
131 class Client(object):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
132 def __init__(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
133 self.proxy = soap.Proxy('http://localhost:8080')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
134 def PUBLISH(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
135 return self.proxy.callRemote('PUBLISH')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
136 def SCENE(self,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
137 return self.proxy.callRemote('SCENE',n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
138 def INSERTKEY(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
139 return self.proxy.callRemote('INSERTKEY',layer,n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
140 def GETDOC(self):
339
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
141 doc = self.proxy.callRemote('GETDOC')
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
142 return doc
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
143 def EXTENDSCENE(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
144 return self.proxy.callRemote('EXTENDSCENE',layer,n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
145 def DELETESCENE(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
146 return self.proxy.callRemote('DELETESCENE',layer,n)
381
29145d2affdb Add function to change the name of the symbol
wycc
parents: 358
diff changeset
147 def CHANGESYMBOL(self,id,name):
29145d2affdb Add function to change the name of the symbol
wycc
parents: 358
diff changeset
148 print "send soap CHANGESYMBOL to to client"
29145d2affdb Add function to change the name of the symbol
wycc
parents: 358
diff changeset
149 return self.proxy.callRemote('CHANGESYMBOL',id,name)
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
150
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
151 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
152 try:
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
153 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
154 pid = int(f.read())
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
155 f.close()
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
156 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
157 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
158 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
159 f.close()
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
160 except:
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
161 traceback.print_exc()
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
162
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
163 pid = os.fork()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
164 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
165 os.execvp("inkscape-mb",["inkscape-mb",sys.argv[1]])
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
166 s = Server()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
167 s.client = None
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
168 s.pid = pid
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
169 site = server.Site(s)
339
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
170 # 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
171 # 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
172 # remove the following wait in the future.
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
173 reactor.listenTCP(19192,site)
339
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
174 time.sleep(5)
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
175 reactor.run()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
176
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
177