annotate inkscape/MB_Frame.py @ 653:34710e86b4a2

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