annotate inkscape/MB_Frame.py @ 236:55f86e2f8d40

Modify the format according to the new design.
author wycc
date Sat, 27 Dec 2008 10:18:33 +0800
parents 889cdc5f23c5
children db7f22ecd3ad
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):
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
56 for n in node:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
57 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
58 self.scenemap={}
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
59 cur = int(n.get("current"))
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
60 self.current = cur
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
61
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
62 for s in n:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
63 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
64 try:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
65 start = int(s.get("start"))
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
66 except:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
67 continue
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
68 try:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
69 end = s.get("end")
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
70 if end == None:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
71 end = start
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
72 except:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
73 end = start
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
74 link = s.get("ref")
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
75 self.scenemap[link] = [int(start),int(end)]
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
76 if cur >= start and cur <= end:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
77 self.currentscene = link
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
78
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
79 pass
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
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
84
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
85
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 = []
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
91 for node in self.document.getroot():
236
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
92 if node.tag == '{http://www.w3.org/2000/svg}metadata':
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
93 self.parseMetadata(node)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
94 elif node.tag == '{http://www.w3.org/2000/svg}g':
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
95 oldscene = None
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
96 #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
97 lyobj = Layer(node)
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
98 self.layer.append(lyobj)
236
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
99 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
100 for scene in node:
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
101 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
102 try:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
103 scmap = self.scenemap[scene.get("id")]
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
104 if scmap == None:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
105 lyobj.current_scene.append(scene)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
106 continue
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
107 if self.current <= scmap[1] and self.current >= scmap[0]:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
108 oldscene = scene
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
109 except:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
110 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
111 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
112
236
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
113 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
114 else:
236
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
115 lyobj.current_scene.append(scene)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
116 pass
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
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
119 if oldscene != None:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
120 # Put the objects back to the current scene
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
121 for o in lyobj.current_scene:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
122 #print o.tag
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
123 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
124 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
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
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
129 self.collectID()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
130 #self.dumpID()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
131 def collectID(self):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
132 self.ID = {}
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
133 root = self.document.getroot()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
134 for n in root:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
135 self.collectID_recursive(n)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
136 def collectID_recursive(self,node):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
137 self.ID[node.get("id")] = 1
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
138 for n in node:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
139 self.collectID_recursive(n)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
140 def newID(self):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
141 while True:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
142 n = 's%d' % int(random.random()*10000)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
143 #print "try %s" % n
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
144 if self.ID.has_key(n) == False:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
145 return n
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
146 def dumpID(self):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
147 for a,v in self.ID.items():
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
148 print a
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
149
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
150
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
151 def getLayer(self, layer):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
152 for l in self.layer:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
153 if l.node.attrib.get("id") == layer:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
154 return l
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
155 return None
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
156
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
157
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
158 def insertKeyScene(self):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
159 """
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
160 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
161 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
162 append a new scene.
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
163
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
164 """
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
165 nth = self.last_cell.nScene
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
166 layer = self.getLayer(self.last_cell.layer)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
167 x = self.last_cell.nScene
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
168 y = self.last_cell.nLayer
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
169 if layer == None: return
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
170 for i in range(0,len(layer.scene)):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
171 s = layer.scene[i]
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
172 if nth >= s.start and nth <= s.end:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
173 if nth == s.start: return
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
174 newscene = Scene(deepcopy(s.node),nth,s.end)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
175 newscene.node.set("id", self.newID())
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
176 layer.scene.insert(i+1,newscene)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
177 layer.scene[i].end = nth-1
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
178 btn = self.newCell('start.png')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
179 btn.nScene = nth
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
180 btn.layer = layer
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
181 btn.nLayer = y
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
182 self.grid.remove(self.last_cell)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
183 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
184 return
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
185 if len(layer.scene) > 0:
236
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
186 last = nth
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
187 lastscene = None
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
188 for s in layer.scene:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
189 if s.end < nth and last < s.end:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
190 last = s.end
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
191 lastscene = s
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
192 for x in range(last+1, nth):
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
193 btn = self.newCell('fill.png')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
194 btn.nScene = x
236
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
195 btn.layer = layer.node.get('id')
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
196 btn.nLayer = y
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
197 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
198 if lastscene == None:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
199 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
200 node.set("id", self.newID())
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
201 newscene = Scene(node,nth,nth)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
202 else:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
203 lastscene.end = nth-1
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
204 newscene = Scene(deepcopy(lastscene.node),nth,nth)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
205 newscene.node.set("id",self.newID())
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
206 layer.scene.append(newscene)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
207 btn = self.newCell('start.png')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
208 x = self.last_cell.nScene
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
209 y = self.last_cell.nLayer
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
210 btn.nScene = nth
236
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
211 btn.layer = layer.node.get('id')
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
212 btn.nLayer = y
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
213 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
214 else:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
215 # This is the first scene in the layer
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
216 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
217 node.set("id", self.newID())
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
218 newscene = Scene(node,nth,nth)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
219 layer.scene.append(newscene)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
220 btn = self.newCell('start.png')
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
221 btn.nScene = nth
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
222 btn.layer = layer
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
223 btn.nLayer = y
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
224 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
225
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
226
236
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
227
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
228
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
229 def removeKeyScene(self):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
230 nth = self.last_cell.nScene
236
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
231 try:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
232 layer = self.getLayer(self.last_cell.layer.node.get('id'))
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
233 except:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
234 return
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
235 x = self.last_cell.nScene
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
236 y = self.last_cell.nLayer
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
237 for i in range(0,len(layer.scene)):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
238 s = layer.scene[i]
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
239 if nth == s.start:
236
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
240 if i == 0:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
241 for j in range(s.start,s.end+1):
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
242 btn = self.newCell('empty.png')
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
243 btn.nScene = nth
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
244 btn.layer = layer
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
245 btn.nLayer = y
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
246 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
247 layer.scene.remove(s)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
248 else:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
249 if s.start == layer.scene[i-1].end+1:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
250 # 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
251 # scene segmenet to the last one
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
252 layer.scene[i-1].end = s.end
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
253 layer.scene.remove(s)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
254 btn = self.newCell('fill.png')
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
255
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
256 btn.nScene = nth
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
257 btn.layer = layer
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
258 btn.nLayer = y
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
259 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
260 else:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
261 # Convert all scenes into empty cell
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
262 layer.scene.remove(s)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
263 for j in range(s.start,s.end+1):
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
264 btn = self.newCell('empty.png')
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
265 btn.nScene = nth
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
266 btn.layer = layer
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
267 btn.nLayer = y
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
268 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
269
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
270
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
271 return
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
272
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
273 def extendScene(self,layer,nth):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
274 layer = self.getLayer(layer)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
275 if layer == None: return
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
276 for i in range(0,len(layer.scene)-1):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
277 s = layer.scene[i]
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
278 if nth >= layer.scene[i].start and nth < layer.scene[i+1].start:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
279 layer.scene[i].end = nth
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
280 if len(layer.scene) > 0:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
281 layer.scene[len(layer.scene)-1].end = nth
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
282 def setCurrentScene(self,nth):
236
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
283 self.current = nth
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
284 for layer in self.layer:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
285 for s in layer.scene:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
286 if nth >= s.start and nth <= s.end:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
287 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
288 #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
289 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
290
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
291 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
292 #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
293 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
294 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
295 s.node.remove(o)
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
296 else:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
297 s.node.set("style","display:none")
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
298 def generate(self):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
299 newdoc = deepcopy(self.document)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
300 root = newdoc.getroot()
236
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
301 has_scene = False
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
302 for n in root:
236
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
303 if n.tag == '{http://www.w3.org/2000/svg}metadata':
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
304 for nn in n:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
305 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
306 nn.clear()
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
307 nn.set("current", "%d" % self.current)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
308 scenes = []
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
309 for l in self.layer:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
310 for s in l.scene:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
311 id = s.node.get("id")
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
312 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
313 scene.set("ref", id)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
314 if s.start == s.end:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
315 scene.set("start", "%d" % s.start)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
316 else:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
317 scene.set("start", "%d" % s.start)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
318 scene.set("end", "%d" % s.end)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
319
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
320 scenes.append(scene)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
321 for s in scenes:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
322 nn.append(s)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
323 has_scene = True
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
324 if has_scene == False:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
325 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
326 scenes.set("current","%d" % self.current)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
327 for l in self.layer:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
328 for s in l.scene:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
329 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
330 scene.set("ref", s.node.get("id"))
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
331 if s.start == s.end:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
332 scene.set("start", "%d" % s.start)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
333 else:
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
334 scene.set("start", "%d" % s.start)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
335 scene.set("end", "%d" % s.end)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
336 scenes.append(scene)
55f86e2f8d40 Modify the format according to the new design.
wycc
parents: 234
diff changeset
337 n.append(scenes)
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
338 if n.tag == '{http://www.w3.org/2000/svg}g':
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
339 root.remove(n)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
340
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
341 for l in self.layer:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
342 # Duplicate all attribute of the layer
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
343 lnode = etree.Element("{http://www.w3.org/2000/svg}g")
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
344 for a,v in l.node.attrib.items():
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
345 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
346 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
347 lnode.append(n)
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
348 root.append(lnode)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
349 for s in l.scene:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
350 snode = etree.Element("{http://www.w3.org/2000/svg}g")
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
351 for a,v in s.node.attrib.items():
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
352 snode.set(a,v)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
353 for n in s.node:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
354 snode.append(deepcopy(n))
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
355 lnode.append(snode)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
356 self.document = newdoc
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
357 def newCell(self,file):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
358 img = gtk.Image()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
359 img.set_from_file(file)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
360 btn = gtk.EventBox()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
361 btn.add(img)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
362 btn.connect("button_press_event", self.cellSelect)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
363 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray"))
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
364 return btn
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
365 def showGrid(self):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
366 max = 0
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
367 for layer in self.layer:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
368 for s in layer.scene:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
369 if s.end > max:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
370 max = s.end
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
371 max = 50
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
372
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
373 self.grid = gtk.Table(len(self.layer)+1, 50)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
374 self.scrollwin = gtk.ScrolledWindow()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
375 self.scrollwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
376 self.scrollwin.add_with_viewport(self.grid)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
377 for i in range(1,max):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
378 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
379 for i in range(1,len(self.layer)+1):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
380 l = self.layer[i-1]
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
381 self.grid.attach(gtk.Label(l.node.get('id')), 0, 1, i, i+1,0,0,10,0)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
382 for s in l.scene:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
383 btn = self.newCell('start.png')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
384 btn.nScene = s.start
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
385 btn.layer = l.node.get('id')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
386 btn.nLayer = i
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
387
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
388 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
389 for j in range(s.start+1,s.end+1):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
390 btn = self.newCell('fill.png')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
391 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
392 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray"))
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
393 btn.nScene = j
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
394 btn.layer = l.node.get('id')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
395 btn.nLayer = i
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
396 if len(l.scene) == 0:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
397 start = 0
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
398 else:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
399 start = l.scene[len(l.scene)-1].end
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
400 for j in range(start,max):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
401 btn = self.newCell('empty.png')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
402 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
403 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray"))
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
404 btn.nScene = j+1
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
405 btn.layer = l.node.get('id')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
406 btn.nLayer = i
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
407 self.last_cell = None
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
408 def cellSelect(self, cell, data):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
409 if self.last_cell:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
410 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
411
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
412 self.last_cell = cell
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
413 cell.modify_bg(gtk.STATE_NORMAL, cell.get_colormap().alloc_color("green"))
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
414
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
415 def doEditScene(self,w):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
416 self.setCurrentScene(self.last_cell.nScene)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
417 self.generate()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
418 gtk.main_quit()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
419 def doInsertKeyScene(self,w):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
420 self.insertKeyScene()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
421 self.grid.show_all()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
422 self.generate()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
423
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
424 def doRemoveScene(self,w):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
425 self.removeKeyScene()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
426 self.grid.show_all()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
427 self.generate()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
428 def addButtons(self,hbox):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
429 btn = gtk.Button('Edit')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
430 btn.connect('clicked', self.doEditScene)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
431 hbox.pack_start(btn)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
432 btn = gtk.Button('Insert Key')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
433 btn.connect('clicked',self.doInsertKeyScene)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
434 hbox.pack_start(btn)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
435 btn=gtk.Button('Remove Key')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
436 btn.connect('clicked', self.doRemoveScene)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
437 hbox.pack_start(btn)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
438 def effect(self):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
439 self.parseScene()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
440 self.showGrid()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
441 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
442 self.window.connect("destroy", gtk.main_quit)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
443 self.window.set_position(gtk.WIN_POS_MOUSE)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
444 vbox = gtk.VBox()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
445 self.window.add(vbox)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
446 vbox.add(self.scrollwin)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
447 self.vbox = vbox
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
448 hbox=gtk.HBox()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
449 self.addButtons(hbox)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
450 vbox.add(hbox)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
451 self.window.set_size_request(600,200)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
452 self.window.show_all()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
453 gtk.main()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
454
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
455
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
456
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
457
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
458
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
459 A = MBScene()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
460 A.affect()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
461
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
462