Mercurial > MadButterfly
annotate pyink/MBScene.py @ 1223:ec964cf4c993
merge
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Thu, 06 Jan 2011 09:39:47 +0800 |
parents | 03daff2d939c 33aa2d63e240 |
children | 5d731460b32c |
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 | 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 | 17 # Please refer to |
18 # http://www.assembla.com/wiki/show/MadButterfly/Inkscape_extention | |
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 |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
79 def _travel_DOM(node): |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
80 nodes = [node] |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
81 while nodes: |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
82 node = nodes.pop(0) |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
83 child = node.firstChild() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
84 while child: |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
85 nodes.append(child) |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
86 child = child.next() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
87 pass |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
88 yield node |
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 pass |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
91 |
1188
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
92 |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
93 ## \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
|
94 # |
1207
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
95 # 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
|
96 # node and scene group ID to 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
|
97 class MBScene_dom_monitor(object): |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
98 def __init__(self, *args, **kws): |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
99 super(MBScene_dom_monitor, self).__init__() |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
100 |
1206
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 pass |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
105 |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
106 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
|
107 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>
diff
changeset
|
108 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
|
109 |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
110 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
|
111 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
|
112 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
|
113 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
|
114 pass |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
115 |
1191
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
116 def _on_insert_node(self, node, child): |
1188
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
117 try: |
1191
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
118 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
|
119 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
|
120 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
|
121 else: |
1191
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
122 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
|
123 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
|
124 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
|
125 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
|
126 |
1191
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
127 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
|
128 try: |
1191
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
129 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
|
130 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
|
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 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
|
133 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
|
134 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
|
135 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
|
136 pass |
1206
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
137 |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
138 try: |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
139 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>
diff
changeset
|
140 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>
diff
changeset
|
141 except: |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
142 pass |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
143 try: |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
144 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>
diff
changeset
|
145 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>
diff
changeset
|
146 except: |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
147 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
|
148 pass |
1188
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
149 pass |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
150 |
1206
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
151 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>
diff
changeset
|
152 maxframe = 0 |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
153 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>
diff
changeset
|
154 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>
diff
changeset
|
155 continue |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
156 |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
157 try: |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
158 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>
diff
changeset
|
159 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>
diff
changeset
|
160 except: |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
161 pass |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
162 try: |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
163 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>
diff
changeset
|
164 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>
diff
changeset
|
165 except: |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
166 pass |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
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>
diff
changeset
|
168 return maxframe |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
169 |
1191
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
170 def _on_remove_node(self, node, child): |
1188
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
171 try: |
1191
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
172 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
|
173 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
|
174 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
|
175 else: |
1191
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
176 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
|
177 raise ValueError, \ |
1191
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
178 '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
|
179 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
|
180 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
|
181 |
1191
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
182 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
|
183 try: |
1191
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 pass |
1206
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
190 |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
191 try: |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
192 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>
diff
changeset
|
193 (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>
diff
changeset
|
194 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>
diff
changeset
|
195 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>
diff
changeset
|
196 pass |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
197 except: |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
198 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
|
199 pass |
1188
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
200 pass |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
201 |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
202 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
|
203 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
|
204 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
|
205 raise ValueError, \ |
1195
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
206 '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
|
207 (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
|
208 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
|
209 raise ValueError, \ |
1195
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
210 '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
|
211 (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
|
212 |
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 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 # 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
|
224 # 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 pass |
1206
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
230 pass |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
231 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>
diff
changeset
|
232 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
|
233 pass |
e8446e138427
Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1182
diff
changeset
|
234 pass |
e8446e138427
Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1182
diff
changeset
|
235 |
1203
b90a1e2eb9ec
Add document for methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1202
diff
changeset
|
236 ## \brief Collect ID of nodes in the document. |
b90a1e2eb9ec
Add document for methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1202
diff
changeset
|
237 # |
b90a1e2eb9ec
Add document for methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1202
diff
changeset
|
238 # 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
|
239 # |
1188
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
240 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
|
241 self._id2node = {} |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 pass |
e8446e138427
Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1182
diff
changeset
|
246 pass |
e8446e138427
Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1182
diff
changeset
|
247 |
1188
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
248 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
|
249 try: |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
250 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
|
251 except: |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
252 return |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
253 |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
254 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
|
255 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
|
256 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
|
257 pass |
e8446e138427
Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1182
diff
changeset
|
258 pass |
e8446e138427
Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1182
diff
changeset
|
259 |
1206
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
260 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>
diff
changeset
|
261 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>
diff
changeset
|
262 |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
263 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>
diff
changeset
|
264 try: |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
265 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>
diff
changeset
|
266 except: |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
267 end = start |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
268 pass |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
269 |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
270 try: |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
271 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>
diff
changeset
|
272 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>
diff
changeset
|
273 scene_type = 'normal' |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
274 pass |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
275 except: |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
276 scene_type = 'normal' |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
277 pass |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
278 |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
279 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>
diff
changeset
|
280 |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
281 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>
diff
changeset
|
282 try: |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
283 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>
diff
changeset
|
284 except: |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
285 cur = 0 |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
286 pass |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
287 self.current = cur |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
288 |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
289 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>
diff
changeset
|
290 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>
diff
changeset
|
291 continue |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
292 |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
293 try: |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
294 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>
diff
changeset
|
295 except: |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
296 continue |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
297 |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
298 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
|
299 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>
diff
changeset
|
300 pass |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
301 pass |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
302 |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
303 ## \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>
diff
changeset
|
304 # |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
305 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>
diff
changeset
|
306 root = self._root |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
307 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>
diff
changeset
|
308 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>
diff
changeset
|
309 continue |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
310 |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
311 metadata_node = child |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
312 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>
diff
changeset
|
313 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>
diff
changeset
|
314 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>
diff
changeset
|
315 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>
diff
changeset
|
316 pass |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
317 pass |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
318 pass |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
319 pass |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
320 |
1203
b90a1e2eb9ec
Add document for methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1202
diff
changeset
|
321 ## \brief Return the node with given ID. |
b90a1e2eb9ec
Add document for methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1202
diff
changeset
|
322 # |
1188
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
323 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
|
324 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
|
325 |
1203
b90a1e2eb9ec
Add document for methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1202
diff
changeset
|
326 ## \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
|
327 # |
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
|
328 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
|
329 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
|
330 |
1188
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
331 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
|
332 while True: |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
333 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
|
334 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
|
335 return candidate |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
336 pass |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
337 pass |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
338 pass |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
339 |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
340 |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
341 ## \brief Layer of MBScene to manipulate DOM tree. |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
342 # |
1207
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
343 # 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
|
344 # 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
|
345 # 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
|
346 # |
1188
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
347 class MBScene_dom(MBScene_dom_monitor): |
1191
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
348 # 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
|
349 _doc = None |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
350 _root = None |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
351 |
1188
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
352 def __init__(self, *args, **kws): |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
353 super(MBScene_dom, self).__init__() |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
354 pass |
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
355 |
1202
2f3d523a3871
Parse all scenes when start handling a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1201
diff
changeset
|
356 ## \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
|
357 # |
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
|
358 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
|
359 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
|
360 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
|
361 break |
1176
0c1ceecb8ddb
Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1174
diff
changeset
|
362 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
|
363 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
|
364 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
|
365 '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
|
366 |
0c1ceecb8ddb
Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1174
diff
changeset
|
367 for n in node.childList(): |
0c1ceecb8ddb
Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1174
diff
changeset
|
368 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
|
369 self._scenes_node = n |
1176
0c1ceecb8ddb
Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1174
diff
changeset
|
370 break |
0c1ceecb8ddb
Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1174
diff
changeset
|
371 pass |
0c1ceecb8ddb
Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1174
diff
changeset
|
372 else: |
0c1ceecb8ddb
Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1174
diff
changeset
|
373 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
|
374 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
|
375 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
|
376 node.appendChild(scenes_node) |
1191
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
377 self._scenes_node = scenes_node |
1176
0c1ceecb8ddb
Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1174
diff
changeset
|
378 pass |
0c1ceecb8ddb
Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1174
diff
changeset
|
379 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
|
380 |
1207
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
381 def _parse_all_layers(self): |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
382 root = self._root |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
383 layers = self._layers |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
384 |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
385 for child in root.childList(): |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
386 if child.name() != 'svg:g': |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
387 continue |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
388 |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
389 layer_group = child |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
390 layer = Layer(layer_group) |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
391 layer.idx = len(layers) |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
392 layers.append(layer) |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
393 self.parse_layer(layer.idx) |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
394 pass |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
395 pass |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
396 |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
397 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
|
398 self._doc = doc |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
399 self._root = root |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
400 self._layers = [] |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
401 |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
402 self._start_monitor() # start MBScene_dom_monitor |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
403 self._init_metadata() |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
404 self._parse_all_layers() |
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 dumpattr(self, n): |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
408 s = "" |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
409 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
|
410 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
|
411 pass |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
412 return s |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
413 |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
414 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
|
415 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
|
416 for n in node: |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
417 self.dump(n, l+1) |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
418 pass |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
419 print " " * l * 2,"/>" |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
420 pass |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
421 |
1191
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
422 ## \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
|
423 # |
1207
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
424 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
|
425 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
|
426 ref=None): |
1191
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
427 type_names = ('normal', 'scale') |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
428 scenes_node = self._scenes_node |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
429 doc = self._doc |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
430 |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
431 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
|
432 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
|
433 if start != end: |
1207
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
434 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
|
435 pass |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
436 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
|
437 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
|
438 if ref: |
1207
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
439 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
|
440 pass |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
441 |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
442 scenes_node.appendChild(scene_node) |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
443 |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
444 return scene_node |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
445 |
1206
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
446 ## \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>
diff
changeset
|
447 # |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
448 # 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
|
449 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
|
450 tween_type=None, ref=None): |
1214
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
451 if start is not None: |
1199
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
452 scene_node.setAttribute('start', str(start)) |
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
453 pass |
1214
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
454 if end is not None: |
1199
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
455 scene_node.setAttribute('end', str(end)) |
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
456 pass |
1214
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
457 if tween_type is not None: |
1199
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
458 scene_node.setAttribute('type', tween_type) |
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
459 pass |
1214
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
460 if ref is not None: |
1199
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
461 scene_node.setAttribute('ref', ref) |
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
462 pass |
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
463 pass |
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
464 |
1207
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
465 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
|
466 self._scenes_node.removeChild(scene_node) |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
467 pass |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
468 |
1191
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
469 ## \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
|
470 # |
1207
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
471 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
|
472 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
|
473 doc = self._doc |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
474 |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
475 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
|
476 gid = self.new_id() |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
477 scene_group.setAttribute("id", gid) |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
478 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
|
479 |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
480 layer.group.appendChild(scene_group) |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
481 |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
482 return scene_group |
1181
f14dbcf19e2b
Move MBScene.insertKeyScene() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1180
diff
changeset
|
483 |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
484 def parse_layer(self, layer_idx): |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
485 layer = self._layers[layer_idx] |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
486 layer_group = layer.group |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
487 |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
488 for child in layer_group.childList(): |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
489 if child.name() != 'svg:g': |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
490 continue |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
491 try: |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
492 child_id = child.getAttribute('id') |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
493 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
|
494 except: |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
495 continue |
1183
e8446e138427
Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1182
diff
changeset
|
496 |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
497 layer.scenes.append(scene_node) |
1181
f14dbcf19e2b
Move MBScene.insertKeyScene() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1180
diff
changeset
|
498 pass |
f14dbcf19e2b
Move MBScene.insertKeyScene() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1180
diff
changeset
|
499 pass |
f14dbcf19e2b
Move MBScene.insertKeyScene() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1180
diff
changeset
|
500 |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
501 ## \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
|
502 # |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
503 # \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
|
504 # |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
505 def add_layer(self, layer_idx, layer_group): |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
506 layers = self._layers |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
507 |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
508 layer = Layer(layer_group) |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
509 if layer_idx >= len(layers): |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
510 layers.append(layer) |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
511 else: |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
512 layers.insert(layer_idx, layer) |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
513 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
|
514 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
|
515 pass |
e8446e138427
Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1182
diff
changeset
|
516 pass |
e8446e138427
Move update_scenes_of_dom() to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1182
diff
changeset
|
517 pass |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
518 |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
519 def rm_layer(self, layer_idx): |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
520 layers = self._layers |
956 | 521 |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
522 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
|
523 |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
524 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
|
525 layers[idx].idx = idx |
956 | 526 pass |
527 pass | |
1176
0c1ceecb8ddb
Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1174
diff
changeset
|
528 pass |
0c1ceecb8ddb
Move parseMetadata to MBScene_dom
Thinker K.F. Li <thinker@codemud.net>
parents:
1174
diff
changeset
|
529 |
1210
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
530 ## \brief Maintain frameline list for MBScene. |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
531 # |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
532 class MBScene_framelines(object): |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
533 _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
|
534 frameline.TWEEN_TYPE_SHAPE) |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
535 |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
536 _framelines = None |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
537 |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
538 def __init__(self, *args, **kws): |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
539 super(MBScene_framelines, self).__init__(*args, **kws) |
1214
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
540 |
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
541 self._last_mouse_over_frameline = None |
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
542 self._last_active_frameline = None |
1210
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
543 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
|
544 |
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
|
545 def search_frameline_by_id(self, id): |
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
|
546 """ |
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
|
547 Search the frameline whose layer is id |
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
|
548 """ |
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
|
549 |
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
|
550 for f in self._framelines: |
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
|
551 idx = f.search_by_id(id) |
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
|
552 if idx != -1: |
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
|
553 return (f,idx) |
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
|
554 pass |
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
|
555 return (None,-1) |
1210
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
556 |
1214
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
557 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
|
558 """ |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
559 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
|
560 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
|
561 """ |
1214
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
562 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
|
563 widget != self._last_mouse_over_frameline: |
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
564 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
|
565 pass |
1214
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
566 self._last_mouse_over_frameline = widget |
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
567 pass |
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
568 |
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
569 ## \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
|
570 # |
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
571 # 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
|
572 # frame in another frameline is activated. |
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
573 def _change_active_frame(self, widget, frame, button): |
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
574 if self._last_active_frameline and \ |
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
575 self._last_active_frameline != widget: |
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
576 self._last_active_frameline.deactive() |
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
577 pass |
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
578 self._last_active_frameline = widget |
1210
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
579 pass |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
580 |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
581 ## \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
|
582 # |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
583 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
|
584 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
|
585 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
|
586 |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
587 vbox = self._frameline_vbox |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
588 |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
589 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
|
590 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
|
591 |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
592 hbox = gtk.HBox() |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
593 label = gtk.Label('') |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
594 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
|
595 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
|
596 hbox.pack_start(line) |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
597 vbox.pack_start(hbox, False) |
1216
61f1b3d424cf
Change order of framelines.
Thinker K.F. Li <thinker@codemud.net>
parents:
1214
diff
changeset
|
598 |
61f1b3d424cf
Change order of framelines.
Thinker K.F. Li <thinker@codemud.net>
parents:
1214
diff
changeset
|
599 # 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
|
600 position = len(self._framelines) - layer_idx + 1 |
61f1b3d424cf
Change order of framelines.
Thinker K.F. Li <thinker@codemud.net>
parents:
1214
diff
changeset
|
601 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
|
602 |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
603 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
|
604 |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
605 line.label = label |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
606 line.layer_idx = layer_idx |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
607 line.connect(line.FRAME_BUT_PRESS, self.onCellClick) |
1214
e55499f7505a
Fix the issues with multiple framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1213
diff
changeset
|
608 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
|
609 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
|
610 pass |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
611 |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
612 ## \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
|
613 # |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
614 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
|
615 vbox = self._frameline_vbox |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
616 line = self._framelines[layer_idx] |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
617 |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
618 hbox = line.parent |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
619 vbox.remove(hbox) |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
620 del self._framelines[layer_idx] |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
621 pass |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
622 |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
623 def _init_framelines(self): |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
624 self._framelines = [] |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
625 |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
626 box = gtk.ScrolledWindow() |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
627 self._frameline_box = box |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
628 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
|
629 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
|
630 vbox = gtk.VBox() |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
631 self._frameline_vbox = vbox |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
632 box.add_with_viewport(vbox) |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
633 |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
634 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
|
635 |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
636 # |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
637 # Set up a ruler |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
638 # |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
639 ruler = frameruler(nframes) |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
640 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
|
641 ruler.show() |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
642 hbox = gtk.HBox() |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
643 label=gtk.Label('') |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
644 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
|
645 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
|
646 hbox.pack_start(ruler) |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
647 vbox.pack_start(hbox, False) |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
648 pass |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
649 |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
650 ## \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
|
651 # |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
652 # 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
|
653 # 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
|
654 # screen and drawing framelines. |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
655 def _show_framelines(self): |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
656 self._frameline_vbox.show_all() |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
657 pass |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
658 pass |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
659 |
1209 | 660 ## \brief MBScene connect GUI and DOM-tree |
661 # | |
662 # This class connect behavior of GUI to the DOM-tree. All about GUI is | |
663 # implemented by this class. It use API provided by MBScene_dom to reflect | |
664 # actions to the DOM-tree. | |
665 # | |
1210
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
666 class MBScene(MBScene_dom, MBScene_framelines): |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
667 _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
|
668 TweenObject.TWEEN_TYPE_SCALE) |
1157
3a891dccabd8
Remove the locate tween. It is a special case for the scale tween
wycc
parents:
1155
diff
changeset
|
669 _tween_type_names = ('normal', 'scale') |
1150
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1149
diff
changeset
|
670 |
1204
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
671 _num_frames_of_line = 100 |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
672 |
1149
0ffef2df6201
Rename MBScene.dom to MBScene.root
Thinker K.F. Li <thinker@codemud.net>
parents:
1148
diff
changeset
|
673 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
|
674 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
|
675 |
956 | 676 self.desktop = desktop |
677 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
|
678 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
|
679 self.last_update = None |
1128
b65ac686a7c5
Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents:
1125
diff
changeset
|
680 pybInkscape.inkscape.connect('change_selection', self.show_selection) |
1099
5ba2cab1d505
Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
wycc
parents:
1097
diff
changeset
|
681 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>
diff
changeset
|
682 self._lockui = False |
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
683 self.tween = None |
1140 | 684 self.document = None |
1149
0ffef2df6201
Rename MBScene.dom to MBScene.root
Thinker K.F. Li <thinker@codemud.net>
parents:
1148
diff
changeset
|
685 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>
diff
changeset
|
686 self.framerate = 12 |
1150
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1149
diff
changeset
|
687 self._disable_tween_type_selector = False |
956 | 688 pass |
941
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
689 |
1128
b65ac686a7c5
Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents:
1125
diff
changeset
|
690 def show_selection(self,w,obj): |
b65ac686a7c5
Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents:
1125
diff
changeset
|
691 objs = self.desktop.selection.list() |
b65ac686a7c5
Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents:
1125
diff
changeset
|
692 try: |
b65ac686a7c5
Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents:
1125
diff
changeset
|
693 o = objs[0] |
b65ac686a7c5
Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents:
1125
diff
changeset
|
694 print o.getCenter() |
b65ac686a7c5
Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents:
1125
diff
changeset
|
695 if o == self.last_select: |
b65ac686a7c5
Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents:
1125
diff
changeset
|
696 return |
b65ac686a7c5
Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents:
1125
diff
changeset
|
697 except: |
b65ac686a7c5
Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents:
1125
diff
changeset
|
698 self.nameEditor.set_text('') |
b65ac686a7c5
Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents:
1125
diff
changeset
|
699 self.last_select = None |
b65ac686a7c5
Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents:
1125
diff
changeset
|
700 return |
b65ac686a7c5
Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents:
1125
diff
changeset
|
701 self.last_select = o |
b65ac686a7c5
Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents:
1125
diff
changeset
|
702 try: |
1139
a2b068594412
Use pybind with new DOM API (at PYNode).
Thinker K.F. Li <thinker@codemud.net>
parents:
1136
diff
changeset
|
703 self.nameEditor.set_text(o.getAttribute("inkscape:label")) |
1128
b65ac686a7c5
Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents:
1125
diff
changeset
|
704 except: |
b65ac686a7c5
Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents:
1125
diff
changeset
|
705 self.nameEditor.set_text('') |
b65ac686a7c5
Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents:
1125
diff
changeset
|
706 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
|
707 |
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
|
708 # The selection is a PYSPObject. Convert it to be PYNode |
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
|
709 self.change_active_frame(self.last_select.repr.parent()) |
1144
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
710 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
|
711 |
1223 | 712 def change_active_frame(self, obj): |
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
|
713 """ |
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
|
714 Change the active frame to the current selected object. This will |
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
|
715 tell users where the current object is. |
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
|
716 """ |
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
|
717 |
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
|
718 while obj: |
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
|
719 id = obj.getAttribute('id') |
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
|
720 try: |
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
|
721 # Search for the frameline which use @obj as one of its scene |
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
|
722 # group. |
1223 | 723 (frameline, frame) = self.search_frameline_by_id(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
|
724 if frameline == None: |
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
|
725 print "Error: internal structure error %s not found" % id |
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
|
726 else: |
1223 | 727 self._change_active_frame(frameline, 0, 0) |
728 self.onCellClick(frameline, frame, 0) | |
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
|
729 return |
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
|
730 except: |
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
|
731 traceback.print_exc() |
1223 | 732 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
|
733 obj = obj.parent() |
1223 | 734 pass |
1144
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
735 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
|
736 |
1207
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
737 def insertKeyScene(self, line, frame): |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
738 """ |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
739 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
|
740 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
|
741 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
|
742 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
|
743 new scene. |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
744 |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
745 """ |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
746 doc = self._doc |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
747 layer_idx = self._framelines.index(line) |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
748 |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
749 scene_group = self.add_scene_group(layer_idx) |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
750 scene_group_id = scene_group.getAttribute('id') |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
751 scene_node = self.add_scene_node(frame, frame, ref=scene_group_id) |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
752 line.add_keyframe(frame, scene_node) |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
753 |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
754 for node in self._layers[layer_idx].group.childList(): |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
755 try: |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
756 label = node.getAttribute('inkscape:label') |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
757 except: |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
758 continue |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
759 if label == 'dup': |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
760 node.setAttribute('style', 'display: none') |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
761 pass |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
762 pass |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
763 pass |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
764 |
1200
213f03dbfc41
Fix issue of removing a scene
Thinker K.F. Li <thinker@codemud.net>
parents:
1199
diff
changeset
|
765 def removeKeyScene(self, frameline, frame_idx): |
213f03dbfc41
Fix issue of removing a scene
Thinker K.F. Li <thinker@codemud.net>
parents:
1199
diff
changeset
|
766 start, end, scene_type = frameline.get_frame_block(frame_idx) |
213f03dbfc41
Fix issue of removing a scene
Thinker K.F. Li <thinker@codemud.net>
parents:
1199
diff
changeset
|
767 scene_node = frameline.get_frame_data(start) |
1184
05d33f0fbc76
Add comment for some TODO item
Thinker K.F. Li <thinker@codemud.net>
parents:
1183
diff
changeset
|
768 |
1200
213f03dbfc41
Fix issue of removing a scene
Thinker K.F. Li <thinker@codemud.net>
parents:
1199
diff
changeset
|
769 frameline.rm_keyframe(start) |
213f03dbfc41
Fix issue of removing a scene
Thinker K.F. Li <thinker@codemud.net>
parents:
1199
diff
changeset
|
770 if start != end: |
213f03dbfc41
Fix issue of removing a scene
Thinker K.F. Li <thinker@codemud.net>
parents:
1199
diff
changeset
|
771 frameline.rm_keyframe(end) |
1144
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
772 pass |
1200
213f03dbfc41
Fix issue of removing a scene
Thinker K.F. Li <thinker@codemud.net>
parents:
1199
diff
changeset
|
773 |
213f03dbfc41
Fix issue of removing a scene
Thinker K.F. Li <thinker@codemud.net>
parents:
1199
diff
changeset
|
774 scene_group_id = scene_node.getAttribute('ref') |
213f03dbfc41
Fix issue of removing a scene
Thinker K.F. Li <thinker@codemud.net>
parents:
1199
diff
changeset
|
775 scene_group = self.get_node(scene_group_id) |
213f03dbfc41
Fix issue of removing a scene
Thinker K.F. Li <thinker@codemud.net>
parents:
1199
diff
changeset
|
776 scene_group.parent().removeChild(scene_group) |
213f03dbfc41
Fix issue of removing a scene
Thinker K.F. Li <thinker@codemud.net>
parents:
1199
diff
changeset
|
777 scene_node.parent().removeChild(scene_node) |
956 | 778 |
1139
a2b068594412
Use pybind with new DOM API (at PYNode).
Thinker K.F. Li <thinker@codemud.net>
parents:
1136
diff
changeset
|
779 try: |
1200
213f03dbfc41
Fix issue of removing a scene
Thinker K.F. Li <thinker@codemud.net>
parents:
1199
diff
changeset
|
780 frameline.duplicateGroup.setAttribute('style', 'display: none') |
213f03dbfc41
Fix issue of removing a scene
Thinker K.F. Li <thinker@codemud.net>
parents:
1199
diff
changeset
|
781 except AttributeError: |
1144
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
782 pass |
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
783 pass |
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
784 |
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
|
785 def extendScene(self): |
1190
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
786 frame_idx = self.last_frame |
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
787 frameline = self.last_line |
1193
0e3a65b7b00c
Simplify extendScened()
Thinker K.F. Li <thinker@codemud.net>
parents:
1192
diff
changeset
|
788 |
0e3a65b7b00c
Simplify extendScened()
Thinker K.F. Li <thinker@codemud.net>
parents:
1192
diff
changeset
|
789 start, end, scene_type = frameline.get_frame_block_floor(frame_idx) |
0e3a65b7b00c
Simplify extendScened()
Thinker K.F. Li <thinker@codemud.net>
parents:
1192
diff
changeset
|
790 if frame_idx <= end: |
0e3a65b7b00c
Simplify extendScened()
Thinker K.F. Li <thinker@codemud.net>
parents:
1192
diff
changeset
|
791 return |
0e3a65b7b00c
Simplify extendScened()
Thinker K.F. Li <thinker@codemud.net>
parents:
1192
diff
changeset
|
792 |
0e3a65b7b00c
Simplify extendScened()
Thinker K.F. Li <thinker@codemud.net>
parents:
1192
diff
changeset
|
793 if start < end: |
0e3a65b7b00c
Simplify extendScened()
Thinker K.F. Li <thinker@codemud.net>
parents:
1192
diff
changeset
|
794 frameline.rm_keyframe(end) |
956 | 795 pass |
1193
0e3a65b7b00c
Simplify extendScened()
Thinker K.F. Li <thinker@codemud.net>
parents:
1192
diff
changeset
|
796 |
0e3a65b7b00c
Simplify extendScened()
Thinker K.F. Li <thinker@codemud.net>
parents:
1192
diff
changeset
|
797 scene_node = frameline.get_frame_data(start) |
1207
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
798 self.chg_scene_node(scene_node, end=frame_idx) |
1193
0e3a65b7b00c
Simplify extendScened()
Thinker K.F. Li <thinker@codemud.net>
parents:
1192
diff
changeset
|
799 frameline.add_keyframe(frame_idx) |
0e3a65b7b00c
Simplify extendScened()
Thinker K.F. Li <thinker@codemud.net>
parents:
1192
diff
changeset
|
800 frameline.tween(start, scene_type) |
956 | 801 pass |
802 | |
1194
319414e4d87a
Fix the issue that is fault to switch scenes
Thinker K.F. Li <thinker@codemud.net>
parents:
1193
diff
changeset
|
803 def setCurrentScene(self, idx): |
1123 | 804 """ |
1144
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
805 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
|
806 data. There are a couple of cases. |
1148 | 807 1. If the type of the scene is normal, we display it when |
808 it contains the current frame. Otherwise hide it. | |
809 2. If the type of the scene is relocate or scale, we need | |
810 to duplicate the scene group and then modify its | |
811 transform matrix according to the definition of the | |
812 scene. Then, hide the original scenr group and display | |
813 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
|
814 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
|
815 |
1148 | 816 For each layer, we will always use the duplicated scene |
817 group whose name as dup. | |
818 We will put the duplicated scene group inside it. We will | |
819 create this group if it is not | |
1123 | 820 available. |
821 """ | |
1194
319414e4d87a
Fix the issue that is fault to switch scenes
Thinker K.F. Li <thinker@codemud.net>
parents:
1193
diff
changeset
|
822 self.current = idx |
1140 | 823 self.tween.updateMapping() |
1190
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
824 for frameline in self._framelines: |
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
|
825 i=0 |
1123 | 826 |
1207
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
827 # Check the duplicated scene group and create it if it is not |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
828 # available |
1123 | 829 try: |
1190
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
830 frameline.duplicateGroup.setAttribute("style","display:none") |
1123 | 831 except: |
1199
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
832 print "*" * 40 |
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
833 layer_idx = frameline.layer_idx |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
834 layer = self._layers[layer_idx] |
1199
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
835 for child in layer.group.childList(): |
1219 | 836 try: |
837 label = child.getAttribute('inkscape:label') | |
838 if label == 'dup': | |
839 frameline.duplicateGroup = child | |
840 break | |
841 except: | |
842 pass | |
1199
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
843 pass |
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
844 else: |
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
845 duplicateGroup = self.document.createElement("svg:g") |
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
846 duplicateGroup.setAttribute("inkscape:label","dup") |
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
847 duplicateGroup.setAttribute("sodipodi:insensitive","1") |
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
848 duplicateGroup.setAttribute("style","") |
1204
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
849 |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
850 layer.group.appendChild(duplicateGroup) |
1199
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
851 frameline.duplicateGroup = duplicateGroup |
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
852 pass |
1123 | 853 pass |
1199
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
854 |
1123 | 855 # Create a new group |
1190
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
856 for start_idx, stop_idx, tween_type in frameline.get_frame_blocks(): |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
857 if start_idx == stop_idx: |
1190
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
858 scene_node = frameline.get_frame_data(start_idx) |
1194
319414e4d87a
Fix the issue that is fault to switch scenes
Thinker K.F. Li <thinker@codemud.net>
parents:
1193
diff
changeset
|
859 scene_group_id = scene_node.getAttribute('ref') |
319414e4d87a
Fix the issue that is fault to switch scenes
Thinker K.F. Li <thinker@codemud.net>
parents:
1193
diff
changeset
|
860 scene_group = self.get_node(scene_group_id) |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
861 if idx == start_idx: |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
862 scene_group.setAttribute('style', '') |
973
84f502fb3e40
Rewrite the MBScene to use framelines. The old layers/scenes data structure is used to load the scenes only. We should remove it completely in the future.
wycc
parents:
964
diff
changeset
|
863 else: |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
864 scene_group.setAttribute('style', 'display: none') |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
865 pass |
1155
5db4d769387c
Show the frame when we select the keyframe. The duplicated group must be shown only in the tweened frame
wycc
parents:
1151
diff
changeset
|
866 elif idx == start_idx: |
1190
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
867 frameline.duplicateGroup.setAttribute("style","display:none") |
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
868 scene_node = frameline.get_frame_data(start_idx) |
1196
42f8cee2118b
Fix the issue that is falut to show first frame of a tween
Thinker K.F. Li <thinker@codemud.net>
parents:
1195
diff
changeset
|
869 scene_group_id = scene_node.getAttribute('ref') |
42f8cee2118b
Fix the issue that is falut to show first frame of a tween
Thinker K.F. Li <thinker@codemud.net>
parents:
1195
diff
changeset
|
870 scene_group = self.get_node(scene_group_id) |
1155
5db4d769387c
Show the frame when we select the keyframe. The duplicated group must be shown only in the tweened frame
wycc
parents:
1151
diff
changeset
|
871 scene_group.setAttribute("style","") |
1199
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
872 elif start_idx < idx and stop_idx >= idx: |
1190
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
873 scene_node = frameline.get_frame_data(start_idx) |
1194
319414e4d87a
Fix the issue that is fault to switch scenes
Thinker K.F. Li <thinker@codemud.net>
parents:
1193
diff
changeset
|
874 scene_group_id = scene_node.getAttribute('ref') |
319414e4d87a
Fix the issue that is fault to switch scenes
Thinker K.F. Li <thinker@codemud.net>
parents:
1193
diff
changeset
|
875 scene_group = self.get_node(scene_group_id) |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
876 scene_group.setAttribute("style","display:none") |
1190
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
877 frameline.duplicateGroup.setAttribute("style","") |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
878 tween_type_idx = \ |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
879 self._frameline_tween_types.index(tween_type) |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
880 tween_obj_tween_type = \ |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
881 self._tween_obj_tween_types[tween_type_idx] |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
882 |
1180
bfd7d466a022
Fix yeiling error message when select a scene.
Thinker K.F. Li <thinker@codemud.net>
parents:
1179
diff
changeset
|
883 try: |
bfd7d466a022
Fix yeiling error message when select a scene.
Thinker K.F. Li <thinker@codemud.net>
parents:
1179
diff
changeset
|
884 next_idx, next_stop_idx, next_tween_type = \ |
1190
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
885 frameline.get_frame_block(stop_idx + 1) |
1180
bfd7d466a022
Fix yeiling error message when select a scene.
Thinker K.F. Li <thinker@codemud.net>
parents:
1179
diff
changeset
|
886 except: |
1190
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
887 next_scene_node = scene_node |
1163 | 888 else: |
1190
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
889 next_scene_node = frameline.get_frame_data(next_idx) |
1180
bfd7d466a022
Fix yeiling error message when select a scene.
Thinker K.F. Li <thinker@codemud.net>
parents:
1179
diff
changeset
|
890 pass |
1194
319414e4d87a
Fix the issue that is fault to switch scenes
Thinker K.F. Li <thinker@codemud.net>
parents:
1193
diff
changeset
|
891 |
319414e4d87a
Fix the issue that is fault to switch scenes
Thinker K.F. Li <thinker@codemud.net>
parents:
1193
diff
changeset
|
892 next_scene_group_id = next_scene_node.getAttribute('ref') |
319414e4d87a
Fix the issue that is fault to switch scenes
Thinker K.F. Li <thinker@codemud.net>
parents:
1193
diff
changeset
|
893 next_scene_group = self.get_node(next_scene_group_id) |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
894 |
1160
1a699dc00fa3
Fix the issue of not removing node in old scene when switching scenes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1159
diff
changeset
|
895 nframes = stop_idx - start_idx + 1 |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
896 percent = float(idx - start_idx) / nframes |
1190
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
897 self.tween.updateTweenContent(frameline.duplicateGroup, |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
898 tween_obj_tween_type, |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
899 scene_group, |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
900 next_scene_group, |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
901 percent) |
959
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
902 else: |
1190
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
903 scene_node = frameline.get_frame_data(start_idx) |
1194
319414e4d87a
Fix the issue that is fault to switch scenes
Thinker K.F. Li <thinker@codemud.net>
parents:
1193
diff
changeset
|
904 scene_group_id = scene_node.getAttribute('ref') |
319414e4d87a
Fix the issue that is fault to switch scenes
Thinker K.F. Li <thinker@codemud.net>
parents:
1193
diff
changeset
|
905 scene_group = self.get_node(scene_group_id) |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
906 scene_group.setAttribute("style","display:none") |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
907 pass |
955
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
908 pass |
956 | 909 pass |
910 pass | |
1125 | 911 |
1191
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
912 def enterGroup(self, obj): |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
913 for l in self._layers: |
1190
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
914 for s in l.group.childList(): |
1139
a2b068594412
Use pybind with new DOM API (at PYNode).
Thinker K.F. Li <thinker@codemud.net>
parents:
1136
diff
changeset
|
915 if s.getAttribute('id') == obj.getAttribute("id"): |
1142
dd6c60c6f41e
Use getAttribute()/spitem instead of .label and DOMtoItem().
Thinker K.F. Li <thinker@codemud.net>
parents:
1141
diff
changeset
|
916 self.desktop.setCurrentLayer(s.spitem) |
1144
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
917 pass |
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
918 pass |
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
919 pass |
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
920 pass |
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
921 |
1178
416e41952b76
Fix issue that pyink does not switch current layer to the new key scene.
Thinker K.F. Li <thinker@codemud.net>
parents:
1177
diff
changeset
|
922 def selectSceneObject(self, frameline, frame_idx): |
1177
ec1ea8555911
Stop selectSceneObject() from using private variable _keys of frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1176
diff
changeset
|
923 try: |
1178
416e41952b76
Fix issue that pyink does not switch current layer to the new key scene.
Thinker K.F. Li <thinker@codemud.net>
parents:
1177
diff
changeset
|
924 start, stop, tween_type = frameline.get_frame_block(frame_idx) |
1177
ec1ea8555911
Stop selectSceneObject() from using private variable _keys of frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1176
diff
changeset
|
925 except: |
ec1ea8555911
Stop selectSceneObject() from using private variable _keys of frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1176
diff
changeset
|
926 return |
1070
afa42d5836cc
Call setCurrentLayer to enter the current scene group.
wycc
parents:
1064
diff
changeset
|
927 |
1190
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
928 scene_node = frameline.get_frame_data(start) |
1191
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
929 scene_group_id = scene_node.getAttribute('ref') |
6442fb198418
Refactory insertKeyScene() and fix bug of ObjectWatcher
Thinker K.F. Li <thinker@codemud.net>
parents:
1190
diff
changeset
|
930 scene_group = self.get_node(scene_group_id) |
1177
ec1ea8555911
Stop selectSceneObject() from using private variable _keys of frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1176
diff
changeset
|
931 self.enterGroup(scene_group) |
ec1ea8555911
Stop selectSceneObject() from using private variable _keys of frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1176
diff
changeset
|
932 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
|
933 pass |
1144
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
934 |
1150
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1149
diff
changeset
|
935 def setTweenType(self, tween_type): |
1210
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
936 sel_type = self._frameline_tween_types.index(tween_type) |
1150
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1149
diff
changeset
|
937 self._disable_tween_type_selector = True |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1149
diff
changeset
|
938 self.tweenTypeSelector.set_active(sel_type) |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1149
diff
changeset
|
939 self._disable_tween_type_selector = False |
1144
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
940 pass |
955
53b0f8dc2284
Add tailing 'pass' commands to close indents
Thinker K.F. Li <thinker@codemud.net>
parents:
943
diff
changeset
|
941 |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
942 ## \brief Remove the layer that lost the layer group. |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
943 # |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
944 # This function is called when a layer group being removed from the |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
945 # DOM-tree. |
1204
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
946 def _remove_lost_group_layer(self, layer_idx): |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
947 layer = self._layers[layer_idx] |
1204
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
948 frameline = self._framelines[layer_idx] |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
949 for start, end, tween_type in frameline.get_frame_blocks(): |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
950 scene_node = frameline.get_frame_data(start) |
1207
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
951 self.rm_scene_node(scene_node) |
1204
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
952 pass |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
953 |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
954 self._remove_frameline(layer_idx) # TODO |
1210
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
955 self._show_framelines() |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
956 del self._layers[layer_idx] |
1204
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
957 pass |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
958 |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
959 ## \brief Make status of layers is updated when DOM is changed. |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
960 # |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
961 # When DOM-tree is changed, this function make sure layer information is up |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
962 # to date. |
1204
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
963 def _make_layers_integral(self): |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
964 root = self._root |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
965 root_id = root.getAttribute('id') |
959
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
966 |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
967 # Remove group of removed layers |
1204
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
968 layer_idx = 0 |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
969 while layer_idx < len(self._layers): |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
970 layer = self._layers[layer_idx] |
1204
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
971 |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
972 if layer.group.name() != 'svg:g': |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
973 self._remove_lost_group_layer(layer_idx) # TODO |
1204
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
974 continue |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
975 |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
976 parent = layer.group.parent() |
1210
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
977 |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
978 if not parent: # parent is None when a node being removed from |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
979 # DOM-tree. |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
980 self._remove_lost_group_layer(layer_idx) |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
981 continue |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
982 |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
983 if parent.name() != 'svg:svg': |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
984 self._remove_lost_group_layer(layer_idx) |
1204
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
985 continue |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
986 |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
987 if parent.getAttribute('id') != root_id: |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
988 self._remove_lost_group_layer(layer_idx) |
1204
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
989 continue |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
990 |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
991 layer_idx = layer_idx + 1 |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
992 pass |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
993 |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
994 # Add new layers |
1204
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
995 layer_idx = 0 |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
996 for child in root.childList(): |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
997 if child.name() != 'svg:g': |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
998 continue |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
999 |
1210
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
1000 try: |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
1001 layer = self._layers[layer_idx] |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
1002 except IndexError: |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
1003 layer = None |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
1004 else: |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
1005 layer_group_id = layer.group.getAttribute('id') |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
1006 pass |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
1007 |
1204
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
1008 child_id = child.getAttribute('id') |
1210
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
1009 if (not layer) or layer_group_id != child_id: |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
1010 self.add_layer(layer_idx, child) |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
1011 self.parse_layer(layer_idx) |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
1012 self._add_frameline(layer_idx) |
1212
962a6fec2198
Set a label for every frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1211
diff
changeset
|
1013 |
962a6fec2198
Set a label for every frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1211
diff
changeset
|
1014 layer = self._layers[layer_idx] |
962a6fec2198
Set a label for every frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1211
diff
changeset
|
1015 frameline = self._framelines[layer_idx] |
962a6fec2198
Set a label for every frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1211
diff
changeset
|
1016 try: |
962a6fec2198
Set a label for every frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1211
diff
changeset
|
1017 label = layer.group.getAttribute('inkscape:label') |
962a6fec2198
Set a label for every frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1211
diff
changeset
|
1018 except: |
962a6fec2198
Set a label for every frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1211
diff
changeset
|
1019 label = layer.group.getAttribute('id') |
962a6fec2198
Set a label for every frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1211
diff
changeset
|
1020 pass |
962a6fec2198
Set a label for every frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1211
diff
changeset
|
1021 frameline.label.set_text(label) |
962a6fec2198
Set a label for every frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1211
diff
changeset
|
1022 |
1210
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
1023 self._show_framelines() |
1204
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
1024 pass |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
1025 |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
1026 layer_idx = layer_idx + 1 |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
1027 pass |
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
1028 pass |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
1029 |
1217
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1030 ## \brief Update content of a frameline from scenes of respective layer. |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1031 # |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1032 def _update_frameline_content(self, layer_idx): |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1033 line = self._framelines[layer_idx] |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1034 layer = self._layers[layer_idx] |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1035 for scene_node in layer.scenes: |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1036 start, end, tween_name = self._parse_one_scene(scene_node) |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1037 |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1038 line.add_keyframe(start) |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1039 if start != end: |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1040 line.add_keyframe(end) |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1041 tween_type_idx = self._tween_type_names.index(tween_name) |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1042 tween_type = self._frameline_tween_types[tween_type_idx] |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1043 line.tween(start, tween_type) |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1044 pass |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1045 line.set_frame_data(start, scene_node) |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1046 pass |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1047 pass |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1048 |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1049 ## \brief Add a frameline for every found layer. |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1050 # |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1051 # This method is called to create a frameline for every layer found when |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1052 # loading a document. |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1053 # |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1054 def _add_frameline_for_every_layer(self): |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
1055 for layer_idx in range(len(self._layers)): |
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
1056 self._add_frameline(layer_idx) |
1212
962a6fec2198
Set a label for every frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1211
diff
changeset
|
1057 line = self._framelines[layer_idx] |
962a6fec2198
Set a label for every frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1211
diff
changeset
|
1058 layer = self._layers[layer_idx] |
962a6fec2198
Set a label for every frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1211
diff
changeset
|
1059 try: |
962a6fec2198
Set a label for every frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1211
diff
changeset
|
1060 label = layer.group.getAttribute('inkscape:label') |
962a6fec2198
Set a label for every frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1211
diff
changeset
|
1061 except: |
962a6fec2198
Set a label for every frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1211
diff
changeset
|
1062 label = layer.group.getAttribute('id') |
962a6fec2198
Set a label for every frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1211
diff
changeset
|
1063 pass |
962a6fec2198
Set a label for every frameline
Thinker K.F. Li <thinker@codemud.net>
parents:
1211
diff
changeset
|
1064 line.label.set_text(label) |
1217
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1065 |
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1066 self._update_frameline_content(layer_idx) |
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
|
1067 pass |
959
67823f7a0a17
Use frameline module in MBScene
Thinker K.F. Li <thinker@codemud.net>
parents:
957
diff
changeset
|
1068 pass |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
1069 |
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
|
1070 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
|
1071 # Search for the current scene |
1195
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
1072 frameline = self.last_line |
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
1073 frame_idx = self.last_frame |
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
1074 |
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
1075 try: |
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
1076 start, end, scene_type = frameline.get_frame_block_floor(frame_idx) |
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
1077 except: |
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
1078 return |
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
1079 if end >= frame_idx: |
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
1080 return |
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
1081 |
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
1082 prev_scene_node = frameline.get_frame_data(start) |
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
1083 prev_scene_group_id = prev_scene_node.getAttribute('ref') |
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
1084 |
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
1085 scene_group = self.duplicateSceneGroup(prev_scene_group_id) |
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
1086 scene_group_id = scene_group.getAttribute('id') |
1207
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1087 scene_node = self.add_scene_node(frame_idx, frame_idx, |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1088 ref=scene_group_id) |
1195
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
1089 |
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
1090 frameline.add_keyframe(frame_idx, scene_node) |
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
1091 |
cb2c611d1656
Fix bug of duplicating a keyframe
Thinker K.F. Li <thinker@codemud.net>
parents:
1194
diff
changeset
|
1092 self.setCurrentScene(frame_idx) |
1144
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
1093 pass |
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
1094 |
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
|
1095 def duplicateSceneGroup(self,gid): |
52d8bf5d12b4
Implement the function to duplicate the previous scene. This require the latest inkscape-pybind, which contains duplicate() for the Node
wycc
parents:
1070
diff
changeset
|
1096 # 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
|
1097 root = self._root |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1098 doc = self._doc |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1099 orig = self.get_node(gid) |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1100 scene_group = orig.duplicate(doc) |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
1101 |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
1102 old_nodes = _travel_DOM(orig) |
1190
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
1103 new_nodes = _travel_DOM(scene_group) |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
1104 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
|
1105 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
|
1106 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
|
1107 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
|
1108 pass |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
1109 |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
1110 layer = self._layers[self.last_line.layer_idx] |
1204
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
1111 gid = layer.group.getAttribute("inkscape:label")+self.new_id() |
1190
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
1112 scene_group.setAttribute("id",gid) |
a4df892fb4e5
Use meaningful name for scene, scene group, and layer group
Thinker K.F. Li <thinker@codemud.net>
parents:
1189
diff
changeset
|
1113 scene_group.setAttribute("inkscape:groupmode","layer") |
1204
78925515836f
Add methods for managing framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1203
diff
changeset
|
1114 layer.group.appendChild(scene_group) |
1193
0e3a65b7b00c
Simplify extendScened()
Thinker K.F. Li <thinker@codemud.net>
parents:
1192
diff
changeset
|
1115 return scene_group |
956 | 1116 |
1207
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1117 def changeObjectLabel(self,w): |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1118 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
|
1119 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
|
1120 pass |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1121 |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1122 def addNameEditor(self,hbox): |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1123 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
|
1124 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
|
1125 self.editDone = gtk.Button('Set') |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1126 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
|
1127 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
|
1128 pass |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1129 |
1210
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
1130 def updateUI(self, *args): |
1207
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1131 if self._lockui: return |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1132 |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1133 if self.last_update!= None: |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1134 glib.source_remove(self.last_update) |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1135 self.last_update = glib.timeout_add(300,self._updateUI) |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1136 |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1137 pass |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1138 |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1139 def _updateUI(self,node=None,arg=None): |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1140 self._lockui = True |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1141 self._make_layers_integral() |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1142 self._lockui = False |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1143 pass |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1144 |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1145 def onCellClick(self, line, frame, but): |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1146 self.last_line = line |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1147 self.last_frame = frame |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1148 self.last_line.active_frame(frame) |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1149 self._lockui = True |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1150 self.doEditScene(None) |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1151 self._lockui = False |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1152 pass |
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1153 |
1178
416e41952b76
Fix issue that pyink does not switch current layer to the new key scene.
Thinker K.F. Li <thinker@codemud.net>
parents:
1177
diff
changeset
|
1154 def doEditScene(self, w): |
1194
319414e4d87a
Fix the issue that is fault to switch scenes
Thinker K.F. Li <thinker@codemud.net>
parents:
1193
diff
changeset
|
1155 self.setCurrentScene(self.last_frame) |
1179
b65df4f0d30a
Change signature of MBScene.insertKeyScene()
Thinker K.F. Li <thinker@codemud.net>
parents:
1178
diff
changeset
|
1156 self.selectSceneObject(self.last_line, self.last_frame) |
956 | 1157 pass |
1158 | |
1159 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
|
1160 self._lockui=True |
1179
b65df4f0d30a
Change signature of MBScene.insertKeyScene()
Thinker K.F. Li <thinker@codemud.net>
parents:
1178
diff
changeset
|
1161 self.insertKeyScene(self.last_line, self.last_frame) |
1178
416e41952b76
Fix issue that pyink does not switch current layer to the new key scene.
Thinker K.F. Li <thinker@codemud.net>
parents:
1177
diff
changeset
|
1162 self.selectSceneObject(self.last_line, self.last_frame) |
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
|
1163 self._lockui=False |
956 | 1164 # self.grid.show_all() |
1165 return | |
1144
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
1166 |
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
|
1167 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
|
1168 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
|
1169 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
|
1170 self._lockui = False |
956 | 1171 |
1172 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
|
1173 self._lockui = True |
1200
213f03dbfc41
Fix issue of removing a scene
Thinker K.F. Li <thinker@codemud.net>
parents:
1199
diff
changeset
|
1174 self.removeKeyScene(self.last_line, self.last_frame) |
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
|
1175 self._lockui = False |
956 | 1176 return |
941
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
1177 |
956 | 1178 |
1179 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
|
1180 self._lockui = True |
956 | 1181 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
|
1182 self._lockui = False |
956 | 1183 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
|
1184 |
1147 | 1185 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
|
1186 """ |
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
|
1187 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
|
1188 """ |
1147 | 1189 if self.btnRun.get_label() == "Run": |
1190 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
|
1191 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>
diff
changeset
|
1192 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>
diff
changeset
|
1193 self.last_update = glib.timeout_add(tmout, self.doRunNext) |
1147 | 1194 else: |
1195 self.btnRun.set_label("Run") | |
1196 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
|
1197 self._lockui = False |
1161
a7faab54e8f8
Fix broken of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1160
diff
changeset
|
1198 pass |
1206
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
1199 pass |
1147 | 1200 |
1201 def doRunNext(self): | |
1206
1d476b35dc79
Merge and move code of tracking max frame number to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
diff
changeset
|
1202 if self.current > self._maxframe: |
1147 | 1203 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>
diff
changeset
|
1204 pass |
1161
a7faab54e8f8
Fix broken of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1160
diff
changeset
|
1205 try: |
1194
319414e4d87a
Fix the issue that is fault to switch scenes
Thinker K.F. Li <thinker@codemud.net>
parents:
1193
diff
changeset
|
1206 self.setCurrentScene(self.current) |
1161
a7faab54e8f8
Fix broken of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1160
diff
changeset
|
1207 except: |
a7faab54e8f8
Fix broken of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1160
diff
changeset
|
1208 traceback.print_exc() |
a7faab54e8f8
Fix broken of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1160
diff
changeset
|
1209 raise |
1199
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1198
diff
changeset
|
1210 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>
diff
changeset
|
1211 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>
diff
changeset
|
1212 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>
diff
changeset
|
1213 pass |
1174 | 1214 |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1215 def remove_frame(self, line, frame): |
1219 | 1216 for start, end, tween_type in line.get_frame_blocks(): |
1217 if frame > end: | |
1218 # Don't change the tween before the select frame | |
1219 continue | |
1220 elif frame == start: | |
1221 # Please use remove key frame ro remove the key frame instead | |
1222 return | |
1223 elif frame < start: | |
1224 # For all tweens after the frame, shift both key frames by one | |
1225 scene_node = line.get_frame_data(start) | |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1226 self.chg_scene_node(scene_node, start=start-1, end=end-1) |
1219 | 1227 line.rm_keyframe(start) |
1228 | |
1229 if start != end: | |
1230 line.rm_keyframe(end) | |
1231 line.add_keyframe(start-1) | |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1232 line.set_frame_data(start-1, scene_node) |
1219 | 1233 if start != end: |
1234 line.add_keyframe(end-1) | |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1235 line.tween(start-1, tween_type) |
1219 | 1236 pass |
1237 else: | |
1238 # For the tween contain the frame, remove the end keyframe | |
1239 # and put it back one frame before. The tween is removed | |
1240 # if the tween has one frame only. In this case, keep only | |
1241 # the start key frame and remove the second one. | |
1242 scene_node = line.get_frame_data(start) | |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1243 self.chg_scene_node(scene_node, end=end-1) |
1219 | 1244 line.rm_keyframe(end) |
1245 if start != end-1: | |
1246 line.add_keyframe(end-1) | |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1247 line.tween(start, tween_type) |
1219 | 1248 pass |
1249 pass | |
1250 pass | |
1251 | |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1252 def insert_frame(self, line, frame): |
1219 | 1253 for start, end, tween_type in line.get_frame_blocks(): |
1254 print "start=",start | |
1255 print "end=",end | |
1256 if frame > end: | |
1257 # Don't change the tween before the select frame | |
1258 continue | |
1259 elif frame <= start: | |
1260 # For all tweens after the frame, shift both key frames by one | |
1261 scene_node = line.get_frame_data(start) | |
1262 if scene_node==None: continue | |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1263 self.chg_scene_node(scene_node, start=start+1, end=end+1) |
1219 | 1264 line.rm_keyframe(start) |
1265 if start != end: | |
1266 line.rm_keyframe(end) | |
1267 line.add_keyframe(start+1) | |
1268 line.set_frame_data(start+1,scene_node) | |
1269 if start != end: | |
1270 line.add_keyframe(end+1) | |
1271 line.tween(start+1,tween_type) | |
1272 pass | |
1273 else: | |
1274 # For the tween contain the frame, remove the end keyframe | |
1275 # and put it back one frame before. The tween is removed | |
1276 # if the tween has one frame only. In this case, keep only | |
1277 # the start key frame and remove the second one. | |
1278 scene_node = line.get_frame_data(start) | |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1279 self.chg_scene_node(scene_node, end=end+1) |
1219 | 1280 line.rm_keyframe(end) |
1281 line.add_keyframe(end+1) | |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1282 line.tween(start, tween_type) |
1219 | 1283 pass |
1284 pass | |
1285 pass | |
1286 | |
1287 | |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1288 def doInsertFrame(self, w): |
1219 | 1289 self.lockui=True |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1290 self.insert_frame(self.last_line, self.last_frame) |
1219 | 1291 self.lockui=False |
1292 | |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1293 def doRemoveFrame(self, w): |
1219 | 1294 self.lockui=True |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1295 self.remove_frame(self.last_line, self.last_frame) |
1219 | 1296 self.lockui=False |
1297 | |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1298 def addButtons(self, hbox): |
956 | 1299 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
|
1300 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
|
1301 hbox.pack_start(btn, expand=False, fill=False) |
1174 | 1302 |
956 | 1303 btn=gtk.Button('Remove Key') |
1304 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
|
1305 hbox.pack_start(btn, expand=False, fill=False) |
1174 | 1306 |
956 | 1307 btn=gtk.Button('Extend scene') |
1308 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
|
1309 hbox.pack_start(btn, expand=False, fill=False) |
1174 | 1310 |
1311 btn=gtk.Button('Duplicate Key') | |
1312 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
|
1313 hbox.pack_start(btn, expand=False, fill=False) |
1174 | 1314 |
1219 | 1315 btn=gtk.Button('insert') |
1316 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
|
1317 hbox.pack_start(btn, expand=False, fill=False) |
1219 | 1318 |
1319 btn=gtk.Button('remove') | |
1320 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
|
1321 hbox.pack_start(btn, expand=False, fill=False) |
1219 | 1322 |
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
|
1323 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
|
1324 btn.connect('clicked', self.doRun) |
1147 | 1325 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
|
1326 hbox.pack_start(btn, expand=False, fill=False) |
1174 | 1327 |
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
|
1328 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
|
1329 self.addTweenTypeSelector(hbox) |
956 | 1330 pass |
1144
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
1331 |
1150
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1149
diff
changeset
|
1332 def onTweenTypeChange(self, w): |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1149
diff
changeset
|
1333 if self._disable_tween_type_selector: |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1149
diff
changeset
|
1334 return |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1149
diff
changeset
|
1335 |
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
|
1336 if self.last_line == None: |
214e1f628d63
Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents:
1099
diff
changeset
|
1337 return |
214e1f628d63
Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents:
1099
diff
changeset
|
1338 frameline = self.last_line |
1197
8c5492b096f1
Fix bug of changing tween type
Thinker K.F. Li <thinker@codemud.net>
parents:
1196
diff
changeset
|
1339 start, end, old_tween_type = frameline.get_frame_block(self.last_frame) |
8c5492b096f1
Fix bug of changing tween type
Thinker K.F. Li <thinker@codemud.net>
parents:
1196
diff
changeset
|
1340 |
8c5492b096f1
Fix bug of changing tween type
Thinker K.F. Li <thinker@codemud.net>
parents:
1196
diff
changeset
|
1341 type_idx = self.tweenTypeSelector.get_active() |
1210
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
1342 tween_type = self._frameline_tween_types[type_idx] |
1197
8c5492b096f1
Fix bug of changing tween type
Thinker K.F. Li <thinker@codemud.net>
parents:
1196
diff
changeset
|
1343 type_name = self._tween_type_names[type_idx] |
8c5492b096f1
Fix bug of changing tween type
Thinker K.F. Li <thinker@codemud.net>
parents:
1196
diff
changeset
|
1344 |
8c5492b096f1
Fix bug of changing tween type
Thinker K.F. Li <thinker@codemud.net>
parents:
1196
diff
changeset
|
1345 frameline.tween(start, tween_type) |
8c5492b096f1
Fix bug of changing tween type
Thinker K.F. Li <thinker@codemud.net>
parents:
1196
diff
changeset
|
1346 |
8c5492b096f1
Fix bug of changing tween type
Thinker K.F. Li <thinker@codemud.net>
parents:
1196
diff
changeset
|
1347 scene_node = frameline.get_frame_data(start) |
1207
489e6e474fdf
Change names of methods and grouping methods
Thinker K.F. Li <thinker@codemud.net>
parents:
1206
diff
changeset
|
1348 self.chg_scene_node(scene_node, tween_type=type_name) |
1144
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
1349 pass |
1120
214e1f628d63
Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents:
1099
diff
changeset
|
1350 |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1351 def addTweenTypeSelector(self, 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
|
1352 tweenbox = gtk.HBox() |
214e1f628d63
Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents:
1099
diff
changeset
|
1353 label = gtk.Label('Tween Type') |
214e1f628d63
Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents:
1099
diff
changeset
|
1354 tweenbox.pack_start(label) |
214e1f628d63
Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents:
1099
diff
changeset
|
1355 |
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
|
1356 self.tweenTypeSelector = gtk.combo_box_new_text() |
214e1f628d63
Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents:
1099
diff
changeset
|
1357 self.tweenTypeSelector.append_text('normal') |
1157
3a891dccabd8
Remove the locate tween. It is a special case for the scale tween
wycc
parents:
1155
diff
changeset
|
1358 #self.tweenTypeSelector.append_text('relocate') |
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
|
1359 self.tweenTypeSelector.append_text('scale') |
214e1f628d63
Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents:
1099
diff
changeset
|
1360 self.tweenTypeSelector.set_active(0) |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1361 tweenbox.pack_start(self.tweenTypeSelector, expand=False, fill=False) |
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1362 hbox.pack_start(tweenbox, expand=False, fill=False) |
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
|
1363 self.tweenTypeSelector.connect('changed', self.onTweenTypeChange) |
1144
257beac7c982
Add blank line between methods.
Thinker K.F. Li <thinker@codemud.net>
parents:
1142
diff
changeset
|
1364 pass |
956 | 1365 |
1366 def onQuit(self, event): | |
1367 self.OK = False | |
1368 gtk.main_quit() | |
1369 pass | |
1370 | |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1371 def onOK(self, event): |
956 | 1372 self.OK = True |
1373 gtk.main_quit() | |
1374 pass | |
941
9ba94c577a6f
Add scene editor. This vewrsion can only switch scene. It can not change the scene yet.
wycc
parents:
diff
changeset
|
1375 |
956 | 1376 def show(self): |
1377 self.OK = True | |
1149
0ffef2df6201
Rename MBScene.dom to MBScene.root
Thinker K.F. Li <thinker@codemud.net>
parents:
1148
diff
changeset
|
1378 if not self.root: |
0ffef2df6201
Rename MBScene.dom to MBScene.root
Thinker K.F. Li <thinker@codemud.net>
parents:
1148
diff
changeset
|
1379 self.root = self.desktop.doc().root().repr |
0ffef2df6201
Rename MBScene.dom to MBScene.root
Thinker K.F. Li <thinker@codemud.net>
parents:
1148
diff
changeset
|
1380 pass |
0ffef2df6201
Rename MBScene.dom to MBScene.root
Thinker K.F. Li <thinker@codemud.net>
parents:
1148
diff
changeset
|
1381 |
1128
b65ac686a7c5
Switch to the DOM-like API. The SPObject become the base of the DOM-like API.
wycc
parents:
1125
diff
changeset
|
1382 self.document = self.desktop.doc().rdoc |
1188
45e3a9273af2
Move code about monitoring DOM-tree to MBScene_dom_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1185
diff
changeset
|
1383 self.handle_doc_root(self.document, self.root) |
1149
0ffef2df6201
Rename MBScene.dom to MBScene.root
Thinker K.F. Li <thinker@codemud.net>
parents:
1148
diff
changeset
|
1384 self.tween = TweenObject(self.document, self.root) |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
1385 self._init_framelines() |
1217
93acb8568ad3
Update frameline when loading a document
Thinker K.F. Li <thinker@codemud.net>
parents:
1216
diff
changeset
|
1386 self._add_frameline_for_every_layer() |
1210
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
1387 self._show_framelines() |
1205
1af64bcdfd7d
Move to MBScene._make_layers_integral()
Thinker K.F. Li <thinker@codemud.net>
parents:
1204
diff
changeset
|
1388 |
1064
16c69756ef5d
Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents:
1032
diff
changeset
|
1389 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
|
1390 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>
diff
changeset
|
1391 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
|
1392 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
|
1393 else: |
16c69756ef5d
Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents:
1032
diff
changeset
|
1394 self.top.remove(self.startWindow) |
1150
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1149
diff
changeset
|
1395 pass |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1149
diff
changeset
|
1396 |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1397 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
|
1398 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
|
1399 self.top.pack_start(vbox, expand=False) |
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1400 vbox.pack_start(self._frameline_box, expand=False) |
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1401 hbox=gtk.HBox(False, 0) |
981 | 1402 self.addButtons(hbox) |
1222
03daff2d939c
Add a space after every comma in an argument list
Thinker K.F. Li <thinker@codemud.net>
parents:
1220
diff
changeset
|
1403 vbox.pack_start(hbox, expand=False) |
981 | 1404 |
1210
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
1405 doc = self.document |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
1406 addEventListener(doc,'DOMNodeInserted', self.updateUI, None) |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
1407 addEventListener(doc,'DOMNodeRemoved', self.updateUI, None) |
3683e02b7482
Refactory frameline management code to MBScene_framelines
Thinker K.F. Li <thinker@codemud.net>
parents:
1209
diff
changeset
|
1408 |
1064
16c69756ef5d
Add NodeObserver to monitor the change of the layer and update it in the scene editor.
wycc
parents:
1032
diff
changeset
|
1409 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
|
1410 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
|
1411 return False |
956 | 1412 pass |