annotate pyink/domview.py @ 1275:776b024ae8f9

Fix the buggy implementation of reset() - old implementation is too buggy to make a lot wrong assumption.
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 12 Jan 2011 21:41:26 +0800
parents a4d3838264dd
children 0442ae9c2ac2
rev   line source
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1 import random
1253
07e0cb1e051d Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1247
diff changeset
2 import dom_event
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
3 from tween import TweenObject
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
4
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
5 class Layer:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
6 def __init__(self, node):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
7 self.scenes = []
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
8 self.group = node
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
9 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
10 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
11
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
12 ## \brief Monitor changes of DOM-tree.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
13 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
14 # This class monitors DOM-tree to maintain _maxframe and maps for node ID to
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
15 # node and scene group ID to scene node.
1244
b241f9768833 Remove MBScene_ from the prefix of class names.
Thinker K.F. Li <thinker@codemud.net>
parents: 1243
diff changeset
16 class domview_monitor(object):
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
17 def __init__(self, *args, **kws):
1244
b241f9768833 Remove MBScene_ from the prefix of class names.
Thinker K.F. Li <thinker@codemud.net>
parents: 1243
diff changeset
18 super(domview_monitor, self).__init__()
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
19
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
20 self._maxframe = 0
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
21 self._id2node = {} # map ID to the node in the DOM tree.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
22 self._group2scene = {} # map ID of a group to associated scene node.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
23 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
24
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
25 def _start_monitor(self):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
26 self._collect_node_ids()
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
27 self._collect_all_scenes()
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
28
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
29 doc = self._doc
1253
07e0cb1e051d Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1247
diff changeset
30 dom_event.addEventListener(doc, 'DOMNodeInserted',
07e0cb1e051d Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1247
diff changeset
31 self._on_insert_node, None)
07e0cb1e051d Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1247
diff changeset
32 dom_event.addEventListener(doc, 'DOMNodeRemoved',
07e0cb1e051d Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1247
diff changeset
33 self._on_remove_node, None)
07e0cb1e051d Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1247
diff changeset
34 dom_event.addEventListener(doc, 'DOMAttrModified',
07e0cb1e051d Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1247
diff changeset
35 self._on_attr_modified, None)
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
36 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
37
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
38 def _on_insert_node(self, node, child):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
39 for cchild in child.childList():
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
40 self._on_insert_node(child, cchild)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
41 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
42
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
43 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
44 child_id = child.getAttribute('id')
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
45 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
46 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
47 else:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
48 if child_id not in self._id2node:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
49 self._id2node[child_id] = child
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
50 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
51 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
52
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
53 if child.name() == 'ns0:scene':
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
54 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
55 ref = child.getAttribute('ref')
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
56 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
57 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
58 else:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
59 if ref not in self._group2scene:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
60 self._group2scene[ref] = child
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
61 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
62 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
63
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
64 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
65 start = child.getAttribute('start')
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
66 self._maxframe = max(int(start), self._maxframe)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
67 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
68 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
69 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
70 start = child.getAttribute('end')
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
71 self._maxframe = max(int(start), self._maxframe)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
72 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
73 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
74 pass
1265
ca301f6abef7 Support undo for insert key frame/rm keyframe. We will refresh all layers and scenes since it is not feasible to collect these changes and update the layers and scenes. We may scan two level only in the future to improve the performance.
wycc
parents: 1262
diff changeset
75 pass
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
76
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
77 def _find_maxframe(self, scenes_node):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
78 maxframe = 0
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
79 for child in scenes_node.childList():
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
80 if child.name() != 'ns0:scene':
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
81 continue
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
82
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
83 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
84 start = child.getAttribute('start')
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
85 maxframe = max(int(start), maxframe)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
86 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
87 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
88 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
89 end = child.getAttribute('end')
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
90 maxframe = max(int(end), maxframe)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
91 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
92 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
93 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
94 return maxframe
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
95
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
96 def _on_remove_node(self, node, child):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
97 for cchild in child.childList():
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
98 self._on_remove_node(child, cchild)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
99 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
100
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
101 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
102 child_id = child.getAttribute('id')
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
103 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
104 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
105 else:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
106 if child_id not in self._id2node:
1269
97302d2a0a1d Raise an error for the error.
Thinker K.F. Li <thinker@codemud.net>
parents: 1265
diff changeset
107 raise ValueError, \
97302d2a0a1d Raise an error for the error.
Thinker K.F. Li <thinker@codemud.net>
parents: 1265
diff changeset
108 'remove a node that is never known (%s)' % (child_id)
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
109 del self._id2node[child_id]
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
110 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
111
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
112 if child.name() == 'ns0:scene':
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
113 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
114 ref = child.getAttribute('ref')
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
115 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
116 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
117 else:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
118 del self._group2scene[ref]
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
119 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
120
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
121 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
122 if node.name() == 'ns0:scenes' and \
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
123 (int(child.getAttribute('start')) == self._maxframe or
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
124 int(child.getAttribute('end')) == self._maxframe):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
125 self._maxframe = self._find_maxframe(node)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
126 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
127 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
128 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
129 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
130 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
131
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
132 def _on_attr_modified(self, node, name, old_value, new_value):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
133 if name == 'id' and old_value != new_value:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
134 if old_value and (old_value not in self._id2node):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
135 raise ValueError, \
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
136 'old ID value of passed node is invalid one (%s)' % \
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
137 (old_value)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
138 if (new_value in self._id2node):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
139 raise ValueError, \
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
140 'new ID value of passed node is invalid one (%s)' % \
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
141 (new_value)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
142
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
143 if old_value:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
144 del self._id2node[old_value]
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
145 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
146 self._id2node[new_value] = node
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
147 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
148 elif name == 'ref' and node.name() == 'ns0:scene':
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
149 if old_value == new_value:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
150 return
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
151 if old_value:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
152 node = self._group2scene[old_value] # use old node. Binding
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
153 # may generate a new
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
154 # wrapper.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
155 del self._group2scene[old_value]
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
156 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
157 if new_value:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
158 self._group2scene[new_value] = node
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
159 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
160 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
161 elif (name in ('start', 'end')) and node.name() == 'ns0:scene':
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
162 self._maxframe = max(int(new_value), self._maxframe)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
163 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
164 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
165
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
166 ## \brief Collect ID of nodes in the document.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
167 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
168 # It is used to implement a fast mapping from an ID to the respective node.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
169 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
170 def _collect_node_ids(self):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
171 self._id2node = {}
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
172 root = self._root
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
173 for n in root.childList():
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
174 self._collect_node_ids_recursive(n)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
175 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
176 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
177
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
178 def _collect_node_ids_recursive(self, node):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
179 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
180 node_id = node.getAttribute('id')
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
181 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
182 return
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
183
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
184 self._id2node[node_id] = node
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
185 for n in node.childList():
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
186 self._collect_node_ids_recursive(n)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
187 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
188 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
189
1274
a4d3838264dd Make public APIs being public for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1270
diff changeset
190 def parse_one_scene(self, scene_node):
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
191 assert scene_node.name() == 'ns0:scene'
1265
ca301f6abef7 Support undo for insert key frame/rm keyframe. We will refresh all layers and scenes since it is not feasible to collect these changes and update the layers and scenes. We may scan two level only in the future to improve the performance.
wycc
parents: 1262
diff changeset
192
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
193 start = int(scene_node.getAttribute("start"))
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
194 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
195 end = int(scene_node.getAttribute("end"))
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
196 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
197 end = start
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
198 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
199
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
200 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
201 scene_type = scene_node.getAttribute('type')
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
202 if scene_type == None:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
203 scene_type = 'normal'
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
204 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
205 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
206 scene_type = 'normal'
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
207 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
208
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
209 return start, end, scene_type
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
210
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
211 def _parse_one_scenes(self, scenes_node):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
212 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
213 cur = int(n.getAttribute("current"))
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
214 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
215 cur = 0
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
216 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
217 self.current = cur
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
218
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
219 for scene_node in scenes_node.childList():
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
220 if scene_node.name() != 'ns0:scene':
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
221 continue
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
222
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
223 try:
1274
a4d3838264dd Make public APIs being public for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1270
diff changeset
224 start, end, scene_type = self.parse_one_scene(scene_node)
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
225 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
226 continue
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
227
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
228 group_id = scene_node.getAttribute("ref")
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
229 self._group2scene[group_id] = scene_node
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
230 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
231 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
232
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
233 ## \brief Parse all scenes node in svg:metadata subtree.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
234 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
235 def _collect_all_scenes(self):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
236 root = self._root
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
237 for child in root.childList():
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
238 if child.name() != 'svg:metadata':
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
239 continue
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
240
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
241 metadata_node = child
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
242 for metachild in metadata_node.childList():
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
243 if metachild.name() == 'ns0:scenes':
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
244 self._parse_one_scenes(metachild)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
245 self._maxframe = self._find_maxframe(metachild)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
246 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
247 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
248 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
249 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
250
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
251 ## \brief Return the node with given ID.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
252 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
253 def get_node(self, node_id):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
254 return self._id2node[node_id]
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
255
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
256 ## \brief Return a scene node corresponding to a scene group of given ID.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
257 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
258 def get_scene(self, group_id):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
259 return self._group2scene[group_id]
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
260
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
261 def new_id(self):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
262 while True:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
263 candidate = 's%d' % int(random.random()*100000)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
264 if candidate not in self._id2node:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
265 return candidate
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
266 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
267 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
268 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
269
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
270
1246
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
271 ## \brief Iterator to travel a sub-tree of DOM.
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
272 #
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
273 def _DOM_iterator(node):
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
274 nodes = [node]
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
275 while nodes:
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
276 node = nodes.pop(0)
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
277 child = node.firstChild()
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
278 while child:
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
279 nodes.append(child)
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
280 child = child.next()
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
281 pass
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
282 yield node
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
283 pass
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
284 pass
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
285
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
286
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
287 ## \brief This layer provide a data view to the DOM-tree.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
288 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
289 # This class maintains layers information, and provides functions to create,
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
290 # change and destroy scene node and scene group. A scene node is a 'ns0:scene'
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
291 # in 'ns0:scenes' tag. A scene group is respective 'svg:g' for a scene.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
292 #
1244
b241f9768833 Remove MBScene_ from the prefix of class names.
Thinker K.F. Li <thinker@codemud.net>
parents: 1243
diff changeset
293 class domview(domview_monitor):
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
294 # Declare variables, here, for keeping tracking
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
295 _doc = None
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
296 _root = None
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
297
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
298 def __init__(self, *args, **kws):
1244
b241f9768833 Remove MBScene_ from the prefix of class names.
Thinker K.F. Li <thinker@codemud.net>
parents: 1243
diff changeset
299 super(domview, self).__init__()
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
300 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
301
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
302 ## \brief Create a scenes node if not existed.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
303 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
304 def _init_metadata(self):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
305 for node in self._root.childList():
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
306 if node.name() == 'svg:metadata':
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
307 break
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
308 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
309 else:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
310 raise RuntimeError, \
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
311 'can not find <svg:metadata> node in the document'
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
312
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
313 for n in node.childList():
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
314 if n.name() == 'ns0:scenes':
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
315 self._scenes_node = n
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
316 break
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
317 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
318 else:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
319 ns = "http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd"
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
320 self._root.setAttribute("xmlns:ns0", ns)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
321 scenes_node = self._doc.createElement("ns0:scenes")
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
322 node.appendChild(scenes_node)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
323 self._scenes_node = scenes_node
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
324 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
325 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
326
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
327 def _parse_all_layers(self):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
328 root = self._root
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
329 layers = self._layers
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
330
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
331 for child in root.childList():
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
332 if child.name() != 'svg:g':
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
333 continue
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
334
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
335 layer_group = child
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
336 layer = Layer(layer_group)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
337 layer.idx = len(layers)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
338 layers.append(layer)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
339 self.parse_layer(layer.idx)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
340 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
341 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
342
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
343 def handle_doc_root(self, doc, root):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
344 self._doc = doc
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
345 self._root = root
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
346 self._layers = []
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
347
1244
b241f9768833 Remove MBScene_ from the prefix of class names.
Thinker K.F. Li <thinker@codemud.net>
parents: 1243
diff changeset
348 self._start_monitor() # start domview_monitor
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
349 self._init_metadata()
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
350 self._parse_all_layers()
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
351 pass
1265
ca301f6abef7 Support undo for insert key frame/rm keyframe. We will refresh all layers and scenes since it is not feasible to collect these changes and update the layers and scenes. We may scan two level only in the future to improve the performance.
wycc
parents: 1262
diff changeset
352
ca301f6abef7 Support undo for insert key frame/rm keyframe. We will refresh all layers and scenes since it is not feasible to collect these changes and update the layers and scenes. We may scan two level only in the future to improve the performance.
wycc
parents: 1262
diff changeset
353 def reset(self):
1275
776b024ae8f9 Fix the buggy implementation of reset()
Thinker K.F. Li <thinker@codemud.net>
parents: 1274
diff changeset
354 self._layers = []
776b024ae8f9 Fix the buggy implementation of reset()
Thinker K.F. Li <thinker@codemud.net>
parents: 1274
diff changeset
355 self._parse_all_layers()
1265
ca301f6abef7 Support undo for insert key frame/rm keyframe. We will refresh all layers and scenes since it is not feasible to collect these changes and update the layers and scenes. We may scan two level only in the future to improve the performance.
wycc
parents: 1262
diff changeset
356 pass
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
357
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
358 def dumpattr(self, n):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
359 s = ""
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
360 for a,v in n.attrib.items():
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
361 s = s + ("%s=%s" % (a,v))
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
362 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
363 return s
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
364
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
365 def dump(self, node, l=0):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
366 print " " * l*2,"<", node.tag, self.dumpattr(node),">"
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
367 for n in node:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
368 self.dump(n, l+1)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
369 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
370 print " " * l * 2,"/>"
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
371 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
372
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
373 ## \brief Create and add a ns0:scene node under ns0:scenes subtree.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
374 #
1247
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
375 def add_scene_node(self, layer_idx, start, end,
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
376 frame_type=TweenObject.TWEEN_TYPE_NORMAL,
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
377 ref=None):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
378 type_names = ('normal', 'scale')
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
379 scenes_node = self._scenes_node
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
380 doc = self._doc
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
381
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
382 scene_node = doc.createElement('ns0:scene')
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
383 self.chg_scene_node(scene_node, start=start)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
384 if start != end:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
385 self.chg_scene_node(scene_node, end=end)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
386 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
387 type_name = type_names[frame_type]
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
388 self.chg_scene_node(scene_node, tween_type=type_name)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
389 if ref:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
390 self.chg_scene_node(scene_node, ref=ref)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
391 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
392
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
393 scenes_node.appendChild(scene_node)
1247
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
394
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
395 self._layers[layer_idx].scenes.append(scene_node)
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
396
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
397 return scene_node
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
398
1262
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
399 ## \brief Manage a existed scene node at given layer.
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
400 #
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
401 def manage_scene_node(self, layer_idx, scene_node):
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
402 self._layers[layer_idx].scenes.append(scene_node)
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
403 pass
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
404
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
405 ## \brief Change attributes of a scene node.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
406 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
407 # This is here to monitor changes of scene node.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
408 def chg_scene_node(self, scene_node, start=None, end=None,
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
409 tween_type=None, ref=None):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
410 if start is not None:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
411 scene_node.setAttribute('start', str(start))
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
412 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
413 if end is not None:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
414 scene_node.setAttribute('end', str(end))
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
415 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
416 if tween_type is not None:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
417 scene_node.setAttribute('type', tween_type)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
418 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
419 if ref is not None:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
420 scene_node.setAttribute('ref', ref)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
421 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
422 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
423
1256
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
424 ## \brief Remove scene node from DOM-tree.
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
425 #
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
426 def rm_scene_node(self, scene_node):
1256
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
427 if not scene_node.parent():
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
428 return # without this, may crash the Inkscape.
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
429
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
430 self._scenes_node.removeChild(scene_node)
1247
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
431 for layer in self._layers:
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
432 try:
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
433 layer.scenes.remove(scene_node)
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
434 except ValueError: # not in the list
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
435 pass
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
436 else:
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
437 break
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
438 pass
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
439 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
440
1256
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
441 ## \brief Remove scene node and asssociated scene group from DOM.
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
442 #
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
443 # It will remove as many as possible. Does not complain about
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
444 # error in the procedure of removing.
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
445 #
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
446 def rm_scene_node_n_group(self, scene_node):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
447 scene_group_id = scene_node.getAttribute('ref')
1256
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
448 try:
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
449 scene_group_node = self.get_node(scene_group_id)
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
450 if scene_group_node.parent(): # Check it, or crash the
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
451 # Inkscape.
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
452 scene_group_node.parent().removeChild(scene_group_node)
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
453 pass
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
454 except:
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
455 pass
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
456
1256
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
457 try:
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
458 self.rm_scene_node(scene_node)
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
459 except:
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
460 pass
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
461 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
462
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
463 ## \brief Create and add a svg:g for a scene under a group for a layer.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
464 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
465 def add_scene_group(self, layer_idx):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
466 layer = self._layers[layer_idx]
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
467 doc = self._doc
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
468
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
469 scene_group = doc.createElement('svg:g')
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
470 gid = self.new_id()
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
471 scene_group.setAttribute("id", gid)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
472 scene_group.setAttribute("inkscape:groupmode", "layer")
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
473
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
474 layer.group.appendChild(scene_group)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
475
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
476 return scene_group
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
477
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
478 def parse_layer(self, layer_idx):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
479 layer = self._layers[layer_idx]
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
480 layer_group = layer.group
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
481
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
482 for child in layer_group.childList():
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
483 if child.name() != 'svg:g':
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
484 continue
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
485 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
486 child_id = child.getAttribute('id')
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
487 scene_node = self.get_scene(child_id)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
488 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
489 continue
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
490
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
491 layer.scenes.append(scene_node)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
492 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
493 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
494
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
495 ## \brief Add/insert a layer at given position.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
496 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
497 # \param layer_idx is the position in the layer list.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
498 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
499 def insert_layer(self, layer_idx, layer_group):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
500 layers = self._layers
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
501
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
502 layer = Layer(layer_group)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
503 if layer_idx >= len(layers):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
504 layers.append(layer)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
505 else:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
506 layers.insert(layer_idx, layer)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
507 for idx in range(layer_idx, len(layers)):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
508 layers[idx].idx = idx
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
509 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
510 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
511 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
512
1262
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
513 ## \brief Manage a existed layer group
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
514 #
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
515 # This method scan layer groups of all managed layers, and find a
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
516 # proper place to insert it.
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
517 #
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
518 # \return -1 for error, or layer index.
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
519 #
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
520 def manage_layer_group(self, layer_group_id):
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
521 layer_group = self.get_node(layer_group_id)
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
522 new_layer = Layer(layer_group)
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
523
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
524 if not self._layers:
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
525 new_layer.idx = 0
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
526 self._layers.append(new_layer)
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
527 return 0
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
528
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
529 #
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
530 # Scan who is after the given group
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
531 #
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
532 next_group = layer_group.next()
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
533 while next_group:
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
534 next_group_id = next_group.getAttribute('id')
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
535
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
536 for vlayer in self._layers:
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
537 vlayer_group_id = vlayer.group.getAttribute('id')
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
538 if vlayer_group_id == next_group_id:
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
539 # This layer group is after given one.
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
540 self._layers.insert(vlayer.idx, new_layer)
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
541
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
542 for idx in range(vlayer.idx, len(self._layers)):
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
543 self._layers[idx].idx = idx
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
544 pass
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
545 return new_layer.idx
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
546 pass
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
547
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
548 next_group = next_group.next()
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
549 pass
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
550
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
551 #
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
552 # Is the given group after last layer group?
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
553 #
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
554 tail_group = self._layers[-1].group.next()
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
555 while tail_group:
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
556 tail_group_id = tail_group.getAttribute('id')
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
557
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
558 if tail_group_id == layer_group_id:
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
559 # it is after last layer group.
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
560 new_layer.idx = len(self._layers)
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
561 self._layers.append(new_layer)
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
562 return new_layer.idx
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
563
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
564 tail_group = tail_group.next()
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
565 pass
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
566
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
567 return -1 # error, can not determinze the position
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
568
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
569 ## \brief Remove layer and associated scene nodes and scene groups.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
570 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
571 def rm_layer(self, layer_idx):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
572 layers = self._layers
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
573
1260
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
574 layer = self._layers[layer_idx]
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
575 for scene_node in layer.scenes:
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
576 scene_group_id = scene_node.getAttribute('ref')
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
577 try:
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
578 scene_group_node = self.get_node(scene_group_id)
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
579 if scene_group_node.parent(): # keep from crashing
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
580 scene_group_node.parent().removeChild(scene_group_node)
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
581 pass
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
582 except:
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
583 pass
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
584
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
585 if scene_node.parent(): # keep from crashing
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
586 scene_node.parent().removeChild(scene_node)
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
587 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
588 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
589
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
590 del layers[layer_idx]
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
591
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
592 for idx in range(layer_idx, len(layers)):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
593 layers[idx].idx = idx
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
594 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
595 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
596
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
597 def get_layer_num(self):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
598 return len(self._layers)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
599
1259
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
600 ## \brief Find layer index and scene info for a given scene node.
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
601 #
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
602 # \return (-1, None) for error.
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
603 #
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
604 def find_layer_n_scene_of_node(self, node_id):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
605 for layer_idx, layer in enumerate(self._layers):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
606 for scene_node in layer.scenes:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
607 scene_group_id = scene_node.getAttribute('ref')
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
608 if scene_group_id == node_id:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
609 return layer_idx, scene_node
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
610 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
611 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
612 return -1, None
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
613
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
614 def get_layer_group(self, layer_idx):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
615 layer = self._layers[layer_idx]
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
616 return layer.group
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
617
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
618 def get_all_scene_node_of_layer(self, layer_idx):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
619 layer = self._layers[layer_idx]
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
620 return layer.scenes
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
621
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
622 def get_layer_data(self, layer_idx):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
623 layer = self._layers[layer_idx]
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
624 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
625 data = layer.data
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
626 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
627 return None
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
628 return data
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
629
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
630 def set_layer_data(self, layer_idx, data):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
631 layer = self._layers[layer_idx]
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
632 layer.data = data
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
633 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
634
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
635 def create_layer_dup_group(self, layer_idx):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
636 layer = self._layers[layer_idx]
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
637
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
638 dup_group = self._doc.createElement('svg:g')
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
639 gid = self.new_id()
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
640 dup_group.setAttribute('id', gid)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
641 dup_group.setAttribute('inkscape:label', 'dup')
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
642 dup_group.setAttribute('sodipodi:insensitive', '1')
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
643 dup_group.setAttribute('style', '')
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
644
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
645 layer.group.appendChild(dup_group)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
646
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
647 return dup_group
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
648
1259
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
649 ## \brief Return associated layer index of given layer group.
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
650 #
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
651 # \return -1 for error.
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
652 #
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
653 def find_layer_of_group(self, group_id):
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
654 for layer_idx, layer in enumerate(self._layers):
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
655 if layer.group.getAttribute('id') == group_id:
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
656 return layer_idx
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
657 pass
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
658 return -1
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
659
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
660 def insert_frames(self, layer_idx, frame_idx, num):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
661 layer = self._layers[layer_idx]
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
662 for scene_node in layer.scenes:
1274
a4d3838264dd Make public APIs being public for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1270
diff changeset
663 start, end, tween_type = self.parse_one_scene(scene_node)
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
664 if start >= frame_idx:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
665 self.chg_scene_node(scene_node, start=(start + num))
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
666 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
667 if end >= frame_idx:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
668 self.chg_scene_node(scene_node, end=(end + num))
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
669 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
670 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
671 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
672
1265
ca301f6abef7 Support undo for insert key frame/rm keyframe. We will refresh all layers and scenes since it is not feasible to collect these changes and update the layers and scenes. We may scan two level only in the future to improve the performance.
wycc
parents: 1262
diff changeset
673 ## \brief add the current position to the undo buffer
ca301f6abef7 Support undo for insert key frame/rm keyframe. We will refresh all layers and scenes since it is not feasible to collect these changes and update the layers and scenes. We may scan two level only in the future to improve the performance.
wycc
parents: 1262
diff changeset
674 #
ca301f6abef7 Support undo for insert key frame/rm keyframe. We will refresh all layers and scenes since it is not feasible to collect these changes and update the layers and scenes. We may scan two level only in the future to improve the performance.
wycc
parents: 1262
diff changeset
675 def mark_undo(self, msg):
ca301f6abef7 Support undo for insert key frame/rm keyframe. We will refresh all layers and scenes since it is not feasible to collect these changes and update the layers and scenes. We may scan two level only in the future to improve the performance.
wycc
parents: 1262
diff changeset
676 self._doc.done("none", msg)
ca301f6abef7 Support undo for insert key frame/rm keyframe. We will refresh all layers and scenes since it is not feasible to collect these changes and update the layers and scenes. We may scan two level only in the future to improve the performance.
wycc
parents: 1262
diff changeset
677 pass
ca301f6abef7 Support undo for insert key frame/rm keyframe. We will refresh all layers and scenes since it is not feasible to collect these changes and update the layers and scenes. We may scan two level only in the future to improve the performance.
wycc
parents: 1262
diff changeset
678
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
679 ## \brief Remove frames
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
680 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
681 # - Scenes covered by removing range were removed.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
682 # - Scenes after removing range were shifted left.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
683 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
684 def rm_frames(self, layer_idx, frame_idx, num):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
685 layer = self._layers[layer_idx]
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
686
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
687 last_rm = frame_idx + num - 1 # last removed frame
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
688 for scene_node in layer.scenes:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
689 start, end, tween_type = \
1274
a4d3838264dd Make public APIs being public for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1270
diff changeset
690 self.parse_one_scene(scene_node)
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
691
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
692 if end < frame_idx:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
693 continue
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
694
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
695 if start > last_rm: # this scene is at right side
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
696 self.chg_scene_node(scene_node,
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
697 start=(start - num),
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
698 end=(end - num))
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
699 else: # this scene is covered by removing range
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
700 self.rm_scene_node_n_group(scene_node)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
701 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
702 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
703 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
704
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
705 def get_max_frame(self):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
706 return self._maxframe
1246
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
707
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
708 ## \brief Copy children of a group.
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
709 #
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
710 # Duplicate children of a group, and append them to another group.
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
711 #
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
712 def copy_group_children(self, src_group, dst_group):
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
713 # Search for the duplicated group
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
714 doc = self._doc
1247
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
715
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
716 dup_group = src_group.duplicate(doc)
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
717
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
718 old_nodes = _DOM_iterator(src_group)
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
719 new_nodes = _DOM_iterator(dup_group)
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
720 new_gids = set()
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
721 for old_node in old_nodes:
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
722 old_node_id = old_node.getAttribute('id')
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
723 new_node = new_nodes.next()
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
724 new_node.setAttribute('ns0:duplicate-src', old_node_id)
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
725
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
726 #
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
727 # Change ID here, or inkscape would insert the node with
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
728 # the same ID, and change it later to avoid duplication.
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
729 # But, our event handler would be called before changing
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
730 # ID. It would confuse our code. We change ID of nodes
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
731 # before inserting them into the DOM-tree.
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
732 #
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
733 gid = self.new_id()
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
734 while gid in new_gids:
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
735 gid = self.new_id()
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
736 pass
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
737 new_gids.add(gid)
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
738 new_node.setAttribute('id', gid)
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
739 pass
1246
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
740
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
741 for child in dup_group.childList():
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
742 dup_group.removeChild(child) # prvent from crash
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
743 dst_group.appendChild(child)
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
744 pass
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
745 pass
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
746 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
747