annotate pyink/MBScene.py @ 1242:1b1eb8f9a866

Rename *_dom to *_domview and *_framelines to *_frameline_stack
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 10 Jan 2011 16:09:18 +0800
parents e64f5bd2270c
children d5f70928e9f1
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
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1149
diff changeset
2 # -*- indent-tabs-mode: t; tab-width: 8; python-indent: 4; fill-column: 79 -*-
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1149
diff changeset
3 # vim: sw=4:ts=8:sts=4:textwidth=79
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
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents: 1136
diff changeset
14 from tween import TweenObject
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1149
diff changeset
15 from frameline import frameline, frameruler
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
16
957
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
17 # Please refer to
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
18 # http://www.assembla.com/wiki/show/MadButterfly/Inkscape_extention
8e3e46c26137 Break long lines
Thinker K.F. Li <thinker@codemud.net>
parents: 956
diff changeset
19 # 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
20
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
21
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
22 # Algorithm:
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
23 #
955
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
24 # 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
25 # layer and scene.
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
26 # - 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
27 # column of the grid.
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
28 # - 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
29 # grid.
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
30 # - 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
31 # 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
32 # 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
33 # 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
34 # for this purpose.
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
35 # - 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
36 # 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
37 # 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
38 # 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
39 # 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
40 # 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
41 # - 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
42 # 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
43 #
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
44
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
45 class Layer:
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
46 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
47 self.scenes = []
1190
a4df892fb4e5 Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents: 1189
diff changeset
48 self.group = node
955
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 pass
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
51
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
52 class ObjectWatcher(pybInkscape.PYNodeObserver):
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
53 def __init__(self, obj, type, func, arg):
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
54 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
55 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
56 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
57 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
58
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
59 def notifyChildAdded(self, node, child, prev):
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
60 if self.type == 'DOMNodeInserted':
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
61 self.func(node, child)
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
62 def notifyChildRemoved(self, node, child, prev):
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
63 if self.type == 'DOMNodeRemoved':
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
64 self.func(node, child)
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
65 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
66 pass
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
67 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
68 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
69 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
70 def notifyAttributeChanged(self,node, name, old_value, new_value):
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
71 if self.type == 'DOMAttrModified':
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
72 self.func(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
73
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
74 def addEventListener(obj, type, func, arg):
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
75 obs = ObjectWatcher(obj, type, func, arg)
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
76 obj.addSubtreeObserver(obs)
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
77 pass
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
78
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
79 ## \brief Iterator to travel a sub-tree of DOM.
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
80 #
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
81 def _DOM_iterator(node):
1151
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
82 nodes = [node]
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
83 while nodes:
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
84 node = nodes.pop(0)
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
85 child = node.firstChild()
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
86 while child:
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
87 nodes.append(child)
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
88 child = child.next()
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
89 pass
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
90 yield node
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
91 pass
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
92 pass
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
93
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
94
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
95 ## \brief Monitor changes of DOM-tree.
1181
f14dbcf19e2b Move MBScene.insertKeyScene() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1180
diff changeset
96 #
1207
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
97 # This class monitors DOM-tree to maintain _maxframe and maps for node ID to
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
98 # node and scene group ID to scene node.
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
99 class MBScene_domview_monitor(object):
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
100 def __init__(self, *args, **kws):
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
101 super(MBScene_domview_monitor, self).__init__()
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
102
1206
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
103 self._maxframe = 0
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
104 self._id2node = {} # map ID to the node in the DOM tree.
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
105 self._group2scene = {} # map ID of a group to associated scene node.
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
106 pass
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
107
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
108 def _start_monitor(self):
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
109 self._collect_node_ids()
1206
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
110 self._collect_all_scenes()
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
111
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
112 doc = self._doc
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
113 addEventListener(doc, 'DOMNodeInserted', self._on_insert_node, None)
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
114 addEventListener(doc, 'DOMNodeRemoved', self._on_remove_node, None)
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
115 addEventListener(doc, 'DOMAttrModified', self._on_attr_modified, None)
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
116 pass
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
117
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
118 def _on_insert_node(self, node, child):
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
119 for cchild in child.childList():
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
120 self._on_insert_node(child, cchild)
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
121 pass
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
122
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
123 try:
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
124 child_id = child.getAttribute('id')
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
125 except:
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
126 pass
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
127 else:
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
128 if child_id not in self._id2node:
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
129 self._id2node[child_id] = child
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
130 pass
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
131 pass
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
132
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
133 if child.name() == 'ns0:scene':
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
134 try:
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
135 ref = child.getAttribute('ref')
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
136 except:
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
137 pass
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
138 else:
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
139 if ref not in self._group2scene:
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
140 self._group2scene[ref] = child
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
141 pass
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
142 pass
1206
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
143
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
144 try:
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
145 start = child.getAttribute('start')
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
146 self._maxframe = max(int(start), self._maxframe)
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
147 except:
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
148 pass
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
149 try:
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
150 start = child.getAttribute('end')
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
151 self._maxframe = max(int(start), self._maxframe)
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
152 except:
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
153 pass
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
154 pass
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
155 pass
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
156
1206
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
157 def _find_maxframe(self, scenes_node):
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
158 maxframe = 0
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
159 for child in scenes_node.childList():
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
160 if child.name() != 'ns0:scene':
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
161 continue
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
162
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
163 try:
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
164 start = child.getAttribute('start')
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
165 maxframe = max(int(start), maxframe)
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
166 except:
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
167 pass
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
168 try:
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
169 end = child.getAttribute('end')
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
170 maxframe = max(int(end), maxframe)
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
171 except:
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
172 pass
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
173 pass
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
174 return maxframe
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
175
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
176 def _on_remove_node(self, node, child):
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
177 for cchild in child.childList():
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
178 self._on_remove_node(child, cchild)
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
179 pass
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
180
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
181 try:
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
182 child_id = child.getAttribute('id')
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
183 except:
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
184 pass
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
185 else:
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
186 if child_id not in self._id2node:
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
187 raise ValueError, \
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
188 'remove a node that is never known (%s)' % (child_id)
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
189 del self._id2node[child_id]
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
190 pass
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
191
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
192 if child.name() == 'ns0:scene':
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
193 try:
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
194 ref = child.getAttribute('ref')
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
195 except:
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
196 pass
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
197 else:
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
198 del self._group2scene[ref]
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
199 pass
1206
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
200
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
201 try:
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
202 if node.name() == 'ns0:scenes' and \
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
203 (int(child.getAttribute('start')) == self._maxframe or
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
204 int(child.getAttribute('end')) == self._maxframe):
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
205 self._maxframe = self._find_maxframe(node)
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
206 pass
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
207 except:
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
208 pass
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
209 pass
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
210 pass
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
211
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
212 def _on_attr_modified(self, node, name, old_value, new_value):
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
213 if name == 'id' and old_value != new_value:
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
214 if old_value and (old_value not in self._id2node):
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
215 raise ValueError, \
1195
cb2c611d1656 Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents: 1194
diff changeset
216 'old ID value of passed node is invalid one (%s)' % \
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
217 (old_value)
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
218 if (new_value in self._id2node):
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
219 raise ValueError, \
1195
cb2c611d1656 Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents: 1194
diff changeset
220 'new ID value of passed node is invalid one (%s)' % \
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
221 (new_value)
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
222
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
223 if old_value:
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
224 del self._id2node[old_value]
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
225 pass
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
226 self._id2node[new_value] = node
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
227 pass
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
228 elif name == 'ref' and node.name() == 'ns0:scene':
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
229 if old_value == new_value:
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
230 return
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
231 if old_value:
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
232 node = self._group2scene[old_value] # use old node. Binding
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
233 # may generate a new
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
234 # wrapper.
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
235 del self._group2scene[old_value]
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
236 pass
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
237 if new_value:
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
238 self._group2scene[new_value] = node
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
239 pass
1206
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
240 pass
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
241 elif (name in ('start', 'end')) and node.name() == 'ns0:scene':
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
242 self._maxframe = max(int(new_value), self._maxframe)
1183
e8446e138427 Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1182
diff changeset
243 pass
e8446e138427 Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1182
diff changeset
244 pass
e8446e138427 Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1182
diff changeset
245
1203
b90a1e2eb9ec Add document for methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1202
diff changeset
246 ## \brief Collect ID of nodes in the document.
b90a1e2eb9ec Add document for methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1202
diff changeset
247 #
b90a1e2eb9ec Add document for methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1202
diff changeset
248 # It is used to implement a fast mapping from an ID to the respective node.
b90a1e2eb9ec Add document for methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1202
diff changeset
249 #
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
250 def _collect_node_ids(self):
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
251 self._id2node = {}
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
252 root = self._root
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
253 for n in root.childList():
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
254 self._collect_node_ids_recursive(n)
1183
e8446e138427 Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1182
diff changeset
255 pass
e8446e138427 Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1182
diff changeset
256 pass
e8446e138427 Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1182
diff changeset
257
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
258 def _collect_node_ids_recursive(self, node):
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
259 try:
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
260 node_id = node.getAttribute('id')
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
261 except:
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
262 return
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
263
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
264 self._id2node[node_id] = node
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
265 for n in node.childList():
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
266 self._collect_node_ids_recursive(n)
1183
e8446e138427 Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1182
diff changeset
267 pass
e8446e138427 Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1182
diff changeset
268 pass
e8446e138427 Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1182
diff changeset
269
1206
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
270 def _parse_one_scene(self, scene_node):
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
271 assert scene_node.name() == 'ns0:scene'
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
272
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
273 start = int(scene_node.getAttribute("start"))
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
274 try:
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
275 end = int(scene_node.getAttribute("end"))
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
276 except:
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
277 end = start
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
278 pass
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
279
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
280 try:
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
281 scene_type = scene_node.getAttribute('type')
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
282 if scene_type == None:
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
283 scene_type = 'normal'
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
284 pass
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
285 except:
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
286 scene_type = 'normal'
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
287 pass
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
288
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
289 return start, end, scene_type
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
290
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
291 def _parse_one_scenes(self, scenes_node):
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
292 try:
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
293 cur = int(n.getAttribute("current"))
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
294 except:
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
295 cur = 0
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
296 pass
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
297 self.current = cur
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
298
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
299 for scene_node in scenes_node.childList():
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
300 if scene_node.name() != 'ns0:scene':
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
301 continue
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
302
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
303 try:
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
304 start, end, scene_type = self._parse_one_scene(scene_node)
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
305 except:
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
306 continue
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
307
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
308 group_id = scene_node.getAttribute("ref")
1217
93acb8568ad3 Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents: 1216
diff changeset
309 self._group2scene[group_id] = scene_node
1206
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
310 pass
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
311 pass
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
312
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
313 ## \brief Parse all scenes node in svg:metadata subtree.
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
314 #
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
315 def _collect_all_scenes(self):
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
316 root = self._root
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
317 for child in root.childList():
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
318 if child.name() != 'svg:metadata':
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
319 continue
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
320
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
321 metadata_node = child
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
322 for metachild in metadata_node.childList():
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
323 if metachild.name() == 'ns0:scenes':
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
324 self._parse_one_scenes(metachild)
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
325 self._maxframe = self._find_maxframe(metachild)
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
326 pass
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
327 pass
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
328 pass
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
329 pass
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
330
1203
b90a1e2eb9ec Add document for methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1202
diff changeset
331 ## \brief Return the node with given ID.
b90a1e2eb9ec Add document for methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1202
diff changeset
332 #
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
333 def get_node(self, node_id):
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
334 return self._id2node[node_id]
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
335
1203
b90a1e2eb9ec Add document for methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1202
diff changeset
336 ## \brief Return a scene node corresponding to a scene group of given ID.
b90a1e2eb9ec Add document for methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1202
diff changeset
337 #
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
338 def get_scene(self, group_id):
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
339 return self._group2scene[group_id]
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
340
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
341 def new_id(self):
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
342 while True:
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
343 candidate = 's%d' % int(random.random()*100000)
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
344 if candidate not in self._id2node:
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
345 return candidate
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
346 pass
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
347 pass
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
348 pass
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
349
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
350
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
351 ## \brief This layer provide a data view to the DOM-tree.
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
352 #
1207
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
353 # This class maintains layers information, and provides functions to create,
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
354 # change and destroy scene node and scene group. A scene node is a 'ns0:scene'
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
355 # in 'ns0:scenes' tag. A scene group is respective 'svg:g' for a scene.
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
356 #
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
357 class MBScene_domview(MBScene_domview_monitor):
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
358 # Declare variables, here, for keeping tracking
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
359 _doc = None
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
360 _root = None
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
361
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
362 def __init__(self, *args, **kws):
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
363 super(MBScene_domview, self).__init__()
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
364 pass
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
365
1202
2f3d523a3871 Parse all scenes when start handling a document
Thinker K.F. Li <thinker@codemud.net>
parents: 1201
diff changeset
366 ## \brief Create a scenes node if not existed.
2f3d523a3871 Parse all scenes when start handling a document
Thinker K.F. Li <thinker@codemud.net>
parents: 1201
diff changeset
367 #
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
368 def _init_metadata(self):
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
369 for node in self._root.childList():
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
370 if node.name() == 'svg:metadata':
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
371 break
1176
0c1ceecb8ddb Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1174
diff changeset
372 pass
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
373 else:
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
374 raise RuntimeError, \
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
375 'can not find <svg:metadata> node in the document'
1176
0c1ceecb8ddb Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1174
diff changeset
376
0c1ceecb8ddb Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1174
diff changeset
377 for n in node.childList():
0c1ceecb8ddb Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1174
diff changeset
378 if n.name() == 'ns0:scenes':
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
379 self._scenes_node = n
1176
0c1ceecb8ddb Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1174
diff changeset
380 break
0c1ceecb8ddb Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1174
diff changeset
381 pass
0c1ceecb8ddb Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1174
diff changeset
382 else:
0c1ceecb8ddb Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1174
diff changeset
383 ns = "http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd"
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
384 self._root.setAttribute("xmlns:ns0", ns)
1190
a4df892fb4e5 Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents: 1189
diff changeset
385 scenes_node = self._doc.createElement("ns0:scenes")
a4df892fb4e5 Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents: 1189
diff changeset
386 node.appendChild(scenes_node)
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
387 self._scenes_node = scenes_node
1176
0c1ceecb8ddb Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1174
diff changeset
388 pass
0c1ceecb8ddb Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1174
diff changeset
389 pass
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
390
1207
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
391 def _parse_all_layers(self):
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
392 root = self._root
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
393 layers = self._layers
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
394
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
395 for child in root.childList():
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
396 if child.name() != 'svg:g':
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
397 continue
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
398
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
399 layer_group = child
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
400 layer = Layer(layer_group)
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
401 layer.idx = len(layers)
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
402 layers.append(layer)
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
403 self.parse_layer(layer.idx)
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
404 pass
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
405 pass
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
406
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
407 def handle_doc_root(self, doc, root):
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
408 self._doc = doc
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
409 self._root = root
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
410 self._layers = []
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
411
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
412 self._start_monitor() # start MBScene_domview_monitor
1207
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
413 self._init_metadata()
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
414 self._parse_all_layers()
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
415 pass
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
416
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
417 def dumpattr(self, n):
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
418 s = ""
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
419 for a,v in n.attrib.items():
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
420 s = s + ("%s=%s" % (a,v))
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
421 pass
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
422 return s
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
423
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
424 def dump(self, node, l=0):
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
425 print " " * l*2,"<", node.tag, self.dumpattr(node),">"
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
426 for n in node:
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
427 self.dump(n, l+1)
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
428 pass
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
429 print " " * l * 2,"/>"
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
430 pass
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
431
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
432 ## \brief Create and add a ns0:scene node under ns0:scenes subtree.
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
433 #
1207
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
434 def add_scene_node(self, start, end,
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
435 frame_type=TweenObject.TWEEN_TYPE_NORMAL,
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
436 ref=None):
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
437 type_names = ('normal', 'scale')
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
438 scenes_node = self._scenes_node
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
439 doc = self._doc
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
440
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
441 scene_node = doc.createElement('ns0:scene')
1207
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
442 self.chg_scene_node(scene_node, start=start)
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
443 if start != end:
1207
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
444 self.chg_scene_node(scene_node, end=end)
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
445 pass
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
446 type_name = type_names[frame_type]
1207
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
447 self.chg_scene_node(scene_node, tween_type=type_name)
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
448 if ref:
1207
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
449 self.chg_scene_node(scene_node, ref=ref)
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
450 pass
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
451
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
452 scenes_node.appendChild(scene_node)
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
453
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
454 return scene_node
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
455
1206
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
456 ## \brief Change attributes of a scene node.
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
457 #
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
458 # This is here to monitor changes of scene node.
1207
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
459 def chg_scene_node(self, scene_node, start=None, end=None,
1199
25e1579ed3d1 Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents: 1198
diff changeset
460 tween_type=None, ref=None):
1214
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
461 if start is not None:
1199
25e1579ed3d1 Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents: 1198
diff changeset
462 scene_node.setAttribute('start', str(start))
25e1579ed3d1 Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents: 1198
diff changeset
463 pass
1214
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
464 if end is not None:
1199
25e1579ed3d1 Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents: 1198
diff changeset
465 scene_node.setAttribute('end', str(end))
25e1579ed3d1 Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents: 1198
diff changeset
466 pass
1214
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
467 if tween_type is not None:
1199
25e1579ed3d1 Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents: 1198
diff changeset
468 scene_node.setAttribute('type', tween_type)
25e1579ed3d1 Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents: 1198
diff changeset
469 pass
1214
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
470 if ref is not None:
1199
25e1579ed3d1 Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents: 1198
diff changeset
471 scene_node.setAttribute('ref', ref)
25e1579ed3d1 Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents: 1198
diff changeset
472 pass
25e1579ed3d1 Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents: 1198
diff changeset
473 pass
25e1579ed3d1 Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents: 1198
diff changeset
474
1207
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
475 def rm_scene_node(self, scene_node):
1204
78925515836f Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1203
diff changeset
476 self._scenes_node.removeChild(scene_node)
78925515836f Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1203
diff changeset
477 pass
78925515836f Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1203
diff changeset
478
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
479 def rm_scene_node_n_group(self, scene_node):
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
480 scene_group_id = scene_node.getAttribute('ref')
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
481 scene_group_node = self.get_node(scene_group_id)
1239
447cd3359cf2 Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents: 1238
diff changeset
482 scene_group_node.parent().removeChild(scene_group_node)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
483
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
484 self._scenes_node.removeChild(scene_node)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
485 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
486
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
487 ## \brief Create and add a svg:g for a scene under a group for a layer.
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
488 #
1207
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
489 def add_scene_group(self, layer_idx):
1205
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
490 layer = self._layers[layer_idx]
1191
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
491 doc = self._doc
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
492
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
493 scene_group = doc.createElement('svg:g')
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
494 gid = self.new_id()
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
495 scene_group.setAttribute("id", gid)
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
496 scene_group.setAttribute("inkscape:groupmode", "layer")
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
497
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
498 layer.group.appendChild(scene_group)
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
499
6442fb198418 Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents: 1190
diff changeset
500 return scene_group
1181
f14dbcf19e2b Move MBScene.insertKeyScene() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1180
diff changeset
501
1205
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
502 def parse_layer(self, layer_idx):
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
503 layer = self._layers[layer_idx]
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
504 layer_group = layer.group
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
505
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
506 for child in layer_group.childList():
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
507 if child.name() != 'svg:g':
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
508 continue
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
509 try:
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
510 child_id = child.getAttribute('id')
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
511 scene_node = self.get_scene(child_id)
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
512 except:
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
513 continue
1183
e8446e138427 Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1182
diff changeset
514
1205
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
515 layer.scenes.append(scene_node)
1181
f14dbcf19e2b Move MBScene.insertKeyScene() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1180
diff changeset
516 pass
f14dbcf19e2b Move MBScene.insertKeyScene() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1180
diff changeset
517 pass
f14dbcf19e2b Move MBScene.insertKeyScene() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1180
diff changeset
518
1205
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
519 ## \brief Add/insert a layer at given position.
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
520 #
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
521 # \param layer_idx is the position in the layer list.
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
522 #
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
523 def insert_layer(self, layer_idx, layer_group):
1205
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
524 layers = self._layers
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
525
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
526 layer = Layer(layer_group)
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
527 if layer_idx >= len(layers):
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
528 layers.append(layer)
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
529 else:
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
530 layers.insert(layer_idx, layer)
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
531 for idx in range(layer_idx, len(layers)):
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
532 layers[idx].idx = idx
1183
e8446e138427 Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1182
diff changeset
533 pass
e8446e138427 Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1182
diff changeset
534 pass
e8446e138427 Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1182
diff changeset
535 pass
1205
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
536
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
537 ## \brief Remove layer and associated scene nodes and scene groups.
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
538 #
1205
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
539 def rm_layer(self, layer_idx):
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
540 layers = self._layers
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
541
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
542 for layer in layers:
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
543 for scene_node in layer.scenes:
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
544 scene_group_id = scene_node.getAttribute('ref')
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
545 scene_group_node = self.get_node(scene_group_id)
1239
447cd3359cf2 Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents: 1238
diff changeset
546 scene_group_node.parent().removeChild(scene_group_node)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
547
1239
447cd3359cf2 Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents: 1238
diff changeset
548 scene_node.parent().removeChild(scene_node)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
549 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
550 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
551
1205
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
552 del layers[layer_idx]
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
553
1205
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
554 for idx in range(layer_idx, len(layers)):
1af64bcdfd7d Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents: 1204
diff changeset
555 layers[idx].idx = idx
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
556 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
557 pass
1224
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
558
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
559 def get_layer_num(self):
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
560 return len(self._layers)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
561
1224
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
562 def find_layer_n_scene_of_node(self, node_id):
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
563 for layer_idx, layer in enumerate(self._layers):
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
564 for scene_node in layer.scenes:
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
565 scene_group_id = scene_node.getAttribute('ref')
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
566 if scene_group_id == node_id:
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
567 return layer_idx, scene_node
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
568 pass
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
569 pass
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
570 return -1, None
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
571
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
572 def get_layer_group(self, layer_idx):
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
573 layer = self._layers[layer_idx]
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
574 return layer.group
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
575
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
576 def get_all_scene_node_of_layer(self, layer_idx):
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
577 layer = self._layers[layer_idx]
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
578 return layer.scenes
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
579
1232
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
580 def get_layer_data(self, layer_idx):
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
581 layer = self._layers[layer_idx]
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
582 try:
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
583 data = layer.data
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
584 except:
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
585 return None
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
586 return data
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
587
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
588 def set_layer_data(self, layer_idx, data):
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
589 layer = self._layers[layer_idx]
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
590 layer.data = data
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
591 pass
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
592
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
593 def create_layer_dup_group(self, layer_idx):
1232
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
594 layer = self._layers[layer_idx]
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
595
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
596 dup_group = self._doc.createElement('svg:g')
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
597 gid = self.new_id()
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
598 dup_group.setAttribute('id', gid)
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
599 dup_group.setAttribute('inkscape:label', 'dup')
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
600 dup_group.setAttribute('sodipodi:insensitive', '1')
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
601 dup_group.setAttribute('style', '')
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
602
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
603 layer.group.appendChild(dup_group)
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
604
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
605 return dup_group
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
606
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
607 def insert_frames(self, layer_idx, frame_idx, num):
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
608 layer = self._layers[layer_idx]
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
609 for scene_node in layer.scenes:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
610 start, end, tween_type = self._parse_one_scene(scene_node)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
611 if start >= frame_idx:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
612 self.chg_scene_node(scene_node, start=(start + num))
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
613 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
614 if end >= frame_idx:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
615 self.chg_scene_node(scene_node, end=(end + num))
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
616 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
617 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
618 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
619
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
620 ## \brief Remove frames
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
621 #
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
622 # - Scenes covered by removing range were removed.
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
623 # - Scenes after removing range were shifted left.
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
624 #
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
625 def rm_frames(self, layer_idx, frame_idx, num):
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
626 layer = self._layers[layer_idx]
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
627
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
628 last_rm = frame_idx + num - 1 # last removed frame
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
629 for scene_node in layer.scenes:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
630 start, end, tween_type = \
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
631 self._dom._parse_one_scene(scene_node)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
632
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
633 if end < frame_idx:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
634 continue
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
635
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
636 if start > last_rm: # this scene is at right side
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
637 self.chg_scene_node(scene_node,
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
638 start=(start - num),
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
639 end=(end - num))
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
640 else: # this scene is covered by removing range
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
641 self.rm_scene_node_n_group(scene_node)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
642 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
643 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
644 pass
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
645
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
646 def get_max_frame(self):
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
647 return self._maxframe
1176
0c1ceecb8ddb Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1174
diff changeset
648 pass
0c1ceecb8ddb Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents: 1174
diff changeset
649
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
650 ## \brief Maintain a stack of frameline UI component.
1210
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
651 #
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
652 # Every layer is assocated with a frameline. Framelines are showed/stacked in
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
653 # virtical. Framelines of lower layers are placed at lower position on the
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
654 # screen. This class provide a set of API to access framelines with layer and
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
655 # frame index number. You access/set content of frameline by specifing layer
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
656 # index and frame index.
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
657 #
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
658 class MBScene_frameline_stack(object):
1210
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
659 _frameline_tween_types = (frameline.TWEEN_TYPE_NONE,
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
660 frameline.TWEEN_TYPE_SHAPE)
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
661 _num_frames_of_line = 100
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
662
1210
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
663 _framelines = None
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
664
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
665 def __init__(self, *args, **kws):
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
666 super(MBScene_frameline_stack, self).__init__(*args, **kws)
1214
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
667
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
668 self._last_mouse_over_frameline = None
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
669 self._last_active_frameline = None
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
670 self._active_frame_callback = None
1210
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
671 pass
1221
33aa2d63e240 When we select a new object, search the scene group which contain it and make it as the active frame.
wycc
parents: 1220
diff changeset
672
1214
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
673 def _change_hover_frameline(self, widget, event):
1210
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
674 """
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
675 Hide all hover frames. This is a hack. We should use the lost focus
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
676 event instead in the future to reduce the overhead.
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
677 """
1214
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
678 if self._last_mouse_over_frameline and \
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
679 widget != self._last_mouse_over_frameline:
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
680 self._last_mouse_over_frameline.mouse_leave()
1210
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
681 pass
1214
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
682 self._last_mouse_over_frameline = widget
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
683 pass
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
684
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
685 ## \brief Switch to new active frameline.
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
686 #
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
687 # Hide active frame mark for the active frame of old active frameline. It
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
688 # always shows at most one active frame mark. When a frame is activated,
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
689 # all active frame mark of other frameline should be hidden.
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
690 #
1224
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
691 def _active_frameline(self, frameline):
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
692 last = self._last_active_frameline
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
693
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
694 if last and last != frameline:
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
695 last.deactive()
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
696 pass
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
697
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
698 self._last_active_frameline = frameline
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
699 pass
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
700
1214
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
701 ## \brief Called for changing of active frame.
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
702 #
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
703 # This handle deactive previous frameline that owns an active frame when a
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
704 # frame in another frameline is activated.
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
705 #
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
706 def _change_active_frame(self, frameline, frame_idx, button):
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
707 frameline.active_frame(frame_idx)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
708 self._active_frameline(frameline)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
709
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
710 if self._active_frame_callback:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
711 layer_idx = frameline.layer_idx
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
712 self._active_frame_callback(layer_idx, frame_idx)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
713 pass
1210
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
714 pass
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
715
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
716 ## \brief Add a frameline into the frameline box for the given layer.
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
717 #
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
718 def _add_frameline(self, layer_idx):
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
719 if layer_idx > len(self._framelines):
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
720 raise ValueError, 'layer number should be a consequence'
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
721
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
722 vbox = self._frameline_vbox
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
723
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
724 line = frameline(self._num_frames_of_line)
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
725 line.set_size_request(self._num_frames_of_line * 10, 20)
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
726
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
727 hbox = gtk.HBox()
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
728 label = gtk.Label('')
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
729 label.set_size_request(100,0)
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
730 hbox.pack_start(label,expand=False, fill=True)
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
731 hbox.pack_start(line)
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
732 vbox.pack_start(hbox, False)
1216
61f1b3d424cf Change order of framelines.
Thinker K.F. Li <thinker@codemud.net>
parents: 1214
diff changeset
733
61f1b3d424cf Change order of framelines.
Thinker K.F. Li <thinker@codemud.net>
parents: 1214
diff changeset
734 # Put later one on the top of earier one, but after the ruler.
61f1b3d424cf Change order of framelines.
Thinker K.F. Li <thinker@codemud.net>
parents: 1214
diff changeset
735 position = len(self._framelines) - layer_idx + 1
61f1b3d424cf Change order of framelines.
Thinker K.F. Li <thinker@codemud.net>
parents: 1214
diff changeset
736 vbox.reorder_child(hbox, position)
1210
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
737
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
738 self._framelines[layer_idx: layer_idx] = [line]
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
739
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
740 for idx in range(layer_idx, len(self._framelines)):
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
741 self._framelines[idx].layer_idx = idx
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
742 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
743
1210
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
744 line.label = label
1214
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
745 line.connect('motion-notify-event', self._change_hover_frameline)
e55499f7505a Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1213
diff changeset
746 line.connect(frameline.FRAME_BUT_PRESS, self._change_active_frame)
1210
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
747 pass
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
748
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
749 ## \brief Remove the given frameline from the frameline box.
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
750 #
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
751 def _remove_frameline(self, layer_idx):
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
752 vbox = self._frameline_vbox
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
753 line = self._framelines[layer_idx]
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
754
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
755 hbox = line.parent
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
756 vbox.remove(hbox)
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
757 del self._framelines[layer_idx]
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
758
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
759 for idx in range(layer_idx, len(self._framelines)):
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
760 self._framelines[idx].layer_idx = idx
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
761 pass
1210
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
762 pass
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
763
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
764 def _init_framelines(self):
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
765 self._framelines = []
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
766
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
767 box = gtk.ScrolledWindow()
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
768 self._frameline_box = box
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
769 box.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
770 box.set_size_request(-1, 150)
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
771 vbox = gtk.VBox()
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
772 self._frameline_vbox = vbox
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
773 box.add_with_viewport(vbox)
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
774
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
775 nframes = self._num_frames_of_line
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
776
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
777 #
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
778 # Set up a ruler
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
779 #
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
780 ruler = frameruler(nframes)
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
781 ruler.set_size_request(nframes * 10, 20)
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
782 ruler.show()
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
783 hbox = gtk.HBox()
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
784 label=gtk.Label('')
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
785 label.set_size_request(100,0)
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
786 hbox.pack_start(label,expand=False,fill=True)
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
787 hbox.pack_start(ruler)
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
788 vbox.pack_start(hbox, False)
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
789 pass
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
790
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
791 ## \brief Show framelines on the screen.
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
792 #
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
793 # When a frameline was inserted or removed, it would not be showed
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
794 # immediately. This function is used to notify toolkit to update the
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
795 # screen and drawing framelines.
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
796 def _show_framelines(self):
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
797 self._frameline_vbox.show_all()
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
798 pass
1224
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
799
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
800 ## \brief Make given frame as current active frame.
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
801 #
1224
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
802 def active_frame(self, layer_idx, frame_idx):
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
803 frameline = self._framelines[layer_idx]
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
804 self._active_frameline(frameline)
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
805 frameline.active_frame(frame_idx)
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
806 pass
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
807
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
808 ## \brief Get layer and frame index of current active frame.
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
809 #
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
810 # \return (-1, -1) for no active, (layer_idx, frame_idx) for current
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
811 # active.
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
812 def get_active_layer_frame(self):
1237
b5cceb2b87bb Sucessful extend and duplicate
Thinker K.F. Li <thinker@codemud.net>
parents: 1236
diff changeset
813 if self._last_active_frameline:
b5cceb2b87bb Sucessful extend and duplicate
Thinker K.F. Li <thinker@codemud.net>
parents: 1236
diff changeset
814 layer_idx = self._last_active_frameline.layer_idx
b5cceb2b87bb Sucessful extend and duplicate
Thinker K.F. Li <thinker@codemud.net>
parents: 1236
diff changeset
815 frame_idx = self._last_active_frameline.get_active_frame()
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
816 if frame_idx != -1:
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
817 return layer_idx, frame_idx
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
818 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
819 return -1, -1
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
820
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
821 ## \brief Get information of the key frame at left-side.
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
822 #
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
823 # The key frame, returned, is at the place of the give frame or its
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
824 # left-side.
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
825 def get_left_key_tween(self, layer_idx, frame_idx):
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
826 frameline = self._framelines[layer_idx]
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
827 start, end, fl_tween_type = frameline.get_frame_block_floor(frame_idx)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
828 tween_type = self._frameline_tween_types.index(fl_tween_type)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
829 return start, end, tween_type
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
830
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
831 ## \brief Return information of a key frame and its tweening.
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
832 #
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
833 # This method return the key frame that the given frame is, or is in its
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
834 # tween.
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
835 #
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
836 # \return (start, end, tween_type)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
837 def get_key_tween(self, layer_idx, frame_idx):
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
838 frameline = self._framelines[layer_idx]
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
839 start, end, fl_tween_type = frameline.get_frame_block(frame_idx)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
840
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
841 tween_type = self._frameline_tween_types.index(fl_tween_type)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
842 return start, end, tween_type
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
843
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
844 def get_all_key_tween_of_layer(self, layer_idx):
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
845 frameline = self._framelines[layer_idx]
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
846 info = frameline.get_frame_blocks()
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
847 tweens = [(tween[0], tween[1],
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
848 self._frameline_tween_types.index(tween[2]))
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
849 for tween in info]
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
850 return tweens
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
851
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
852 ## \brief Tweening key frame to a give size
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
853 #
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
854 # The tween can be changed by tweening it again.
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
855 def tween(self, layer_idx, key_frame_idx, tween_len,
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
856 tween_type=TweenObject.TWEEN_TYPE_NORMAL):
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
857 assert tween_len > 0
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
858 frameline = self._framelines[layer_idx]
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
859 right_frame_idx = key_frame_idx + tween_len - 1
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
860 fl_tween_type = self._frameline_tween_types[tween_type]
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
861
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
862 start, end, old_fl_tween_type = \
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
863 frameline.get_frame_block(key_frame_idx)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
864 if start != key_frame_idx:
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
865 ValueError, 'invalid key frame (%d)' % (key_frame_idx)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
866 if start < end:
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
867 frameline.unmark_keyframe(end)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
868 pass
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
869 frameline.mark_keyframe(right_frame_idx)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
870 frameline.tween(start, fl_tween_type)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
871 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
872
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
873 ## \brief Unmark a key frame.
1240
84bcd398cccc Fix bug of removing keyframe
Thinker K.F. Li <thinker@codemud.net>
parents: 1239
diff changeset
874 #
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
875 # Once a key frame was unmark, the associated tween was also removed
1240
84bcd398cccc Fix bug of removing keyframe
Thinker K.F. Li <thinker@codemud.net>
parents: 1239
diff changeset
876 # totally.
84bcd398cccc Fix bug of removing keyframe
Thinker K.F. Li <thinker@codemud.net>
parents: 1239
diff changeset
877 #
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
878 def unmark_keyframe(self, layer_idx, frame_idx):
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
879 frameline = self._framelines[layer_idx]
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
880 start, end, fl_tween_type = frameline.get_frame_block(frame_idx)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
881 if start != frame_idx:
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
882 raise ValueError, 'no such key (%d, %d)' % (layer_idx, frame_idx)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
883
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
884 frameline.unmark_keyframe(frame_idx)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
885 if start < end:
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
886 frameline.unmark_keyframe(end)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
887 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
888 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
889
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
890 ## \brief Makr a key frame.
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
891 #
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
892 # Make a frame as a key frame.
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
893 #
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
894 def mark_keyframe(self, layer_idx, frame_idx):
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
895 frameline = self._framelines[layer_idx]
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
896 frameline.mark_keyframe(frame_idx)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
897 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
898
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
899 ## \brief Get data associated with the given key frame.
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
900 #
1234
0f597a2073eb Enter the group after insert/extend a key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 1233
diff changeset
901 # The given frame index must be exactly a key frame.
0f597a2073eb Enter the group after insert/extend a key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 1233
diff changeset
902 #
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
903 def get_keyframe_data(self, layer_idx, frame_idx):
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
904 frameline = self._framelines[layer_idx]
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
905 data = frameline.get_frame_data(frame_idx)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
906 return data
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
907
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
908 ## \brief Set/associate data with the given key frame.
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
909 #
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
910 def set_keyframe_data(self, layer_idx, frame_idx, data):
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
911 frameline = self._framelines[layer_idx]
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
912 frameline.set_frame_data(frame_idx, data)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
913 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
914
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
915 ## \brief Insert frames before specified frame.
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
916 #
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
917 # Specified frame and frames after it are shift right for \ref num
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
918 # positions to make a space for new frames.
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
919 #
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
920 def insert_frames(self, layer_idx, frame_idx, num):
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
921 assert num > 0
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
922 assert frame_idx >= 0
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
923 frameline = self._framelines[layer_idx]
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
924 for i in range(num):
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
925 frameline.add_frame(frame_idx)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
926 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
927 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
928
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
929 ## \brief Remove a number of frames from the frameline.
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
930 #
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
931 # All key frames and associated tween info covered by removing range would
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
932 # be removed.
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
933 #
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
934 def rm_frames(self, layer_idx, frame_idx, num):
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
935 assert num > 0
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
936 assert frame_idx >= 0
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
937
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
938 frameline = self._framelines[layer_idx]
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
939
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
940 #
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
941 # Remove right key frame of last tween which left one will be removed.
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
942 #
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
943 last_rm = frame_idx + num - 1 # last removed frame
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
944 try:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
945 start, end, tween_type = frameline.get_frame_block(last_rm)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
946 except ValueError: # last removed frame is not in any tween
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
947 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
948 else:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
949 if start >= frame_idx and end > last_rm:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
950 # Left key frame of the tween was removed, but not right one.
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
951 frameline.untween(start)
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
952 frameline.unmark_keyframe(end)
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
953 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
954 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
955
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
956 #
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
957 # Remove left key of the tween that right key frame is in removing
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
958 # range.
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
959 #
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
960 try:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
961 start, end, tween_type = frameline.get_frame_block(frame_idx)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
962 except ValueError:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
963 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
964 else:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
965 if start < frame_idx and end <= last_rm:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
966 # right key frame is in removing range but left one.
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
967 frameline.untween(start)
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
968 frameline.unmark_keyframe(start)
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
969 frameline.unmark_keyframe(end)
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
970 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
971 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
972
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
973 for i in range(num):
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
974 frameline.rm_frame(frame_idx)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
975 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
976 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
977
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
978 ## \brief Set label for a layer.
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
979 #
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
980 def set_layer_label(self, layer_idx, txt):
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
981 frameline = self._framelines[layer_idx]
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
982 frameline.label.set_text(txt)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
983 pass
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
984
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
985 ## \brief Register a callback for active frame event.
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
986 #
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
987 # The callback would be called when a frame is activated.
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
988 #
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
989 def register_active_frame_callback(self, cb):
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
990 self._active_frame_callback = cb
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
991 pass
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
992 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
993
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
994 ## \brief Bridge of DOM-tree to syncrhonize data-model and UI.
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
995 #
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
996 # This class is a wrapper
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
997 class MBScene_domview_ui(object):
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
998 _tween_type_names = ('normal', 'scale')
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
999
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1000 def __init__(self):
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1001 super(MBScene_domview_ui, self).__init__()
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1002 self._fl_stack = MBScene_frameline_stack()
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1003 self._dom = MBScene_domview()
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1004 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1005
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1006 ## \brief Update content of a frameline from scenes of respective layer.
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1007 #
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1008 def _update_frameline_content(self, layer_idx):
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1009 fl_stack = self._fl_stack
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1010 scene_nodes = self._dom.get_all_scene_node_of_layer(layer_idx)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1011 for scene_node in scene_nodes:
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1012 start, end, tween_name = self._dom._parse_one_scene(scene_node)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1013
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1014 fl_stack.mark_keyframe(layer_idx, start)
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1015 fl_stack.set_keyframe_data(layer_idx, start, scene_node)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1016 if start != end:
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1017 tween_type = self._tween_type_names.index(tween_name)
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1018 tween_len = end - start + 1
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1019 fl_stack.tween(layer_idx, start, tween_len, tween_type)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1020 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1021 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1022 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1023
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1024 ## \brief Add a frameline for every found layer.
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1025 #
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1026 # This method is called to create a frameline for every layer found when
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1027 # loading a document.
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1028 #
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1029 def _add_frameline_for_every_layer(self):
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1030 for layer_idx in range(self._dom.get_layer_num()):
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1031 layer_group_node = self._dom.get_layer_group(layer_idx)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1032 label = layer_group_node.getAttribute('inkscape:label')
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1033
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1034 self._fl_stack._add_frameline(layer_idx)
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1035 self._fl_stack.set_layer_label(layer_idx, label)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1036
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1037 self._update_frameline_content(layer_idx)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1038 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1039 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1040
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1041 ## \brief This method is called to handle a new document.
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1042 #
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1043 def handle_doc_root(self, doc, root):
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1044 self._dom.handle_doc_root(doc, root)
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1045 self._fl_stack._init_framelines()
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1046 self._add_frameline_for_every_layer()
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1047 self._fl_stack._show_framelines()
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1048 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1049
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1050 ## \brief Mark given frame as a key frame.
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1051 #
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1052 def mark_key(self, layer_idx, key_idx):
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1053 scene_group = self._dom.add_scene_group(layer_idx)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1054 scene_group_id = scene_group.getAttribute('id')
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1055
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1056 scene_node = self._dom.add_scene_node(key_idx, key_idx)
1237
b5cceb2b87bb Sucessful extend and duplicate
Thinker K.F. Li <thinker@codemud.net>
parents: 1236
diff changeset
1057 self._dom.chg_scene_node(scene_node, ref=scene_group_id)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1058
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1059 self._fl_stack.mark_keyframe(layer_idx, key_idx)
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1060 self._fl_stack.set_keyframe_data(layer_idx, key_idx, scene_node)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1061 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1062
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1063 ## \brief Tweening a key frame.
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1064 #
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1065 # To tween a key spanning several frames at right-side.
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1066 # The tween of a key frame can be changed by tweening it again.
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1067 #
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1068 def tween(self, layer_idx, key_frame_idx, tween_len,
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1069 tween_type=TweenObject.TWEEN_TYPE_NORMAL):
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1070 self._fl_stack.tween(layer_idx, key_frame_idx, tween_len, tween_type)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1071
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1072 end_frame_idx = key_frame_idx + tween_len - 1
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1073 scene_node = self._fl_stack.get_keyframe_data(layer_idx, key_frame_idx)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1074 tween_name = self._tween_type_names[tween_type]
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1075 self._dom.chg_scene_node(scene_node, end=end_frame_idx,
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1076 tween_type=tween_name)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1077 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1078
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1079 ## \brief Change tween info of a key frame
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1080 #
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1081 def chg_tween(self, layer_idx, key_frame_idx,
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1082 tween_len=None, tween_type=None):
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1083 scene_node = self._fl_stack.get_keyframe_data(layer_idx, key_frame_idx)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1084 start, end, old_tween_type = \
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1085 self._fl_stack.get_key_tween(layer_idx, key_frame_idx)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1086
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1087 if tween_len is not None:
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1088 end = start + tween_len - 1
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1089 self._dom.chg_scene_node(scene_node, end=end)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1090 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1091 if tween_type is not None:
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1092 tween_name = self._tween_type_names[tween_type]
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1093 self._dom.chg_scene_node(scene_node, tween_type=tween_name)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1094 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1095
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1096 if tween_type is None:
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1097 tween_type = old_tween_type
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1098 pass
1238
2febe4a301fa fix bug of changing tween type
Thinker K.F. Li <thinker@codemud.net>
parents: 1237
diff changeset
1099
2febe4a301fa fix bug of changing tween type
Thinker K.F. Li <thinker@codemud.net>
parents: 1237
diff changeset
1100 tween_len = end - start + 1
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1101 self._fl_stack.tween(layer_idx, start, tween_len, tween_type)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1102 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1103
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1104 ## \brief Unmark a frame from a key frame.
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1105 #
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1106 def unmark_key(self, layer_idx, key_frame_idx):
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1107 scene_node = self._fl_stack.get_keyframe_data(layer_idx, key_frame_idx)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1108 self._dom.rm_scene_node_n_group(scene_node)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1109
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1110 self._fl_stack.unmark_keyframe(layer_idx, key_frame_idx)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1111 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1112
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1113 ## \brief Insert frames at specified position.
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1114 #
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1115 # All frame at and after given position will shift right.
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1116 #
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1117 def insert_frames(self, layer_idx, frame_idx, num):
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1118 self._fl_stack.insert_frames(layer_idx, frame_idx, num)
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1119 self._dom.insert_frames(layer_idx, frame_idx, num)
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1120 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1121
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1122 ## \brief Insert frames at specified position.
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1123 #
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1124 # All frame at and after given position will shift left, except nearest
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1125 # \ref num frames are removed.
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1126 #
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1127 def rm_frames(self, layer_idx, frame_idx, num):
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1128 self._fl_stack.insert_frames(layer_idx, frame_idx, num)
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1129 self._dom.rm_frames(layer_idx, frame_idx, num)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1130 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1131
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1132 ## \brief Insert a layer at given position.
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1133 #
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1134 # Original layer \ref layer_idx and later ones would be shifted to make a
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1135 # space for the new layer.
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1136 #
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1137 def insert_layer(self, layer_idx):
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1138 self._dom.insert_layer(layer_idx)
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1139 self._fl_stack._add_frameline(layer_idx)
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1140 self._fl_stack._show_framelines()
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1141 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1142
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1143 ## \brief Remove given layer.
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1144 #
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1145 def rm_layer(self, layer_idx):
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1146 self._dom.rm_layer(layer_idx)
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1147 self._fl_stack._remove_frameline(layer_idx)
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1148 self._fl_stack._show_framelines()
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1149 pass
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1150
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1151 def set_active_layer_frame(self, layer_idx, frame_idx):
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1152 self._fl_stack.active_frame(layer_idx, frame_idx)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1153 pass
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1154
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1155 ## \bref Return current active frame and its layer.
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1156 #
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1157 # \return (layer_idx, frame_idx) of active frame, or (-1, -1) when no
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1158 # active one.
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1159 def get_active_layer_frame(self):
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1160 layer_idx, frame_idx = self._fl_stack.get_active_layer_frame()
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1161 return layer_idx, frame_idx
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1162
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1163 def get_layer_num(self):
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1164 return self._dom.get_layer_num()
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1165
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1166 ## \brief Return associated group node for a key frame.
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1167 #
1234
0f597a2073eb Enter the group after insert/extend a key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 1233
diff changeset
1168 # The given frame index must be exactly a key frame.
0f597a2073eb Enter the group after insert/extend a key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 1233
diff changeset
1169 #
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1170 def get_key_group(self, layer_idx, frame_idx):
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1171 scene_node = self._fl_stack.get_keyframe_data(layer_idx, frame_idx)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1172 scene_group_id = scene_node.getAttribute('ref')
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1173 scene_group_node = self._dom.get_node(scene_group_id)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1174 return scene_group_node
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1175
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1176 ## \brief Find an associated key frame and tween info for a group ID.
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1177 #
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1178 def find_key_from_group(self, scene_group_id):
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1179 layer_idx, scene_node = \
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1180 self._dom.find_layer_n_scene_of_node(scene_group_id)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1181 start, end, tween_name = self._dom._parse_one_scene(scene_node)
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1182 tween_type = self._tween_type_names.index(tween_name)
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1183 return layer_idx, (start, end, tween_type)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1184
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1185 ## \brief Return key and tween info for given frame index.
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1186 #
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1187 # The return key is at given frame, or its tween covers given frame.
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1188 #
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1189 def get_key(self, layer_idx, frame_idx):
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1190 start, end, tween_type = \
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1191 self._fl_stack.get_key_tween(layer_idx, frame_idx)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1192 return start, end, tween_type
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1193
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1194 def get_left_key(self, layer_idx, frame_idx):
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1195 start, end, tween_type = \
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1196 self._fl_stack.get_left_key_tween(layer_idx, frame_idx)
1230
f0864d7177e3 Add MBDOM_UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1229
diff changeset
1197 return start, end, tween_type
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1198
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1199 ## \brief Return information of key frames in the given layer.
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1200 #
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1201 def get_layer_keys(self, layer_idx):
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1202 key_tweens = self._fl_stack.get_all_key_tween_of_layer(layer_idx)
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1203 return key_tweens
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1204
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1205 ## \brief Return widget showing frames and layers.
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1206 #
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1207 def get_frame_ui_widget(self):
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1208 return self._fl_stack._frameline_box
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1209
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1210 ## \brief Register a callback for activating a frame event.
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1211 #
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1212 # The callback function is called when a frame is activated.
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1213 #
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1214 def register_active_frame_callback(self, cb):
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1215 self._fl_stack.register_active_frame_callback(cb)
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1216 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1217
1232
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1218 ## \brief Get duplicate group of a layer.
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1219 #
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1220 def get_layer_dup_group(self, layer_idx):
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1221 data = self._dom.get_layer_data(layer_idx)
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1222 if not data:
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1223 data = dict()
1232
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1224 self._dom.set_layer_data(layer_idx, data)
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1225 pass
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1226
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1227 dup_group = None
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1228 if data.has_key('dup_group_id'):
1232
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1229 try:
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1230 dup_group = self._dom.get_node(data['dup_group_id'])
1232
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1231 except KeyError:
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1232 pass
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1233 pass
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1234
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1235 if not dup_group:
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1236 # Search dup group from children of the layer group
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1237 layer_group = self._dom.get_layer_group(layer_idx)
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1238 for child in layer_group.childList():
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1239 try:
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1240 label = child.getAttribute('inkscape:label')
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1241 except:
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1242 pass
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1243 else:
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1244 if label == 'dup':
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1245 data['dup_group_id'] = child
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1246 return child
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1247 pass
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1248 pass
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1249
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1250 # Or create a new dup group for the layer
1241
e64f5bd2270c Change naming.
Thinker K.F. Li <thinker@codemud.net>
parents: 1240
diff changeset
1251 dup_group = self._dom.create_layer_dup_group(layer_idx)
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1252 data['dup_group_id'] = dup_group.getAttribute('id')
1232
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1253 pass
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1254
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1255 return dup_group
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1256
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1257 def get_max_frame(self):
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1258 max_frame = self._dom.get_max_frame()
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1259 return max_frame
1210
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
1260 pass
3683e02b7482 Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1209
diff changeset
1261
1209
41d13feeecc4 Doc MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1208
diff changeset
1262 ## \brief MBScene connect GUI and DOM-tree
41d13feeecc4 Doc MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1208
diff changeset
1263 #
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1264 # This method accepts user actions and involves MBScene_domview_ui to update
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1265 # data on the document.
1209
41d13feeecc4 Doc MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1208
diff changeset
1266 #
1234
0f597a2073eb Enter the group after insert/extend a key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 1233
diff changeset
1267 class MBScene(object):
1151
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
1268 _tween_obj_tween_types = (TweenObject.TWEEN_TYPE_NORMAL,
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
1269 TweenObject.TWEEN_TYPE_SCALE)
1157
3a891dccabd8 Remove the locate tween. It is a special case for the scale tween
wycc
parents: 1155
diff changeset
1270 _tween_type_names = ('normal', 'scale')
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1149
diff changeset
1271
1204
78925515836f Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1203
diff changeset
1272 _num_frames_of_line = 100
78925515836f Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 1203
diff changeset
1273
1149
0ffef2df6201 Rename MBScene.dom to MBScene.root
Thinker K.F. Li <thinker@codemud.net>
parents: 1148
diff changeset
1274 def __init__(self, desktop, win, root=None):
1188
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
1275 super(MBScene, self).__init__()
45e3a9273af2 Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1185
diff changeset
1276
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1277 self.desktop = desktop
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1278 self.window = win
1064
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
1279 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
1280 self.last_update = None
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1281 pybInkscape.inkscape.connect('change_selection', self.on_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
1282 self.last_select = None
1206
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
1283 self._lockui = False
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
1284 self.tween = None
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents: 1136
diff changeset
1285 self.document = None
1237
b5cceb2b87bb Sucessful extend and duplicate
Thinker K.F. Li <thinker@codemud.net>
parents: 1236
diff changeset
1286 self._root = root
1206
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
1287 self.framerate = 12
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1149
diff changeset
1288 self._disable_tween_type_selector = False
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1289 self.current = 0
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
1290
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1291 self._domview = MBScene_domview_ui()
1144
257beac7c982 Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents: 1142
diff changeset
1292 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
1293
1224
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
1294 def change_active_frame(self, node):
1221
33aa2d63e240 When we select a new object, search the scene group which contain it and make it as the active frame.
wycc
parents: 1220
diff changeset
1295 """
1224
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
1296 Change the active frame to the current selected node. This will
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
1297 tell users where the current node is.
1221
33aa2d63e240 When we select a new object, search the scene group which contain it and make it as the active frame.
wycc
parents: 1220
diff changeset
1298 """
1224
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
1299 while node:
1221
33aa2d63e240 When we select a new object, search the scene group which contain it and make it as the active frame.
wycc
parents: 1220
diff changeset
1300 try:
1224
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
1301 node_id = node.getAttribute('id')
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
1302 except:
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
1303 node = node.parent()
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
1304 continue
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
1305
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
1306 try:
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1307 layer_idx, (start, end, tween_type) = \
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1308 self._domview.find_key_from_group(node_id)
1221
33aa2d63e240 When we select a new object, search the scene group which contain it and make it as the active frame.
wycc
parents: 1220
diff changeset
1309 except:
1223
Thinker K.F. Li <thinker@codemud.net>
parents: 1222 1221
diff changeset
1310 pass
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1311 else:
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1312 self._domview.set_active_layer_frame(layer_idx, start)
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1313 break
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1314
1224
5d731460b32c Remove search_by_id() from frameline.
Thinker K.F. Li <thinker@codemud.net>
parents: 1223
diff changeset
1315 node = node.parent()
1223
Thinker K.F. Li <thinker@codemud.net>
parents: 1222 1221
diff changeset
1316 pass
1144
257beac7c982 Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents: 1142
diff changeset
1317 pass
1221
33aa2d63e240 When we select a new object, search the scene group which contain it and make it as the active frame.
wycc
parents: 1220
diff changeset
1318
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1319 def insertKeyScene(self, layer_idx, frame_idx):
1207
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1320 """
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1321 Insert a new key scene into the stage. If the nth is always a
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1322 key scene, we will return without changing anything. If the
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1323 nth is a filled scene, we will break the original scene into
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1324 two parts. If the nth is out of any scene, we will append a
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1325 new scene.
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1326
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1327 """
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1328 try:
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1329 self._domview.mark_key(layer_idx, frame_idx)
1234
0f597a2073eb Enter the group after insert/extend a key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 1233
diff changeset
1330 except ValueError: # existed key frame
0f597a2073eb Enter the group after insert/extend a key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 1233
diff changeset
1331 pass
1207
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1332 pass
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1333
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1334 def removeKeyScene(self, layer_idx, frame_idx):
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1335 self._domview.unmark_key(layer_idx, frame_idx)
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1336 self.setCurrentScene(frame_idx)
1144
257beac7c982 Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents: 1142
diff changeset
1337 pass
257beac7c982 Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents: 1142
diff changeset
1338
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
1339 def extendScene(self):
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1340 layer_idx, frame_idx = self._domview.get_active_layer_frame()
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1341 start, end, tween_type = \
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1342 self._domview.get_left_key(layer_idx, frame_idx)
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1343 tween_len = frame_idx - start + 1
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1344 self._domview.tween(layer_idx, start, tween_len, tween_type)
1234
0f597a2073eb Enter the group after insert/extend a key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 1233
diff changeset
1345
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1346 scene_group = self._domview.get_key_group(layer_idx, start)
1237
b5cceb2b87bb Sucessful extend and duplicate
Thinker K.F. Li <thinker@codemud.net>
parents: 1236
diff changeset
1347 self._enterGroup(scene_group)
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1348 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1349
1194
319414e4d87a Fix the issue that is fault to switch scenes
Thinker K.F. Li <thinker@codemud.net>
parents: 1193
diff changeset
1350 def setCurrentScene(self, idx):
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
1351 """
1144
257beac7c982 Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents: 1142
diff changeset
1352 Update the scene group according to the curretn scene
257beac7c982 Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents: 1142
diff changeset
1353 data. There are a couple of cases.
1148
wycc
parents: 1147 1145
diff changeset
1354 1. If the type of the scene is normal, we display it when
wycc
parents: 1147 1145
diff changeset
1355 it contains the current frame. Otherwise hide it.
wycc
parents: 1147 1145
diff changeset
1356 2. If the type of the scene is relocate or scale, we need
wycc
parents: 1147 1145
diff changeset
1357 to duplicate the scene group and then modify its
wycc
parents: 1147 1145
diff changeset
1358 transform matrix according to the definition of the
wycc
parents: 1147 1145
diff changeset
1359 scene. Then, hide the original scenr group and display
wycc
parents: 1147 1145
diff changeset
1360 the duplciate scene group. In addition, we may need to
1144
257beac7c982 Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents: 1142
diff changeset
1361 delete the old duplicated scene group as well.
257beac7c982 Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents: 1142
diff changeset
1362
1148
wycc
parents: 1147 1145
diff changeset
1363 For each layer, we will always use the duplicated scene
wycc
parents: 1147 1145
diff changeset
1364 group whose name as dup.
wycc
parents: 1147 1145
diff changeset
1365 We will put the duplicated scene group inside it. We will
wycc
parents: 1147 1145
diff changeset
1366 create this group if it is not
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
1367 available.
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
1368 """
1194
319414e4d87a Fix the issue that is fault to switch scenes
Thinker K.F. Li <thinker@codemud.net>
parents: 1193
diff changeset
1369 self.current = idx
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents: 1136
diff changeset
1370 self.tween.updateMapping()
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1371 for layer_idx in range(self._domview.get_layer_num()):
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1372 dup_group = self._domview.get_layer_dup_group(layer_idx)
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1373 dup_group.setAttribute('style', 'display: none')
1123
aad659b6b625 Add motion animation editor.
wycc
parents: 1120
diff changeset
1374
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1375 all_key_tweens = self._domview.get_layer_keys(layer_idx)
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1376 for start, end, tween_type in all_key_tweens:
1232
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1377 if start == idx: # at key frame
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1378 scene_group = \
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1379 self._domview.get_key_group(layer_idx, start)
1232
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1380 scene_group.setAttribute('style', '')
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1381 elif start < idx and end >= idx: # in Tween
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1382 dup_group.setAttribute('style', '')
1232
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1383 scene_group = \
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1384 self._domview.get_key_group(layer_idx, start)
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1385 scene_group.setAttribute('style', 'display: none')
1151
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
1386
1180
bfd7d466a022 Fix yeiling error message when select a scene.
Thinker K.F. Li <thinker@codemud.net>
parents: 1179
diff changeset
1387 try:
1232
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1388 next_scene_group = \
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1389 self._domview.get_key_group(layer_idx, end + 1)
1232
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1390 except: # no next key frame
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1391 next_scene_group = scene_group
1180
bfd7d466a022 Fix yeiling error message when select a scene.
Thinker K.F. Li <thinker@codemud.net>
parents: 1179
diff changeset
1392 pass
1194
319414e4d87a Fix the issue that is fault to switch scenes
Thinker K.F. Li <thinker@codemud.net>
parents: 1193
diff changeset
1393
1232
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1394 tween_obj_type = self._tween_obj_tween_types[tween_type]
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1395 nframes = end - start + 1
1232
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1396 percent = float(idx - start) / nframes
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1397 self.tween.updateTweenContent(dup_group,
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1398 tween_obj_type,
1151
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
1399 scene_group,
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
1400 next_scene_group,
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
1401 percent)
1232
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1402 pass
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1403 else: # this scene should not be showed.
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1404 scene_group = \
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1405 self._domview.get_key_group(layer_idx, start)
1236
2eeac97853eb Running animation successful
Thinker K.F. Li <thinker@codemud.net>
parents: 1235
diff changeset
1406 scene_group.setAttribute('style', 'display: none')
1151
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
1407 pass
955
53b0f8dc2284 Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents: 943
diff changeset
1408 pass
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1409 pass
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1410 pass
1232
6d4de488389e Change setCurrentScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1231
diff changeset
1411
1234
0f597a2073eb Enter the group after insert/extend a key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 1233
diff changeset
1412 def _enterGroup(self, scene_group):
1233
7f17a7e70d82 Integrate MBScene.entrGroup()
Thinker K.F. Li <thinker@codemud.net>
parents: 1232
diff changeset
1413 self.desktop.setCurrentLayer(scene_group.spitem)
1144
257beac7c982 Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents: 1142
diff changeset
1414 pass
257beac7c982 Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents: 1142
diff changeset
1415
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1416 def setTweenType(self, tween_type):
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1417 self._disable_tween_type_selector = True
1240
84bcd398cccc Fix bug of removing keyframe
Thinker K.F. Li <thinker@codemud.net>
parents: 1239
diff changeset
1418 self.tweenTypeSelector.set_active(tween_type)
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1419 self._disable_tween_type_selector = False
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1420 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1421
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1422 def selectSceneObject(self, layer_idx, frame_idx):
1177
ec1ea8555911 Stop selectSceneObject() from using private variable _keys of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 1176
diff changeset
1423 try:
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1424 start, stop, tween_type = \
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1425 self._domview.get_key(layer_idx, frame_idx)
1177
ec1ea8555911 Stop selectSceneObject() from using private variable _keys of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 1176
diff changeset
1426 except:
ec1ea8555911 Stop selectSceneObject() from using private variable _keys of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 1176
diff changeset
1427 return
1070
afa42d5836cc Call setCurrentLayer to enter the current scene group.
wycc
parents: 1064
diff changeset
1428
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1429 scene_group = self._domview.get_key_group(layer_idx, start)
1234
0f597a2073eb Enter the group after insert/extend a key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 1233
diff changeset
1430 self._enterGroup(scene_group)
1177
ec1ea8555911 Stop selectSceneObject() from using private variable _keys of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 1176
diff changeset
1431 self.setTweenType(tween_type)
ec1ea8555911 Stop selectSceneObject() from using private variable _keys of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 1176
diff changeset
1432 pass
1144
257beac7c982 Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents: 1142
diff changeset
1433
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
1434 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
1435 # Search for the current scene
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1436 layer_idx, frame_idx = self._domview.get_active_layer_frame()
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1437
1195
cb2c611d1656 Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents: 1194
diff changeset
1438 try:
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1439 left_start, left_end, left_tween_type = \
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1440 self._domview.get_left_key(layer_idx, frame_idx)
1195
cb2c611d1656 Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents: 1194
diff changeset
1441 except:
cb2c611d1656 Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents: 1194
diff changeset
1442 return
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1443 if left_end >= frame_idx:
1195
cb2c611d1656 Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents: 1194
diff changeset
1444 return
cb2c611d1656 Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents: 1194
diff changeset
1445
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1446 self._domview.mark_key(layer_idx, frame_idx)
1195
cb2c611d1656 Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents: 1194
diff changeset
1447
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1448 scene_group = self._domview.get_key_group(layer_idx, frame_idx)
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1449 left_scene_group = \
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1450 self._domview.get_key_group(layer_idx, left_start)
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1451
1237
b5cceb2b87bb Sucessful extend and duplicate
Thinker K.F. Li <thinker@codemud.net>
parents: 1236
diff changeset
1452 dup_group = self._duplicate_group(left_scene_group, scene_group)
1195
cb2c611d1656 Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents: 1194
diff changeset
1453
cb2c611d1656 Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents: 1194
diff changeset
1454 self.setCurrentScene(frame_idx)
1144
257beac7c982 Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents: 1142
diff changeset
1455 pass
257beac7c982 Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents: 1142
diff changeset
1456
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1457 ## \brief Duplicate children of a group.
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1458 #
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1459 # Duplicate children of a group, and append them to another group.
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1460 #
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1461 def _duplicate_group(self, src_group, dst_group):
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
1462 # Search for the duplicated group
1207
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1463 root = self._root
1237
b5cceb2b87bb Sucessful extend and duplicate
Thinker K.F. Li <thinker@codemud.net>
parents: 1236
diff changeset
1464 doc = self.document
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1465
1237
b5cceb2b87bb Sucessful extend and duplicate
Thinker K.F. Li <thinker@codemud.net>
parents: 1236
diff changeset
1466 dup_group = src_group.duplicate(doc)
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1467 for child in dup_group.childList():
1237
b5cceb2b87bb Sucessful extend and duplicate
Thinker K.F. Li <thinker@codemud.net>
parents: 1236
diff changeset
1468 dup_group.removeChild(child) # prvent from crash
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1469 dst_group.appendChild(child)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1470 pass
1151
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
1471
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1472 old_nodes = _DOM_iterator(src_group)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1473 new_nodes = _DOM_iterator(dst_group)
1151
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
1474 for old_node in old_nodes:
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
1475 old_node_id = old_node.getAttribute('id')
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
1476 new_node = new_nodes.next()
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
1477 new_node.setAttribute('ns0:duplicate-src', old_node_id)
71c72e8d6755 Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents: 1150
diff changeset
1478 pass
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1479 pass
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1480
1207
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1481 def changeObjectLabel(self,w):
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1482 o = self.desktop.selection.list()[0]
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1483 o.setAttribute("inkscape:label", self.nameEditor.get_text())
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1484 pass
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1485
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1486 def addNameEditor(self,hbox):
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1487 self.nameEditor = gtk.Entry(max=40)
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1488 hbox.pack_start(self.nameEditor,expand=False,fill=False)
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1489 self.editDone = gtk.Button('Set')
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1490 hbox.pack_start(self.editDone,expand=False,fill=False)
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1491 self.editDone.connect('clicked', self.changeObjectLabel)
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1492 pass
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1493
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1494 def addTweenTypeSelector(self, hbox):
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1495 tweenbox = gtk.HBox()
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1496 label = gtk.Label('Tween Type')
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1497 tweenbox.pack_start(label)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1498
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1499 self.tweenTypeSelector = gtk.combo_box_new_text()
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1500 self.tweenTypeSelector.append_text('normal')
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1501 self.tweenTypeSelector.append_text('scale')
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1502 self.tweenTypeSelector.set_active(0)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1503 tweenbox.pack_start(self.tweenTypeSelector, expand=False, fill=False)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1504 hbox.pack_start(tweenbox, expand=False, fill=False)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1505 self.tweenTypeSelector.connect('changed', self.onTweenTypeChange)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1506 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1507
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1508 def on_selection(self,w,obj):
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1509 objs = self.desktop.selection.list()
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1510 try:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1511 o = objs[0]
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1512 print o.getCenter()
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1513 if o == self.last_select:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1514 return
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1515 except:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1516 self.nameEditor.set_text('')
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1517 self.last_select = None
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1518 return
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1519 self.last_select = o
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1520 try:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1521 self.nameEditor.set_text(o.getAttribute("inkscape:label"))
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1522 except:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1523 self.nameEditor.set_text('')
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1524 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1525
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1526 # The selection is a PYSPObject. Convert it to be PYNode
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1527 self.change_active_frame(self.last_select.repr.parent())
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1528 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1529
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1530 def onCellClick(self, layer_idx, frame_idx):
1207
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1531 self._lockui = True
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1532
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1533 self.setCurrentScene(frame_idx)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1534 self.selectSceneObject(layer_idx, frame_idx)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1535
1207
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1536 self._lockui = False
489e6e474fdf Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1206
diff changeset
1537 pass
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1538
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1539 def doInsertKeyScene(self,w):
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
1540 self._lockui=True
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1541 layer_idx, frame_idx = self._domview.get_active_layer_frame()
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1542 self.insertKeyScene(layer_idx, frame_idx)
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1543 self.selectSceneObject(layer_idx, frame_idx)
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
1544 self._lockui=False
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1545 return
1144
257beac7c982 Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents: 1142
diff changeset
1546
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
1547 def doDuplicateKeyScene(self,w):
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
1548 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
1549 self.duplicateKeyScene()
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
1550 self._lockui = False
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1551
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1552 def doRemoveScene(self,w):
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
1553 self._lockui = True
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1554 layer_idx, frame_idx = self._domview.get_active_layer_frame()
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1555 self.removeKeyScene(layer_idx, frame_idx)
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
1556 self._lockui = False
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1557 return
941
9ba94c577a6f Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff changeset
1558
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1559
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1560 def doExtendScene(self,w):
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
1561 self._lockui = True
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1562 self.extendScene()
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
1563 self._lockui = False
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1564 pass
1146
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
1565
1147
5cfa73d7e80f Add the Run button to simulate the animation
wycc
parents: 1146
diff changeset
1566 def doRun(self,arg):
1146
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
1567 """
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
1568 Execute the current animation till the last frame.
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
1569 """
1147
5cfa73d7e80f Add the Run button to simulate the animation
wycc
parents: 1146
diff changeset
1570 if self.btnRun.get_label() == "Run":
5cfa73d7e80f Add the Run button to simulate the animation
wycc
parents: 1146
diff changeset
1571 self.btnRun.set_label("Stop")
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
1572 self._lockui = True
1206
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
1573 tmout = 1000 / self.framerate
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
1574 self.last_update = glib.timeout_add(tmout, self.doRunNext)
1147
5cfa73d7e80f Add the Run button to simulate the animation
wycc
parents: 1146
diff changeset
1575 else:
5cfa73d7e80f Add the Run button to simulate the animation
wycc
parents: 1146
diff changeset
1576 self.btnRun.set_label("Run")
5cfa73d7e80f Add the Run button to simulate the animation
wycc
parents: 1146
diff changeset
1577 glib.source_remove(self.last_update)
1189
9cf183faf89f Maintaining scene group ID to scene node mapping in MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1188
diff changeset
1578 self._lockui = False
1161
a7faab54e8f8 Fix broken of running animation
Thinker K.F. Li <thinker@codemud.net>
parents: 1160
diff changeset
1579 pass
1206
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
1580 pass
1147
5cfa73d7e80f Add the Run button to simulate the animation
wycc
parents: 1146
diff changeset
1581
5cfa73d7e80f Add the Run button to simulate the animation
wycc
parents: 1146
diff changeset
1582 def doRunNext(self):
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1583 if self.current > self._domview.get_max_frame():
1147
5cfa73d7e80f Add the Run button to simulate the animation
wycc
parents: 1146
diff changeset
1584 self.current = 0
1206
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
1585 pass
1161
a7faab54e8f8 Fix broken of running animation
Thinker K.F. Li <thinker@codemud.net>
parents: 1160
diff changeset
1586 try:
1194
319414e4d87a Fix the issue that is fault to switch scenes
Thinker K.F. Li <thinker@codemud.net>
parents: 1193
diff changeset
1587 self.setCurrentScene(self.current)
1161
a7faab54e8f8 Fix broken of running animation
Thinker K.F. Li <thinker@codemud.net>
parents: 1160
diff changeset
1588 except:
a7faab54e8f8 Fix broken of running animation
Thinker K.F. Li <thinker@codemud.net>
parents: 1160
diff changeset
1589 traceback.print_exc()
a7faab54e8f8 Fix broken of running animation
Thinker K.F. Li <thinker@codemud.net>
parents: 1160
diff changeset
1590 raise
1199
25e1579ed3d1 Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents: 1198
diff changeset
1591 self.current = self.current + 1
1206
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
1592 tmout = 1000 / self.framerate
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
1593 self.last_update = glib.timeout_add(tmout, self.doRunNext)
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
1594 pass
1174
96a7abce774a Add functions to insert and remove frame.
wycc
parents: 1171
diff changeset
1595
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
1596 def doInsertFrame(self, w):
1219
b5e648a317eb Add insert and remove frame function.
wycc
parents: 1217
diff changeset
1597 self.lockui=True
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1598 layer_idx, frame_idx = self._domview.get_active_layer_frame()
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1599 self._domview.insert_frames(layer_idx, frame_idx, 1)
1219
b5e648a317eb Add insert and remove frame function.
wycc
parents: 1217
diff changeset
1600 self.lockui=False
b5e648a317eb Add insert and remove frame function.
wycc
parents: 1217
diff changeset
1601
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
1602 def doRemoveFrame(self, w):
1219
b5e648a317eb Add insert and remove frame function.
wycc
parents: 1217
diff changeset
1603 self.lockui=True
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1604 layer_idx, frame_idx = self._domview.get_active_layer_frame()
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1605 self._domview.rm_frames(layer_idx, frame_idx, 1)
1219
b5e648a317eb Add insert and remove frame function.
wycc
parents: 1217
diff changeset
1606 self.lockui=False
b5e648a317eb Add insert and remove frame function.
wycc
parents: 1217
diff changeset
1607
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1608 def onTweenTypeChange(self, w):
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1609 if self._disable_tween_type_selector:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1610 return
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1611
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1612 layer_idx, frame_idx = self._domview.get_active_layer_frame()
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1613 tween_type = self.tweenTypeSelector.get_active()
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1614
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1615 start, end, old_tween_type = \
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1616 self._domview.get_left_key(layer_idx, frame_idx)
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1617 if end >= frame_idx and start != end:
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1618 # Length of tween > 1 and cover this frame
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1619 self._domview.chg_tween(layer_idx, start, tween_type=tween_type)
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1620 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1621 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1622
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1623 def onQuit(self, event):
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1624 self.OK = False
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1625 gtk.main_quit()
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1626 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1627
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1628 def onOK(self, event):
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1629 self.OK = True
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1630 gtk.main_quit()
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1631 pass
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1632
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1633 def _add_buttons(self, hbox):
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1634 btn = gtk.Button('Insert Key')
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
1635 btn.connect('clicked', self.doInsertKeyScene)
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
1636 hbox.pack_start(btn, expand=False, fill=False)
1174
96a7abce774a Add functions to insert and remove frame.
wycc
parents: 1171
diff changeset
1637
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1638 btn=gtk.Button('Remove Key')
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1639 btn.connect('clicked', self.doRemoveScene)
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
1640 hbox.pack_start(btn, expand=False, fill=False)
1174
96a7abce774a Add functions to insert and remove frame.
wycc
parents: 1171
diff changeset
1641
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1642 btn=gtk.Button('Extend scene')
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1643 btn.connect('clicked', self.doExtendScene)
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
1644 hbox.pack_start(btn, expand=False, fill=False)
1174
96a7abce774a Add functions to insert and remove frame.
wycc
parents: 1171
diff changeset
1645
96a7abce774a Add functions to insert and remove frame.
wycc
parents: 1171
diff changeset
1646 btn=gtk.Button('Duplicate Key')
96a7abce774a Add functions to insert and remove frame.
wycc
parents: 1171
diff changeset
1647 btn.connect('clicked', self.doDuplicateKeyScene)
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
1648 hbox.pack_start(btn, expand=False, fill=False)
1174
96a7abce774a Add functions to insert and remove frame.
wycc
parents: 1171
diff changeset
1649
1219
b5e648a317eb Add insert and remove frame function.
wycc
parents: 1217
diff changeset
1650 btn=gtk.Button('insert')
b5e648a317eb Add insert and remove frame function.
wycc
parents: 1217
diff changeset
1651 btn.connect('clicked', self.doInsertFrame)
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
1652 hbox.pack_start(btn, expand=False, fill=False)
1219
b5e648a317eb Add insert and remove frame function.
wycc
parents: 1217
diff changeset
1653
b5e648a317eb Add insert and remove frame function.
wycc
parents: 1217
diff changeset
1654 btn=gtk.Button('remove')
b5e648a317eb Add insert and remove frame function.
wycc
parents: 1217
diff changeset
1655 btn.connect('clicked', self.doRemoveFrame)
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
1656 hbox.pack_start(btn, expand=False, fill=False)
1219
b5e648a317eb Add insert and remove frame function.
wycc
parents: 1217
diff changeset
1657
1146
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
1658 btn=gtk.Button('Run')
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
1659 btn.connect('clicked', self.doRun)
1147
5cfa73d7e80f Add the Run button to simulate the animation
wycc
parents: 1146
diff changeset
1660 self.btnRun = btn
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
1661 hbox.pack_start(btn, expand=False, fill=False)
1174
96a7abce774a Add functions to insert and remove frame.
wycc
parents: 1171
diff changeset
1662
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
1663 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
1664 self.addTweenTypeSelector(hbox)
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1665 pass
1144
257beac7c982 Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents: 1142
diff changeset
1666
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1667 def show(self):
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1668 self.OK = True
1237
b5cceb2b87bb Sucessful extend and duplicate
Thinker K.F. Li <thinker@codemud.net>
parents: 1236
diff changeset
1669 if not self._root:
b5cceb2b87bb Sucessful extend and duplicate
Thinker K.F. Li <thinker@codemud.net>
parents: 1236
diff changeset
1670 self._root = self.desktop.doc().root().repr
1149
0ffef2df6201 Rename MBScene.dom to MBScene.root
Thinker K.F. Li <thinker@codemud.net>
parents: 1148
diff changeset
1671 pass
0ffef2df6201 Rename MBScene.dom to MBScene.root
Thinker K.F. Li <thinker@codemud.net>
parents: 1148
diff changeset
1672
1128
b65ac686a7c5 Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents: 1125
diff changeset
1673 self.document = self.desktop.doc().rdoc
1240
84bcd398cccc Fix bug of removing keyframe
Thinker K.F. Li <thinker@codemud.net>
parents: 1239
diff changeset
1674
1237
b5cceb2b87bb Sucessful extend and duplicate
Thinker K.F. Li <thinker@codemud.net>
parents: 1236
diff changeset
1675 self.tween = TweenObject(self.document, self._root)
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1676 self._domview.handle_doc_root(self.document, self._root)
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1677 self._domview.register_active_frame_callback(self.onCellClick)
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1678
1064
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
1679 if self.top == None:
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
1680 self.top = gtk.VBox(False, 0)
1206
1d476b35dc79 Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents: 1205 1186
diff changeset
1681 toplevel = self.desktop.getToplevel()
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
1682 toplevel.child.child.pack_end(self.top, expand=False)
1064
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
1683 else:
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
1684 self.top.remove(self.startWindow)
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1149
diff changeset
1685 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1149
diff changeset
1686
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
1687 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
1688 self.startWindow = vbox
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
1689 self.top.pack_start(vbox, expand=False)
1242
1b1eb8f9a866 Rename *_dom to *_domview and *_framelines to *_frameline_stack
Thinker K.F. Li <thinker@codemud.net>
parents: 1241
diff changeset
1690 frame_ui = self._domview.get_frame_ui_widget()
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1691 vbox.pack_start(frame_ui, expand=False)
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
1692 hbox=gtk.HBox(False, 0)
1231
d28b1b840bfc Integrate MBDOM_UI to MBScene
Thinker K.F. Li <thinker@codemud.net>
parents: 1230
diff changeset
1693 self._add_buttons(hbox)
1222
03daff2d939c Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents: 1220
diff changeset
1694 vbox.pack_start(hbox, expand=False)
981
9e7865906bfc Add MadButterfly name space
wycc
parents: 980
diff changeset
1695
1064
16c69756ef5d Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents: 1032
diff changeset
1696 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
1697 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
1698 return False
956
167e359c9d5b Re-indent MBScene.py
Thinker K.F. Li <thinker@codemud.net>
parents: 955
diff changeset
1699 pass