annotate inkscape/firefox/MBServer.py @ 1535:9aff42a7e2b9 tip

Fix issue of add/remove a frame at a scene before all key frames of a layer. When you added or removed a frame at a scene before all key frames of a layer, frameline was not updated correctly. It seems nothing happened, but domview is updated. This changeset fix this issue by correcting logic for boundary case.
author Thinker K.F. Li <thinker@codemud.net>
date Fri, 30 Sep 2011 22:07:28 +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 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
381
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
245 def findNodeById(self,root,id):
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
246 for n in root:
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
247 if n.attrib.get('id') == id:
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
248 return n
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
249 nn = self.findNodeById(n,id)
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
250 if nn is not None:
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
251 return nn
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
252 return None
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
253 def changeSymbol(self,id,newname):
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
254 node = self.findNodeById(self.document.getroot(),id)
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
255 if node is not None:
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
256 node.set('mbname',newname);
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
257
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
258
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
259 def setCurrentScene(self,nth):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
260 self.current = nth
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
261 for layer in self.layer:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
262 for s in layer.scene:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
263 if nth >= s.start and nth <= s.end:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
264 s.node.set("style","")
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
265 #print "Put the elemenets out"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
266 layer.nodes = []
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
267
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
268 for o in s.node:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
269 #print " ",o.tag
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
270 layer.nodes.append(o)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
271 for o in s.node:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
272 s.node.remove(o)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
273 else:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
274 s.node.set("style","display:none")
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
275 def generate(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
276 newdoc = deepcopy(self.document)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
277 root = newdoc.getroot()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
278 has_scene = False
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
279 for n in root:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
280 if n.tag == '{http://www.w3.org/2000/svg}metadata':
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
281 for nn in n:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
282 if nn.tag == '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scenes':
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
283 nn.clear()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
284 nn.set("current", "%d" % self.current)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
285 scenes = []
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
286 for l in self.layer:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
287 for s in l.scene:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
288 id = s.node.get("id")
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
289 scene = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
290 scene.set("ref", id)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
291 if s.start == s.end:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
292 scene.set("start", "%d" % s.start)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
293 else:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
294 scene.set("start", "%d" % s.start)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
295 scene.set("end", "%d" % s.end)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
296
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
297 scenes.append(scene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
298 for s in scenes:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
299 nn.append(s)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
300 has_scene = True
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
301 if has_scene == False:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
302 scenes = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scenes')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
303 scenes.set("current","%d" % self.current)
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 for s in l.scene:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
306 scene = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
307 scene.set("ref", s.node.get("id"))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
308 if s.start == s.end:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
309 scene.set("start", "%d" % s.start)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
310 else:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
311 scene.set("start", "%d" % s.start)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
312 scene.set("end", "%d" % s.end)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
313 scenes.append(scene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
314 n.append(scenes)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
315 if n.tag == '{http://www.w3.org/2000/svg}g':
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
316 root.remove(n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
317
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
318 for l in self.layer:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
319 # Duplicate all attribute of the layer
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
320 lnode = etree.Element("{http://www.w3.org/2000/svg}g")
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
321 for a,v in l.node.attrib.items():
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
322 lnode.set(a,v)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
323 for n in l.nodes:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
324 lnode.append(n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
325 root.append(lnode)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
326 for s in l.scene:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
327 snode = etree.Element("{http://www.w3.org/2000/svg}g")
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
328 for a,v in s.node.attrib.items():
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
329 snode.set(a,v)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
330 for n in s.node:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
331 snode.append(deepcopy(n))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
332 lnode.append(snode)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
333 self.document = newdoc
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
334 def newCell(self,file):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
335 img = gtk.Image()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
336 img.set_from_file(file)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
337 btn = gtk.EventBox()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
338 btn.add(img)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
339 btn.connect("button_press_event", self.cellSelect)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
340 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray"))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
341 return btn
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
342 def showGrid(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
343 max = 0
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
344 for layer in self.layer:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
345 for s in layer.scene:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
346 if s.end > max:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
347 max = s.end
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
348 max = 50
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
349
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
350 self.grid = gtk.Table(len(self.layer)+1, 50)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
351 self.scrollwin = gtk.ScrolledWindow()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
352 self.scrollwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
353 self.scrollwin.add_with_viewport(self.grid)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
354 for i in range(1,max):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
355 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
356 for i in range(1,len(self.layer)+1):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
357 l = self.layer[i-1]
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
358 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
359 for s in l.scene:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
360 btn = self.newCell('start.png')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
361 btn.nScene = s.start
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
362 btn.layer = l.node.get('id')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
363 btn.nLayer = i
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
364
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
365 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
366 for j in range(s.start+1,s.end+1):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
367 btn = self.newCell('fill.png')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
368 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
369 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray"))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
370 btn.nScene = j
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
371 btn.layer = l.node.get('id')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
372 btn.nLayer = i
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
373 if len(l.scene) == 0:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
374 start = 0
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
375 else:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
376 start = l.scene[len(l.scene)-1].end
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
377 for j in range(start,max):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
378 btn = self.newCell('empty.png')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
379 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
380 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray"))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
381 btn.nScene = j+1
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
382 btn.layer = l.node.get('id')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
383 btn.nLayer = i
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
384 self.last_cell = None
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
385 def cellSelect(self, cell, data):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
386 if self.last_cell:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
387 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
388
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
389 self.last_cell = cell
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
390 cell.modify_bg(gtk.STATE_NORMAL, cell.get_colormap().alloc_color("green"))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
391
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
392 def doEditScene(self,w):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
393 self.setCurrentScene(self.last_cell.nScene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
394 self.generate()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
395 gtk.main_quit()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
396
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
397 def doRemoveScene(self,w):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
398 self.removeKeyScene()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
399 self.grid.show_all()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
400 self.generate()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
401 def addButtons(self,hbox):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
402 btn = gtk.Button('Edit')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
403 btn.connect('clicked', self.doEditScene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
404 hbox.pack_start(btn)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
405 btn = gtk.Button('Insert Key')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
406 btn.connect('clicked',self.doInsertKeyScene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
407 hbox.pack_start(btn)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
408 btn=gtk.Button('Remove Key')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
409 btn.connect('clicked', self.doRemoveScene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
410 hbox.pack_start(btn)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
411 btn=gtk.Button('Extend scene')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
412 btn.connect('clicked', self.doExtendScene)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
413 hbox.pack_start(btn)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
414 def onQuit(self, event):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
415 self.OK = False
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
416 gtk.main_quit()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
417 def onOK(self,event):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
418 self.OK = True
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
419 gtk.main_quit()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
420
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
421 def onConfirmDelete(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
422 if self.scenemap == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
423 vbox = gtk.VBox()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
424 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
425 hbox = gtk.HBox()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
426 self.button = gtk.Button('OK')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
427 hbox.pack_start(self.button)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
428 self.button.connect('clicked', self.onOK)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
429 self.button = gtk.Button('Cancel')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
430 hbox.pack_start(self.button)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
431 self.button.connect("clicked", self.onQuit)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
432 vbox.pack_start(hbox)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
433 self.window.add(vbox)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
434 self.window.show_all()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
435 gtk.main()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
436 self.window.remove(vbox)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
437
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
438 def start_server(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
439 root = MB()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
440 root.target = self
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
441 site = server.Site(root)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
442 reactor.listenTCP(8080, site)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
443 reactor.run()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
444
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
445
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
446 def effect(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
447 self.OK = False
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
448 self.parseScene()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
449 self.start_server()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
450 self.generate()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
451
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
452 class MB(soap.SOAPPublisher):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
453 """
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
454 SOAP server for inkscape extension.
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
455 """
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
456
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
457 def soap_PUBLISH(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
458 reactor.callLater(1,self.quit)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
459 return "OK"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
460 def quit(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
461 reactor.stop()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
462 def soap_SCENE(self,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
463 self.target.setCurrentScene(int(n))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
464 return "OK"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
465 def soap_INSERTKEY(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.insertKeyScene(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_EXTENDSCENE(self,layer,n):
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 layer = self.target.getLayer(layer)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
475 self.target.extendScene(layer,int(n))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
476 return "OK"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
477 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
478 return traceback.format_exc()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
479 def soap_DELETESCENE(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
480 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
481 layer = self.target.getLayer(layer)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
482 self.target.deleteScene(layer,int(n))
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
483 return "OK"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
484 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
485 return traceback.format_exc()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
486 def soap_GETDOC(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
487 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
488 self.target.generate()
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 339
diff changeset
489 newdoc = deepcopy(self.target.document)
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 339
diff changeset
490 root = newdoc.getroot()
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 339
diff changeset
491 for id,node in self.target.selected.iteritems():
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 339
diff changeset
492 select = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}select')
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 339
diff changeset
493 select.set('ref', id)
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 339
diff changeset
494 root.append(select)
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 339
diff changeset
495 return etree.tostring(newdoc)
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
496 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
497 return traceback.format_exc()
381
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
498 def soap_CHANGESYMBOL(self,id,newname):
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
499 try:
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
500 self.target.changeSymbol(id,newname)
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
501 return "OK"
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
502 except:
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
503 return traceback.format_exc()
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
504 import os
339
63aaf96209cd * Move location of files so that we can produce XPI file from them.
wycc
parents: 288
diff changeset
505 os.chdir('/usr/local/share/inkscape/extensions')
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
506
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
507 A = MBScene()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
508 A.affect()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
509
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
510