Mercurial > MadButterfly
annotate pyink/domview.py @ 1431:60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
- Add functions to remember frame and layer for timeline at domview.
- Recall active frame and layer when calling switch_component() and
switch_timeline().
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 11 Apr 2011 00:05:25 +0800 |
parents | bf405cb2d7cb |
children | 8e8c9ab3818f |
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 |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
4 from trait import trait, require, composite |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
5 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
6 |
1318
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
7 ## \brief Compare two nodes with ID. |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
8 # |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
9 # \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
|
10 # |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
11 def _id_eq(node1, node2): |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
12 try: |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
13 node1_id = node1.getAttribute('id') |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
14 except: |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
15 return False |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
16 |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
17 try: |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
18 node2_id = node2.getAttribute('id') |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
19 except: |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
20 return False |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
21 return node1_id == node2_id |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
22 |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
23 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
24 class Layer: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
25 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
|
26 self.scenes = [] |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
27 self.group = node |
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 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
30 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
31 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
32 class Timeline(object): |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
33 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
|
34 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
|
35 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
36 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
37 def name(self): |
1407 | 38 try: |
39 name = self.scenes_node.getAttribute('name') | |
40 except: | |
41 name='default' | |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
42 return name |
1331
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
43 |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
44 def rename(self, new_name): |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
45 scenes_node = self.scenes_node |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
46 scenes_node.setAttribute('name', new_name) |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
47 pass |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
48 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
49 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
50 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
51 class Component(object): |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
52 # |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
53 # \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
|
54 # |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
55 def __init__(self, comp_mgr, comp_node): |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
56 self._comp_mgr = comp_mgr |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
57 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
|
58 self.layers = [] |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
59 self.timelines = [] |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
60 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
61 if comp_node: |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
62 self._initialize_comp() |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
63 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
64 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
65 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
66 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
|
67 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
|
68 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
|
69 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
|
70 break |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
71 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
72 else: # no any ns0:scenes |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
73 doc = self._comp_mgr._doc |
1310
85d04ba11146
Support adding new components
Thinker K.F. Li <thinker@codemud.net>
parents:
1308
diff
changeset
|
74 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
|
75 scenes_node.setAttribute('name', 'default') |
1310
85d04ba11146
Support adding new components
Thinker K.F. Li <thinker@codemud.net>
parents:
1308
diff
changeset
|
76 |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
77 node_id = self._comp_mgr.new_id() |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
78 scenes_node.setAttribute('id', node_id) |
1310
85d04ba11146
Support adding new components
Thinker K.F. Li <thinker@codemud.net>
parents:
1308
diff
changeset
|
79 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
80 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
|
81 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
82 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
83 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
84 def name(self): |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
85 if self.node: |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
86 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
|
87 else: |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
88 name = 'main' |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
89 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
90 return name |
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 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
|
93 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
|
94 return names |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
95 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
96 def parse_timelines(self): |
1336
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
97 self.timelines[:] = [] |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
98 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
99 if self.node: |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
100 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
|
101 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
102 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
103 comp_node = self.node |
1310
85d04ba11146
Support adding new components
Thinker K.F. Li <thinker@codemud.net>
parents:
1308
diff
changeset
|
104 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
|
105 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
|
106 tl = Timeline(child) |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
107 self.timelines.append(tl) |
1336
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
108 print ' ' + tl.name() |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
109 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
110 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
111 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
112 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
113 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
|
114 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
|
115 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
|
116 return tl |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
117 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
118 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
|
119 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
120 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
|
121 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
|
122 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
|
123 return True |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
124 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
125 return False |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
126 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
127 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
|
128 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
|
129 raise ValueError, \ |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
130 '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
|
131 |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
132 doc = self._comp_mgr._doc |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
133 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
|
134 |
1310
85d04ba11146
Support adding new components
Thinker K.F. Li <thinker@codemud.net>
parents:
1308
diff
changeset
|
135 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
|
136 scenes_node.setAttribute('name', name) |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
137 node_id = self._comp_mgr.new_id() |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
138 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
|
139 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
140 comp_node.appendChild(scenes_node) |
1317
e2ad9eb7f7a4
Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
1316
diff
changeset
|
141 |
e2ad9eb7f7a4
Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
1316
diff
changeset
|
142 tl = Timeline(scenes_node) |
e2ad9eb7f7a4
Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
1316
diff
changeset
|
143 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
|
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 ## \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
|
147 # |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
148 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
|
149 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
|
150 name = tl.name() |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
151 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
|
152 raise ValueError, \ |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
153 '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
|
154 |
e2ad9eb7f7a4
Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
1316
diff
changeset
|
155 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
|
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 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
|
159 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
|
160 if tl.name() == name: |
1317
e2ad9eb7f7a4
Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
1316
diff
changeset
|
161 comp_node = self.node |
e2ad9eb7f7a4
Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
1316
diff
changeset
|
162 comp_node.removeChild(tl.scenes_node) |
e2ad9eb7f7a4
Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
1316
diff
changeset
|
163 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
164 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
|
165 return |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
166 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
167 raise ValueError, 'try to remove a non-existed timeline - %s' % (name) |
1331
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
168 |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
169 def rename_timeline(self, timeline_name, new_name): |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
170 for i, tl in enumerate(self.timelines): |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
171 if tl.name() == timeline_name: |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
172 tl.rename(new_name) |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
173 return |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
174 pass |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
175 raise ValueError, 'try to remove a non-existed timeline - %s' % (name) |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
176 |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
177 def rename(self, new_name): |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
178 self.node.setAttribute('name', new_name) |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
179 pass |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
180 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
181 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
182 |
1336
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
183 ## \brief A mix-in for class component_manager for UI updating. |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
184 # |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
185 # This class collects all methods for supporting UI updating. |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
186 # |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
187 class component_manager_ui_update(object): |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
188 ## \brief Update the list of components. |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
189 # |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
190 def reparse_components(self): |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
191 saved_cur_comp = self._cur_comp |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
192 self._components[:] = [self._main_comp] |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
193 self._comp_names.clear() |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
194 self._parse_components() |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
195 |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
196 for comp in self._components: |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
197 if comp.name() == saved_cur_comp.name(): |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
198 self._cur_comp = comp |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
199 break |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
200 pass |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
201 else: |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
202 self._cur_comp = self._main_comp |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
203 pass |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
204 pass |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
205 |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
206 ## \brief Update the list of timelines of current component. |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
207 # |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
208 def reparse_timelines(self): |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
209 comp = self._cur_comp |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
210 saved_cur_timeline = self._cur_timeline |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
211 comp.parse_timelines() |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
212 |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
213 for timeline in comp.timelines: |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
214 if timeline.name() == saved_cur_timeline.name(): |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
215 self._cur_timeline = timeline |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
216 break |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
217 pass |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
218 else: |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
219 self._cur_timeline = comp.timelines[0] |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
220 pass |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
221 pass |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
222 pass |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
223 |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
224 |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
225 ## \brief A trait for class domview for managing components. |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
226 # |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
227 # 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
|
228 # 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
|
229 # 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
|
230 # 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
|
231 # 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
|
232 # 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
|
233 # 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
|
234 # 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
|
235 # meaningful names.) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
236 # |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
237 # 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
|
238 # 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
|
239 # removed and normalized to normal components. |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
240 # |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
241 @trait |
1336
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
242 class component_manager(component_manager_ui_update): |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
243 _scenes_node = require |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
244 _metadata_node = require |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
245 _doc = require |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
246 _root = require |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
247 _layers = require |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
248 _layers_parent = require |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
249 new_id = require |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
250 get_node = require |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
251 reset = require |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
252 |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
253 def __init__(self): |
1342
972d749b9656
Move component_manager to a separated object.
Thinker K.F. Li <thinker@codemud.net>
parents:
1340
diff
changeset
|
254 super(component_manager, self).__init__() |
1302
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
255 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
|
256 self._components = [] |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
257 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
|
258 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
|
259 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
|
260 self._cur_timeline = None |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
261 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
|
262 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
263 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
264 def _set_main_component(self): |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
265 comp = Component(self, None) |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
266 comp.layers = self._layers |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
267 scenes_node = self._scenes_node |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
268 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
|
269 comp.timelines = [timeline] |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
270 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
271 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
|
272 self._comp_names.add('main') |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
273 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
274 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
|
275 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
276 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
277 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
|
278 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
|
279 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
|
280 for child in components_node.childList(): |
1428
43369f3314d8
Fix the issue of loading components from SVG.
Thinker K.F. Li <thinker@codemud.net>
parents:
1427
diff
changeset
|
281 child_node_name = child.name() |
43369f3314d8
Fix the issue of loading components from SVG.
Thinker K.F. Li <thinker@codemud.net>
parents:
1427
diff
changeset
|
282 if child_node_name != 'ns0:component': |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
283 continue |
1428
43369f3314d8
Fix the issue of loading components from SVG.
Thinker K.F. Li <thinker@codemud.net>
parents:
1427
diff
changeset
|
284 |
43369f3314d8
Fix the issue of loading components from SVG.
Thinker K.F. Li <thinker@codemud.net>
parents:
1427
diff
changeset
|
285 child_name = child.getAttribute('name') |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
286 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
|
287 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
|
288 |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
289 comp = Component(self, child) |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
290 comp.parse_timelines() |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
291 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
292 self._components.append(comp) |
1428
43369f3314d8
Fix the issue of loading components from SVG.
Thinker K.F. Li <thinker@codemud.net>
parents:
1427
diff
changeset
|
293 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
294 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
|
295 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
296 pass |
1302
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
297 |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
298 ## \brief To initialize subtree of metadata. |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
299 # |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
300 # 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
|
301 # |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
302 def _component_manager_init_metadata(self): |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
303 metadata_node = self._metadata_node |
1321
6a014a4ec79e
Fix missed variable name after refactory
Thinker K.F. Li <thinker@codemud.net>
parents:
1318
diff
changeset
|
304 |
6a014a4ec79e
Fix missed variable name after refactory
Thinker K.F. Li <thinker@codemud.net>
parents:
1318
diff
changeset
|
305 # Make sure ns0:components in metadata |
6a014a4ec79e
Fix missed variable name after refactory
Thinker K.F. Li <thinker@codemud.net>
parents:
1318
diff
changeset
|
306 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
|
307 if n.name() == 'ns0:components': |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
308 self._components_node = n |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
309 break |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
310 pass |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
311 else: |
1342
972d749b9656
Move component_manager to a separated object.
Thinker K.F. Li <thinker@codemud.net>
parents:
1340
diff
changeset
|
312 components_node = \ |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
313 self._doc.createElement("ns0:components") |
1321
6a014a4ec79e
Fix missed variable name after refactory
Thinker K.F. Li <thinker@codemud.net>
parents:
1318
diff
changeset
|
314 metadata_node.appendChild(components_node) |
1302
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
315 self._components_node = components_node |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
316 pass |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
317 |
1321
6a014a4ec79e
Fix missed variable name after refactory
Thinker K.F. Li <thinker@codemud.net>
parents:
1318
diff
changeset
|
318 # Make sure the group for containing components. |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
319 for n in self._root.childList(): |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
320 if n.name() != 'svg:g': |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
321 continue |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
322 try: |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
323 nlabel = n.getAttribute('inkscape:label') |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
324 except: |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
325 continue |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
326 if nlabel == 'components': |
1427
5b69baa49a8b
Abandon head #6fa411fd9549
Thinker K.F. Li <thinker@codemud.net>
parents:
1419
diff
changeset
|
327 self._components_group = n |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
328 break |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
329 pass |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
330 else: # no components group |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
331 components_group = self._doc.createElement('svg:g') |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
332 components_group.setAttribute('inkscape:label', 'components') |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
333 gid = self.new_id() |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
334 components_group.setAttribute('id', gid) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
335 |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
336 self._root.appendChild(components_group) |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
337 self._components_group = components_group |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
338 pass |
1302
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
339 pass |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
340 |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
341 def _start_component_manager(self): |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
342 self._component_manager_init_metadata() |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
343 self._set_main_component() |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
344 self._parse_components() |
1316
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
345 |
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
346 self._cur_comp = self._main_comp |
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
347 tl = self._main_comp.get_timeline('default') |
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
348 self._cur_timeline = tl |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
349 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
|
350 pass |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
351 |
1327
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
352 ## \brief Create component group |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
353 # |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
354 # 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
|
355 # 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
|
356 # |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
357 def _create_component_group(self): |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
358 doc = self._doc |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
359 group = doc.createElement('svg:g') |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
360 gid = self.new_id() |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
361 group.setAttribute('id', gid) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
362 |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
363 self._components_group.appendChild(group) |
1327
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
364 |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
365 # Create layers group |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
366 layers_group = doc.createElement('svg:g') |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
367 gid = self.new_id() |
1327
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
368 layers_group.setAttribute('id', gid) |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
369 layers_group.setAttribute('inkscape:label', 'layers') |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
370 group.appendChild(layers_group) |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
371 |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
372 return group |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
373 |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
374 ## \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
|
375 # |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
376 # \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
|
377 # \param comp_group_id is the component group. |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
378 # \return a ns0:component node. |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
379 # |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
380 def _create_component_node(self, comp_name, comp_group_id): |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
381 comp_node = self._doc.createElement('ns0:component') |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
382 comp_id = self.new_id() |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
383 comp_node.setAttribute('id', comp_id) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
384 comp_node.setAttribute('name', comp_name) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
385 comp_node.setAttribute('ref', comp_group_id) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
386 self._components_node.appendChild(comp_node) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
387 return comp_node |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
388 |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
389 ## \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
|
390 # |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
391 def _get_component(self, comp_name): |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
392 if comp_name in self._comp_names: |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
393 for comp in self._components: |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
394 if comp.name() == comp_name: |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
395 return comp |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
396 pass |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
397 pass |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
398 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
|
399 |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
400 ## \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
|
401 # |
1327
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
402 def _create_comp_layer_group(self, layers_group, layer_name): |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
403 doc = self._doc |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
404 gid = self.new_id() |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
405 |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
406 layer_group = doc.createElement('svg:g') |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
407 layer_group.setAttribute('id', gid) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
408 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
|
409 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
|
410 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
|
411 |
1323
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
412 return layer_group |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
413 |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
414 ## \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
|
415 # |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
416 # 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
|
417 # component. |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
418 # |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
419 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
|
420 comp = self._get_component(comp_name) |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
421 layer = comp.layers[layer_idx] |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
422 return layer.group |
1327
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
423 |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
424 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
|
425 if comp_name == 'main': |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
426 return self._root |
1327
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
427 |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
428 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
|
429 layers_group = comp_group.firstChild() |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
430 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
|
431 |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
432 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
|
433 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
434 def all_comp_names(self): |
1317
e2ad9eb7f7a4
Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
1316
diff
changeset
|
435 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
|
436 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
437 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
|
438 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
|
439 |
1326
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
440 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
|
441 if comp_name == 'main': |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
442 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
|
443 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
|
444 group = layer.group |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
445 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
|
446 pass |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
447 return |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
448 |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
449 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
|
450 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
|
451 pass |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
452 |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
453 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
|
454 if comp_name == 'main': |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
455 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
|
456 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
|
457 group = layer.group |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
458 group.setAttribute('style', '') |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
459 pass |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
460 return |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
461 |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
462 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
|
463 comp_group.setAttribute('style', '') |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
464 pass |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
465 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
466 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
|
467 old_comp = self._cur_comp |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
468 |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
469 comp = self._get_component(comp_name) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
470 self._cur_comp = comp |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
471 self._layers = comp.layers |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
472 comp_name = self._cur_comp.name() |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
473 # for domview |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
474 self._layers_parent = \ |
1342
972d749b9656
Move component_manager to a separated object.
Thinker K.F. Li <thinker@codemud.net>
parents:
1340
diff
changeset
|
475 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
|
476 |
1430
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
477 self.make_sure_timeline() |
1323
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
478 |
1419
3519f43da037
Check old component before hiding it for a component switching.
Thinker K.F. Li <thinker@codemud.net>
parents:
1418
diff
changeset
|
479 try: |
3519f43da037
Check old component before hiding it for a component switching.
Thinker K.F. Li <thinker@codemud.net>
parents:
1418
diff
changeset
|
480 comp_grp = self.get_component_group(old_comp.name()) |
3519f43da037
Check old component before hiding it for a component switching.
Thinker K.F. Li <thinker@codemud.net>
parents:
1418
diff
changeset
|
481 old_comp_existed = True |
3519f43da037
Check old component before hiding it for a component switching.
Thinker K.F. Li <thinker@codemud.net>
parents:
1418
diff
changeset
|
482 except ValueError: |
3519f43da037
Check old component before hiding it for a component switching.
Thinker K.F. Li <thinker@codemud.net>
parents:
1418
diff
changeset
|
483 old_comp_existed = False |
3519f43da037
Check old component before hiding it for a component switching.
Thinker K.F. Li <thinker@codemud.net>
parents:
1418
diff
changeset
|
484 pass |
3519f43da037
Check old component before hiding it for a component switching.
Thinker K.F. Li <thinker@codemud.net>
parents:
1418
diff
changeset
|
485 |
3519f43da037
Check old component before hiding it for a component switching.
Thinker K.F. Li <thinker@codemud.net>
parents:
1418
diff
changeset
|
486 if old_comp_existed: |
3519f43da037
Check old component before hiding it for a component switching.
Thinker K.F. Li <thinker@codemud.net>
parents:
1418
diff
changeset
|
487 self.hide_component(old_comp.name()) |
3519f43da037
Check old component before hiding it for a component switching.
Thinker K.F. Li <thinker@codemud.net>
parents:
1418
diff
changeset
|
488 pass |
3519f43da037
Check old component before hiding it for a component switching.
Thinker K.F. Li <thinker@codemud.net>
parents:
1418
diff
changeset
|
489 |
1326
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
490 self.show_component(comp.name()) |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
491 pass |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
492 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
493 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
|
494 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
|
495 raise ValueError, \ |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
496 '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
|
497 |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
498 comp_group = self._create_component_group() |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
499 comp_group_id = comp_group.getAttribute('id') |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
500 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
|
501 |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
502 comp = Component(self, comp_node) |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
503 comp.parse_timelines() |
1323
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
504 |
1327
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
505 self._components.append(comp) |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
506 self._comp_names.add(comp_name) |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
507 |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
508 # 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
|
509 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
|
510 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
|
511 layer = Layer(layer_group) |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
512 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
|
513 |
1326
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
514 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
|
515 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
516 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
517 def add_component_node(self, comp_node): |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
518 comp = Component(self, comp_node) |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
519 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
|
520 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
|
521 raise ValueError, \ |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
522 '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
|
523 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
524 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
|
525 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
|
526 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
527 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
528 def rm_component(self, comp_name): |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
529 comp = self._get_component(comp_name) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
530 comp_name = comp.name() |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
531 comp_node = comp.node |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
532 comp_group = self.get_component_group(comp_name) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
533 |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
534 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
|
535 self._comp_names.remove(comp_name) |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
536 self._components_node.removeChild(comp_node) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
537 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
|
538 pass |
1331
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
539 |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
540 def rename_component(self, comp_name, new_name): |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
541 comp = self._get_component(comp_name) |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
542 comp.rename(new_name) |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
543 pass |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
544 |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
545 def get_component_group(self, comp_name): |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
546 comp = self._get_component(comp_name) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
547 |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
548 comp_name = comp.name() |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
549 if comp_name == 'main': |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
550 return self._root |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
551 |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
552 comp_node = comp.node |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
553 gid = comp_node.getAttribute('ref') |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
554 comp_group = self.get_node(gid) |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
555 return comp_group |
1316
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
556 |
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
557 def get_current_component(self): |
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
558 return self._cur_comp.name() |
1344
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
559 |
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
560 ## \brief Hide scene groups of current timeline. |
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
561 # |
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
562 # This method all scene groups of current timeline invisible. |
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
563 # |
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
564 def _hide_current_timeline(self): |
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
565 tl = self._cur_timeline |
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
566 scenes_node = tl.scenes_node |
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
567 for child in scenes_node.childList(): |
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
568 if child.name() != 'ns0:scene': |
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
569 continue |
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
570 gid = child.getAttribute('ref') |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
571 group = self.get_node(gid) |
1344
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
572 group.setAttribute('style', 'display: none') |
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
573 pass |
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
574 pass |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
575 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
576 def switch_timeline(self, timeline_name): |
1344
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
577 if self._cur_timeline: |
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
578 self._hide_current_timeline() |
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
579 pass |
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
580 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
581 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
|
582 self._cur_timeline = tl |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
583 self._scenes_node = tl.scenes_node # of class domview |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
584 |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
585 # Make domview to rescan layers and scenes. |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
586 self.reset() # from domview |
1430
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
587 |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
588 cur_comp_name = self.get_current_component() |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
589 cur_comp_node = self.get_component_group(cur_comp_name) |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
590 cur_comp_node.setAttribute("cur_timeline", timeline_name) |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
591 pass |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
592 |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
593 def make_sure_timeline(self): |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
594 cur_comp_name = self.get_current_component() |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
595 cur_comp_node = self.get_component_group(cur_comp_name) |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
596 try: |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
597 timeline_name = cur_comp_node.getAttribute("cur_timeline") |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
598 except KeyError: |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
599 timeline_name = self.all_timeline_names()[0] |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
600 pass |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
601 self._cur_timeline = None |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
602 self.switch_timeline(timeline_name) |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
603 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
604 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
605 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
|
606 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
|
607 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
608 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
609 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
|
610 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
|
611 pass |
1306
8c0a4684c1f7
Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1302
diff
changeset
|
612 |
1331
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
613 def rename_timeline_of_component(self, timeline_name, new_name, comp_name): |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
614 comp = self._get_component(comp_name) |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
615 comp.rename_timeline(timeline_name, new_name) |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
616 pass |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
617 |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
618 def rename_timeline(self, timeline_name, new_name): |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
619 comp_name = self._cur_comp.name() |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
620 self.rename_timeline_of_component(timeline_name, new_name, comp_name) |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
621 pass |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
622 |
1306
8c0a4684c1f7
Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1302
diff
changeset
|
623 def all_timeline_names(self): |
8c0a4684c1f7
Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1302
diff
changeset
|
624 r = self._cur_comp.all_timeline_names() |
8c0a4684c1f7
Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1302
diff
changeset
|
625 return r |
8c0a4684c1f7
Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1302
diff
changeset
|
626 |
8c0a4684c1f7
Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1302
diff
changeset
|
627 def has_timeline(self, name): |
8c0a4684c1f7
Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1302
diff
changeset
|
628 r = self._cur_comp.has_timeline(name) |
8c0a4684c1f7
Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1302
diff
changeset
|
629 return r |
1316
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
630 |
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
631 def get_current_timeline(self): |
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
632 return self._cur_timeline.name() |
1323
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
633 |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
634 ## \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
|
635 # |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
636 # 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
|
637 # specified component. |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
638 # |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
639 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
|
640 group_parent = group.parent() |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
641 if group_parent: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
642 group_parent.removeChild(group) |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
643 pass |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
644 |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
645 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
|
646 layer_group.appendChild(group) |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
647 pass |
1328
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
648 |
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
649 ## \brief Create a link to a component. |
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
650 # |
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
651 # \param parent_group is where the link will be pliaced in. |
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
652 # \return link node. |
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
653 # |
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
654 def link_to_component(self, comp_name, parent_group): |
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
655 layers_group = self._get_layers_group_of_component(comp_name) |
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
656 |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
657 use_node = self._doc.createElement('svg:use') |
1328
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
658 layers_group_id = layers_group.getAttribute('id') |
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
659 use_node.setAttribute('xlink:href', '#' + layers_group_id) |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
660 use_node_id = self.new_id() |
1328
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
661 use_node.setAttribute('id', use_node_id) |
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
662 use_node.setAttribute('use_component', 'true') |
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
663 |
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
664 parent_group.appendChild(use_node) |
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
665 |
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
666 return use_node |
1431
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
667 |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
668 def remember_current_frame(self, layer_idx, frame_idx): |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
669 if not isinstance(layer_idx, int): |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
670 raise TypeError, 'layer index should be a integer' |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
671 if not isinstance(frame_idx, int): |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
672 raise TypeError, 'frame index should be a integer' |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
673 |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
674 timeline_name = self.get_current_timeline() |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
675 timeline = self._cur_comp.get_timeline(timeline_name) |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
676 timeline_scenes = timeline.scenes_node |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
677 timeline_scenes.setAttribute('cur_layer', str(layer_idx)) |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
678 timeline_scenes.setAttribute('cur_frame', str(frame_idx)) |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
679 pass |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
680 |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
681 def get_current_frame(self): |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
682 timeline_name = self.get_current_timeline() |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
683 timeline = self._cur_comp.get_timeline(timeline_name) |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
684 timeline_scenes = timeline.scenes_node |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
685 try: |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
686 cur_layer = timeline_scenes.getAttribute('cur_layer') |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
687 except KeyError: |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
688 cur_layer_idx = 0 |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
689 else: |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
690 cur_layer_idx = int(cur_layer) |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
691 pass |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
692 try: |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
693 cur_frame = timeline_scenes.getAttribute('cur_frame') |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
694 except KeyError: |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
695 cur_frame_idx = 0 |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
696 else: |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
697 cur_frame_idx = int(cur_frame) |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
698 pass |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
699 |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
700 return cur_layer_idx, cur_frame_idx |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
701 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
702 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
703 |
1350
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
704 ## \brief Parser for scenes nodes. |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
705 # |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
706 # This class parses scenes nodes and collect ID of all nodes. |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
707 # |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
708 @trait |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
709 class scenes_parser(object): |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
710 _root = require |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
711 _scenes_node = require |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
712 _id2node = require |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
713 _group2scene = require |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
714 current = require |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
715 _maxframe = require |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
716 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
717 def _find_maxframe(self, scenes_node): |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
718 maxframe = 0 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
719 for child in scenes_node.childList(): |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
720 if child.name() != 'ns0:scene': |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
721 continue |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
722 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
723 try: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
724 start = child.getAttribute('start') |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
725 maxframe = max(int(start), maxframe) |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
726 except: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
727 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
728 try: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
729 end = child.getAttribute('end') |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
730 maxframe = max(int(end), maxframe) |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
731 except: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
732 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
733 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
734 return maxframe |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
735 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
736 ## \brief Collect ID of nodes in the document. |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
737 # |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
738 # It is used to implement a fast mapping from an ID to the respective node. |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
739 # |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
740 def _collect_node_ids(self): |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
741 self._id2node = {} |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
742 root = self._root |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
743 for n in root.childList(): |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
744 self._collect_node_ids_recursive(n) |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
745 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
746 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
747 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
748 def _collect_node_ids_recursive(self, node): |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
749 try: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
750 node_id = node.getAttribute('id') |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
751 except: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
752 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
753 else: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
754 self._id2node[node_id] = node |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
755 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
756 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
757 for n in node.childList(): |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
758 self._collect_node_ids_recursive(n) |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
759 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
760 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
761 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
762 def parse_one_scene(self, scene_node): |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
763 assert scene_node.name() == 'ns0:scene' |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
764 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
765 start = int(scene_node.getAttribute("start")) |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
766 try: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
767 end = int(scene_node.getAttribute("end")) |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
768 except: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
769 end = start |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
770 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
771 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
772 try: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
773 scene_type = scene_node.getAttribute('type') |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
774 if scene_type == None: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
775 scene_type = 'normal' |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
776 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
777 except: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
778 scene_type = 'normal' |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
779 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
780 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
781 return start, end, scene_type |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
782 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
783 def _parse_one_scenes(self, scenes_node): |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
784 try: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
785 cur = int(n.getAttribute("current")) |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
786 except: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
787 cur = 0 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
788 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
789 self.current = cur |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
790 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
791 for scene_node in scenes_node.childList(): |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
792 if scene_node.name() != 'ns0:scene': |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
793 continue |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
794 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
795 try: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
796 start, end, scene_type = self.parse_one_scene(scene_node) |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
797 group_id = scene_node.getAttribute("ref") |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
798 except: # the scene node is incompleted. |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
799 continue |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
800 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
801 self._group2scene[group_id] = scene_node |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
802 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
803 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
804 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
805 ## \brief Parse all scenes node in svg:metadata subtree. |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
806 # |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
807 def _collect_all_scenes(self): |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
808 scenes_node = self._scenes_node |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
809 self._parse_one_scenes(scenes_node) |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
810 self._maxframe = self._find_maxframe(scenes_node) |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
811 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
812 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
813 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
814 ## \brief Return the node with given ID. |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
815 # |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
816 def get_node(self, node_id): |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
817 value = self._id2node[node_id] |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
818 if isinstance(value, list): |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
819 return value[-1] |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
820 return value |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
821 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
822 ## \brief Return a scene node corresponding to a scene group of given ID. |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
823 # |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
824 def get_scene(self, group_id): |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
825 return self._group2scene[group_id] |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
826 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
827 def new_id(self): |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
828 while True: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
829 candidate = 's%d' % int(random.random()*100000) |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
830 if candidate not in self._id2node: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
831 return candidate |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
832 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
833 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
834 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
835 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
836 ## \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
|
837 # |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
838 # 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
|
839 # node and scene group ID to scene node. |
1350
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
840 @composite |
1244
b241f9768833
Remove MBScene_ from the prefix of class names.
Thinker K.F. Li <thinker@codemud.net>
parents:
1243
diff
changeset
|
841 class domview_monitor(object): |
1350
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
842 use_traits = (scenes_parser,) |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
843 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
844 method_map_traits = { |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
845 scenes_parser._find_maxframe: '_find_maxframe', |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
846 scenes_parser._collect_all_scenes: '_collect_all_scenes', |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
847 scenes_parser._collect_node_ids: '_collect_node_ids'} |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
848 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
849 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
|
850 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
|
851 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
852 self._maxframe = 0 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
853 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
|
854 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
|
855 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
856 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
857 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
|
858 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
|
859 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
|
860 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
861 doc = self._doc |
1253
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1247
diff
changeset
|
862 dom_event.addEventListener(doc, 'DOMNodeInserted', |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1247
diff
changeset
|
863 self._on_insert_node, None) |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1247
diff
changeset
|
864 dom_event.addEventListener(doc, 'DOMNodeRemoved', |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1247
diff
changeset
|
865 self._on_remove_node, None) |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1247
diff
changeset
|
866 dom_event.addEventListener(doc, 'DOMAttrModified', |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1247
diff
changeset
|
867 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
|
868 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
869 |
1340
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
870 ## \brief Add a node to id2node mapping. |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
871 # |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
872 # domview_monitor._id2node is a multiple mapping to map a key to |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
873 # multiple node. The reason that it is not a single mapping is |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
874 # Inkscape would insert a node with the ID from the node been |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
875 # copied, and change its ID to a unique one later. So, we must |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
876 # provide the capability to handle two or more nodes with the same |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
877 # ID. |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
878 def _map_id2node(self, node, node_id): |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
879 if node_id in self._id2node: |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
880 old_value = self._id2node[node_id] |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
881 if isinstance(old_value, list): |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
882 old_value.append(node) |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
883 else: |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
884 self._id2node[node_id] = [old_value, node] |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
885 pass |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
886 else: |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
887 self._id2node[node_id] = node |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
888 pass |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
889 pass |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
890 |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
891 def _unmap_id2node(self, node, node_id): |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
892 if node_id not in self._id2node: |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
893 raise ValueError, 'invalide node ID (%s)' % (node_id) |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
894 |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
895 value = self._id2node[node_id] |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
896 if isinstance(value, list): |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
897 value.remove(node) |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
898 if not value: |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
899 del self._id2node[node_id] |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
900 pass |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
901 pass |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
902 else: |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
903 del self._id2node[node_id] |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
904 pass |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
905 pass |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
906 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
907 ## \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
|
908 # |
1302
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
909 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
|
910 self._maxframe = 0 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
911 self._id2node = {} |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
912 self._group2scene = {} |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
913 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
914 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
|
915 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
|
916 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
917 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
918 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
|
919 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
|
920 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
|
921 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
922 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
923 try: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
924 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
|
925 except: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
926 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
927 else: |
1340
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
928 self._map_id2node(child, child_id) |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
929 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
930 |
1318
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
931 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
|
932 try: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
933 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
|
934 except: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
935 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
936 else: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
937 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
|
938 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
|
939 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
940 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
941 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
942 try: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
943 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
|
944 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
|
945 except: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
946 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
947 try: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
948 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
|
949 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
|
950 except: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
951 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
952 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
|
953 pass |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
954 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
955 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
|
956 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
|
957 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
|
958 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
959 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
960 try: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
961 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
|
962 except: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
963 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
964 else: |
1340
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
965 self._unmap_id2node(child, child_id) |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
966 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
967 |
1318
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
968 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
|
969 try: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
970 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
|
971 except: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
972 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
973 else: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
974 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
|
975 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
976 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
977 try: |
1318
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
978 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
|
979 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
|
980 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
|
981 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
982 except: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
983 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
984 pass |
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 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
987 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
|
988 if old_value == new_value: |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
989 return |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
990 |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
991 if name == 'id': |
1340
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
992 if old_value and old_value in self._id2node: |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
993 self._unmap_id2node(node, old_value) |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
994 pass |
1336
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
995 if new_value: |
1340
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
996 self._map_id2node(node, new_value) |
1336
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
997 pass |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
998 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
999 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
|
1000 parent_node = node.parent() |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
1001 scenes_node = self._scenes_node |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
1002 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
|
1003 return # not in current timeline |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
1004 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1005 if old_value: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1006 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
|
1007 # 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
|
1008 # wrapper. |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1009 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
|
1010 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1011 if new_value: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1012 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
|
1013 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1014 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1015 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
|
1016 parent_node = node.parent() |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
1017 scenes_node = self._scenes_node |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
1018 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
|
1019 return # not in current timeline |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
1020 |
1276
0442ae9c2ac2
Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents:
1275
diff
changeset
|
1021 try: |
0442ae9c2ac2
Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents:
1275
diff
changeset
|
1022 new_value = int(new_value) |
0442ae9c2ac2
Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents:
1275
diff
changeset
|
1023 old_value = int(old_value) |
0442ae9c2ac2
Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents:
1275
diff
changeset
|
1024 except TypeError: |
0442ae9c2ac2
Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents:
1275
diff
changeset
|
1025 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
|
1026 else: |
0442ae9c2ac2
Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents:
1275
diff
changeset
|
1027 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
|
1028 # _maxframe may be reduced. |
0442ae9c2ac2
Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents:
1275
diff
changeset
|
1029 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
|
1030 else: |
0442ae9c2ac2
Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents:
1275
diff
changeset
|
1031 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
|
1032 pass |
0442ae9c2ac2
Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents:
1275
diff
changeset
|
1033 pass |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1034 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1035 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1036 pass |
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 |
1246
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1039 ## \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
|
1040 # |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1041 def _DOM_iterator(node): |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1042 nodes = [node] |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1043 while nodes: |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1044 node = nodes.pop(0) |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1045 child = node.firstChild() |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1046 while child: |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1047 nodes.append(child) |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1048 child = child.next() |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1049 pass |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1050 yield node |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1051 pass |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1052 pass |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1053 |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1054 |
1352
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1055 @trait |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1056 class layers_parser(object): |
1356
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1057 _doc = require |
1352
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1058 _layers = require |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1059 _layers_parent = require |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1060 get_scene = require |
1356
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1061 get_node = require |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1062 new_id = require |
1352
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1063 |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1064 def parse_all_layers(self): |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1065 layers = self._layers |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1066 layers_parent = self._layers_parent |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1067 |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1068 for child in layers_parent.childList(): |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1069 if child.name() != 'svg:g': |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1070 continue |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1071 |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1072 try: |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1073 label = child.getAttribute('inkscape:label') |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1074 except: |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1075 pass |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1076 else: # has no label |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1077 if label == 'components': |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1078 continue |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1079 pass |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1080 |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1081 layer_group = child |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1082 layer = Layer(layer_group) |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1083 layer.idx = len(layers) |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1084 layers.append(layer) |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1085 self.parse_layer(layer.idx) |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1086 pass |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1087 pass |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1088 |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1089 def parse_layer(self, layer_idx): |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1090 layer = self._layers[layer_idx] |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1091 layer_group = layer.group |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1092 |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1093 for child in layer_group.childList(): |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1094 if child.name() != 'svg:g': |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1095 continue |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1096 try: |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1097 child_id = child.getAttribute('id') |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1098 scene_node = self.get_scene(child_id) |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1099 except: |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1100 continue |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1101 |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1102 layer.scenes.append(scene_node) |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1103 pass |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1104 pass |
1354
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1352
diff
changeset
|
1105 |
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1352
diff
changeset
|
1106 def get_layer_num(self): |
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1352
diff
changeset
|
1107 return len(self._layers) |
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1352
diff
changeset
|
1108 |
1356
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1109 ## \brief Add/insert a layer at given position. |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1110 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1111 # \param layer_idx is the position in the layer list. |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1112 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1113 def insert_layer(self, layer_idx, layer_group): |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1114 layers = self._layers |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1115 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1116 layer = Layer(layer_group) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1117 if layer_idx >= len(layers): |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1118 layers.append(layer) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1119 else: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1120 layers.insert(layer_idx, layer) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1121 for idx in range(layer_idx, len(layers)): |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1122 layers[idx].idx = idx |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1123 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1124 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1125 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1126 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1127 ## \brief Manage a existed layer group |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1128 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1129 # This method scan layer groups of all managed layers, and find a |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1130 # proper place to insert it. |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1131 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1132 # \return -1 for error, or layer index. |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1133 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1134 def manage_layer_group(self, layer_group_id): |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1135 layer_group = self.get_node(layer_group_id) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1136 new_layer = Layer(layer_group) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1137 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1138 if not self._layers: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1139 new_layer.idx = 0 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1140 self._layers.append(new_layer) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1141 return 0 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1142 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1143 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1144 # Scan who is after the given group |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1145 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1146 next_group = layer_group.next() |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1147 while next_group: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1148 next_group_id = next_group.getAttribute('id') |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1149 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1150 for vlayer in self._layers: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1151 vlayer_group_id = vlayer.group.getAttribute('id') |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1152 if vlayer_group_id == next_group_id: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1153 # This layer group is after given one. |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1154 self._layers.insert(vlayer.idx, new_layer) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1155 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1156 for idx in range(vlayer.idx, len(self._layers)): |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1157 self._layers[idx].idx = idx |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1158 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1159 return new_layer.idx |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1160 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1161 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1162 next_group = next_group.next() |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1163 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1164 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1165 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1166 # Is the given group after last layer group? |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1167 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1168 tail_group = self._layers[-1].group.next() |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1169 while tail_group: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1170 tail_group_id = tail_group.getAttribute('id') |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1171 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1172 if tail_group_id == layer_group_id: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1173 # it is after last layer group. |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1174 new_layer.idx = len(self._layers) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1175 self._layers.append(new_layer) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1176 return new_layer.idx |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1177 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1178 tail_group = tail_group.next() |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1179 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1180 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1181 return -1 # error, can not determinze the position |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1182 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1183 ## \brief Remove layer and associated scene nodes and scene groups. |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1184 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1185 def rm_layer(self, layer_idx): |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1186 layers = self._layers |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1187 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1188 layer = self._layers[layer_idx] |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1189 for scene_node in layer.scenes: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1190 scene_group_id = scene_node.getAttribute('ref') |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1191 try: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1192 scene_group_node = self.get_node(scene_group_id) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1193 if scene_group_node.parent(): # keep from crashing |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1194 scene_group_node.parent().removeChild(scene_group_node) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1195 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1196 except: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1197 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1198 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1199 if scene_node.parent(): # keep from crashing |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1200 scene_node.parent().removeChild(scene_node) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1201 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1202 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1203 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1204 del layers[layer_idx] |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1205 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1206 for idx in range(layer_idx, len(layers)): |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1207 layers[idx].idx = idx |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1208 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1209 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1210 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1211 def get_layer_group(self, layer_idx): |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1212 layer = self._layers[layer_idx] |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1213 return layer.group |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1214 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1215 def get_all_scene_node_of_layer(self, layer_idx): |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1216 layer = self._layers[layer_idx] |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1217 return layer.scenes |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1218 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1219 def get_layer_data(self, layer_idx): |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1220 layer = self._layers[layer_idx] |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1221 try: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1222 data = layer.data |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1223 except: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1224 return None |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1225 return data |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1226 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1227 def set_layer_data(self, layer_idx, data): |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1228 layer = self._layers[layer_idx] |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1229 layer.data = data |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1230 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1231 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1232 def create_layer_dup_group(self, layer_idx): |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1233 layer = self._layers[layer_idx] |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1234 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1235 dup_group = self._doc.createElement('svg:g') |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1236 gid = self.new_id() |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1237 dup_group.setAttribute('id', gid) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1238 dup_group.setAttribute('inkscape:label', 'dup') |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1239 dup_group.setAttribute('sodipodi:insensitive', '1') |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1240 dup_group.setAttribute('style', '') |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1241 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1242 layer.group.appendChild(dup_group) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1243 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1244 return dup_group |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1245 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1246 ## \brief Return associated layer index of given layer group. |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1247 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1248 # \return -1 for error. |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1249 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1250 def find_layer_of_group(self, group_id): |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1251 for layer_idx, layer in enumerate(self._layers): |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1252 if layer.group.getAttribute('id') == group_id: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1253 return layer_idx |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1254 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1255 return -1 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1256 |
1354
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1352
diff
changeset
|
1257 def reset_layers(self): |
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1352
diff
changeset
|
1258 self._layers[:] = [] |
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1352
diff
changeset
|
1259 self.parse_all_layers() |
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1352
diff
changeset
|
1260 pass |
1352
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1261 pass |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1262 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1263 ## \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
|
1264 # |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1265 # 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
|
1266 # 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
|
1267 # 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
|
1268 # |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
1269 @composite |
1342
972d749b9656
Move component_manager to a separated object.
Thinker K.F. Li <thinker@codemud.net>
parents:
1340
diff
changeset
|
1270 class domview(domview_monitor): |
1352
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1271 use_traits = (component_manager, layers_parser) |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
1272 |
1348
22a79dcbaec6
Change structure of provide_traits and method_map_traits
Thinker K.F. Li <thinker@codemud.net>
parents:
1345
diff
changeset
|
1273 method_map_traits = {component_manager._start_component_manager: |
22a79dcbaec6
Change structure of provide_traits and method_map_traits
Thinker K.F. Li <thinker@codemud.net>
parents:
1345
diff
changeset
|
1274 '_start_component_manager'} |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
1275 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1276 # 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
|
1277 _doc = None |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1278 _root = None |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1279 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1280 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
|
1281 super(domview, self).__init__() |
1302
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
1282 self._metadata_node = None |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
1283 # |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
1284 # Following two variables would be changed by class |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
1285 # component_manager to switch components and timelines. |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
1286 # |
1302
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
1287 self._scenes_node = None |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
1288 self._layers_parent = None |
1323
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1289 self._layers = [] |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1290 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1291 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1292 ## \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
|
1293 # |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1294 def _init_metadata(self): |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
1295 self._layers_parent = self._root |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
1296 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1297 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
|
1298 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
|
1299 break |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1300 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1301 else: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1302 raise RuntimeError, \ |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1303 '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
|
1304 |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
1305 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
|
1306 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1307 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
|
1308 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
|
1309 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
|
1310 break |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1311 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1312 else: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1313 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
|
1314 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
|
1315 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
|
1316 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
|
1317 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
|
1318 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
|
1319 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
|
1320 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
|
1321 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1322 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1323 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1324 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
|
1325 self._doc = doc |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1326 self._root = root |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1327 |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
1328 self._init_metadata() |
1302
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
1329 self._start_monitor() # from domview_monitor |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
1330 self._start_component_manager() |
1354
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1352
diff
changeset
|
1331 self.reset_layers() |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1332 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
|
1333 |
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
|
1334 def reset(self): |
1302
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
1335 self._monitor_reparse() # from domview_monitor |
1354
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1352
diff
changeset
|
1336 self.reset_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
|
1337 pass |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1338 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1339 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
|
1340 s = "" |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1341 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
|
1342 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
|
1343 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1344 return s |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1345 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1346 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
|
1347 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
|
1348 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
|
1349 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
|
1350 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1351 print " " * l * 2,"/>" |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1352 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1353 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1354 ## \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
|
1355 # |
1247
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1356 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
|
1357 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
|
1358 ref=None): |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1359 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
|
1360 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
|
1361 doc = self._doc |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1362 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1363 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
|
1364 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
|
1365 if start != end: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1366 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
|
1367 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1368 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
|
1369 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
|
1370 if ref: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1371 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
|
1372 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1373 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1374 scenes_node.appendChild(scene_node) |
1247
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1375 |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1376 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
|
1377 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1378 return scene_node |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1379 |
1262
2f861eea1214
Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents:
1260
diff
changeset
|
1380 ## \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
|
1381 # |
2f861eea1214
Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents:
1260
diff
changeset
|
1382 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
|
1383 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
|
1384 pass |
2f861eea1214
Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents:
1260
diff
changeset
|
1385 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1386 ## \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
|
1387 # |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1388 # 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
|
1389 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
|
1390 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
|
1391 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
|
1392 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
|
1393 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1394 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
|
1395 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
|
1396 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1397 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
|
1398 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
|
1399 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1400 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
|
1401 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
|
1402 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1403 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1404 |
1256
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1405 ## \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
|
1406 # |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1407 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
|
1408 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
|
1409 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
|
1410 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1411 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
|
1412 for layer in self._layers: |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1413 try: |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1414 layer.scenes.remove(scene_node) |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1415 except ValueError: # not in the list |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1416 pass |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1417 else: |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1418 break |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1419 pass |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1420 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1421 |
1256
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1422 ## \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
|
1423 # |
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1424 # 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
|
1425 # 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
|
1426 # |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1427 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
|
1428 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
|
1429 try: |
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1430 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
|
1431 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
|
1432 # Inkscape. |
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1433 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
|
1434 pass |
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1435 except: |
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1436 pass |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1437 |
1256
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1438 try: |
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1439 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
|
1440 except: |
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1441 pass |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1442 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1443 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1444 ## \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
|
1445 # |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1446 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
|
1447 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
|
1448 doc = self._doc |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1449 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1450 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
|
1451 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
|
1452 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
|
1453 scene_group.setAttribute("inkscape:groupmode", "layer") |
1299
6949e2b6cae2
Add unlink clone checker.
Thinker K.F. Li <thinker@codemud.net>
parents:
1298
diff
changeset
|
1454 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
|
1455 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1456 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
|
1457 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1458 return scene_group |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1459 |
1259
df474448364e
Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents:
1256
diff
changeset
|
1460 ## \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
|
1461 # |
df474448364e
Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents:
1256
diff
changeset
|
1462 # \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
|
1463 # |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1464 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
|
1465 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
|
1466 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
|
1467 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
|
1468 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
|
1469 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
|
1470 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1471 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1472 return -1, None |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1473 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1474 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
|
1475 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
|
1476 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
|
1477 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
|
1478 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
|
1479 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
|
1480 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1481 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
|
1482 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
|
1483 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1484 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1485 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1486 |
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
|
1487 ## \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
|
1488 # |
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
|
1489 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
|
1490 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
|
1491 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
|
1492 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1493 ## \brief Remove frames |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1494 # |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1495 # - 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
|
1496 # - 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
|
1497 # |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1498 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
|
1499 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
|
1500 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1501 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
|
1502 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
|
1503 start, end, tween_type = \ |
1274
a4d3838264dd
Make public APIs being public for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1270
diff
changeset
|
1504 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
|
1505 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1506 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
|
1507 continue |
1286
922d1caf6632
Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1285
diff
changeset
|
1508 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1509 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
|
1510 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
|
1511 start=(start - num), |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1512 end=(end - num)) |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1513 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
|
1514 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
|
1515 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1516 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1517 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1518 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1519 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
|
1520 return self._maxframe |
1246
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1521 |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1522 ## \brief Copy children of a group. |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1523 # |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1524 # 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
|
1525 # |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1526 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
|
1527 # Search for the duplicated group |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1528 doc = self._doc |
1286
922d1caf6632
Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1285
diff
changeset
|
1529 |
922d1caf6632
Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1285
diff
changeset
|
1530 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
|
1531 |
1247
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1532 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
|
1533 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
|
1534 new_gids = set() |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1535 for old_node in old_nodes: |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1536 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
|
1537 new_node = new_nodes.next() |
1247
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1538 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
|
1539 |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1540 # |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1541 # 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
|
1542 # 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
|
1543 # 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
|
1544 # 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
|
1545 # 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
|
1546 # |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1547 gid = self.new_id() |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1548 while gid in new_gids: |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1549 gid = self.new_id() |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1550 pass |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1551 new_gids.add(gid) |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1552 new_node.setAttribute('id', gid) |
1246
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1553 pass |
1286
922d1caf6632
Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1285
diff
changeset
|
1554 |
922d1caf6632
Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1285
diff
changeset
|
1555 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
|
1556 dup_group.removeChild(child) # prevent from crash |
1298 | 1557 dst_group.appendChild(child) |
1286
922d1caf6632
Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1285
diff
changeset
|
1558 pass |
1246
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1559 pass |
1291
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
1560 |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
1561 ## \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
|
1562 # |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
1563 # 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
|
1564 # and append nodes to the desitnate group. |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
1565 # |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
1566 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
|
1567 doc = self._doc |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
1568 |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
1569 for src_child in src_group.childList(): |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
1570 src_child_id = src_child.getAttribute('id') |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
1571 dst_child_id = self.new_id() |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
1572 |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
1573 dst_child = doc.createElement('svg:use') |
1294 | 1574 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
|
1575 dst_child.setAttribute('xlink:href', '#' + src_child_id) |
1294 | 1576 dst_child.setAttribute('ns0:duplicate-src', src_child_id) |
1295 | 1577 dst_group.appendChild(dst_child) |
1291
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
1578 pass |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
1579 pass |
1323
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1580 |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1581 ## \brief To test a graphic node. |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1582 # |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1583 # 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
|
1584 # 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
|
1585 # scene group. |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1586 def is_graph_node(self, node): |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1587 try: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1588 mode = node.getAttribute('inkscape:groupmode') |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1589 except: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1590 pass |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1591 else: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1592 if mode == 'layer': |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1593 return False |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1594 pass |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1595 |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1596 try: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1597 label = node.geteAttribute('inkscape:label') |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1598 except: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1599 pass |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1600 else: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1601 return False |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1602 |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1603 try: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1604 scene_group = node.geteAttribute('scene_group') |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1605 except: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1606 pass |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1607 else: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1608 if scene_group == 'true': |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1609 return False |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1610 pass |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1611 |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1612 return True |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1613 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1614 |