annotate pyink/MBScene.py @ 1133:bc619172bd2c

Do translation for every elements.
author wycc
date Sun, 19 Dec 2010 00:02:31 +0800
parents 3ec0ad89e443
children 950076863b7e
rev   line source
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
1 #!/usr/bin/python
955
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
2 # -*- indent-tabs-mode: t; tab-width: 8; python-indent: 4; -*-
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
3 # vim: sw=4:ts=8:sts=4
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
4 import pygtk
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
5 import gtk
1064
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
6 import glib
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
7 from copy import deepcopy
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
8 from lxml import etree
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
9 import random
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
10 import traceback
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
11 import time
1064
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
12 import pybInkscape
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
13 import math
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
14
957
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
15 # Please refer to
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
16 # http://www.assembla.com/wiki/show/MadButterfly/Inkscape_extention
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
17 # for the designed document.
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
18
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
19
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
20 # Algorithm:
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
21 #
955
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
22 # We will parse the first two level of the SVG DOM. collect a table of
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
23 # layer and scene.
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
24 # - 1. Collect the layer table which will be displayed as the first
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
25 # column of the grid.
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
26 # - 2. Get the maximum scene number. This will decide the size of the
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
27 # grid.
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
28 # - 3. When F6 is pressed, we will check if this scene has been
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
29 # defined. This can be done by scan all second level group and
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
30 # check if the current scene number is within the range specified
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
31 # by scene field. The function IsSceneDefined(scene) can be used
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
32 # for this purpose.
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
33 # - 4. If this is a new scene, we will append a new group which
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
34 # duplication the content of the last scene in the same
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
35 # group. The scene field will contain the number from the last
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
36 # scene number of the last scene to the current scenen
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
37 # number. For example, if the last scene is from 4-7 and the new
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
38 # scene is 10, we will set the scene field as "8-10".
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
39 # - 5. If this scene are filled screne, we will split the existing
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
40 # scene into two scenes with the same content.
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
41 #
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
42
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
43 class Layer:
955
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
44 def __init__(self,node):
962
6612fd386ea9 Rename Layer.scene to Layer.scenes since it is a list of scenes
Thinker K.F. Li <thinker@codemud.net>
parents: 961
diff changeset
45 self.scenes = []
955
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
46 self.node = node
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
47 self.nodes=[]
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
48 pass
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
49 pass
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
50
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
51 class Scene:
1120
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
52 def __init__(self, node, start,end,typ):
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
53 self.node = node
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
54 self.start = int(start)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
55 self.end = int(end)
1120
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
56 self.type = typ
955
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
57 pass
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
58 pass
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
59 class DOM(pybInkscape.PYSPObject):
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
60 def __init__(self,obj=None):
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
61 self.proxy = obj
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
62 pass
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
63 def duplicate(self,doc):
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
64 return DOM(self.repr.duplicate(doc))
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
65
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
66 class ObjectWatcher(pybInkscape.PYNodeObserver):
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
67 def __init__(self,obj,type,func,arg):
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
68 self.obj = obj
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
69 self.type = type
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
70 self.func = func
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
71 self.arg = arg
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
72
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
73 def notifyChildAdded(self,node,child,prev):
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
74 if self.type == 'DOMNodeInserted':
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
75 self.func(node)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
76 def notifyChildRemoved(self,node,child,prev):
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
77 if self.type == 'DOMNodeRemoved':
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
78 self.func(node)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
79 def notifyChildOrderChanged(self,node,child,prev):
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
80 pass
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
81 def notifyContentChanged(self,node,old_content,new_content):
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
82 print 'cont'
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
83 if self.type == 'DOMSubtreeModified':
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
84 self.func(node)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
85 def notifyAttributeChanged(self,node, name, old_value, new_value):
1130
37a0f6ab2f91 Lock the UI from refreshing during the update procedure
wycc
parents: 1128
diff changeset
86 print 'attr',node,name,old_value,new_value
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
87 if self.type == 'DOMAttrModified':
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
88 self.func(node,name)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
89
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
90 def addEventListener(obj, type, func,arg):
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
91 obs = ObjectWatcher(obj,type,func,arg)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
92 obj.addSubtreeObserver(obs)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
93
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
94
957
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
95 _scenes = '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scenes'
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
96 _scene = '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene'
1064
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
97 class LayerAttributeWatcher(pybInkscape.PYNodeObserver):
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
98 def __init__(self,ui):
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
99 self.ui = ui
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
100 def notifyChildAdded(self,node,child,prev):
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
101 pass
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
102 def notifyChildRemoved(self,node,child,prev):
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
103 pass
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
104 def notifyChildOrderChanged(self,node,child,prev):
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
105 pass
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
106 def notifyContentChanged(self,node,old_content,new_content):
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
107 pass
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
108 def notifyAttributeChanged(self,node, name, old_value, new_value):
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
109 self.ui.updateUI()
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
110 class LayerAddRemoveWatcher(pybInkscape.PYNodeObserver):
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
111 def __init__(self,ui):
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
112 self.ui = ui
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
113 def notifyChildAdded(self,node,child,prev):
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
114 self.ui.updateUI()
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
115 def notifyChildRemoved(self,node,child,prev):
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
116 self.ui.updateUI()
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
117 def notifyChildOrderChanged(self,node,child,prev):
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
118 self.ui.updateUI()
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
119 def notifyContentChanged(self,node,old_content,new_content):
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
120 self.ui.updateUI()
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
121 def notifyAttributeChanged(self,node, name, old_value, new_value):
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
122 self.ui.updateUI()
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
123 class MBScene():
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
124 def __init__(self,desktop,win):
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
125 self.desktop = desktop
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
126 self.window = win
961
b6375e74c69e Rename MBScene.layer to MBScene.layers
Thinker K.F. Li <thinker@codemud.net>
parents: 960
diff changeset
127 self.layers = []
b6375e74c69e Rename MBScene.layer to MBScene.layers
Thinker K.F. Li <thinker@codemud.net>
parents: 960
diff changeset
128 self.layers.append(Layer(None))
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
129 self.scenemap = None
1064
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
130 self.top = None
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
131 self.last_update = None
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
132 pybInkscape.inkscape.connect('change_selection', self.show_selection)
1099
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
133 self.last_select = None
1130
37a0f6ab2f91 Lock the UI from refreshing during the update procedure
wycc
parents: 1128
diff changeset
134 self.lockui=False
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
135 pass
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
136
1099
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
137 def startPolling(self):
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
138 objs = self.desktop.selection.list()
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
139 if len(objs) != 1:
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
140 glib.timeout_add(500,self.startPolling)
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
141 try:
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
142 self.nameEditor.set_text('')
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
143 except:
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
144 traceback.print_exc()
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
145 pass
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
146 return
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
147 o = objs[0]
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
148 if o == self.last_select:
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
149 glib.timeout_add(500,self.startPolling)
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
150 return
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
151 self.last_select = o
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
152 try:
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
153 self.nameEditor.set_text(o.repr.attribute("inkscape:label"))
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
154 except:
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
155 self.nameEditor.set_text('')
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
156 pass
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
157 glib.timeout_add(500,self.startPolling)
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
158 def show_selection(self,w,obj):
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
159 objs = self.desktop.selection.list()
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
160 try:
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
161 o = objs[0]
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
162 print o.getCenter()
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
163 if o == self.last_select:
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
164 return
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
165 except:
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
166 self.nameEditor.set_text('')
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
167 self.last_select = None
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
168 return
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
169 self.last_select = o
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
170 try:
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
171 self.nameEditor.set_text(o.repr.attribute("inkscape:label"))
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
172 except:
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
173 self.nameEditor.set_text('')
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
174 pass
1099
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
175
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
176 def confirm(self,msg):
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
177 vbox = gtk.VBox()
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
178 vbox.pack_start(gtk.Label(msg))
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
179 self.button = gtk.Button('OK')
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
180 vbox.pack_start(self.button)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
181 self.button.connect("clicked", self.onQuit)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
182 self.window.add(vbox)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
183 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
184
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
185 def dumpattr(self,n):
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
186 s = ""
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
187 for a,v in n.attrib.items():
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
188 s = s + ("%s=%s" % (a,v))
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
189 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
190 return s
955
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
191
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
192 def dump(self,node,l=0):
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
193 print " " * l*2,"<", node.tag, self.dumpattr(node),">"
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
194 for n in node:
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
195 self.dump(n,l+1)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
196 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
197 print " " * l * 2,"/>"
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
198 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
199
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
200 def parseMetadata(self,node):
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
201 self.current = 1
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
202 for n in node.childList():
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
203 if n.name() == 'ns0:scenes':
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
204 self.scenemap={}
976
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
205 try:
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
206 cur = int(n.attribute("current"))
976
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
207 except:
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
208 cur = 1
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
209 self.current = cur
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
210
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
211 for s in n.childList():
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
212 if s.name() == 'ns0:scene':
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
213 try:
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
214 start = int(s.attribute("start"))
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
215 except:
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
216 traceback.print_exc()
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
217 continue
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
218 try:
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
219 end = s.attribute("end")
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
220 if end == None:
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
221 end = start
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
222 pass
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
223 except:
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
224 end = start
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
225 pass
1120
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
226 try:
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
227 typ = s.attribute('type')
1120
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
228 if typ == None:
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
229 typ = 'normal'
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
230 except:
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
231 traceback.print_exc()
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
232 typ = 'normal'
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
233 link = s.attribute("ref")
1120
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
234 self.scenemap[link] = [int(start),int(end),typ]
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
235 if cur >= start and cur <= end:
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
236 self.currentscene = link
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
237 pass
955
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
238 pass
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
239 pass
955
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
240 pass
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
241 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
242 pass
981
9e7865906bfc Add MadButterfly name space
wycc
parents: 980
diff changeset
243 if self.scenemap==None:
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
244 #self.desktop.doc().root().repr.setAttribute("xmlns:ns0","http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd")
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
245 self.dom.setAttribute("xmlns:ns0","http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd")
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
246 scenes = self.document.createElement("ns0:scenes")
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
247 node.appendChild(scenes)
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
248 def update(self):
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
249 doc = self.dom
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
250 rdoc = self.document
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
251 for node in doc.childList():
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
252 if node.name() == 'svg:metadata':
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
253 for t in node.childList():
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
254 if t.name() == "ns0:scenes":
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
255 node.removeChild(t)
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
256 ns = rdoc.createElement("ns0:scenes")
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
257 node.appendChild(ns)
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
258 for layer in range(0,len(self._framelines)):
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
259 lobj = self._framelines[layer]
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
260 lobj.addScenes(rdoc,ns)
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
261
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
262
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
263 def parseScene(self):
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
264 """
957
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
265 In this function, we will collect all items for the current
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
266 scene and then relocate them back to the appropriate scene
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
267 object.
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
268 """
961
b6375e74c69e Rename MBScene.layer to MBScene.layers
Thinker K.F. Li <thinker@codemud.net>
parents: 960
diff changeset
269 self.layers = []
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
270 self.scenemap = None
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
271 doc = self.dom
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
272
1064
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
273 #obs = pybInkscape.PYNodeObserver()
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
274 #obs = LayerAddRemoveWatcher(self)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
275 #doc.addObserver(obs)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
276 addEventListener(doc,'DOMNodeInserted',self.updateUI,None)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
277 addEventListener(doc,'DOMNodeRemoved',self.updateUI,None)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
278 doc.childList()
1131
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
279 try:
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
280 self.width = float(doc.attribute("width"))
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
281 self.height= float(doc.attribute("height"))
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
282 except:
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
283 self.width = 640
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
284 self.height=480
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
285
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
286 for node in doc.childList():
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
287 print node.name()
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
288 if node.name() == 'svg:metadata':
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
289 self.parseMetadata(node)
955
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
290 pass
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
291 elif node.name() == 'svg:g':
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
292 oldscene = None
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
293 #obs = LayerAttributeWatcher(self)
1130
37a0f6ab2f91 Lock the UI from refreshing during the update procedure
wycc
parents: 1128
diff changeset
294 #addEventListener(doc,'DOMAttrModified',self.updateUI,None)
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
295 #node.addObserver(obs)
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
296 lyobj = Layer(node)
961
b6375e74c69e Rename MBScene.layer to MBScene.layers
Thinker K.F. Li <thinker@codemud.net>
parents: 960
diff changeset
297 self.layers.append(lyobj)
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
298 lyobj.current_scene = []
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
299 for scene in node.childList():
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
300 print scene.getCenter()
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
301 if scene.name() == 'svg:g':
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
302 try:
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
303 label = scene.attribute('inkscape:label')
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
304 if label == 'dup':
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
305 node.removeChild(scene)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
306 except:
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
307 pass
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
308
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
309 try:
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
310 scmap = self.scenemap[scene.getId()]
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
311 if scmap == None:
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
312 lyobj.current_scene.append(scene)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
313 continue
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
314 except:
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
315 lyobj.current_scene.append(scene)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
316 continue
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
317
1120
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
318 lyobj.scenes.append(Scene(scene,scmap[0],scmap[1],scmap[2]))
955
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
319 pass
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
320 else:
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
321 lyobj.current_scene.append(scene)
955
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
322 pass
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
323 pass
955
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
324 pass
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
325 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
326
981
9e7865906bfc Add MadButterfly name space
wycc
parents: 980
diff changeset
327
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
328 self.collectID()
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
329 self.dumpID()
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
330 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
331
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
332 def collectID(self):
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
333 self.ID = {}
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
334 root = self.dom
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
335 for n in root.childList():
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
336 self.collectID_recursive(n)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
337 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
338 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
339
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
340 def collectID_recursive(self,node):
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
341 self.ID[node.getId()] = 1
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
342 for n in node.childList():
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
343 self.collectID_recursive(n)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
344 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
345 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
346
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
347 def newID(self):
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
348 while True:
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
349 n = 's%d' % int(random.random()*10000)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
350 #print "try %s" % n
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
351 if self.ID.has_key(n) == False:
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
352 return n
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
353 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
354 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
355
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
356 def dumpID(self):
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
357 for a,v in self.ID.items():
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
358 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
359 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
360
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
361 def getLayer(self, layer):
961
b6375e74c69e Rename MBScene.layer to MBScene.layers
Thinker K.F. Li <thinker@codemud.net>
parents: 960
diff changeset
362 for l in self.layers:
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
363 if l.node.getId() == layer:
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
364 return l
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
365 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
366 return None
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
367
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
368
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
369 def insertKeyScene(self):
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
370 """
957
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
371 Insert a new key scene into the stage. If the nth is always a
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
372 key scene, we will return without changing anything. If the
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
373 nth is a filled scene, we will break the original scene into
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
374 two parts. If the nth is out of any scene, we will append a
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
375 new scene.
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
376
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
377 """
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
378 x = self.last_frame
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
379 y = self.last_line
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
380 rdoc = self.document
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
381 ns = rdoc.createElement("svg:g")
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
382 txt = rdoc.createElement("svg:rect")
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
383 txt.setAttribute("x","0")
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
384 txt.setAttribute("y","0")
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
385 txt.setAttribute("width","100")
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
386 txt.setAttribute("height","100")
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
387 txt.setAttribute("style","fill:#ff00")
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
388 ns.appendChild(txt)
982
1bda9f9e00ea Set the inkscape:groupmode attribute so that the inkscape will put the scene groups in the layer manager and protect it from detection.
wycc
parents: 981
diff changeset
389 gid = self.last_line.node.label()+self.newID()
975
ed7e8e309d55 Remove generate function
wycc
parents: 973
diff changeset
390 self.ID[gid]=1
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
391 ns.setAttribute("id",gid)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
392 ns.setAttribute("inkscape:groupmode","layer")
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
393 self.last_line.node.appendChild(ns)
976
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
394 print 'Add key ', x
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
395 self.last_line.add_keyframe(x,ns)
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
396 self.update()
976
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
397 self.last_line.update()
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
398
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
399
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
400 def removeKeyScene(self):
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
401 nth = self.last_frame
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
402 y = self.last_line
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
403 rdoc = self.document
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
404 i = 0
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
405 layer = self.last_line
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
406 while i < len(layer._keys):
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
407 s = layer._keys[i]
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
408 print "nth:%d idx %d" % (nth,s.idx)
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
409 if nth > s.idx:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
410 if i == len(layer._keys)-1:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
411 return
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
412 if nth == s.idx:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
413 if s.left_tween:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
414 # This is left tween, we move the keyframe one frame ahead
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
415 if s.idx == layer._keys[i-1].idx:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
416 layer._keys[i].ref.parent().removeChild(layer._keys[i].ref)
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
417 self.last_line.rm_keyframe(nth)
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
418 self.last_line.rm_keyframe(nth-1)
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
419 else:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
420 s.idx = s.idx-1
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
421 else:
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
422 layer._keys[i].ref.parent().removeChild(layer._keys[i].ref)
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
423 if s.right_tween:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
424 self.last_line.rm_keyframe(layer._keys[i+1].idx)
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
425 self.last_line.rm_keyframe(nth)
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
426 else:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
427 self.last_line.rm_keyframe(nth)
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
428
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
429 self.update()
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
430 self.last_line._draw_all_frames()
976
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
431 self.last_line.update()
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
432 return
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
433 i = i + 1
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
434 def extendScene(self):
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
435 nth = self.last_frame
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
436 layer = self.last_line
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
437 i = 0
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
438 while i < len(layer._keys):
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
439 s = layer._keys[i]
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
440 if s.right_tween:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
441 if nth > s.idx:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
442 if nth <= layer._keys[i+1].idx:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
443 return
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
444 try:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
445 if nth <= layer._keys[i+2].idx:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
446 layer._keys[i+1].idx = nth
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
447 layer.draw_all_frames()
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
448 self.update()
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
449 self.setCurrentScene(nth)
976
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
450 self.last_line.update()
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
451 return
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
452 else:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
453 # We may in the next scene
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
454 i = i + 2
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
455 pass
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
456 except:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
457 # This is the last keyframe, extend the keyframe by
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
458 # relocate the location of the keyframe
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
459 layer._keys[i+1].idx = nth
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
460 layer._draw_all_frames()
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
461 self.update()
976
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
462 self.last_line.update()
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
463 self.setCurrentScene(nth)
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
464 return
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
465 else:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
466 # We are in the front of all keyframes
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
467 return
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
468 else:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
469 # This is a single keyframe
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
470 if nth < s.idx:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
471 return
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
472 if nth == s.idx:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
473 return
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
474 try:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
475 if nth < layer._keys[i+1].idx:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
476 # We are after a single keyframe and no scene is
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
477 # available here. Create a new tween here
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
478 idx = layer._keys[i].idx
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
479 layer.add_keyframe(nth,layer._keys[i].ref)
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
480 layer.tween(idx)
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
481 layer._draw_all_frames()
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
482 self.update()
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
483 self.setCurrentScene(nth)
976
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
484 self.last_line.update()
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
485 return
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
486 else:
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
487 # We may in the next scene
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
488 i = i + 1
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
489 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
490 pass
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
491 except:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
492 # This is the last scene, create a new one
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
493 idx = layer._keys[i].idx
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
494 layer.add_keyframe(nth,layer._keys[i].ref)
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
495 layer.tween(idx)
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
496 layer._draw_all_frames()
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
497 self.update()
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
498 self.setCurrentScene(nth)
976
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
499 self.last_line.update()
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
500 return
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
501 pass
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
502 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
503 pass
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
504
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
505 def updateMapping(self):
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
506 self.nodeToItem={}
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
507 root = self.dom
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
508 self.updateMappingNode(root)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
509 def updateMappingNode(self,node):
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
510 for c in node.childList():
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
511 self.updateMappingNode(c)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
512 self.nodeToItem[c.getId()] = c
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
513 print "Add",c.getId()
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
514
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
515
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
516 def setCurrentScene(self,nth):
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
517 """
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
518 Update the scene group according to the curretn scene data. There are a couple of cases.
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
519 1. If the type of the scene is normal, we display it when it contains the current
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
520 frame. Otherwise hide it.
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
521 2. If the type of the scene is relocate or scale, we need to duplicate the scene group
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
522 and then modify its transform matrix according to the definition of the scene. Then,
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
523 hide the original scenr group and display the duplciate scene group. In addition,
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
524 we may need to delete the old duplicated scene group as well.
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
525
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
526 For each layer, we will always use the duplicated scene group whose name as dup.
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
527 We will put the duplicated scene group inside it. We will create this group if it is not
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
528 available.
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
529 """
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
530 self.current = nth
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
531 self.updateMapping()
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
532 for layer in self._framelines:
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
533 i=0
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
534
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
535 # Check the duplicated scene group and create it if it is not available
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
536 try:
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
537 if layer.duplicateGroup:
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
538 layer.duplicateGroup.parent().removeChild(layer.duplicateGroup)
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
539 layer.duplicateGroup = None
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
540 except:
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
541 traceback.print_exc()
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
542 pass
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
543 # Create a new group
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
544 layer.duplicateGroup = None
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
545
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
546
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
547 while i < len(layer._keys):
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
548 s = layer._keys[i]
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
549 print s.ref.attribute("id"),s.idx,s.left_tween,s.right_tween
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
550 if s.right_tween is False:
976
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
551 if nth == s.idx+1:
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
552 s.ref.setAttribute("style","")
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
553 else:
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
554 s.ref.setAttribute("style","display:none")
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
555 i = i + 1
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
556 continue
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
557 if nth == s.idx + 1:
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
558 s.ref.setAttribute("style","")
959
67823f7a0a17 Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 957
diff changeset
559 else:
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
560 if nth > (s.idx+1) and nth <= (layer._keys[i+1].idx+1):
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
561 if i+2 < len(layer._keys):
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
562 layer.duplicateGroup = self.document.createElement("svg:g")
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
563 layer.duplicateGroup.setAttribute("inkscape:label","dup")
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
564 s.ref.setAttribute("style","display:none")
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
565 s.ref.parent().appendChild(layer.duplicateGroup)
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
566 self.updateTweenContent(layer.duplicateGroup, layer.get_tween_type(s.idx),s, layer._keys[i+2], nth)
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
567 else:
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
568 s.ref.setAttribute("style","display:none")
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
569 i = i + 2
955
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
570 pass
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
571 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
572 pass
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
573 def updateTweenContent(self,obj, typ, source,dest,cur):
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
574 """
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
575 Update the content of the duplicate scene group. We will use the (start,end) and cur to calculate the percentage of
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
576 the tween motion effect and then use it to update the transform matrix of the duplicated scene group.
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
577 """
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
578 start = source.idx
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
579 end = dest.idx
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
580 print cur,start,end
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
581 percent = (cur-start)*1.0/(end-start)
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
582 i = 0
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
583 s = source.ref.firstChild()
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
584 d = dest.ref.firstChild()
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
585 sources={}
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
586 dests={}
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
587
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
588 # Collect all objects
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
589 while d:
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
590 try:
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
591 label = d.attribute("inkscape:label")
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
592 except:
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
593 d = d.getNext()
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
594 continue
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
595 dests[label] = d
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
596 d = d.getNext()
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
597 # Check if the object in the source exists in the destination
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
598 s = source.ref.firstChild()
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
599 d = dest.ref.firstChild()
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
600 while s:
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
601 print s,d
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
602 try:
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
603 label = s.attribute("inkscape:label")
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
604 # Use i8nkscape:label to identidy the equipvalent objects
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
605 if label:
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
606 if dests.hasattr(label.value()):
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
607 self.updateTweenObject(obj,typ,s,dests[label.value()],percent)
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
608 s = s.getNext()
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
609 continue
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
610 except:
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
611 pass
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
612 # Search obejcts in the destination
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
613 while d:
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
614 try:
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
615 d.attribute("inkscape:label")
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
616 d = d.getNext()
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
617 continue
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
618 except:
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
619 pass
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
620 if s.name() == d.name():
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
621 self.updateTweenObject(obj,typ,s,d,percent)
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
622 d = d.getNext()
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
623 break
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
624 d = d.getNext()
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
625 s = s.getNext()
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
626 def parseTransform(self,obj):
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
627 """
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
628 Return the transform matrix of an object
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
629 """
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
630 try:
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
631 t = obj.attribute("transform")
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
632 print t
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
633 if t[0:9] == 'translate':
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
634 print "translate"
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
635 fields = t[10:].split(',')
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
636 x = float(fields[0])
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
637 fields = fields[1].split(')')
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
638 y = float(fields[0])
1125
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
639 return [1,0,0,1,x,y]
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
640 elif t[0:6] == 'matrix':
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
641 print "matrix"
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
642 fields=t[7:].split(')')
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
643 fields = fields[0].split(',')
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
644 return [float(fields[0]),float(fields[1]),float(fields[2]),float(fields[3]),float(fields[4]),float(fields[5])]
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
645 except:
1125
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
646 #traceback.print_exc()
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
647 return [1,0,0,1,0,0]
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
648
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
649 def invA(self,m):
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
650 d = m[0]*m[3]-m[2]*m[1]
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
651 return [m[3]/d, -m[1]/d, -m[2]/d, m[0]/d, (m[1]*m[5]-m[4]*m[3])/d, (m[4]*m[2]-m[0]*m[5])/d]
1125
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
652 def mulA(self,a,b):
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
653 return [a[0]*b[0]+a[1]*b[2],
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
654 a[0]*b[1]+a[1]*b[3],
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
655 a[2]*b[0]+a[3]*b[2],
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
656 a[2]*b[1]+a[3]*b[3],
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
657 a[0]*b[4]+a[1]*b[5]+a[4],
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
658 a[2]*b[4]+a[3]*b[5]+a[5]]
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
659 def parseMatrix(self,m):
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
660 d = (1-m[0])*(1-m[3])-m[1]*m[2]
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
661 if d == 0:
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
662 return [1,0,0,1,m[4],m[5]]
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
663 else:
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
664 return [m[0],m[1],m[2],m[3],(m[4]-m[3]*m[4]+m[1]*m[5])/d,(m[5]-m[0]*m[5]+m[2]*m[4])/d]
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
665
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
666 def decomposition(self,m):
1133
bc619172bd2c Do translation for every elements.
wycc
parents: 1131
diff changeset
667 """
bc619172bd2c Do translation for every elements.
wycc
parents: 1131
diff changeset
668 Decompose the affine matrix into production of translation,rotation,shear and scale.
bc619172bd2c Do translation for every elements.
wycc
parents: 1131
diff changeset
669 The algorithm is documented at http://lists.w3.org/Archives/Public/www-style/2010Jun/0602.html
bc619172bd2c Do translation for every elements.
wycc
parents: 1131
diff changeset
670 """
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
671 if m[0]*m[3] == m[1]*m[2]:
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
672 print "The affine matrix is singular"
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
673 return [1,0,0,1,0,0]
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
674 A=m[0]
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
675 B=m[2]
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
676 C=m[1]
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
677 D=m[3]
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
678 E=m[4]
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
679 F=m[5]
1131
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
680 sx = math.sqrt(A*A+B*B)
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
681 A = A/sx
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
682 B = B/sx
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
683 shear = m[0]*m[1]+m[2]*m[3]
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
684 C = C - A*shear
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
685 D = D - B*shear
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
686 sy = math.sqrt(C*C+D*D)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
687 C = C/sy
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
688 D = D/sy
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
689 r = A*D-B*C
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
690 if r == -1:
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
691 shear = -shear
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
692 sy = -sy
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
693 R = math.atan2(B,A)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
694 return [sx,sy, R, E,F]
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
695
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
696
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
697 def updateTweenObject(self,obj,typ,s,d,p):
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
698 """
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
699 Generate tweened object in the @obj by using s and d in the @p percent
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
700 http://lists.w3.org/Archives/Public/www-style/2010Jun/0602.html
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
701 """
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
702 print 'compare',s,d
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
703 if typ == 'relocate':
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
704 print "percent",p
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
705 newobj = s.duplicate(self.document)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
706 newobj.setAttribute("ref", s.getId())
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
707 top = self.document.createElement("svg:g")
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
708 top.appendChild(newobj)
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
709 obj.appendChild(top)
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
710 print s.name()
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
711 if s.name() == 'svg:g':
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
712 # Parse the translate or matrix
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
713 sm = self.parseTransform(s)
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
714 dm = self.parseTransform(d)
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
715 top.setAttribute("transform","translate(%g,%g)" % ((dm[2]-sm[2])*p,(dm[5]-sm[5])*p))
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
716 else:
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
717 try:
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
718 sx = float(s.attribute("x"))
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
719 sy = float(s.attribute("y"))
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
720 dx = float(d.attribute("x"))
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
721 dy = float(d.attribute("y"))
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
722 tx = (dx-sx)*p
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
723 ty = (dy-sy)*p
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
724 print tx,ty
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
725 top.setAttribute("transform","translate(%g,%g)" % (tx,ty))
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
726 except:
1125
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
727 #traceback.print_exc()
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
728 pass
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
729 pass
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
730 elif typ == 'scale':
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
731 newobj = s.duplicate(self.document)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
732 top = self.document.createElement("svg:g")
1125
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
733 top.appendChild(newobj)
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
734 obj.appendChild(top)
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
735
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
736 print s,d
1125
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
737 if s.name() == 'svg:g':
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
738 # Parse the translate or matrix
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
739 #
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
740 # D = B inv(A)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
741 try:
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
742 item = self.nodeToItem[s.attribute("id")]
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
743 (ox,oy) = item.getCenter()
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
744 except:
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
745 ox = 0
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
746 oy = 0
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
747 try:
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
748 item = self.nodeToItem[d.attribute("id")]
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
749 (dx,dy) = item.getCenter()
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
750 except:
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
751 dx = 0
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
752 dy = 0
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
753
1125
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
754 sm = self.parseTransform(s)
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
755 ss = self.decomposition(sm)
1125
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
756 dm = self.parseTransform(d)
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
757 dd = self.decomposition(dm)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
758 sx = ss[0]*(1-p)+dd[0]*p
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
759 sy = ss[1]*(1-p)+dd[1]*p
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
760 a = ss[2]*(1-p)+dd[2]*p
1131
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
761 tx = ox*(1-p)+dx*p
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
762 ty = oy*(1-p)+dy*p
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
763 m = [math.cos(a),math.sin(a),-math.sin(a),math.cos(a),0,0]
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
764 m = self.mulA([sx,0,0,sy,0,0],m)
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
765 m = self.mulA(m,[1,0,0,1,-ox,oy-self.height])
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
766 m = self.mulA([1,0,0,1,tx,self.height-ty],m)
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
767
1133
bc619172bd2c Do translation for every elements.
wycc
parents: 1131
diff changeset
768 top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5]))
1125
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
769 else:
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
770 try:
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
771 sw = float(s.attribute("width"))
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
772 sh = float(s.attribute("height"))
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
773 dw = float(d.attribute("width"))
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
774 dh = float(d.attribute("height"))
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
775 tx = (dw-sw)*p+sw
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
776 ty = (dh-sh)*p+sh
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
777 print tx,ty
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
778 top.setAttribute("transform","matrix(%g,0,0,%g,0,0)" % (tx,ty))
1125
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
779 except:
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
780 traceback.print_exc()
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
781 pass
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
782 pass
1125
5b2394f67ad0 Add shape tween support.
wycc
parents: 1123
diff changeset
783
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
784 pass
1070
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
785 def enterGroup(self,obj):
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
786 for l in self.layers:
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
787 for s in l.node.childList():
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
788 if s.getId() == obj.attribute("id"):
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
789 self.desktop.setCurrentLayer(s)
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
790
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
791 def selectSceneObject(self,frameline, nth):
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
792 i = 0
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
793 while i < len(frameline._keys):
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
794 s = frameline._keys[i]
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
795 if s.right_tween is False:
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
796 if nth == s.idx+1:
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
797 self.enterGroup(s.ref)
1120
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
798 self.setTweenType(frameline.get_tween_type(s.idx))
1070
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
799 return
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
800 else:
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
801 pass
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
802 i = i + 1
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
803 continue
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
804
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
805 if nth >= (s.idx+1) and nth <= (frameline._keys[i+1].idx+1):
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
806 self.enterGroup(s.ref)
1120
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
807 self.setTweenType(frameline.get_tween_type(s.idx))
1070
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
808 return
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
809 else:
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
810 pass
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
811 i = i + 2
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
812 pass
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
813 pass
1120
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
814 def setTweenType(self,typ):
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
815 if typ == 'normal':
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
816 self.tweenTypeSelector.set_active(0)
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
817 elif typ == 'relocate':
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
818 self.tweenTypeSelector.set_active(1)
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
819 elif typ == 'scale':
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
820 self.tweenTypeSelector.set_active(2)
1070
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
821
955
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
822
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
823
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
824 def newCell(self,file):
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
825 img = gtk.Image()
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
826 img.set_from_file(file)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
827 btn = gtk.EventBox()
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
828 btn.add(img)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
829 btn.connect("button_press_event", self.cellSelect)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
830 btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray"))
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
831 return btn
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
832
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
833 def onCellClick(self,line,frame,but):
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
834 self.last_line = line
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
835 self.last_frame = frame
976
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
836 self.last_line.active_frame(frame)
1130
37a0f6ab2f91 Lock the UI from refreshing during the update procedure
wycc
parents: 1128
diff changeset
837 self.lockui = True
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
838 self.doEditScene(frame)
1130
37a0f6ab2f91 Lock the UI from refreshing during the update procedure
wycc
parents: 1128
diff changeset
839 self.lockui = False
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
840
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
841
976
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
842 def _remove_active_frame(self,widget,event):
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
843 """
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
844 Hide all hover frames. This is a hack. We should use the lost focus event
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
845 instead in the future to reduce the overhead.
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
846 """
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
847 for f in self._framelines:
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
848 if f != widget:
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
849 f.hide_hover()
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
850
963
a05ec4fb1c20 update framelines according content 0f layers
Thinker K.F. Li <thinker@codemud.net>
parents: 962
diff changeset
851 def _create_framelines(self):
959
67823f7a0a17 Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 957
diff changeset
852 import frameline
67823f7a0a17 Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 957
diff changeset
853 self.scrollwin = gtk.ScrolledWindow()
67823f7a0a17 Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 957
diff changeset
854 self.scrollwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
67823f7a0a17 Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 957
diff changeset
855 self.scrollwin.set_size_request(-1,150)
67823f7a0a17 Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 957
diff changeset
856
67823f7a0a17 Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 957
diff changeset
857 nframes = 100
67823f7a0a17 Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 957
diff changeset
858
67823f7a0a17 Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 957
diff changeset
859 vbox = gtk.VBox()
67823f7a0a17 Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 957
diff changeset
860 vbox.show()
67823f7a0a17 Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 957
diff changeset
861 self.scrollwin.add_with_viewport(vbox)
67823f7a0a17 Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 957
diff changeset
862
67823f7a0a17 Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 957
diff changeset
863 ruler = frameline.frameruler(nframes)
67823f7a0a17 Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 957
diff changeset
864 ruler.set_size_request(nframes * 10, 20)
67823f7a0a17 Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 957
diff changeset
865 ruler.show()
1032
148ce30a861d SHift the ruler to the right to align to the frames
wycc
parents: 983
diff changeset
866 hbox = gtk.HBox()
148ce30a861d SHift the ruler to the right to align to the frames
wycc
parents: 983
diff changeset
867 label=gtk.Label('')
148ce30a861d SHift the ruler to the right to align to the frames
wycc
parents: 983
diff changeset
868 label.set_size_request(100,0)
148ce30a861d SHift the ruler to the right to align to the frames
wycc
parents: 983
diff changeset
869 hbox.pack_start(label,expand=False,fill=True)
148ce30a861d SHift the ruler to the right to align to the frames
wycc
parents: 983
diff changeset
870 hbox.pack_start(ruler)
148ce30a861d SHift the ruler to the right to align to the frames
wycc
parents: 983
diff changeset
871 vbox.pack_start(hbox, False)
959
67823f7a0a17 Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 957
diff changeset
872
960
8fd97e0becb3 Add a frameline for each layer
Thinker K.F. Li <thinker@codemud.net>
parents: 959
diff changeset
873 #
8fd97e0becb3 Add a frameline for each layer
Thinker K.F. Li <thinker@codemud.net>
parents: 959
diff changeset
874 # Add a frameline for each layer
8fd97e0becb3 Add a frameline for each layer
Thinker K.F. Li <thinker@codemud.net>
parents: 959
diff changeset
875 #
8fd97e0becb3 Add a frameline for each layer
Thinker K.F. Li <thinker@codemud.net>
parents: 959
diff changeset
876 self._framelines = []
983
ee31add87843 Change the order of layer in the scene editor to make it consistent with the inkscape layer manager
wycc
parents: 982
diff changeset
877 for i in range(len(self.layers)-1,-1,-1):
960
8fd97e0becb3 Add a frameline for each layer
Thinker K.F. Li <thinker@codemud.net>
parents: 959
diff changeset
878 line = frameline.frameline(nframes)
983
ee31add87843 Change the order of layer in the scene editor to make it consistent with the inkscape layer manager
wycc
parents: 982
diff changeset
879 hbox = gtk.HBox()
ee31add87843 Change the order of layer in the scene editor to make it consistent with the inkscape layer manager
wycc
parents: 982
diff changeset
880 label = gtk.Label(self.layers[i].node.label())
ee31add87843 Change the order of layer in the scene editor to make it consistent with the inkscape layer manager
wycc
parents: 982
diff changeset
881 label.set_size_request(100,0)
ee31add87843 Change the order of layer in the scene editor to make it consistent with the inkscape layer manager
wycc
parents: 982
diff changeset
882 hbox.pack_start(label,expand=False,fill=True)
ee31add87843 Change the order of layer in the scene editor to make it consistent with the inkscape layer manager
wycc
parents: 982
diff changeset
883 hbox.pack_start(line)
960
8fd97e0becb3 Add a frameline for each layer
Thinker K.F. Li <thinker@codemud.net>
parents: 959
diff changeset
884 line.set_size_request(nframes * 10, 20)
983
ee31add87843 Change the order of layer in the scene editor to make it consistent with the inkscape layer manager
wycc
parents: 982
diff changeset
885 vbox.pack_start(hbox, False)
ee31add87843 Change the order of layer in the scene editor to make it consistent with the inkscape layer manager
wycc
parents: 982
diff changeset
886 line.label = label
960
8fd97e0becb3 Add a frameline for each layer
Thinker K.F. Li <thinker@codemud.net>
parents: 959
diff changeset
887 self._framelines.append(line)
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
888 line.connect(line.FRAME_BUT_PRESS, self.onCellClick)
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
889 line.nLayer = i
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
890 line.node = self.layers[i].node
983
ee31add87843 Change the order of layer in the scene editor to make it consistent with the inkscape layer manager
wycc
parents: 982
diff changeset
891 line.layer = self.layers[i]
976
ab09c536a137 Hide the hover of all inactive framelines. This fix the issue of multiple hover in every frameline objects.
wycc
parents: 975
diff changeset
892 line.connect('motion-notify-event', self._remove_active_frame)
960
8fd97e0becb3 Add a frameline for each layer
Thinker K.F. Li <thinker@codemud.net>
parents: 959
diff changeset
893 pass
8fd97e0becb3 Add a frameline for each layer
Thinker K.F. Li <thinker@codemud.net>
parents: 959
diff changeset
894 pass
8fd97e0becb3 Add a frameline for each layer
Thinker K.F. Li <thinker@codemud.net>
parents: 959
diff changeset
895
963
a05ec4fb1c20 update framelines according content 0f layers
Thinker K.F. Li <thinker@codemud.net>
parents: 962
diff changeset
896 ## \brief Update conetent of frameliens according layers.
a05ec4fb1c20 update framelines according content 0f layers
Thinker K.F. Li <thinker@codemud.net>
parents: 962
diff changeset
897 #
a05ec4fb1c20 update framelines according content 0f layers
Thinker K.F. Li <thinker@codemud.net>
parents: 962
diff changeset
898 def _update_framelines(self):
983
ee31add87843 Change the order of layer in the scene editor to make it consistent with the inkscape layer manager
wycc
parents: 982
diff changeset
899 for frameline in self._framelines:
ee31add87843 Change the order of layer in the scene editor to make it consistent with the inkscape layer manager
wycc
parents: 982
diff changeset
900 layer = frameline.layer
1064
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
901 if frameline.node.label()==None:
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
902 frameline.label.set_text('???')
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
903 else:
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
904 frameline.label.set_text(frameline.node.label())
962
6612fd386ea9 Rename Layer.scene to Layer.scenes since it is a list of scenes
Thinker K.F. Li <thinker@codemud.net>
parents: 961
diff changeset
905 for scene in layer.scenes:
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
906 frameline.add_keyframe(scene.start-1,scene.node)
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
907 if scene.start != scene.end:
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
908 frameline.add_keyframe(scene.end-1,scene.node)
1120
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
909 frameline.tween(scene.start-1,scene.type)
962
6612fd386ea9 Rename Layer.scene to Layer.scenes since it is a list of scenes
Thinker K.F. Li <thinker@codemud.net>
parents: 961
diff changeset
910 pass
6612fd386ea9 Rename Layer.scene to Layer.scenes since it is a list of scenes
Thinker K.F. Li <thinker@codemud.net>
parents: 961
diff changeset
911 pass
959
67823f7a0a17 Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 957
diff changeset
912 pass
67823f7a0a17 Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 957
diff changeset
913
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
914 def cellSelect(self, cell, data):
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
915 if self.last_cell:
957
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
916 color = self.last_cell.get_colormap().alloc_color("gray")
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
917 self.last_cell.modify_bg(gtk.STATE_NORMAL, color)
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
918 pass
955
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
919
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
920 self.last_cell = cell
957
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
921 color = cell.get_colormap().alloc_color("green")
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
922 cell.modify_bg(gtk.STATE_NORMAL, color)
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
923 pass
1097
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
924 def duplicateKeyScene(self):
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
925 self.last_line.add_keyframe(self.last_frame)
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
926 # Search for the current scene
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
927 i = 0
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
928 while i < len(self.last_line._keys):
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
929 key = self.last_line._keys[i]
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
930 if key.idx == self.last_frame:
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
931 if i == 0:
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
932 # This is the first frame, we can not duplicate it
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
933 self.last_line.rm_keyframe(self.last_frame)
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
934 return
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
935 node = self.duplicateSceneGroup(last_key.ref.attribute("id"))
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
936 key.ref = node
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
937 self.update()
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
938 self.show()
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
939 self.doEditScene(None)
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
940 return
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
941 last_key = key
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
942 i = i + 1
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
943 def duplicateSceneGroup(self,gid):
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
944 # Search for the duplicated group
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
945 doc = self.dom
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
946 rdoc = self.document
1097
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
947 orig = None
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
948 for node in doc.childList():
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
949 if node.name() == 'svg:g':
1097
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
950 for t in node.childList():
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
951 if t.name() == "svg:g":
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
952 if t.attribute("id") == gid:
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
953 orig = t
1097
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
954 break
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
955 if orig == None:
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
956 return None
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
957 ns = orig.duplicate(rdoc)
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
958 gid = self.last_line.node.label()+self.newID()
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
959 self.ID[gid]=1
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
960 ns.setAttribute("id",gid)
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
961 ns.setAttribute("inkscape:groupmode","layer")
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
962 self.last_line.node.appendChild(ns)
1097
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
963 return ns
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
964
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
965 def doEditScene(self,w):
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
966 self.setCurrentScene(self.last_frame+1)
1070
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
967 self.selectSceneObject(self.last_line,self.last_frame+1)
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
968 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
969
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
970 def doInsertKeyScene(self,w):
1131
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
971 self.lockui=True
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
972 self.insertKeyScene()
1131
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
973 self.lockui=False
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
974 # self.grid.show_all()
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
975 return
1097
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
976 def doDuplicateKeyScene(self,w):
1131
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
977 self.lockui = True
1097
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
978 self.duplicateKeyScene()
1131
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
979 self.lockui = False
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
980
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
981 def doRemoveScene(self,w):
1131
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
982 self.lockui = True
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
983 self.removeKeyScene()
1131
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
984 self.lockui = False
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
985 return
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
986
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
987
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
988 def doExtendScene(self,w):
1131
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
989 self.lockui = True
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
990 self.extendScene()
1131
3ec0ad89e443 Fix the mtraix animation.
wycc
parents: 1130
diff changeset
991 self.lockui = False
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
992 #self.grid.show_all()
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
993 pass
1099
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
994 def changeObjectLabel(self,w):
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
995 o = self.desktop.selection.list()[0]
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
996 o.setAttribute("inkscape:label", self.nameEditor.get_text())
1099
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
997 def addNameEditor(self,hbox):
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
998 self.nameEditor = gtk.Entry(max=40)
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
999 hbox.pack_start(self.nameEditor,expand=False,fill=False)
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
1000 self.editDone = gtk.Button('Set')
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
1001 hbox.pack_start(self.editDone,expand=False,fill=False)
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
1002 self.editDone.connect('clicked', self.changeObjectLabel)
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1003
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1004 def addButtons(self,hbox):
973
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
1005 #btn = gtk.Button('Edit')
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
1006 #btn.connect('clicked', self.doEditScene)
84f502fb3e40 Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents: 964
diff changeset
1007 #hbox.pack_start(btn,expand=False,fill=False)
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1008 btn = gtk.Button('Insert Key')
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1009 btn.connect('clicked',self.doInsertKeyScene)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1010 hbox.pack_start(btn,expand=False,fill=False)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1011 btn=gtk.Button('Remove Key')
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1012 btn.connect('clicked', self.doRemoveScene)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1013 hbox.pack_start(btn,expand=False,fill=False)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1014 btn=gtk.Button('Extend scene')
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1015 btn.connect('clicked', self.doExtendScene)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1016 hbox.pack_start(btn,expand=False,fill=False)
1097
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
1017 btn=gtk.Button('Duplicate Key')
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
1018 btn.connect('clicked', self.doDuplicateKeyScene)
52d8bf5d12b4 Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents: 1070
diff changeset
1019 hbox.pack_start(btn,expand=False,fill=False)
1099
5ba2cab1d505 Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents: 1097
diff changeset
1020 self.addNameEditor(hbox)
1120
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1021 self.addTweenTypeSelector(hbox)
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1022 pass
1120
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1023 def onTweenTypeChange(self,w):
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1024 n = self.tweenTypeSelector.get_active()
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1025 if self.last_line == None:
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1026 return
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1027 frameline = self.last_line
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1028 i = 0
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1029 found = -1
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1030 while i < len(frameline._keys):
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1031 s = frameline._keys[i]
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1032 if s.right_tween is False:
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1033 if self.last_frame == s.idx:
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1034 found = s.idx
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1035 break
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1036 else:
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1037 pass
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1038 i = i + 1
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1039 continue
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1040
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1041 if self.last_frame >= s.idx and self.last_frame <= frameline._keys[i+1].idx:
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1042 found = s.idx
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1043 break
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1044 else:
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1045 pass
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1046 i = i + 2
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1047 pass
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1048 pass
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1049 if found == -1: return
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1050 self.last_line.set_tween_type(found,self.tweenTypeSelector.get_active_text())
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1051 self.last_line.update()
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1052 self.update()
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1053
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1054 def addTweenTypeSelector(self,hbox):
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1055 tweenbox = gtk.HBox()
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1056 label = gtk.Label('Tween Type')
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1057 tweenbox.pack_start(label)
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1058
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1059 self.tweenTypeSelector = gtk.combo_box_new_text()
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1060 self.tweenTypeSelector.append_text('normal')
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1061 self.tweenTypeSelector.append_text('relocate')
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1062 self.tweenTypeSelector.append_text('scale')
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1063 self.tweenTypeSelector.set_active(0)
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1064 tweenbox.pack_start(self.tweenTypeSelector, expand=False,fill=False)
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1065 hbox.pack_start(tweenbox,expand=False,fill=False)
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 1099
diff changeset
1066 self.tweenTypeSelector.connect('changed', self.onTweenTypeChange)
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1067
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1068 def onQuit(self, event):
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1069 self.OK = False
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1070 gtk.main_quit()
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1071 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1072
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1073 def onOK(self,event):
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1074 self.OK = True
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1075 gtk.main_quit()
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1076 pass
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
1077
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
1078 def updateUI(self,node=None,arg=None):
1130
37a0f6ab2f91 Lock the UI from refreshing during the update procedure
wycc
parents: 1128
diff changeset
1079 if self.lockui: return
37a0f6ab2f91 Lock the UI from refreshing during the update procedure
wycc
parents: 1128
diff changeset
1080 self.lockui = True
37a0f6ab2f91 Lock the UI from refreshing during the update procedure
wycc
parents: 1128
diff changeset
1081 self._updateUI()
37a0f6ab2f91 Lock the UI from refreshing during the update procedure
wycc
parents: 1128
diff changeset
1082 self.lockui = False
37a0f6ab2f91 Lock the UI from refreshing during the update procedure
wycc
parents: 1128
diff changeset
1083 def _updateUI(self,node=None,arg=None):
1064
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
1084 if self.last_update!= None:
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
1085 glib.source_remove(self.last_update)
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
1086 self.last_update = glib.timeout_add(300,self.show)
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1087 def show(self):
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1088 self.OK = True
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
1089 self.dom = self.desktop.doc().root()
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
1090 self.document = self.desktop.doc().rdoc
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1091 self.parseScene()
963
a05ec4fb1c20 update framelines according content 0f layers
Thinker K.F. Li <thinker@codemud.net>
parents: 962
diff changeset
1092 self._create_framelines()
a05ec4fb1c20 update framelines according content 0f layers
Thinker K.F. Li <thinker@codemud.net>
parents: 962
diff changeset
1093 self._update_framelines()
1064
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
1094 if self.top == None:
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
1095 self.top = gtk.VBox(False,0)
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
1096 self.desktop.getToplevel().child.child.pack_end(self.top,expand=False)
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
1097 else:
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
1098 self.top.remove(self.startWindow)
981
9e7865906bfc Add MadButterfly name space
wycc
parents: 980
diff changeset
1099 vbox = gtk.VBox(False,0)
1064
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
1100 self.startWindow = vbox
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
1101 self.top.pack_start(vbox,expand=False)
981
9e7865906bfc Add MadButterfly name space
wycc
parents: 980
diff changeset
1102 vbox.pack_start(self.scrollwin,expand=False)
9e7865906bfc Add MadButterfly name space
wycc
parents: 980
diff changeset
1103 hbox=gtk.HBox(False,0)
9e7865906bfc Add MadButterfly name space
wycc
parents: 980
diff changeset
1104 self.addButtons(hbox)
9e7865906bfc Add MadButterfly name space
wycc
parents: 980
diff changeset
1105 vbox.pack_start(hbox,expand=False)
9e7865906bfc Add MadButterfly name space
wycc
parents: 980
diff changeset
1106
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1107 # self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1108 # self.window.connect("destroy", gtk.main_quit)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1109 # self.window.set_position(gtk.WIN_POS_MOUSE)
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1110
1064
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
1111 self.top.show_all()
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
1112 self.last_update = None
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
1113 return False
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1114 pass