annotate inkscape/MB_Frame.py @ 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.
author wycc
date Wed, 24 Dec 2008 23:43:39 +0800
parents ec62453bbb2b
children 55f86e2f8d40
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
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
9 # In the inkscape, the top layer group are treated as layer. The Mad butter fly add another structure under the layer as frame. It means that each layer can has multiple frame.
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
10 # Like the layer, the frames are represented by special groups. All groups directly under a layer will be treated as frames. However, a group may be spanned for more than one
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
11 # frame. For example
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
12 # <g id="layer1">
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
13 # <g id="g1222">
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
14 # </g>
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
15 # <g id="g1234" scene="1">
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
16 # </g>
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
17 # <g id="g1235" scene="2-7" current="3">
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
18 # </g>
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
19 # <g id="g1333"/>
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
20 # </g>
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
21 # This will stand for 7 scenes. Scene 1 and scene 2 are key scenes. 3,4,5,6,7 are filled scenes. The current scene is defined by the 'current' attribute. In the above example, it is 3.
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
22 # All elements without scene attributes are items in the current scene.
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
23 # Therefore, when we switch scene, we will move all items into the current scene and then move items out from the new scene.
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
24 #
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
25 # In the inkscape extention, we will provide an grid for users to select the current scene or change the scene structure. Users are allowed to
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
26 # Insert a new key scene
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
27 # Delete a key scene
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
28 # Insert a filled scene
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
29 # Delete a filled scene
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
30 # Select a scene for edit.
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
31 #
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
32 # When user select a scene to edit, we will hide all scenes which is not in the selected scene. For example, if we select scene 4, g1234 will be hidden and g1235 and g1236 will
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
33 # be displayed.
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
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
37 # Algorithm:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
38 #
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
39 # 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
40 # 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
41 # 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
42 # 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
43 # 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
44 # 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
45 # 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
46 # "8-10".
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
47 # 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
48
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
49 class Layer:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
50 def __init__(self,node):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
51 self.scene = []
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
52 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
53 self.nodes=[]
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
54 class Scene:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
55 def __init__(self, node, start,end):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
56 self.node = node
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
57 self.start = int(start)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
58 self.end = int(end)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
59
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
60
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
61 class MBScene(inkex.Effect):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
62 def confirm(self,msg):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
63 vbox = gtk.VBox()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
64 vbox.pack_start(gtk.Label(msg))
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
65 self.button = gtk.Button('OK')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
66 vbox.pack_start(self.button)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
67 self.button.connect("clicked", self.onQuit)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
68 self.window.add(vbox)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
69 def dumpattr(self,n):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
70 s = ""
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
71 for a,v in n.attrib.items():
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
72 s = s + ("%s=%s" % (a,v))
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
73 return s
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
74
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
75 def dump(self,node,l=0):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
76 print " " * l*2,"<", node.tag, self.dumpattr(node),">"
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
77 for n in node:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
78 self.dump(n,l+1)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
79 print " " * l * 2,"/>"
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
80
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
81 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
82 """
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
83 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
84 """
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
85 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
86 current_scene = []
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 oldscene = None
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 for node in self.document.getroot():
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 if node.tag == '{http://www.w3.org/2000/svg}g':
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
90 #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
91 lyobj = Layer(node)
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
92 self.layer.append(lyobj)
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
93 for scene in node:
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
94 if scene.tag == '{http://www.w3.org/2000/svg}g':
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
95 s = scene.get("scene")
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
96 if s == None:
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 # group without scene is part of the current scene
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 current_scene.append(scene)
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
99 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
100 range = s.split('-')
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
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
102 cur = scene.get("current")
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
103 try:
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
104 self.current_scene = int(cur)
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
105 del scene.attrib["current"]
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
106 oldscene = scene
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
107 except:
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
108 pass
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
109 if len(range) == 1:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
110 #print " scene %d" % int(range[0])
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
111 lyobj.scene.append(Scene(scene,range[0],range[0]))
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
112 elif len(range) == 2:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
113 #print " scene%d-%d" % (int(range[0]),int(range[1]))
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
114 lyobj.scene.append(Scene(scene,range[0],range[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:
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
116 current_scene.append(scene)
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
117 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
118 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
119 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
120 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
121
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
122 if oldscene != None:
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
123 # Put the objects back to the current scene
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 #print "Add elements back"
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 for o in current_scene:
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 #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
127 oldscene.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
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:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
186 last = layer.scene[len(layer.scene)-1]
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
187 for x in range(last.end+1, nth):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
188 btn = self.newCell('fill.png')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
189 btn.nScene = x
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
190 btn.layer = layer
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
191 btn.nLayer = y
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
192 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
193 last.end = nth-1
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
194 newscene = Scene(deepcopy(s.node),nth,nth)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
195 newscene.node.set("id",self.newID())
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
196 layer.scene.append(newscene)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
197 btn = self.newCell('start.png')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
198 x = self.last_cell.nScene
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
199 y = self.last_cell.nLayer
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
200 btn.nScene = nth
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
201 btn.layer = layer
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
202 btn.nLayer = y
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
203 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
204
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
205
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
206 def removeKeyScene(self):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
207 nth = self.last_cell.nScene
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
208 layer = self.getLayer(self.last_cell.layer)
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 # We can not remove the key scene at the first scene
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
212 if nth == 1: return
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
213 for i in range(0,len(layer.scene)):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
214 s = layer.scene[i]
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
215 if nth == s.start:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
216 layer.scene[i-1].end = s.end
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
217 layer.scene.remove(s)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
218 btn = self.newCell('fill.png')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
219 btn.nScene = nth
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
220 btn.layer = layer
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
221 btn.nLayer = y
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
222 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
223 return
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
224
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
225 def extendScene(self,layer,nth):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
226 layer = self.getLayer(layer)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
227 if layer == None: return
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
228 for i in range(0,len(layer.scene)-1):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
229 s = layer.scene[i]
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
230 if nth >= layer.scene[i].start and nth < layer.scene[i+1].start:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
231 layer.scene[i].end = nth
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
232 if len(layer.scene) > 0:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
233 layer.scene[len(layer.scene)-1].end = nth
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
234 def setCurrentScene(self,nth):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
235 for layer in self.layer:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
236 for s in layer.scene:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
237 if nth >= s.start and nth <= s.end:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
238 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
239 s.node.set("current","%d"%nth)
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
240 #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
241 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
242
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
243 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
244 #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
245 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
246 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
247 s.node.remove(o)
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
248 else:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
249 s.node.set("style","display:none")
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
250 def generate(self):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
251 newdoc = deepcopy(self.document)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
252 root = newdoc.getroot()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
253 for n in root:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
254 if n.tag == '{http://www.w3.org/2000/svg}g':
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
255 root.remove(n)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
256
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
257 for l in self.layer:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
258 # Duplicate all attribute of the layer
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
259 lnode = etree.Element("{http://www.w3.org/2000/svg}g")
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
260 for a,v in l.node.attrib.items():
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
261 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
262 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
263 lnode.append(n)
233
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
264 root.append(lnode)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
265 for s in l.scene:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
266 snode = etree.Element("{http://www.w3.org/2000/svg}g")
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
267 for a,v in s.node.attrib.items():
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
268 snode.set(a,v)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
269 if s.start == s.end:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
270 snode.set("scene", "%d" % s.start)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
271 else:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
272 snode.set("scene","%d-%d" % (s.start,s.end))
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
273 for n in s.node:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
274 snode.append(deepcopy(n))
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
275 lnode.append(snode)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
276 self.document = newdoc
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
277 def newCell(self,file):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
278 img = gtk.Image()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
279 img.set_from_file(file)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
280 btn = gtk.EventBox()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
281 btn.add(img)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
282 btn.connect("button_press_event", self.cellSelect)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
283 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray"))
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
284 return btn
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
285 def showGrid(self):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
286 max = 0
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
287 for layer in self.layer:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
288 for s in layer.scene:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
289 if s.end > max:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
290 max = s.end
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
291 max = 50
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
292
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
293 self.grid = gtk.Table(len(self.layer)+1, 50)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
294 self.scrollwin = gtk.ScrolledWindow()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
295 self.scrollwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
296 self.scrollwin.add_with_viewport(self.grid)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
297 for i in range(1,max):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
298 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
299 for i in range(1,len(self.layer)+1):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
300 l = self.layer[i-1]
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
301 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
302 for s in l.scene:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
303 btn = self.newCell('start.png')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
304 btn.nScene = s.start
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
305 btn.layer = l.node.get('id')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
306 btn.nLayer = i
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
307
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
308 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
309 for j in range(s.start+1,s.end+1):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
310 btn = self.newCell('fill.png')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
311 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
312 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray"))
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
313 btn.nScene = j
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
314 btn.layer = l.node.get('id')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
315 btn.nLayer = i
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
316 if len(l.scene) == 0:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
317 start = 0
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
318 else:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
319 start = l.scene[len(l.scene)-1].end
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
320 for j in range(start,max):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
321 btn = self.newCell('empty.png')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
322 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
323 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray"))
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
324 btn.nScene = j+1
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
325 btn.layer = l.node.get('id')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
326 btn.nLayer = i
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
327 self.last_cell = None
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
328 def cellSelect(self, cell, data):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
329 if self.last_cell:
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
330 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
331
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
332 self.last_cell = cell
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
333 cell.modify_bg(gtk.STATE_NORMAL, cell.get_colormap().alloc_color("green"))
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
334
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
335 def doEditScene(self,w):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
336 self.setCurrentScene(self.last_cell.nScene)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
337 self.generate()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
338 gtk.main_quit()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
339 def doInsertKeyScene(self,w):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
340 self.insertKeyScene()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
341 self.grid.show_all()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
342 self.generate()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
343
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
344 def doRemoveScene(self,w):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
345 self.removeKeyScene()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
346 self.grid.show_all()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
347 self.generate()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
348 def addButtons(self,hbox):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
349 btn = gtk.Button('Edit')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
350 btn.connect('clicked', self.doEditScene)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
351 hbox.pack_start(btn)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
352 btn = gtk.Button('Insert Key')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
353 btn.connect('clicked',self.doInsertKeyScene)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
354 hbox.pack_start(btn)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
355 btn=gtk.Button('Remove Key')
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
356 btn.connect('clicked', self.doRemoveScene)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
357 hbox.pack_start(btn)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
358 def effect(self):
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
359 self.parseScene()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
360 self.showGrid()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
361 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
362 self.window.connect("destroy", gtk.main_quit)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
363 self.window.set_position(gtk.WIN_POS_MOUSE)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
364 vbox = gtk.VBox()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
365 self.window.add(vbox)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
366 vbox.add(self.scrollwin)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
367 self.vbox = vbox
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
368 hbox=gtk.HBox()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
369 self.addButtons(hbox)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
370 vbox.add(hbox)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
371 self.window.set_size_request(600,200)
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
372 self.window.show_all()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
373 gtk.main()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
374
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
375
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
376
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
377
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
378
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
379 A = MBScene()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
380 A.affect()
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
381
ec62453bbb2b Add frame support into the inkscape.
wycc
parents:
diff changeset
382