annotate pyink/domview.py @ 1327:ab281ec3eeec

Add a layers group for components The children of the layers group of a components is layers of the component. All layers are children of a layers group instead of a component group.
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 30 Jan 2011 23:04:06 +0800
parents 0a2034f490e5
children 407f321f0d7c
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
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
5
1318
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
6 ## \brief Compare two nodes with ID.
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
7 #
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
8 # \return True if node1 ID equivalent to ndoe2 ID.
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
9 #
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
10 def _id_eq(node1, node2):
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
11 try:
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
12 node1_id = node1.getAttribute('id')
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
13 except:
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
14 return False
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
15
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
16 try:
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
17 node2_id = node2.getAttribute('id')
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
18 except:
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
19 return False
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
20 return node1_id == node2_id
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
21
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
22
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
23 class Layer:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
24 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
25 self.scenes = []
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
26 self.group = node
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
27 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
28 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
29
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
30
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
31 class Timeline(object):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
32 def __init__(self, scenes_node):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
33 self.scenes_node = scenes_node
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
34 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
35
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
36 def name(self):
1308
49775feefbcf Show components and timelines in comp_dock
Thinker K.F. Li <thinker@codemud.net>
parents: 1306
diff changeset
37 name = self.scenes_node.getAttribute('name')
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
38 return name
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
39 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
40
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
41
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
42 class Component(object):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
43 #
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
44 # \param comp_node is None for main component.
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
45 #
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
46 def __init__(self, comp_mgr, comp_node):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
47 self._comp_mgr = comp_mgr
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
48 self.node = comp_node
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
49 self.layers = []
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
50 self.timelines = []
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
51
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
52 if comp_node:
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
53 self._initialize_comp()
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
54 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
55 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
56
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
57 def _initialize_comp(self):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
58 comp_node = self.node
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
59 for child in comp_node.childList():
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
60 if child.name() == 'ns0:scenes':
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
61 break
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
62 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
63 else: # no any ns0:scenes
1310
85d04ba11146 Support adding new components
Thinker K.F. Li <thinker@codemud.net>
parents: 1308
diff changeset
64 doc = self._comp_mgr._doc
85d04ba11146 Support adding new components
Thinker K.F. Li <thinker@codemud.net>
parents: 1308
diff changeset
65 scenes_node = doc.createElement('ns0:scenes')
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
66 scenes_node.setAttribute('name', 'default')
1310
85d04ba11146 Support adding new components
Thinker K.F. Li <thinker@codemud.net>
parents: 1308
diff changeset
67
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
68 node_id = self._comp_mgr.new_id()
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
69 scenes_node.setAttribute('id', node_id)
1310
85d04ba11146 Support adding new components
Thinker K.F. Li <thinker@codemud.net>
parents: 1308
diff changeset
70
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
71 comp_node.appendChild(scenes_node)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
72 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
73 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
74
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
75 def name(self):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
76 if self.node:
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
77 name = self.node.getAttribute('name')
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
78 else:
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
79 name = 'main'
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
80 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
81 return name
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
82
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
83 def all_timeline_names(self):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
84 names = [tl.name() for tl in self.timelines]
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
85 return names
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
86
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
87 def parse_timelines(self):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
88 if self.node:
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
89 assert self.node.name() == 'ns0:component'
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
90 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
91
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
92 comp_node = self.node
1310
85d04ba11146 Support adding new components
Thinker K.F. Li <thinker@codemud.net>
parents: 1308
diff changeset
93 for child in comp_node.childList():
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
94 if child.name() == 'ns0:scenes':
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
95 tl = Timeline(child)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
96 self.timelines.append(tl)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
97 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
98 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
99 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
100
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
101 def get_timeline(self, name):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
102 for tl in self.timelines:
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
103 if tl.name() == name:
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
104 return tl
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
105 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
106 raise Value, 'invalid timeline name - %s' % (name)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
107
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
108 def has_timeline(self, name):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
109 for tl in self.timelines:
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
110 if tl.name() == name:
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
111 return True
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
112 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
113 return False
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
114
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
115 def add_timeline(self, name):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
116 if self.has_timeline(name):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
117 raise ValueError, \
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
118 'try add a timeline with duplicated name - %s' % (name)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
119
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
120 doc = self._comp_mgr._doc
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
121 comp_node = self.node
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
122
1310
85d04ba11146 Support adding new components
Thinker K.F. Li <thinker@codemud.net>
parents: 1308
diff changeset
123 scenes_node = doc.createElement('ns0:scenes')
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
124 scenes_node.setAttribute('name', name)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
125 node_id = self._comp_mgr.new_id()
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
126 scenes_node.setAttribute('id', node_id)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
127
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
128 comp_node.appendChild(scenes_node)
1317
e2ad9eb7f7a4 Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 1316
diff changeset
129
e2ad9eb7f7a4 Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 1316
diff changeset
130 tl = Timeline(scenes_node)
e2ad9eb7f7a4 Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 1316
diff changeset
131 self.timelines.append(tl)
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
132 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
133
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
134 ## \brief Add a timeline for an existed scenes node.
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
135 #
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
136 def add_timeline_scenes(self, scenes_node):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
137 tl = Timeline(scenes_node)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
138 name = tl.name()
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
139 if self.has_timeline(name):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
140 raise ValueError, \
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
141 'name of scenes node of a timeline is duplicated'
1317
e2ad9eb7f7a4 Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 1316
diff changeset
142
e2ad9eb7f7a4 Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 1316
diff changeset
143 self.timeline.append(tl)
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
144 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
145
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
146 def rm_timeline(self, name):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
147 for i, tl in enumerate(self.timelines):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
148 if tl.name() == name:
1317
e2ad9eb7f7a4 Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 1316
diff changeset
149 comp_node = self.node
e2ad9eb7f7a4 Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 1316
diff changeset
150 comp_node.removeChild(tl.scenes_node)
e2ad9eb7f7a4 Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 1316
diff changeset
151
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
152 del self.timelines[i]
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
153 return
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
154 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
155 raise ValueError, 'try to remove a non-existed timeline - %s' % (name)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
156 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
157
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
158
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
159 ## \brief A mix-in for class domview for management of components.
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
160 #
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
161 # This class is responsible for manage components and timelines. It
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
162 # is also responsible for switching component and timeline. Switching
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
163 # to a component is actually switching to a timeline in another
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
164 # component. When switch to a timeline, it actuall change
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
165 # domview._scense_node, parent of all scene nodes of a component, and
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
166 # domview._layers_parent, parent of all layer group of a component.
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
167 # domview relys on these two variables to operate on right component
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
168 # and timeline. (It should be changed to get more hint with
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
169 # meaningful names.)
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
170 #
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
171 # FIXME: The root node is always the 'main' component. It is a
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
172 # special case with slightly different in structure. It should be
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
173 # removed and normalized to normal components.
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
174 #
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
175 class component_manager(object):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
176 def __init__(self):
1302
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
177 self._components_node = None
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
178 self._components = []
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
179 self._comp_names = set()
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
180 self._main_comp = None
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
181 self._cur_comp = None
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
182 self._cur_timeline = None
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
183 self._components_group = None
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
184 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
185
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
186 def _set_main_component(self):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
187 comp = Component(self, None)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
188 comp.layers = self._layers
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
189 scenes_node = self._scenes_node
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
190 timeline = Timeline(scenes_node)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
191 comp.timelines = [timeline]
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
192
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
193 self._components.append(comp)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
194 self._comp_names.add('main')
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
195
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
196 self._main_comp = comp
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
197 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
198
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
199 def _parse_components(self):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
200 comp_names = self._comp_names
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
201 components_node = self._components_node
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
202 for child in components_node.childList():
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
203 child_name = child.name()
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
204 if child_name != 'ns0:component':
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
205 continue
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
206 if child_name in comp_names:
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
207 raise ValueError, 'duplicate component name %s' % (child_name)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
208
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
209 comp = Component(self, child)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
210 comp.parse_timelines()
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
211
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
212 self._components.append(comp)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
213 comp_names.add(child_name)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
214 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
215 pass
1302
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
216
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
217 ## \brief To initialize subtree of metadata.
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
218 #
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
219 # This method is called by domview._init_metadata().
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
220 #
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
221 def _component_manager_init_metadata(self):
1321
6a014a4ec79e Fix missed variable name after refactory
Thinker K.F. Li <thinker@codemud.net>
parents: 1318
diff changeset
222 metadata_node = self._metadata_node
6a014a4ec79e Fix missed variable name after refactory
Thinker K.F. Li <thinker@codemud.net>
parents: 1318
diff changeset
223
6a014a4ec79e Fix missed variable name after refactory
Thinker K.F. Li <thinker@codemud.net>
parents: 1318
diff changeset
224 # Make sure ns0:components in metadata
6a014a4ec79e Fix missed variable name after refactory
Thinker K.F. Li <thinker@codemud.net>
parents: 1318
diff changeset
225 for n in metadata_node.childList():
1302
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
226 if n.name() == 'ns0:components':
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
227 self._components_node = n
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
228 break
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
229 pass
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
230 else:
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
231 components_node = self._doc.createElement("ns0:components")
1321
6a014a4ec79e Fix missed variable name after refactory
Thinker K.F. Li <thinker@codemud.net>
parents: 1318
diff changeset
232 metadata_node.appendChild(components_node)
1302
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
233 self._components_node = components_node
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
234 pass
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
235
1321
6a014a4ec79e Fix missed variable name after refactory
Thinker K.F. Li <thinker@codemud.net>
parents: 1318
diff changeset
236 # Make sure the group for containing components.
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
237 for n in self._root.childList():
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
238 if n.name() != 'svg:g':
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
239 continue
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
240 try:
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
241 nlabel = n.getAttribute('inkscape:label')
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
242 except:
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
243 continue
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
244 if nlabel == 'components':
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
245 self._components_group
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
246 break
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
247 pass
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
248 else: # no components group
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
249 components_group = self._doc.createElement('svg:g')
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
250 components_group.setAttribute('inkscape:label', 'components')
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
251 gid = self.new_id()
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
252 components_group.setAttribute('id', gid)
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
253
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
254 self._root.appendChild(components_group)
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
255 self._components_group = components_group
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
256 pass
1302
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
257 pass
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
258
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
259 def _start_component_manager(self):
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
260 self._component_manager_init_metadata()
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
261 self._set_main_component()
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
262 self._parse_components()
1316
9ab8d50dcf7e Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1315
diff changeset
263
9ab8d50dcf7e Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1315
diff changeset
264 self._cur_comp = self._main_comp
9ab8d50dcf7e Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1315
diff changeset
265 tl = self._main_comp.get_timeline('default')
9ab8d50dcf7e Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1315
diff changeset
266 self._cur_timeline = tl
9ab8d50dcf7e Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1315
diff changeset
267 self._scenes_node = tl.scenes_node
1302
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
268 pass
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
269
1327
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
270 ## \brief Create component group
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
271 #
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
272 # A component group is a group with a layers group as child.
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
273 # The layers group is where layer groups is in.
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
274 #
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
275 def _create_component_group(self):
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
276 doc = self._doc
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
277 group = doc.createElement('svg:g')
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
278 gid = self.new_id()
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
279 group.setAttribute('id', gid)
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
280
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
281 self._components_group.appendChild(group)
1327
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
282
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
283 # Create layers group
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
284 layers_group = doc.createElement('svg:g')
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
285 gid = self.new_id()
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
286 layers_group.setAttribute('id', gid)
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
287 layers_group.setAttribute('inkscape:label', 'layers')
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
288 group.appendChild(layers_group)
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
289
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
290 return group
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
291
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
292 ## \brief Create a ns0:component node for a given name.
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
293 #
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
294 # \param comp_name is the name of the created component.
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
295 # \param comp_group_id is the component group.
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
296 # \return a ns0:component node.
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
297 #
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
298 def _create_component_node(self, comp_name, comp_group_id):
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
299 comp_node = self._doc.createElement('ns0:component')
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
300 comp_id = self.new_id()
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
301 comp_node.setAttribute('id', comp_id)
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
302 comp_node.setAttribute('name', comp_name)
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
303 comp_node.setAttribute('ref', comp_group_id)
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
304 self._components_node.appendChild(comp_node)
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
305 return comp_node
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
306
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
307 ## \brief Get Component object associated with the given name.
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
308 #
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
309 def _get_component(self, comp_name):
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
310 if comp_name in self._comp_names:
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
311 for comp in self._components:
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
312 if comp.name() == comp_name:
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
313 return comp
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
314 pass
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
315 pass
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
316 raise ValueError, 'can not find component node - %s' % (comp_name)
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
317
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
318 ## \brief Create a layer group for give layer of a component.
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
319 #
1327
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
320 def _create_comp_layer_group(self, layers_group, layer_name):
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
321 doc = self._doc
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
322 gid = self.new_id()
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
323
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
324 layer_group = doc.createElement('svg:g')
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
325 layer_group.setAttribute('id', gid)
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
326 layer_group.setAttribute('inkscape:label', layer_name)
1323
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
327 layer_group.setAttribute('inkscape:groupmode', 'layer')
1327
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
328 layers_group.appendChild(layer_group)
1326
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
329
1323
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
330 return layer_group
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
331
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
332 ## \brief Return group of specified layer in a component.
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
333 #
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
334 # This is here for getting layer group without switch current
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
335 # component.
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
336 #
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
337 def _get_group_of_component_layer(self, comp_name, layer_idx):
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
338 comp = self._get_component(comp_name)
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
339 layer = comp.layers[layer_idx]
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
340 return layer.group
1327
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
341
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
342 def _get_layers_group_of_component(self, comp_name):
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
343 if comp_name == 'main':
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
344 return self._root
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
345
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
346 comp_group = self.get_component_group(comp_name)
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
347 layers_group = comp_group.firstChild()
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
348 assert layers_group.getAttribute('inkscape:label') == 'layers'
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
349
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
350 return layers_group
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
351
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
352 def all_comp_names(self):
1317
e2ad9eb7f7a4 Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 1316
diff changeset
353 return [comp.name() for comp in self._components]
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
354
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
355 def has_component(self, name):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
356 return name in self._comp_names
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
357
1326
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
358 def hide_component(self, comp_name):
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
359 if comp_name == 'main':
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
360 comp = self._get_component(comp_name)
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
361 for layer in comp.layers:
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
362 group = layer.group
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
363 group.setAttribute('style', 'display: none')
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
364 pass
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
365 return
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
366
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
367 comp_group = self.get_component_group(comp_name)
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
368 comp_group.setAttribute('style', 'display: none')
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
369 pass
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
370
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
371 def show_component(self, comp_name):
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
372 if comp_name == 'main':
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
373 comp = self._get_component(comp_name)
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
374 for layer in comp.layers:
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
375 group = layer.group
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
376 group.setAttribute('style', '')
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
377 pass
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
378 return
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
379
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
380 comp_group = self.get_component_group(comp_name)
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
381 comp_group.setAttribute('style', '')
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
382 pass
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
383
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
384 def switch_component(self, comp_name):
1323
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
385 old_comp = self._cur_comp
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
386
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
387 comp = self._get_component(comp_name)
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
388 self._cur_comp = comp
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
389 self._layers = comp.layers
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
390 comp_name = self._cur_comp.name()
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
391 # for domview
1327
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
392 self._layers_parent = self._get_layers_group_of_component(comp_name)
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
393
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
394 first_name = comp.all_timeline_names()[0]
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
395 self.switch_timeline(first_name)
1323
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
396
1326
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
397 self.hide_component(old_comp.name())
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
398 self.show_component(comp.name())
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
399 pass
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
400
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
401 def add_component(self, comp_name):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
402 if self.has_component(comp_name):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
403 raise ValueError, \
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
404 'try add a component with existed name %s' % (comp_name)
1327
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
405
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
406 comp_group = self._create_component_group()
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
407 comp_group_id = comp_group.getAttribute('id')
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
408 comp_node = self._create_component_node(comp_name, comp_group_id)
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
409
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
410 comp = Component(self, comp_node)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
411 comp.parse_timelines()
1323
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
412
1327
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
413 self._components.append(comp)
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
414 self._comp_names.add(comp_name)
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
415
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
416 # Create Layer1 (at least one layer for a component)
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
417 layers_group = self._get_layers_group_of_component(comp_name)
ab281ec3eeec Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents: 1326
diff changeset
418 layer_group = self._create_comp_layer_group(layers_group, 'Layer1')
1323
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
419 layer = Layer(layer_group)
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
420 comp.layers.append(layer)
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
421
1326
0a2034f490e5 Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1323
diff changeset
422 self.hide_component(comp_name)
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
423 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
424
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
425 def add_component_node(self, comp_node):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
426 comp = Component(self, comp_node)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
427 comp_name = comp.name()
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
428 if self.has_component(comp_name):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
429 raise ValueError, \
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
430 'the name of a ns0:component is duplicated'
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
431
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
432 self._components.append(comp)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
433 self._comp_names.add(comp_name)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
434 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
435
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
436 def rm_component(self, comp_name):
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
437 comp = self._get_component(comp_name)
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
438 comp_name = comp.name()
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
439 comp_node = comp.node
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
440 comp_group = self.get_component_group(comp_name)
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
441
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
442 self._components.remove(comp)
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
443 self._comp_names.remove(comp_name)
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
444 self._components_node.removeChild(comp_node)
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
445 self._components_group.removeChild(comp_group)
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
446 pass
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
447
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
448 def get_component_group(self, comp_name):
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
449 comp = self._get_component(comp_name)
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
450
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
451 comp_name = comp.name()
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
452 if comp_name == 'main':
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
453 return self._root
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
454
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
455 comp_node = comp.node
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
456 gid = comp_node.getAttribute('ref')
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
457 comp_group = self.get_node(gid)
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
458 return comp_group
1316
9ab8d50dcf7e Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1315
diff changeset
459
9ab8d50dcf7e Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1315
diff changeset
460 def get_current_component(self):
9ab8d50dcf7e Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1315
diff changeset
461 return self._cur_comp.name()
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
462
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
463 def switch_timeline(self, timeline_name):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
464 tl = self._cur_comp.get_timeline(timeline_name)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
465 self._cur_timeline = tl
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
466 self._scenes_node = tl.scenes_node # of class domview
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
467
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
468 # Make domview to rescan layers and scenes.
1302
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
469 self.reset() # from domview
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
470 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
471
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
472 def add_timeline(self, timeline_name):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
473 self._cur_comp.add_timeline(timeline_name)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
474 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
475
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
476 def rm_timeline(self, timeline_name):
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
477 self._cur_comp.rm_timeline(timeline_name)
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
478 pass
1306
8c0a4684c1f7 Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1302
diff changeset
479
8c0a4684c1f7 Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1302
diff changeset
480 def all_timeline_names(self):
8c0a4684c1f7 Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1302
diff changeset
481 r = self._cur_comp.all_timeline_names()
8c0a4684c1f7 Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1302
diff changeset
482 return r
8c0a4684c1f7 Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1302
diff changeset
483
8c0a4684c1f7 Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1302
diff changeset
484 def has_timeline(self, name):
8c0a4684c1f7 Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1302
diff changeset
485 r = self._cur_comp.has_timeline(name)
8c0a4684c1f7 Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1302
diff changeset
486 return r
1316
9ab8d50dcf7e Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1315
diff changeset
487
9ab8d50dcf7e Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1315
diff changeset
488 def get_current_timeline(self):
9ab8d50dcf7e Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents: 1315
diff changeset
489 return self._cur_timeline.name()
1323
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
490
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
491 ## \brief Add a new component from a group node.
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
492 #
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
493 # The group node is reparented to the group of first layer of
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
494 # specified component.
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
495 #
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
496 def mv_group_to_component(self, group, comp_name):
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
497 group_parent = group.parent()
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
498 if group_parent:
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
499 group_parent.removeChild(group)
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
500 pass
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
501
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
502 layer_group = self._get_group_of_component_layer(comp_name, 0)
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
503 layer_group.appendChild(group)
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
504 pass
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
505 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
506
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
507
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
508 ## \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
509 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
510 # 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
511 # 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
512 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
513 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
514 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
515
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
516 self._maxframe = 0
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
517 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
518 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
519 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
520
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
521 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
522 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
523 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
524
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
525 doc = self._doc
1253
07e0cb1e051d Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1247
diff changeset
526 dom_event.addEventListener(doc, 'DOMNodeInserted',
07e0cb1e051d Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1247
diff changeset
527 self._on_insert_node, None)
07e0cb1e051d Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1247
diff changeset
528 dom_event.addEventListener(doc, 'DOMNodeRemoved',
07e0cb1e051d Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1247
diff changeset
529 self._on_remove_node, None)
07e0cb1e051d Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1247
diff changeset
530 dom_event.addEventListener(doc, 'DOMAttrModified',
07e0cb1e051d Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1247
diff changeset
531 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
532 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
533
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
534 ## \brief Rescan the tree.
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
535 #
1302
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
536 def _monitor_reparse(self):
1301
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
537 self._maxframe = 0
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
538 self._id2node = {}
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
539 self._group2scene = {}
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
540
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
541 self._collect_node_ids()
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
542 self._collect_all_scenes()
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
543 pass
18af917cf855 Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1299
diff changeset
544
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
545 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
546 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
547 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
548 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
549
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
550 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
551 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
552 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
553 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
554 else:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
555 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
556 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
557 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
558 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
559
1318
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
560 if child.name() == 'ns0:scene' and _id_eq(node, self._scenes_node):
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
561 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
562 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
563 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
564 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
565 else:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
566 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
567 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
568 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
569 pass
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 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
572 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
573 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
574 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
575 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
576 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
577 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
578 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
579 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
580 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
581 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
582 pass
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
583
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
584 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
585 maxframe = 0
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
586 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
587 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
588 continue
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 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
591 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
592 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
593 except:
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 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
596 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
597 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
598 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
599 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
600 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
601 return maxframe
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
602
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
603 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
604 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
605 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
606 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
607
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
608 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
609 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
610 except:
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 else:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
613 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
614 raise ValueError, \
97302d2a0a1d Raise an error for the error.
Thinker K.F. Li <thinker@codemud.net>
parents: 1265
diff changeset
615 '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
616 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
617 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
618
1318
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
619 if child.name() == 'ns0:scene' and _id_eq(node, self._scenes_node):
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
620 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
621 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
622 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
623 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
624 else:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
625 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
626 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
627
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
628 try:
1318
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
629 if int(child.getAttribute('start')) == self._maxframe or \
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
630 int(child.getAttribute('end')) == self._maxframe:
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
631 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
632 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
633 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
634 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
635 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
636 pass
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 def _on_attr_modified(self, node, name, old_value, new_value):
1318
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
639 if old_value == new_value:
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
640 return
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
641
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
642 if name == 'id':
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
643 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
644 raise ValueError, \
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
645 '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
646 (old_value)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
647 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
648 raise ValueError, \
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
649 '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
650 (new_value)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
651
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
652 if old_value:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
653 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
654 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
655 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
656 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
657 elif name == 'ref' and node.name() == 'ns0:scene':
1318
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
658 parent_node = node.parent()
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
659 scenes_node = self._scenes_node
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
660 if not _id_eq(parent_node, scenes_node):
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
661 return # not in current timeline
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
662
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
663 if old_value:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
664 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
665 # 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
666 # wrapper.
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
667 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
668 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
669 if new_value:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
670 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
671 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
672 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
673 elif (name in ('start', 'end')) and node.name() == 'ns0:scene':
1318
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
674 parent_node = node.parent()
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
675 scenes_node = self._scenes_node
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
676 if not _id_eq(parent_node, scenes_node):
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
677 return # not in current timeline
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
678
1276
0442ae9c2ac2 Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents: 1275
diff changeset
679 try:
0442ae9c2ac2 Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents: 1275
diff changeset
680 new_value = int(new_value)
0442ae9c2ac2 Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents: 1275
diff changeset
681 old_value = int(old_value)
0442ae9c2ac2 Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents: 1275
diff changeset
682 except TypeError:
0442ae9c2ac2 Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents: 1275
diff changeset
683 self._maxframe = self._find_maxframe(scenes_node)
0442ae9c2ac2 Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents: 1275
diff changeset
684 else:
0442ae9c2ac2 Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents: 1275
diff changeset
685 if old_value == self._maxframe and old_value > new_value:
0442ae9c2ac2 Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents: 1275
diff changeset
686 # _maxframe may be reduced.
0442ae9c2ac2 Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents: 1275
diff changeset
687 self._maxframe = self._find_maxframe(scenes_node)
0442ae9c2ac2 Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents: 1275
diff changeset
688 else:
0442ae9c2ac2 Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents: 1275
diff changeset
689 self._maxframe = max(int(new_value), self._maxframe)
0442ae9c2ac2 Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents: 1275
diff changeset
690 pass
0442ae9c2ac2 Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents: 1275
diff changeset
691 pass
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
692 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
693 pass
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 ## \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
696 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
697 # 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
698 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
699 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
700 self._id2node = {}
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
701 root = self._root
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
702 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
703 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
704 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
705 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
706
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
707 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
708 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
709 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
710 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
711 return
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
712
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
713 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
714 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
715 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
716 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
717 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
718
1274
a4d3838264dd Make public APIs being public for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1270
diff changeset
719 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
720 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
721
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
722 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
723 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
724 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
725 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
726 end = start
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
727 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
728
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
729 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
730 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
731 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
732 scene_type = 'normal'
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
733 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
734 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
735 scene_type = 'normal'
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
736 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
737
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
738 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
739
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
740 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
741 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
742 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
743 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
744 cur = 0
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
745 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
746 self.current = cur
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
747
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
748 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
749 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
750 continue
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
751
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
752 try:
1274
a4d3838264dd Make public APIs being public for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1270
diff changeset
753 start, end, scene_type = self.parse_one_scene(scene_node)
1285
e2d2532c3115 Replace a workaround with a more semantic one.
Thinker K.F. Li <thinker@codemud.net>
parents: 1284
diff changeset
754 group_id = scene_node.getAttribute("ref")
e2d2532c3115 Replace a workaround with a more semantic one.
Thinker K.F. Li <thinker@codemud.net>
parents: 1284
diff changeset
755 except: # the scene node is incompleted.
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
756 continue
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
757
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
758 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
759 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
760 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
761
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
762 ## \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
763 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
764 def _collect_all_scenes(self):
1318
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
765 scenes_node = self._scenes_node
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
766 self._parse_one_scenes(scenes_node)
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
767 self._maxframe = self._find_maxframe(scenes_node)
b1776f441e8a Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents: 1317
diff changeset
768 pass
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
769 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
770
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
771 ## \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
772 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
773 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
774 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
775
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
776 ## \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
777 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
778 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
779 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
780
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
781 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
782 while True:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
783 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
784 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
785 return candidate
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
786 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
787 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
788 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
789
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
790
1246
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
791 ## \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
792 #
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
793 def _DOM_iterator(node):
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
794 nodes = [node]
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
795 while nodes:
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
796 node = nodes.pop(0)
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
797 child = node.firstChild()
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
798 while child:
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
799 nodes.append(child)
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
800 child = child.next()
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
801 pass
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
802 yield node
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
803 pass
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
804 pass
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
805
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
806
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
807 ## \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
808 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
809 # 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
810 # 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
811 # 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
812 #
1302
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
813 class domview(domview_monitor, component_manager):
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
814 # 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
815 _doc = None
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
816 _root = None
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
817
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
818 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
819 super(domview, self).__init__()
1302
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
820 self._metadata_node = None
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
821 #
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
822 # Following two variables would be changed by class
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
823 # component_manager to switch components and timelines.
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
824 #
1302
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
825 self._scenes_node = None
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
826 self._layers_parent = None
1323
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
827 self._layers = []
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
828 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
829
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
830 ## \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
831 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
832 def _init_metadata(self):
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
833 self._layers_parent = self._root
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
834
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
835 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
836 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
837 break
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
838 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
839 else:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
840 raise RuntimeError, \
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
841 'can not find <svg:metadata> node in the document'
1302
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
842
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
843 self._metadata_node = node
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
844
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
845 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
846 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
847 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
848 break
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
849 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
850 else:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
851 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
852 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
853 scenes_node = self._doc.createElement("ns0:scenes")
1322
7f25abbc1b61 Assign a name and ID for scenes node of main component
Thinker K.F. Li <thinker@codemud.net>
parents: 1321
diff changeset
854 scenes_node_id = 'main_default_scenes'
7f25abbc1b61 Assign a name and ID for scenes node of main component
Thinker K.F. Li <thinker@codemud.net>
parents: 1321
diff changeset
855 scenes_node.setAttribute('id', scenes_node_id)
7f25abbc1b61 Assign a name and ID for scenes node of main component
Thinker K.F. Li <thinker@codemud.net>
parents: 1321
diff changeset
856 scenes_node.setAttribute('name', 'default')
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
857 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
858 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
859 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
860 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
861
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
862 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
863 layers = self._layers
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
864 layers_parent = self._layers_parent
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
865
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
866 for child in layers_parent.childList():
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
867 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
868 continue
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
869
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
870 try:
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
871 label = child.getAttribute('inkscape:label')
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
872 except:
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
873 pass
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
874 else: # has no label
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
875 if label == 'components':
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
876 continue
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
877 pass
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
878
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
879 layer_group = child
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
880 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
881 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
882 layers.append(layer)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
883 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
884 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
885 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
886
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
887 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
888 self._doc = doc
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
889 self._root = root
1323
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
890 self._layers[:] = []
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
891
1315
fcff6978f9bf User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents: 1310
diff changeset
892 self._init_metadata()
1302
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
893 self._start_monitor() # from domview_monitor
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
894 self._start_component_manager() # from component_manager
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
895 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
896 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
897
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
898 def reset(self):
1302
c53331c55a23 Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents: 1301
diff changeset
899 self._monitor_reparse() # from domview_monitor
1323
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
900 self._layers[:] = []
1275
776b024ae8f9 Fix the buggy implementation of reset()
Thinker K.F. Li <thinker@codemud.net>
parents: 1274
diff changeset
901 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
902 pass
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
903
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
904 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
905 s = ""
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
906 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
907 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
908 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
909 return s
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
910
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
911 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
912 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
913 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
914 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
915 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
916 print " " * l * 2,"/>"
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
917 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
918
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
919 ## \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
920 #
1247
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
921 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
922 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
923 ref=None):
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
924 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
925 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
926 doc = self._doc
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
927
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
928 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
929 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
930 if start != end:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
931 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
932 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
933 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
934 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
935 if ref:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
936 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
937 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
938
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
939 scenes_node.appendChild(scene_node)
1247
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
940
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
941 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
942
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
943 return scene_node
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
944
1262
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
945 ## \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
946 #
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
947 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
948 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
949 pass
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
950
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
951 ## \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
952 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
953 # 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
954 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
955 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
956 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
957 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
958 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
959 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
960 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
961 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
962 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
963 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
964 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
965 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
966 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
967 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
968 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
969
1256
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
970 ## \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
971 #
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
972 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
973 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
974 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
975
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
976 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
977 for layer in self._layers:
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
978 try:
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
979 layer.scenes.remove(scene_node)
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
980 except ValueError: # not in the list
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
981 pass
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
982 else:
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
983 break
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
984 pass
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
985 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
986
1256
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
987 ## \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
988 #
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
989 # 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
990 # 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
991 #
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
992 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
993 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
994 try:
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
995 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
996 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
997 # Inkscape.
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
998 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
999 pass
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
1000 except:
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
1001 pass
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1002
1256
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
1003 try:
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
1004 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
1005 except:
8755415b5e99 More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1253
diff changeset
1006 pass
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1007 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1008
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1009 ## \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
1010 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1011 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
1012 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
1013 doc = self._doc
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1014
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1015 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
1016 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
1017 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
1018 scene_group.setAttribute("inkscape:groupmode", "layer")
1299
6949e2b6cae2 Add unlink clone checker.
Thinker K.F. Li <thinker@codemud.net>
parents: 1298
diff changeset
1019 scene_group.setAttribute('scene_group', 'true')
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1020
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1021 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
1022
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1023 return scene_group
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1024
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1025 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
1026 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
1027 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
1028
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1029 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
1030 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
1031 continue
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1032 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1033 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
1034 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
1035 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1036 continue
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1037
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1038 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
1039 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1040 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1041
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1042 ## \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
1043 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1044 # \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
1045 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1046 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
1047 layers = self._layers
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1048
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1049 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
1050 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
1051 layers.append(layer)
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1052 else:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1053 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
1054 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
1055 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
1056 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1057 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1058 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1059
1262
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1060 ## \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
1061 #
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1062 # 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
1063 # 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
1064 #
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1065 # \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
1066 #
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1067 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
1068 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
1069 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
1070
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1071 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
1072 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
1073 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
1074 return 0
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1075
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1076 #
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1077 # 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
1078 #
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1079 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
1080 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
1081 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
1082
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1083 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
1084 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
1085 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
1086 # 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
1087 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
1088
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1089 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
1090 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
1091 pass
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1092 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
1093 pass
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1094
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1095 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
1096 pass
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1097
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1098 #
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1099 # 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
1100 #
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1101 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
1102 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
1103 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
1104
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1105 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
1106 # 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
1107 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
1108 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
1109 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
1110
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1111 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
1112 pass
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1113
2f861eea1214 Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents: 1260
diff changeset
1114 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
1115
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1116 ## \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
1117 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1118 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
1119 layers = self._layers
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1120
1260
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
1121 layer = self._layers[layer_idx]
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
1122 for scene_node in layer.scenes:
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
1123 scene_group_id = scene_node.getAttribute('ref')
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
1124 try:
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
1125 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
1126 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
1127 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
1128 pass
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
1129 except:
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
1130 pass
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
1131
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
1132 if scene_node.parent(): # keep from crashing
bbd6bc0d079a Fix bug of removing layer.
Thinker K.F. Li <thinker@codemud.net>
parents: 1259
diff changeset
1133 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
1134 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1135 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1136
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1137 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
1138
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1139 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
1140 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
1141 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1142 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1143
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1144 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
1145 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
1146
1259
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
1147 ## \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
1148 #
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
1149 # \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
1150 #
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1151 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
1152 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
1153 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
1154 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
1155 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
1156 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
1157 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1158 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1159 return -1, None
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1160
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1161 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
1162 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
1163 return layer.group
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1164
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1165 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
1166 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
1167 return layer.scenes
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1168
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1169 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
1170 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
1171 try:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1172 data = layer.data
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1173 except:
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1174 return None
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1175 return data
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1176
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1177 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
1178 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
1179 layer.data = data
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1180 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1181
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1182 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
1183 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
1184
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1185 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
1186 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
1187 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
1188 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
1189 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
1190 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
1191
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1192 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
1193
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1194 return dup_group
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1195
1259
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
1196 ## \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
1197 #
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
1198 # \return -1 for error.
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
1199 #
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
1200 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
1201 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
1202 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
1203 return layer_idx
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
1204 pass
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
1205 return -1
df474448364e Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents: 1256
diff changeset
1206
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1207 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
1208 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
1209 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
1210 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
1211 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
1212 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
1213 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1214 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
1215 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
1216 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1217 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1218 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1219
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
1220 ## \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
1221 #
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
1222 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
1223 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
1224 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
1225
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1226 ## \brief Remove frames
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1227 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1228 # - 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
1229 # - 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
1230 #
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1231 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
1232 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
1233
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1234 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
1235 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
1236 start, end, tween_type = \
1274
a4d3838264dd Make public APIs being public for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1270
diff changeset
1237 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
1238
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1239 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
1240 continue
1286
922d1caf6632 Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents: 1285
diff changeset
1241
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1242 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
1243 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
1244 start=(start - num),
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1245 end=(end - num))
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1246 else: # this scene is covered by removing range
1286
922d1caf6632 Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents: 1285
diff changeset
1247 self.rm_scene_node_n_group(scene_node)
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1248 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1249 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1250 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1251
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1252 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
1253 return self._maxframe
1246
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
1254
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
1255 ## \brief Copy children of a group.
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
1256 #
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
1257 # 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
1258 #
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
1259 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
1260 # Search for the duplicated group
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
1261 doc = self._doc
1286
922d1caf6632 Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents: 1285
diff changeset
1262
922d1caf6632 Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents: 1285
diff changeset
1263 dup_group = src_group.duplicate(doc)
922d1caf6632 Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents: 1285
diff changeset
1264
1247
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
1265 old_nodes = _DOM_iterator(src_group)
1286
922d1caf6632 Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents: 1285
diff changeset
1266 new_nodes = _DOM_iterator(dup_group)
1247
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
1267 new_gids = set()
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
1268 for old_node in old_nodes:
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
1269 old_node_id = old_node.getAttribute('id')
1286
922d1caf6632 Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents: 1285
diff changeset
1270 new_node = new_nodes.next()
1247
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
1271 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
1272
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
1273 #
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
1274 # 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
1275 # 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
1276 # 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
1277 # 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
1278 # 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
1279 #
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
1280 gid = self.new_id()
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
1281 while gid in new_gids:
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
1282 gid = self.new_id()
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
1283 pass
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
1284 new_gids.add(gid)
45e9566ea5c0 Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents: 1246
diff changeset
1285 new_node.setAttribute('id', gid)
1246
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
1286 pass
1286
922d1caf6632 Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents: 1285
diff changeset
1287
922d1caf6632 Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents: 1285
diff changeset
1288 for child in dup_group.childList():
922d1caf6632 Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents: 1285
diff changeset
1289 dup_group.removeChild(child) # prevent from crash
1298
2a5da457474d Fix typo
Thinker K.F. Li <thinker@codemud.net>
parents: 1295
diff changeset
1290 dst_group.appendChild(child)
1286
922d1caf6632 Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents: 1285
diff changeset
1291 pass
1246
42c4874c8d1e Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents: 1244
diff changeset
1292 pass
1291
a3e04b3f2a8c Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1286
diff changeset
1293
a3e04b3f2a8c Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1286
diff changeset
1294 ## \brief Clone children of a source group to a destinate group.
a3e04b3f2a8c Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1286
diff changeset
1295 #
a3e04b3f2a8c Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1286
diff changeset
1296 # It create a 'svg:use' node for every child of the source group,
a3e04b3f2a8c Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1286
diff changeset
1297 # and append nodes to the desitnate group.
a3e04b3f2a8c Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1286
diff changeset
1298 #
a3e04b3f2a8c Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1286
diff changeset
1299 def clone_group_children(self, src_group, dst_group):
a3e04b3f2a8c Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1286
diff changeset
1300 doc = self._doc
a3e04b3f2a8c Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1286
diff changeset
1301
a3e04b3f2a8c Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1286
diff changeset
1302 for src_child in src_group.childList():
a3e04b3f2a8c Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1286
diff changeset
1303 src_child_id = src_child.getAttribute('id')
a3e04b3f2a8c Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1286
diff changeset
1304 dst_child_id = self.new_id()
a3e04b3f2a8c Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1286
diff changeset
1305
a3e04b3f2a8c Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1286
diff changeset
1306 dst_child = doc.createElement('svg:use')
1294
Thinker K.F. Li <thinker@codemud.net>
parents: 1291 1290
diff changeset
1307 dst_child.setAttribute('id', dst_child_id)
1291
a3e04b3f2a8c Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1286
diff changeset
1308 dst_child.setAttribute('xlink:href', '#' + src_child_id)
1294
Thinker K.F. Li <thinker@codemud.net>
parents: 1291 1290
diff changeset
1309 dst_child.setAttribute('ns0:duplicate-src', src_child_id)
1295
71118bff7d61 CHange the wrong append to appendCHild
wycc
parents: 1294
diff changeset
1310 dst_group.appendChild(dst_child)
1291
a3e04b3f2a8c Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1286
diff changeset
1311 pass
a3e04b3f2a8c Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1286
diff changeset
1312 pass
1323
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1313
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1314 ## \brief To test a graphic node.
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1315 #
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1316 # A graphic node is a SVG node that is not layer group, scene
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1317 # group, ... etc. It is only a normal node in a layer group or a
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1318 # scene group.
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1319 def is_graph_node(self, node):
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1320 try:
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1321 mode = node.getAttribute('inkscape:groupmode')
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1322 except:
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1323 pass
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1324 else:
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1325 if mode == 'layer':
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1326 return False
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1327 pass
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1328
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1329 try:
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1330 label = node.geteAttribute('inkscape:label')
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1331 except:
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1332 pass
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1333 else:
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1334 return False
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1335
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1336 try:
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1337 scene_group = node.geteAttribute('scene_group')
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1338 except:
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1339 pass
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1340 else:
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1341 if scene_group == 'true':
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1342 return False
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1343 pass
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1344
ffbbd3aa218d Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents: 1322
diff changeset
1345 return True
1243
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1346 pass
d5f70928e9f1 Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1347