annotate inkscape/firefox/MBServer.py @ 334:02e457d374f5

Clean generated code in examples/dynamic/.
author Thinker K.F. Li <thinker@branda.to>
date Sat, 07 Mar 2009 11:03:18 +0800
parents d5327265da1e
children 63aaf96209cd
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 import inkex
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
3 import pygtk
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
4 import gtk
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
5 from copy import deepcopy
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
6 from lxml import etree
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
7 from twisted.web import server, resource,soap
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
8 from twisted.internet import reactor
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
9 import traceback
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
10
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
11 import random
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
12
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
13 # Please refer to http://www.assembla.com/wiki/show/MadButterfly/Inkscape_extention for the designed document.
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
14
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
15
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
16 # Algorithm:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
17 #
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
18 # We will parse the first two level of the SVG DOM. collect a table of layer and scene.
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
19 # 1. Collect the layer table which will be displayed as the first column of the grid.
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
20 # 2. Get the maximum scene number. This will decide the size of the grid.
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
21 # 3. When F6 is pressed, we will check if this scene has been defined. This can be done by scan all second level group and check if the current scene number is within the
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
22 # range specified by scene field. The function IsSceneDefined(scene) can be used for this purpose.
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
23 # 4. If this is a new scene, we will append a new group which duplication the content of the last scene in the same group. The scene field will contain the number from the
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
24 # last scene number of the last scene to the current scenen number. For example, if the last scene is from 4-7 and the new scene is 10, we will set the scene field as
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
25 # "8-10".
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
26 # 5. If this scene are filled screne, we will split the existing scene into two scenes with the same content.
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
27
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
28 class Layer:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
29 def __init__(self,node):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
30 self.scene = []
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
31 self.node = node
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
32 self.nodes=[]
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
33 class Scene:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
34 def __init__(self, node, start,end):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
35 self.node = node
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
36 self.start = int(start)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
37 self.end = int(end)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
38
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
39
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
40 class MBScene(inkex.Effect):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
41 def confirm(self,msg):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
42 vbox = gtk.VBox()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
43 vbox.pack_start(gtk.Label(msg))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
44 self.button = gtk.Button('OK')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
45 vbox.pack_start(self.button)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
46 self.button.connect("clicked", self.onQuit)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
47 self.window.add(vbox)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
48 def dumpattr(self,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
49 s = ""
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
50 for a,v in n.attrib.items():
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
51 s = s + ("%s=%s" % (a,v))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
52 return s
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
53
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
54 def dump(self,node,l=0):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
55 print " " * l*2,"<", node.tag, self.dumpattr(node),">"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
56 for n in node:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
57 self.dump(n,l+1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
58 print " " * l * 2,"/>"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
59 def parseMetadata(self,node):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
60 self.current = 1
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
61 for n in node:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
62 if n.tag == '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scenes':
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
63 self.scenemap={}
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
64 cur = int(n.get("current"))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
65 self.current = cur
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
66
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
67 for s in n:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
68 if s.tag == '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene':
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
69 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
70 start = int(s.get("start"))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
71 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
72 continue
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
73 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
74 end = s.get("end")
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
75 if end == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
76 end = start
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
77 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
78 end = start
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
79 link = s.get("ref")
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
80 self.scenemap[link] = [int(start),int(end)]
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
81 if cur >= start and cur <= end:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
82 self.currentscene = link
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
83
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
84 pass
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
85 pass
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
86 pass
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
87 pass
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
88
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
89
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
90 def parseScene(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
91 """
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
92 In this function, we will collect all items for the current scene and then relocate them back to the appropriate scene object.
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
93 """
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
94 self.layer = []
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
95 self.scenemap = None
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
96 for node in self.document.getroot():
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
97 if node.tag == '{http://www.w3.org/2000/svg}metadata':
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
98 self.parseMetadata(node)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
99 elif node.tag == '{http://www.w3.org/2000/svg}g':
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
100 oldscene = None
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
101 #print layer.attrib.get("id")
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
102 lyobj = Layer(node)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
103 self.layer.append(lyobj)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
104 lyobj.current_scene = []
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
105 for scene in node:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
106 if scene.tag == '{http://www.w3.org/2000/svg}g':
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
107 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
108 scmap = self.scenemap[scene.get("id")]
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
109 if scmap == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
110 lyobj.current_scene.append(scene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
111 continue
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
112 if self.current <= scmap[1] and self.current >= scmap[0]:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
113 oldscene = scene
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
114 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
115 lyobj.current_scene.append(scene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
116 continue
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
117
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
118 lyobj.scene.append(Scene(scene,scmap[0],scmap[1]))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
119 else:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
120 lyobj.current_scene.append(scene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
121 pass
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
122 pass
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
123
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
124 if oldscene != None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
125 # Put the objects back to the current scene
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
126 for o in lyobj.current_scene:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
127 #print o.tag
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
128 oldscene.append(o)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
129 pass
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
130 pass
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
131 pass
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
132 pass
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
133
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
134 self.collectID()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
135 #self.dumpID()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
136 def collectID(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
137 self.ID = {}
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
138 root = self.document.getroot()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
139 for n in root:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
140 self.collectID_recursive(n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
141 def collectID_recursive(self,node):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
142 self.ID[node.get("id")] = 1
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
143 for n in node:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
144 self.collectID_recursive(n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
145 def newID(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
146 while True:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
147 n = 's%d' % int(random.random()*10000)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
148 #print "try %s" % n
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
149 if self.ID.has_key(n) == False:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
150 return n
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
151 def dumpID(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
152 for a,v in self.ID.items():
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
153 print a
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
154
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
155
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
156 def getLayer(self, layer):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
157 for l in self.layer:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
158 if l.node.attrib.get("id") == layer:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
159 return l
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
160 return None
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
161
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
162
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
163 def insertKeyScene(self,layer,nth):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
164 """
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
165 Insert a new key scene into the stage. If the nth is always a key scene, we will return without changing anything.
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
166 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
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
167 append a new scene.
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
168
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
169 """
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
170 if layer == None: return
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
171
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
172 # Check if the nth is in the middle of any scene
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
173 for i in range(0,len(layer.scene)):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
174 s = layer.scene[i]
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
175 if nth >= s.start and nth <= s.end:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
176 if nth == s.start: return
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
177 newscene = Scene(deepcopy(s.node),nth,s.end)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
178 newscene.node.set("id", self.newID())
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
179 layer.scene.insert(i+1,newscene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
180 layer.scene[i].end = nth-1
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
181 return
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
182 if len(layer.scene) > 0:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
183 # extend the last scene befor eit automatically
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
184 last = nth
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
185 lastscene = None
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
186 # Find the last scene before it
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
187 for s in layer.scene:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
188 if s.end < nth and last < s.end:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
189 last = s.end
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
190 lastscene = s
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
191 if lastscene == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
192 node = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
193 node.set("id", self.newID())
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
194 newscene = Scene(node,nth,nth)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
195 else:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
196 lastscene.end = nth-1
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
197 newscene = Scene(deepcopy(lastscene.node),nth,nth)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
198 newscene.node.set("id",self.newID())
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
199 layer.scene.append(newscene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
200 else:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
201 # This is the first scene in the layer
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
202 node = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
203 node.set("id", self.newID())
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
204 newscene = Scene(node,nth,nth)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
205 layer.scene.append(newscene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
206
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
207
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
208 def deleteScene(self,layer,nth):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
209 for i in range(0,len(layer.scene)):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
210 s = layer.scene[i]
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
211 if nth == s.start:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
212 if i == 0:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
213 layer.scene.remove(s)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
214 else:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
215 if s.start == layer.scene[i-1].end+1:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
216 # If the start of the delete scene segment is the end of the last scene segmenet, convert all scenes in the deleted
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
217 # scene segmenet to the last one
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
218 layer.scene[i-1].end = s.end
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
219 layer.scene.remove(s)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
220 else:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
221 # Convert all scenes into empty cell
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
222 layer.scene.remove(s)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
223
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
224 return
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
225 pass
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
226 pass
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
227
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
228
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
229 def extendScene(self,layer,nth):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
230 if layer == None: return
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
231
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
232 for i in range(0,len(layer.scene)-1):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
233 s = layer.scene[i]
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
234 if nth >= layer.scene[i].start and nth <= layer.scene[i].end:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
235 return
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
236
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
237 for i in range(0,len(layer.scene)-1):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
238 s = layer.scene[i]
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
239 if nth >= layer.scene[i].start and nth < layer.scene[i+1].start:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
240 layer.scene[i].end = nth
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
241 return
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
242 if len(layer.scene) > 0 and nth > layer.scene[len(layer.scene)-1].end:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
243 layer.scene[len(layer.scene)-1].end = nth
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
244
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
245 def setCurrentScene(self,nth):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
246 self.current = nth
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
247 for layer in self.layer:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
248 for s in layer.scene:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
249 if nth >= s.start and nth <= s.end:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
250 s.node.set("style","")
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
251 #print "Put the elemenets out"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
252 layer.nodes = []
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
253
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
254 for o in s.node:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
255 #print " ",o.tag
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
256 layer.nodes.append(o)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
257 for o in s.node:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
258 s.node.remove(o)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
259 else:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
260 s.node.set("style","display:none")
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
261 def generate(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
262 newdoc = deepcopy(self.document)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
263 root = newdoc.getroot()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
264 has_scene = False
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
265 for n in root:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
266 if n.tag == '{http://www.w3.org/2000/svg}metadata':
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
267 for nn in n:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
268 if nn.tag == '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scenes':
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
269 nn.clear()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
270 nn.set("current", "%d" % self.current)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
271 scenes = []
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
272 for l in self.layer:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
273 for s in l.scene:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
274 id = s.node.get("id")
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
275 scene = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
276 scene.set("ref", id)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
277 if s.start == s.end:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
278 scene.set("start", "%d" % s.start)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
279 else:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
280 scene.set("start", "%d" % s.start)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
281 scene.set("end", "%d" % s.end)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
282
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
283 scenes.append(scene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
284 for s in scenes:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
285 nn.append(s)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
286 has_scene = True
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
287 if has_scene == False:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
288 scenes = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scenes')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
289 scenes.set("current","%d" % self.current)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
290 for l in self.layer:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
291 for s in l.scene:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
292 scene = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
293 scene.set("ref", s.node.get("id"))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
294 if s.start == s.end:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
295 scene.set("start", "%d" % s.start)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
296 else:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
297 scene.set("start", "%d" % s.start)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
298 scene.set("end", "%d" % s.end)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
299 scenes.append(scene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
300 n.append(scenes)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
301 if n.tag == '{http://www.w3.org/2000/svg}g':
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
302 root.remove(n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
303
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
304 for l in self.layer:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
305 # Duplicate all attribute of the layer
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
306 lnode = etree.Element("{http://www.w3.org/2000/svg}g")
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
307 for a,v in l.node.attrib.items():
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
308 lnode.set(a,v)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
309 for n in l.nodes:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
310 lnode.append(n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
311 root.append(lnode)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
312 for s in l.scene:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
313 snode = etree.Element("{http://www.w3.org/2000/svg}g")
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
314 for a,v in s.node.attrib.items():
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
315 snode.set(a,v)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
316 for n in s.node:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
317 snode.append(deepcopy(n))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
318 lnode.append(snode)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
319 self.document = newdoc
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
320 def newCell(self,file):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
321 img = gtk.Image()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
322 img.set_from_file(file)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
323 btn = gtk.EventBox()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
324 btn.add(img)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
325 btn.connect("button_press_event", self.cellSelect)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
326 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray"))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
327 return btn
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
328 def showGrid(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
329 max = 0
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
330 for layer in self.layer:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
331 for s in layer.scene:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
332 if s.end > max:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
333 max = s.end
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
334 max = 50
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
335
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
336 self.grid = gtk.Table(len(self.layer)+1, 50)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
337 self.scrollwin = gtk.ScrolledWindow()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
338 self.scrollwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
339 self.scrollwin.add_with_viewport(self.grid)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
340 for i in range(1,max):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
341 self.grid.attach(gtk.Label('%d'% i), i,i+1,0,1,0,0,0,0)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
342 for i in range(1,len(self.layer)+1):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
343 l = self.layer[i-1]
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
344 self.grid.attach(gtk.Label(l.node.get('{http://www.inkscape.org/namespaces/inkscape}label')), 0, 1, i, i+1,0,0,10,0)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
345 for s in l.scene:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
346 btn = self.newCell('start.png')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
347 btn.nScene = s.start
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
348 btn.layer = l.node.get('id')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
349 btn.nLayer = i
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
350
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
351 self.grid.attach(btn, s.start, s.start+1, i, i+1,0,0,0,0)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
352 for j in range(s.start+1,s.end+1):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
353 btn = self.newCell('fill.png')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
354 self.grid.attach(btn, j, j+1, i , i+1,0,0,0,0)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
355 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray"))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
356 btn.nScene = j
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
357 btn.layer = l.node.get('id')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
358 btn.nLayer = i
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
359 if len(l.scene) == 0:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
360 start = 0
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
361 else:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
362 start = l.scene[len(l.scene)-1].end
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
363 for j in range(start,max):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
364 btn = self.newCell('empty.png')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
365 self.grid.attach(btn, j+1, j+2,i,i+1,0,0,0,0)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
366 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray"))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
367 btn.nScene = j+1
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
368 btn.layer = l.node.get('id')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
369 btn.nLayer = i
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
370 self.last_cell = None
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
371 def cellSelect(self, cell, data):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
372 if self.last_cell:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
373 self.last_cell.modify_bg(gtk.STATE_NORMAL, self.last_cell.get_colormap().alloc_color("gray"))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
374
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
375 self.last_cell = cell
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
376 cell.modify_bg(gtk.STATE_NORMAL, cell.get_colormap().alloc_color("green"))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
377
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
378 def doEditScene(self,w):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
379 self.setCurrentScene(self.last_cell.nScene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
380 self.generate()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
381 gtk.main_quit()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
382
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
383 def doRemoveScene(self,w):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
384 self.removeKeyScene()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
385 self.grid.show_all()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
386 self.generate()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
387 def addButtons(self,hbox):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
388 btn = gtk.Button('Edit')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
389 btn.connect('clicked', self.doEditScene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
390 hbox.pack_start(btn)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
391 btn = gtk.Button('Insert Key')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
392 btn.connect('clicked',self.doInsertKeyScene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
393 hbox.pack_start(btn)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
394 btn=gtk.Button('Remove Key')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
395 btn.connect('clicked', self.doRemoveScene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
396 hbox.pack_start(btn)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
397 btn=gtk.Button('Extend scene')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
398 btn.connect('clicked', self.doExtendScene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
399 hbox.pack_start(btn)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
400 def onQuit(self, event):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
401 self.OK = False
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
402 gtk.main_quit()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
403 def onOK(self,event):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
404 self.OK = True
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
405 gtk.main_quit()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
406
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
407 def onConfirmDelete(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
408 if self.scenemap == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
409 vbox = gtk.VBox()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
410 vbox.pack_start(gtk.Label('Convert the SVG into a MadButterfly SVG file. All current element will be delted'))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
411 hbox = gtk.HBox()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
412 self.button = gtk.Button('OK')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
413 hbox.pack_start(self.button)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
414 self.button.connect('clicked', self.onOK)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
415 self.button = gtk.Button('Cancel')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
416 hbox.pack_start(self.button)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
417 self.button.connect("clicked", self.onQuit)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
418 vbox.pack_start(hbox)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
419 self.window.add(vbox)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
420 self.window.show_all()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
421 gtk.main()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
422 self.window.remove(vbox)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
423
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
424 def start_server(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
425 root = MB()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
426 root.target = self
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
427 site = server.Site(root)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
428 reactor.listenTCP(8080, site)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
429 reactor.run()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
430
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
431
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
432 def effect(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
433 self.OK = False
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
434 self.parseScene()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
435 self.start_server()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
436 self.generate()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
437
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
438 class MB(soap.SOAPPublisher):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
439 """
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
440 SOAP server for inkscape extension.
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
441 """
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
442
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
443 def soap_PUBLISH(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
444 reactor.callLater(1,self.quit)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
445 return "OK"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
446 def quit(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
447 reactor.stop()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
448 def soap_SCENE(self,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
449 self.target.setCurrentScene(int(n))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
450 return "OK"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
451 def soap_INSERTKEY(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
452 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
453 layer = self.target.getLayer(layer)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
454 self.target.insertKeyScene(layer,int(n))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
455 return "OK"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
456 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
457 return traceback.format_exc()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
458 def soap_EXTENDSCENE(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
459 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
460 layer = self.target.getLayer(layer)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
461 self.target.extendScene(layer,int(n))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
462 return "OK"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
463 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
464 return traceback.format_exc()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
465 def soap_DELETESCENE(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
466 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
467 layer = self.target.getLayer(layer)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
468 self.target.deleteScene(layer,int(n))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
469 return "OK"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
470 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
471 return traceback.format_exc()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
472 def soap_GETDOC(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
473 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
474 self.target.generate()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
475 return etree.tostring(self.target.document)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
476 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
477 return traceback.format_exc()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
478 import os
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
479 os.chdir('/usr/share/inkscape/extensions')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
480
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
481 A = MBScene()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
482 A.affect()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
483
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
484