Mercurial > MadButterfly
annotate pyink/domview.py @ 1470:2a9b9c281f80
Fix wiring error
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Sun, 24 Apr 2011 13:39:33 +0800 |
parents | c1e70540541c |
children | 4a57650bb926 |
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 |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
51 class Transition(object): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
52 node = None |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
53 condition = None |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
54 target = None |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
55 action = None |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
56 path = None |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
57 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
58 def __init__(self, node=None): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
59 self.node = node |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
60 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
61 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
62 def set_condition(self, cond): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
63 node = self.node |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
64 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
65 node.setAttribute('condition', cond) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
66 self.condition = cond |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
67 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
68 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
69 def set_action(self, action): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
70 self.action = action |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
71 node = self.node |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
72 node.setAttribute('action', action) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
73 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
74 |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
75 def set_path(self, path): |
1470 | 76 self.path = path |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
77 node = self.node |
1470 | 78 path_txt = ' '.join([str(c) for c in path]) |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
79 node.setAttribute('path', path_txt) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
80 pass |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
81 |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
82 def reparse(self): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
83 condition = node.getAttribute('condition') |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
84 target = node.getAttribute('target') |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
85 try: |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
86 action = node.getAttribute('action') |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
87 except: |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
88 action = None |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
89 pass |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
90 try: |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
91 path = node.getAttribute('path').strip().split() |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
92 path = [float(c) for c in path] |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
93 except: |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
94 path = None |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
95 pass |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
96 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
97 self.condition = condition |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
98 self.target = target |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
99 self.action = action |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
100 self.path = path |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
101 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
102 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
103 def update_node(self): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
104 node = self.node |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
105 node.setAttribute('condition', self.condition) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
106 node.setAttribute('target', self.target) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
107 if self.action: |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
108 node.setAttribute('action', self.action) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
109 pass |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
110 if self.path: |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
111 node.setAttribute('path', self.path) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
112 pass |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
113 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
114 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
115 ## \brief Create a node according status of the object. |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
116 # |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
117 # A new node is created for the object, and attributes of the node |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
118 # is initialized with information from the object. |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
119 # |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
120 def create_node(self, doc): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
121 node = doc.createElement('ns0:transition') |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
122 self.node = node |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
123 self.update_node() |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
124 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
125 return node |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
126 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
127 @staticmethod |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
128 def parse_transition(node): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
129 trn = Transition(node) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
130 trn.reparse() |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
131 return trn |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
132 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
133 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
134 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
135 ## \brief A state in a FSM |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
136 # |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
137 # Every component can have a FSM to describe its behavior. Every |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
138 # state has an entry action and transitions to other states. Every |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
139 # transition can have a transition action. |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
140 # |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
141 # The FSM of a component is defined as a child of ns0:component node. |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
142 # \verbatim |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
143 # <ns0:component> |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
144 # <ns0:states start_state="UP"> |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
145 # <ns0:state name="UP" entry_action="entry action"> |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
146 # <ns0:transition target="DOWN" |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
147 # condition="button_down" action="..."/> |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
148 # </ns0:state> |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
149 # </ns0:states> |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
150 # </ns0:/component> |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
151 # \endverbatim |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
152 # |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
153 class State(object): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
154 name = None |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
155 entry_action = None |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
156 transitions = None |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
157 r = None |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
158 x = 0 |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
159 y = 0 |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
160 |
1467
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1465
diff
changeset
|
161 def __init__(self, node=None): |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
162 self.node = node |
1467
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1465
diff
changeset
|
163 self.transitions = {} |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
164 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
165 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
166 def rename(self, name): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
167 self.name = name |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
168 self.node.setAttribute('name', name) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
169 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
170 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
171 def set_entry_action(self, action): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
172 self.entry_action = action |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
173 self.node.setAttribute('entry_action', action) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
174 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
175 |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
176 def set_r(self, r): |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
177 self.r = r |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
178 self.node.setAttribute('r', str(r)) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
179 pass |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
180 |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
181 def set_xy(self, x, y): |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
182 self.x = x |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
183 self.y = y |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
184 self.node.setAttribute('x', str(x)) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
185 self.node.setAttribute('y', str(y)) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
186 pass |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
187 |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
188 def reparse(self): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
189 node = self.node |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
190 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
191 name = node.getAttribute('name') |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
192 try: |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
193 entry_action = node.getAttribute('entry_action') |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
194 except: |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
195 entry_action = None |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
196 pass |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
197 try: |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
198 r = float(node.getAttribute('r')) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
199 except: |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
200 r = None |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
201 pass |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
202 try: |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
203 x = float(node.getAttribute('x')) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
204 except: |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
205 x = 0 |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
206 pass |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
207 try: |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
208 y = float(node.getAttribute('y')) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
209 except: |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
210 y = 0 |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
211 pass |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
212 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
213 all_transitions = [Transition.parse_transition(child) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
214 for child in node.childList() |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
215 if child.name() == 'ns0:transition'] |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
216 transitions = dict([(trn.condition, trn) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
217 for trn in all_transitions]) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
218 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
219 self.name = name |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
220 self.transitions = transitions |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
221 self.entry_action = entry_action |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
222 self.r = r |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
223 self.x = x |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
224 self.y = y |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
225 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
226 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
227 def update_node(self): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
228 node = self.node |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
229 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
230 node.setAttribute('name', self.name) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
231 if self.entry_action: |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
232 node.setAttribute('entry_action', self.entry_action) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
233 pass |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
234 if self.r: |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
235 node.setAttribute('r', self.r) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
236 pass |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
237 if self.x: |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
238 node.setAttribute('x', self.x) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
239 pass |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
240 if self.y: |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
241 node.setAttribute('y', self.y) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
242 pass |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
243 |
1467
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1465
diff
changeset
|
244 transitions = self.transitions |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
245 for trn in transitions: |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
246 trn.update_node() |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
247 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
248 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
249 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
250 def create_node(self, doc): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
251 node = doc.createElement('ns0:state') |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
252 self.node = node |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
253 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
254 self.update_node() |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
255 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
256 return node |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
257 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
258 @staticmethod |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
259 def parse_state(node): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
260 state = State(node) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
261 state.parse() |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
262 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
263 return state |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
264 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
265 def change_transition_cond(self, old_cond, new_cond): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
266 transitions = self.transitions |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
267 trn = transitions[old_cond] |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
268 del transitions[old_cond] |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
269 transitions[new_cond] = trn |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
270 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
271 trn.set_condition(new_cond) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
272 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
273 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
274 def add_transition(self, cond, target): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
275 transitions = self.transitions |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
276 assert cond not in transitions |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
277 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
278 node = self.node |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
279 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
280 trn = Transition() |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
281 trn.condition = cond |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
282 trn.target = target |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
283 trn_node = trn.create_node(node.document()) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
284 |
1467
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1465
diff
changeset
|
285 node.appendChild(trn_node) |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
286 transitions[cond] = trn |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
287 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
288 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
289 def rm_transition(self, cond): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
290 transitions = self.transitions |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
291 if cond not in transitions: |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
292 raise ValueError, \ |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
293 'There is no transition defined for this condition (%s)' % \ |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
294 (cond) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
295 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
296 trn = transitions[cond] |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
297 trn_node = trn.node |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
298 node = self.node |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
299 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
300 node.removeChild(trn_node) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
301 del transitions[cond] |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
302 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
303 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
304 def all_transitions(self): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
305 return self.transitions.keys() |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
306 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
307 def get_transition(self, cond): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
308 transitions = self.transitions |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
309 transition = transitions[cond] |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
310 return transition |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
311 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
312 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
313 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
314 class Component(object): |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
315 # |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
316 # \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
|
317 # |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
318 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
|
319 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
|
320 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
|
321 self.layers = [] |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
322 self.timelines = [] |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
323 self.fsm_states = {} |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
324 self.fsm_states_node = None |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
325 self.fsm_start_state = None |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
326 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
327 if comp_node: |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
328 self._initialize_comp() |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
329 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
330 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
331 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
332 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
|
333 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
|
334 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
|
335 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
|
336 break |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
337 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
338 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
|
339 doc = self._comp_mgr._doc |
1310
85d04ba11146
Support adding new components
Thinker K.F. Li <thinker@codemud.net>
parents:
1308
diff
changeset
|
340 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
|
341 scenes_node.setAttribute('name', 'default') |
1310
85d04ba11146
Support adding new components
Thinker K.F. Li <thinker@codemud.net>
parents:
1308
diff
changeset
|
342 |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
343 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
|
344 scenes_node.setAttribute('id', node_id) |
1310
85d04ba11146
Support adding new components
Thinker K.F. Li <thinker@codemud.net>
parents:
1308
diff
changeset
|
345 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
346 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
|
347 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
348 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
349 |
1467
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1465
diff
changeset
|
350 def _get_comp_node(self): |
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1465
diff
changeset
|
351 return self.node or self._comp_mgr._metadata_node |
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1465
diff
changeset
|
352 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
353 def name(self): |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
354 if self.node: |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
355 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
|
356 else: |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
357 name = 'main' |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
358 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
359 return name |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
360 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
361 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
|
362 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
|
363 return names |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
364 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
365 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
|
366 self.timelines[:] = [] |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
367 |
1467
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1465
diff
changeset
|
368 if self.node: # main component has None value for self.node |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
369 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
|
370 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
371 |
1467
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1465
diff
changeset
|
372 comp_node = self._get_comp_node() |
1310
85d04ba11146
Support adding new components
Thinker K.F. Li <thinker@codemud.net>
parents:
1308
diff
changeset
|
373 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
|
374 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
|
375 tl = Timeline(child) |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
376 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
|
377 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
|
378 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
379 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
380 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
381 |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
382 ## \brief Parse FSM from a ns0:states node. |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
383 # |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
384 def parse_states(self): |
1467
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1465
diff
changeset
|
385 comp_node = self._get_comp_node() |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
386 assert (not comp_node) or comp_node.name() == 'ns0:component' |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
387 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
388 states_nodes = [node |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
389 for node in comp_node.childList() |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
390 if node.name() == 'ns0:states'] |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
391 if not states_nodes: |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
392 self.fsm_states = {} |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
393 return |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
394 states_node = states_nodes[0] |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
395 |
1465
a3ce8d22d163
Parse states while parsing a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1463
diff
changeset
|
396 try: |
a3ce8d22d163
Parse states while parsing a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1463
diff
changeset
|
397 self.fsm_start_state = states_node.getAttribute('start_state') |
a3ce8d22d163
Parse states while parsing a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1463
diff
changeset
|
398 except: |
a3ce8d22d163
Parse states while parsing a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1463
diff
changeset
|
399 pass |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
400 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
401 state_nodes = [child |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
402 for child in states_node.childList |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
403 if child.name() == 'ns0:state'] |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
404 states = [State.parse_state(node) for state_node in state_nodes] |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
405 self.fsm_states = dict([(state.name, state) for state in states]) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
406 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
407 self.fsm_states_node = states_node |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
408 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
409 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
410 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
|
411 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
|
412 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
|
413 return tl |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
414 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
415 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
|
416 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
417 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
|
418 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
|
419 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
|
420 return True |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
421 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
422 return False |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
423 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
424 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
|
425 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
|
426 raise ValueError, \ |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
427 '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
|
428 |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
429 doc = self._comp_mgr._doc |
1467
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1465
diff
changeset
|
430 comp_node = self._get_comp_node() |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
431 |
1310
85d04ba11146
Support adding new components
Thinker K.F. Li <thinker@codemud.net>
parents:
1308
diff
changeset
|
432 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
|
433 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
|
434 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
|
435 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
|
436 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
437 comp_node.appendChild(scenes_node) |
1317
e2ad9eb7f7a4
Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
1316
diff
changeset
|
438 |
e2ad9eb7f7a4
Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
1316
diff
changeset
|
439 tl = Timeline(scenes_node) |
e2ad9eb7f7a4
Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
1316
diff
changeset
|
440 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
|
441 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
442 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
443 ## \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
|
444 # |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
445 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
|
446 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
|
447 name = tl.name() |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
448 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
|
449 raise ValueError, \ |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
450 '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
|
451 |
e2ad9eb7f7a4
Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
1316
diff
changeset
|
452 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
|
453 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
454 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
455 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
|
456 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
|
457 if tl.name() == name: |
1467
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1465
diff
changeset
|
458 comp_node = self._get_comp_node() |
1317
e2ad9eb7f7a4
Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
1316
diff
changeset
|
459 comp_node.removeChild(tl.scenes_node) |
e2ad9eb7f7a4
Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
1316
diff
changeset
|
460 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
461 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
|
462 return |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
463 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
464 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
|
465 |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
466 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
|
467 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
|
468 if tl.name() == timeline_name: |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
469 tl.rename(new_name) |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
470 return |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
471 pass |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
472 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
|
473 |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
474 def rename(self, new_name): |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
475 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
|
476 pass |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
477 |
1465
a3ce8d22d163
Parse states while parsing a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1463
diff
changeset
|
478 def _create_states_node(self): |
1467
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1465
diff
changeset
|
479 node = self._get_comp_node() |
1465
a3ce8d22d163
Parse states while parsing a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1463
diff
changeset
|
480 doc = self._comp_mgr._doc |
a3ce8d22d163
Parse states while parsing a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1463
diff
changeset
|
481 |
a3ce8d22d163
Parse states while parsing a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1463
diff
changeset
|
482 states_node = doc.createElement('ns0:states') |
1467
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1465
diff
changeset
|
483 node.appendChild(states_node) |
1465
a3ce8d22d163
Parse states while parsing a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1463
diff
changeset
|
484 self.fsm_states_node = states_node |
a3ce8d22d163
Parse states while parsing a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1463
diff
changeset
|
485 pass |
a3ce8d22d163
Parse states while parsing a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1463
diff
changeset
|
486 |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
487 def get_start_state_name(self): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
488 return self.fsm_start_state |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
489 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
490 def set_start_state(self, state_name): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
491 assert state_name in self.fsm_states |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
492 self.fsm_start_state = state_name |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
493 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
494 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
495 def all_state_names(self): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
496 return self.fsm_states.keys() |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
497 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
498 def get_state(self, name): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
499 return self.fsm_states[name] |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
500 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
501 def add_state(self, name): |
1465
a3ce8d22d163
Parse states while parsing a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1463
diff
changeset
|
502 if not self.fsm_states_node: |
a3ce8d22d163
Parse states while parsing a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1463
diff
changeset
|
503 self._create_states_node() |
a3ce8d22d163
Parse states while parsing a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1463
diff
changeset
|
504 pass |
a3ce8d22d163
Parse states while parsing a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1463
diff
changeset
|
505 |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
506 doc = self._comp_mgr._doc |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
507 |
1468
c586981ecf1a
Avoid duplication in state names
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
508 if name in self.fsm_states: |
c586981ecf1a
Avoid duplication in state names
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
509 raise KeyError, \ |
c586981ecf1a
Avoid duplication in state names
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
510 'Add a state with a name (%s) been used' % (name) |
c586981ecf1a
Avoid duplication in state names
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
511 |
1467
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1465
diff
changeset
|
512 state = State() |
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1465
diff
changeset
|
513 state.name = name |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
514 self.fsm_states[name] = state |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
515 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
516 state_node = state.create_node(doc) |
1465
a3ce8d22d163
Parse states while parsing a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1463
diff
changeset
|
517 states_node = self.fsm_states_node |
1467
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1465
diff
changeset
|
518 states_node.appendChild(state_node) |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
519 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
520 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
521 def rename_state(self, state_name, new_name): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
522 state = self.fsm_states[state_name] |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
523 del self.fsm_states[state_name] |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
524 self.fsm_states[new_name] = state |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
525 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
526 state.rename(new_name) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
527 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
528 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
529 def rm_state(self, name): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
530 fsm_states = self.fsm_states |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
531 state = fsm_states[name] |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
532 del self.fsm_states[name] |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
533 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
534 state_node = state.node |
1465
a3ce8d22d163
Parse states while parsing a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1463
diff
changeset
|
535 states_node = self.fsm_states_node |
a3ce8d22d163
Parse states while parsing a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1463
diff
changeset
|
536 states_node.removeChild(state_node) |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
537 pass |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
538 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
539 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
540 |
1336
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
541 ## \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
|
542 # |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
543 # 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
|
544 # |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
545 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
|
546 ## \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
|
547 # |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
548 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
|
549 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
|
550 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
|
551 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
|
552 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
|
553 |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
554 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
|
555 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
|
556 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
|
557 break |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
558 pass |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
559 else: |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
560 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
|
561 pass |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
562 pass |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
563 |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
564 ## \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
|
565 # |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
566 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
|
567 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
|
568 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
|
569 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
|
570 |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
571 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
|
572 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
|
573 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
|
574 break |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
575 pass |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
576 else: |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
577 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
|
578 pass |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
579 pass |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
580 pass |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
581 |
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
582 |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
583 ## \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
|
584 # |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
585 # 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
|
586 # 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
|
587 # 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
|
588 # 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
|
589 # 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
|
590 # 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
|
591 # 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
|
592 # 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
|
593 # meaningful names.) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
594 # |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
595 # 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
|
596 # 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
|
597 # removed and normalized to normal components. |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
598 # |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
599 @trait |
1336
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
600 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
|
601 _scenes_node = require |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
602 _metadata_node = require |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
603 _doc = require |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
604 _root = require |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
605 _layers = require |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
606 _layers_parent = require |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
607 _cur_comp = require |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
608 new_id = require |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
609 get_node = require |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
610 reset = require |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
611 |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
612 def __init__(self): |
1342
972d749b9656
Move component_manager to a separated object.
Thinker K.F. Li <thinker@codemud.net>
parents:
1340
diff
changeset
|
613 super(component_manager, self).__init__() |
1302
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
614 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
|
615 self._components = [] |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
616 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
|
617 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
|
618 self._cur_timeline = None |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
619 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
|
620 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
621 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
622 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
|
623 comp = Component(self, None) |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
624 comp.layers = self._layers |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
625 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
|
626 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
|
627 comp.timelines = [timeline] |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
628 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
629 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
|
630 self._comp_names.add('main') |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
631 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
632 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
|
633 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
634 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
635 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
|
636 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
|
637 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
|
638 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
|
639 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
|
640 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
|
641 continue |
1428
43369f3314d8
Fix the issue of loading components from SVG.
Thinker K.F. Li <thinker@codemud.net>
parents:
1427
diff
changeset
|
642 |
43369f3314d8
Fix the issue of loading components from SVG.
Thinker K.F. Li <thinker@codemud.net>
parents:
1427
diff
changeset
|
643 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
|
644 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
|
645 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
|
646 |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
647 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
|
648 comp.parse_timelines() |
1465
a3ce8d22d163
Parse states while parsing a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1463
diff
changeset
|
649 comp.parse_states() |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
650 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
651 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
|
652 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
653 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
|
654 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
655 pass |
1302
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
656 |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
657 ## \brief To initialize subtree of metadata. |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
658 # |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
659 # 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
|
660 # |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
661 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
|
662 metadata_node = self._metadata_node |
1321
6a014a4ec79e
Fix missed variable name after refactory
Thinker K.F. Li <thinker@codemud.net>
parents:
1318
diff
changeset
|
663 |
6a014a4ec79e
Fix missed variable name after refactory
Thinker K.F. Li <thinker@codemud.net>
parents:
1318
diff
changeset
|
664 # Make sure ns0:components in metadata |
6a014a4ec79e
Fix missed variable name after refactory
Thinker K.F. Li <thinker@codemud.net>
parents:
1318
diff
changeset
|
665 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
|
666 if n.name() == 'ns0:components': |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
667 self._components_node = n |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
668 break |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
669 pass |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
670 else: |
1342
972d749b9656
Move component_manager to a separated object.
Thinker K.F. Li <thinker@codemud.net>
parents:
1340
diff
changeset
|
671 components_node = \ |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
672 self._doc.createElement("ns0:components") |
1321
6a014a4ec79e
Fix missed variable name after refactory
Thinker K.F. Li <thinker@codemud.net>
parents:
1318
diff
changeset
|
673 metadata_node.appendChild(components_node) |
1302
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
674 self._components_node = components_node |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
675 pass |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
676 |
1321
6a014a4ec79e
Fix missed variable name after refactory
Thinker K.F. Li <thinker@codemud.net>
parents:
1318
diff
changeset
|
677 # 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
|
678 for n in self._root.childList(): |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
679 if n.name() != 'svg:g': |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
680 continue |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
681 try: |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
682 nlabel = n.getAttribute('inkscape:label') |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
683 except: |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
684 continue |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
685 if nlabel == 'components': |
1427
5b69baa49a8b
Abandon head #6fa411fd9549
Thinker K.F. Li <thinker@codemud.net>
parents:
1419
diff
changeset
|
686 self._components_group = n |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
687 break |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
688 pass |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
689 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
|
690 components_group = self._doc.createElement('svg:g') |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
691 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
|
692 gid = self.new_id() |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
693 components_group.setAttribute('id', gid) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
694 |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
695 self._root.appendChild(components_group) |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
696 self._components_group = components_group |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
697 pass |
1302
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
698 pass |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
699 |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
700 def _start_component_manager(self): |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
701 self._component_manager_init_metadata() |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
702 self._set_main_component() |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
703 self._parse_components() |
1316
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
704 |
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
705 self._cur_comp = self._main_comp |
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
706 tl = self._main_comp.get_timeline('default') |
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
707 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
|
708 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
|
709 pass |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
710 |
1327
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
711 ## \brief Create component group |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
712 # |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
713 # 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
|
714 # 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
|
715 # |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
716 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
|
717 doc = self._doc |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
718 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
|
719 gid = self.new_id() |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
720 group.setAttribute('id', gid) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
721 |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
722 self._components_group.appendChild(group) |
1327
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
723 |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
724 # Create layers group |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
725 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
|
726 gid = self.new_id() |
1327
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
727 layers_group.setAttribute('id', gid) |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
728 layers_group.setAttribute('inkscape:label', 'layers') |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
729 group.appendChild(layers_group) |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
730 |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
731 return group |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
732 |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
733 ## \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
|
734 # |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
735 # \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
|
736 # \param comp_group_id is the component group. |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
737 # \return a ns0:component node. |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
738 # |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
739 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
|
740 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
|
741 comp_id = self.new_id() |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
742 comp_node.setAttribute('id', comp_id) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
743 comp_node.setAttribute('name', comp_name) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
744 comp_node.setAttribute('ref', comp_group_id) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
745 self._components_node.appendChild(comp_node) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
746 return comp_node |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
747 |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
748 ## \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
|
749 # |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
750 def _get_component(self, comp_name): |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
751 if comp_name in self._comp_names: |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
752 for comp in self._components: |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
753 if comp.name() == comp_name: |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
754 return comp |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
755 pass |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
756 pass |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
757 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
|
758 |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
759 ## \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
|
760 # |
1327
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
761 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
|
762 doc = self._doc |
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
763 gid = self.new_id() |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
764 |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
765 layer_group = doc.createElement('svg:g') |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
766 layer_group.setAttribute('id', gid) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
767 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
|
768 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
|
769 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
|
770 |
1323
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
771 return layer_group |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
772 |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
773 ## \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
|
774 # |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
775 # 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
|
776 # component. |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
777 # |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
778 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
|
779 comp = self._get_component(comp_name) |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
780 layer = comp.layers[layer_idx] |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
781 return layer.group |
1327
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
782 |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
783 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
|
784 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
|
785 return self._root |
1327
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
786 |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
787 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
|
788 layers_group = comp_group.firstChild() |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
789 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
|
790 |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
791 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
|
792 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
793 def all_comp_names(self): |
1317
e2ad9eb7f7a4
Show timelines correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
1316
diff
changeset
|
794 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
|
795 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
796 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
|
797 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
|
798 |
1326
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
799 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
|
800 if comp_name == 'main': |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
801 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
|
802 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
|
803 group = layer.group |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
804 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
|
805 pass |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
806 return |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
807 |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
808 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
|
809 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
|
810 pass |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
811 |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
812 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
|
813 if comp_name == 'main': |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
814 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
|
815 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
|
816 group = layer.group |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
817 group.setAttribute('style', '') |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
818 pass |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
819 return |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
820 |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
821 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
|
822 comp_group.setAttribute('style', '') |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
823 pass |
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
824 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
825 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
|
826 old_comp = self._cur_comp |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
827 |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
828 comp = self._get_component(comp_name) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
829 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
|
830 self._layers = comp.layers |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
831 comp_name = self._cur_comp.name() |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
832 # for domview |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
833 self._layers_parent = \ |
1342
972d749b9656
Move component_manager to a separated object.
Thinker K.F. Li <thinker@codemud.net>
parents:
1340
diff
changeset
|
834 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
|
835 |
1430
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
836 self.make_sure_timeline() |
1323
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
837 |
1419
3519f43da037
Check old component before hiding it for a component switching.
Thinker K.F. Li <thinker@codemud.net>
parents:
1418
diff
changeset
|
838 try: |
3519f43da037
Check old component before hiding it for a component switching.
Thinker K.F. Li <thinker@codemud.net>
parents:
1418
diff
changeset
|
839 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
|
840 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
|
841 except ValueError: |
3519f43da037
Check old component before hiding it for a component switching.
Thinker K.F. Li <thinker@codemud.net>
parents:
1418
diff
changeset
|
842 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
|
843 pass |
3519f43da037
Check old component before hiding it for a component switching.
Thinker K.F. Li <thinker@codemud.net>
parents:
1418
diff
changeset
|
844 |
3519f43da037
Check old component before hiding it for a component switching.
Thinker K.F. Li <thinker@codemud.net>
parents:
1418
diff
changeset
|
845 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
|
846 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
|
847 pass |
3519f43da037
Check old component before hiding it for a component switching.
Thinker K.F. Li <thinker@codemud.net>
parents:
1418
diff
changeset
|
848 |
1326
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
849 self.show_component(comp.name()) |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
850 pass |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
851 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
852 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
|
853 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
|
854 raise ValueError, \ |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
855 '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
|
856 |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
857 comp_group = self._create_component_group() |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
858 comp_group_id = comp_group.getAttribute('id') |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
859 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
|
860 |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
861 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
|
862 comp.parse_timelines() |
1323
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
863 |
1327
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
864 self._components.append(comp) |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
865 self._comp_names.add(comp_name) |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
866 |
ab281ec3eeec
Add a layers group for components
Thinker K.F. Li <thinker@codemud.net>
parents:
1326
diff
changeset
|
867 # 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
|
868 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
|
869 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
|
870 layer = Layer(layer_group) |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
871 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
|
872 |
1326
0a2034f490e5
Show/hide components by showing/hiding component group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1323
diff
changeset
|
873 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
|
874 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
875 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
876 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
|
877 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
|
878 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
|
879 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
|
880 raise ValueError, \ |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
881 '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
|
882 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
883 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
|
884 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
|
885 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
886 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
887 def rm_component(self, comp_name): |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
888 comp = self._get_component(comp_name) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
889 comp_name = comp.name() |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
890 comp_node = comp.node |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
891 comp_group = self.get_component_group(comp_name) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
892 |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
893 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
|
894 self._comp_names.remove(comp_name) |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
895 self._components_node.removeChild(comp_node) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
896 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
|
897 pass |
1331
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
898 |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
899 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
|
900 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
|
901 comp.rename(new_name) |
1459
8eecaca2a125
Fix bug when renaming component
Thinker K.F. Li <thinker@codemud.net>
parents:
1432
diff
changeset
|
902 self._comp_names.remove(comp_name) |
8eecaca2a125
Fix bug when renaming component
Thinker K.F. Li <thinker@codemud.net>
parents:
1432
diff
changeset
|
903 self._comp_names.add(new_name) |
1331
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
904 pass |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
905 |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
906 def get_component_group(self, comp_name): |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
907 comp = self._get_component(comp_name) |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
908 |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
909 comp_name = comp.name() |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
910 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
|
911 return self._root |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
912 |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
913 comp_node = comp.node |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
914 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
|
915 comp_group = self.get_node(gid) |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
916 return comp_group |
1316
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
917 |
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
918 def get_current_component(self): |
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
919 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
|
920 |
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
921 ## \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
|
922 # |
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
923 # 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
|
924 # |
8f1f8ef5c9ea
Hide scene groups of old timeline when switching to a new timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1343
diff
changeset
|
925 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
|
926 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
|
927 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
|
928 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
|
929 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
|
930 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
|
931 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
|
932 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
|
933 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
|
934 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
|
935 pass |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
936 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
937 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
|
938 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
|
939 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
|
940 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
|
941 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
942 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
|
943 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
|
944 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
|
945 |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
946 # 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
|
947 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
|
948 |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
949 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
|
950 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
|
951 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
|
952 pass |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
953 |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
954 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
|
955 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
|
956 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
|
957 try: |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
958 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
|
959 except KeyError: |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
960 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
|
961 pass |
bf405cb2d7cb
Switch to latest timeline when switching back to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1429
diff
changeset
|
962 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
|
963 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
|
964 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
965 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
966 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
|
967 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
|
968 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
969 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
970 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
|
971 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
|
972 pass |
1306
8c0a4684c1f7
Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1302
diff
changeset
|
973 |
1331
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
974 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
|
975 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
|
976 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
|
977 pass |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
978 |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
979 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
|
980 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
|
981 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
|
982 pass |
5da64f67d00d
Rename components and timelines with context menu
Thinker K.F. Li <thinker@codemud.net>
parents:
1328
diff
changeset
|
983 |
1306
8c0a4684c1f7
Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1302
diff
changeset
|
984 def all_timeline_names(self): |
8c0a4684c1f7
Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1302
diff
changeset
|
985 r = self._cur_comp.all_timeline_names() |
8c0a4684c1f7
Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1302
diff
changeset
|
986 return r |
8c0a4684c1f7
Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1302
diff
changeset
|
987 |
8c0a4684c1f7
Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1302
diff
changeset
|
988 def has_timeline(self, name): |
8c0a4684c1f7
Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1302
diff
changeset
|
989 r = self._cur_comp.has_timeline(name) |
8c0a4684c1f7
Expose methods from component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1302
diff
changeset
|
990 return r |
1316
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
991 |
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
992 def get_current_timeline(self): |
9ab8d50dcf7e
Refactory code of refreshing UI
Thinker K.F. Li <thinker@codemud.net>
parents:
1315
diff
changeset
|
993 return self._cur_timeline.name() |
1323
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
994 |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
995 ## \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
|
996 # |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
997 # 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
|
998 # specified component. |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
999 # |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1000 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
|
1001 group_parent = group.parent() |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1002 if group_parent: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1003 group_parent.removeChild(group) |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1004 pass |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1005 |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1006 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
|
1007 layer_group.appendChild(group) |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1008 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
|
1009 |
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
1010 ## \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
|
1011 # |
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
1012 # \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
|
1013 # \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
|
1014 # |
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
1015 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
|
1016 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
|
1017 |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
1018 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
|
1019 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
|
1020 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
|
1021 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
|
1022 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
|
1023 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
|
1024 |
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
1025 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
|
1026 |
407f321f0d7c
Add a svg:use after transform a group to a component
Thinker K.F. Li <thinker@codemud.net>
parents:
1327
diff
changeset
|
1027 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
|
1028 |
1432 | 1029 ## \brief Remember current frame and layer on the scenes node. |
1030 # | |
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
|
1031 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
|
1032 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
|
1033 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
|
1034 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
|
1035 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
|
1036 |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
1037 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
|
1038 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
|
1039 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
|
1040 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
|
1041 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
|
1042 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
|
1043 |
1432 | 1044 ## \brief Get current frame and layer from the scenes node. |
1045 # | |
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
|
1046 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
|
1047 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
|
1048 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
|
1049 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
|
1050 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
|
1051 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
|
1052 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
|
1053 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
|
1054 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
|
1055 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
|
1056 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
|
1057 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
|
1058 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
|
1059 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
|
1060 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
|
1061 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
|
1062 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
|
1063 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
|
1064 |
60f2c9a24cdb
Keep the same active layer and frame when switching back a timeline.
Thinker K.F. Li <thinker@codemud.net>
parents:
1430
diff
changeset
|
1065 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
|
1066 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
1067 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
1068 |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1069 ## \brief A trait for management FSM associated with current component. |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1070 # |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1071 @trait |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1072 class FSM_manager(object): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1073 _cur_comp = require |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1074 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1075 def __init__(self): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1076 super(FSM_manager, self).__init__() |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1077 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1078 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1079 def all_state_names(self): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1080 return self._cur_comp.all_state_names() |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1081 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1082 def get_start_state_name(self): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1083 return self._cur_comp.get_start_state_name() |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1084 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1085 ## \brief To return state object for the given name. |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1086 # |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1087 # This method should only be used by component_manager internally. |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1088 # |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1089 def _get_state(self, state_name): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1090 return self._cur_comp.get_state(state_name) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1091 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1092 def rm_state(self, state_name): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1093 self._cur_comp.rm_state(state_name) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1094 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1095 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1096 def add_state(self, state_name): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1097 self._cur_comp.add_state(state_name) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1098 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1099 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1100 def rename_state(self, state_name, new_name): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1101 self._cur_comp.rename_state(state_name, new_name) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1102 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1103 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1104 def set_start_state(self, state_name): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1105 self._cur_comp.set_start_state(state_name) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1106 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1107 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1108 def set_state_entry_action(self, state_name, entry_action): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1109 state = self._get_state(state_name) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1110 state.set_entry_action(entry_action) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1111 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1112 |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1113 def set_state_r(self, state_name, r): |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1114 state = self._get_state(state_name) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1115 state.set_r(r) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1116 pass |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1117 |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1118 def set_state_xy(self, state_name, x, y): |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1119 state = self._get_state(state_name) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1120 state.set_xy(x, y) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1121 pass |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1122 |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1123 def get_state_entry_action(self, state_name): |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1124 state = self._get_state(state_name) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1125 action = state.get_entry_action() |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1126 return action |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1127 |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1128 def get_state_r(self, state_name): |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1129 state = self._get_state(state_name) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1130 r = state.r |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1131 return r |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1132 |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1133 def get_state_xy(self, state_name): |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1134 state = self._get_state(state_name) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1135 xy = state.x, state.y |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1136 return xy |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1137 |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1138 def all_transitions(self, state_name): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1139 state = self._get_state(state_name) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1140 trn_names = state.all_transitions() |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1141 return trn_names |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1142 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1143 def add_transition(self, state_name, cond, target): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1144 state = self._get_state(state_name) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1145 state.add_transition(cond, target) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1146 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1147 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1148 def rm_transition(self, state_name, cond): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1149 state = self._get_state(state_name) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1150 state.rm_transition(cond) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1151 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1152 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1153 def change_transition_cond(self, state_name, old_cond, new_cond): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1154 state = self._get_state(state_name) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1155 state.change_transition_cond(old_cond, new_cond) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1156 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1157 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1158 def get_transition(self, state_name, cond): |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1159 state = self._get_state(state_name) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1160 trn = state.get_transition(cond) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1161 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1162 cond = trn.condition |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1163 target = trn.target |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1164 action = trn.action |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1165 path = trn.path |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1166 |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1167 return cond, target, action, path |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1168 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1169 def set_transition_action(self, state_name, cond, action): |
1470 | 1170 state = self._get_state(state_name) |
1171 trn = state.get_transition(cond) | |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1172 trn.set_action(action) |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1173 pass |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1174 |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1175 def set_transition_path(self, state_name, cond, path): |
1470 | 1176 state = self._get_state(state_name) |
1177 trn = state.get_transition(cond) | |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1178 trn.set_path(path) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1468
diff
changeset
|
1179 pass |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1180 pass |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1181 |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1182 |
1350
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1183 ## \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
|
1184 # |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1185 # 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
|
1186 # |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1187 @trait |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1188 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
|
1189 _root = require |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1190 _scenes_node = require |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1191 _id2node = require |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1192 _group2scene = require |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1193 current = require |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1194 _maxframe = require |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1195 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1196 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
|
1197 maxframe = 0 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1198 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
|
1199 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
|
1200 continue |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1201 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1202 try: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1203 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
|
1204 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
|
1205 except: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1206 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1207 try: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1208 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
|
1209 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
|
1210 except: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1211 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1212 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1213 return maxframe |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1214 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1215 ## \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
|
1216 # |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1217 # 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
|
1218 # |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1219 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
|
1220 self._id2node = {} |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1221 root = self._root |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1222 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
|
1223 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
|
1224 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1225 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1226 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1227 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
|
1228 try: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1229 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
|
1230 except: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1231 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1232 else: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1233 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
|
1234 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1235 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1236 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
|
1237 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
|
1238 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1239 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1240 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1241 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
|
1242 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
|
1243 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1244 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
|
1245 try: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1246 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
|
1247 except: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1248 end = start |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1249 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1250 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1251 try: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1252 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
|
1253 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
|
1254 scene_type = 'normal' |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1255 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1256 except: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1257 scene_type = 'normal' |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1258 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1259 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1260 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
|
1261 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1262 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
|
1263 try: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1264 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
|
1265 except: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1266 cur = 0 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1267 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1268 self.current = cur |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1269 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1270 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
|
1271 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
|
1272 continue |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1273 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1274 try: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1275 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
|
1276 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
|
1277 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
|
1278 continue |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1279 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1280 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
|
1281 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1282 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1283 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1284 ## \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
|
1285 # |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1286 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
|
1287 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
|
1288 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
|
1289 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
|
1290 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1291 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1292 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1293 ## \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
|
1294 # |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1295 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
|
1296 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
|
1297 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
|
1298 return value[-1] |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1299 return value |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1300 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1301 ## \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
|
1302 # |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1303 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
|
1304 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
|
1305 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1306 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
|
1307 while True: |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1308 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
|
1309 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
|
1310 return candidate |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1311 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1312 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1313 pass |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1314 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1315 ## \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
|
1316 # |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1317 # 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
|
1318 # 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
|
1319 @composite |
1244
b241f9768833
Remove MBScene_ from the prefix of class names.
Thinker K.F. Li <thinker@codemud.net>
parents:
1243
diff
changeset
|
1320 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
|
1321 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
|
1322 |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1323 method_map_traits = { |
17fa5d78200b
Refactory domview_monitor to move code to scenes_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1348
diff
changeset
|
1324 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
|
1325 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
|
1326 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
|
1327 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1328 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
|
1329 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
|
1330 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1331 self._maxframe = 0 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1332 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
|
1333 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
|
1334 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1335 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1336 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
|
1337 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
|
1338 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
|
1339 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1340 doc = self._doc |
1253
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1247
diff
changeset
|
1341 dom_event.addEventListener(doc, 'DOMNodeInserted', |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1247
diff
changeset
|
1342 self._on_insert_node, None) |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1247
diff
changeset
|
1343 dom_event.addEventListener(doc, 'DOMNodeRemoved', |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1247
diff
changeset
|
1344 self._on_remove_node, None) |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1247
diff
changeset
|
1345 dom_event.addEventListener(doc, 'DOMAttrModified', |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1247
diff
changeset
|
1346 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
|
1347 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1348 |
1340
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
1349 ## \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
|
1350 # |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
1351 # 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
|
1352 # 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
|
1353 # 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
|
1354 # 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
|
1355 # 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
|
1356 # ID. |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
1357 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
|
1358 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
|
1359 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
|
1360 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
|
1361 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
|
1362 else: |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
1363 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
|
1364 pass |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
1365 else: |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
1366 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
|
1367 pass |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
1368 pass |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
1369 |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
1370 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
|
1371 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
|
1372 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
|
1373 |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
1374 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
|
1375 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
|
1376 value.remove(node) |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
1377 if not value: |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
1378 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
|
1379 pass |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
1380 pass |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
1381 else: |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
1382 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
|
1383 pass |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
1384 pass |
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
1385 |
1301
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
1386 ## \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
|
1387 # |
1302
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
1388 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
|
1389 self._maxframe = 0 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
1390 self._id2node = {} |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
1391 self._group2scene = {} |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
1392 |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
1393 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
|
1394 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
|
1395 pass |
18af917cf855
Add component_manager as a mix-in of domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1299
diff
changeset
|
1396 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1397 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
|
1398 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
|
1399 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
|
1400 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1401 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1402 try: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1403 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
|
1404 except: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1405 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1406 else: |
1340
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
1407 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
|
1408 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1409 |
1318
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
1410 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
|
1411 try: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1412 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
|
1413 except: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1414 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1415 else: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1416 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
|
1417 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
|
1418 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1419 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1420 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1421 try: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1422 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
|
1423 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
|
1424 except: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1425 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1426 try: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1427 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
|
1428 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
|
1429 except: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1430 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1431 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
|
1432 pass |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1433 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1434 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
|
1435 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
|
1436 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
|
1437 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1438 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1439 try: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1440 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
|
1441 except: |
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 else: |
1340
10d5f06f7566
Fix issue of shouting error when removing a node.
Thinker K.F. Li <thinker@codemud.net>
parents:
1336
diff
changeset
|
1444 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
|
1445 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1446 |
1318
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
1447 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
|
1448 try: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1449 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
|
1450 except: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1451 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1452 else: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1453 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
|
1454 pass |
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 try: |
1318
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
1457 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
|
1458 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
|
1459 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
|
1460 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1461 except: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1462 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1463 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1464 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1465 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1466 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
|
1467 if old_value == new_value: |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
1468 return |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
1469 |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
1470 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
|
1471 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
|
1472 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
|
1473 pass |
1336
0b5ee9c90af7
Update components and timelines list for async changes on DOM
Thinker K.F. Li <thinker@codemud.net>
parents:
1331
diff
changeset
|
1474 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
|
1475 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
|
1476 pass |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1477 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1478 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
|
1479 parent_node = node.parent() |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
1480 scenes_node = self._scenes_node |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
1481 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
|
1482 return # not in current timeline |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
1483 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1484 if old_value: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1485 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
|
1486 # 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
|
1487 # wrapper. |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1488 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
|
1489 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1490 if new_value: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1491 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
|
1492 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1493 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1494 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
|
1495 parent_node = node.parent() |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
1496 scenes_node = self._scenes_node |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
1497 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
|
1498 return # not in current timeline |
b1776f441e8a
Fix issue of parsing scene nodes
Thinker K.F. Li <thinker@codemud.net>
parents:
1317
diff
changeset
|
1499 |
1276
0442ae9c2ac2
Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents:
1275
diff
changeset
|
1500 try: |
0442ae9c2ac2
Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents:
1275
diff
changeset
|
1501 new_value = int(new_value) |
0442ae9c2ac2
Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents:
1275
diff
changeset
|
1502 old_value = int(old_value) |
0442ae9c2ac2
Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents:
1275
diff
changeset
|
1503 except TypeError: |
0442ae9c2ac2
Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents:
1275
diff
changeset
|
1504 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
|
1505 else: |
0442ae9c2ac2
Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents:
1275
diff
changeset
|
1506 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
|
1507 # _maxframe may be reduced. |
0442ae9c2ac2
Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents:
1275
diff
changeset
|
1508 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
|
1509 else: |
0442ae9c2ac2
Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents:
1275
diff
changeset
|
1510 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
|
1511 pass |
0442ae9c2ac2
Fix bug of max frame of domview.
Thinker K.F. Li <thinker@codemud.net>
parents:
1275
diff
changeset
|
1512 pass |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1513 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1514 pass |
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 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1517 |
1246
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1518 ## \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
|
1519 # |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1520 def _DOM_iterator(node): |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1521 nodes = [node] |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1522 while nodes: |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1523 node = nodes.pop(0) |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1524 child = node.firstChild() |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1525 while child: |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1526 nodes.append(child) |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1527 child = child.next() |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1528 pass |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1529 yield node |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1530 pass |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1531 pass |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1532 |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
1533 |
1352
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1534 @trait |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1535 class layers_parser(object): |
1356
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1536 _doc = require |
1352
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1537 _layers = require |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1538 _layers_parent = require |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1539 get_scene = require |
1356
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1540 get_node = require |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1541 new_id = require |
1352
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1542 |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1543 def parse_all_layers(self): |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1544 layers = self._layers |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1545 layers_parent = self._layers_parent |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1546 |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1547 for child in layers_parent.childList(): |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1548 if child.name() != 'svg:g': |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1549 continue |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1550 |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1551 try: |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1552 label = child.getAttribute('inkscape:label') |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1553 except: |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1554 pass |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1555 else: # has no label |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1556 if label == 'components': |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1557 continue |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1558 pass |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1559 |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1560 layer_group = child |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1561 layer = Layer(layer_group) |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1562 layer.idx = len(layers) |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1563 layers.append(layer) |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1564 self.parse_layer(layer.idx) |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1565 pass |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1566 pass |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1567 |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1568 def parse_layer(self, layer_idx): |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1569 layer = self._layers[layer_idx] |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1570 layer_group = layer.group |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1571 |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1572 for child in layer_group.childList(): |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1573 if child.name() != 'svg:g': |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1574 continue |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1575 try: |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1576 child_id = child.getAttribute('id') |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1577 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
|
1578 except: |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1579 continue |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1580 |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1581 layer.scenes.append(scene_node) |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1582 pass |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1583 pass |
1354
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1352
diff
changeset
|
1584 |
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1352
diff
changeset
|
1585 def get_layer_num(self): |
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1352
diff
changeset
|
1586 return len(self._layers) |
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1352
diff
changeset
|
1587 |
1356
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1588 ## \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
|
1589 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1590 # \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
|
1591 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1592 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
|
1593 layers = self._layers |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1594 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1595 layer = Layer(layer_group) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1596 if layer_idx >= len(layers): |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1597 layers.append(layer) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1598 else: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1599 layers.insert(layer_idx, layer) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1600 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
|
1601 layers[idx].idx = idx |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1602 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1603 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1604 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1605 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1606 ## \brief Manage a existed layer group |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1607 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1608 # 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
|
1609 # proper place to insert it. |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1610 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1611 # \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
|
1612 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1613 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
|
1614 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
|
1615 new_layer = Layer(layer_group) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1616 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1617 if not self._layers: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1618 new_layer.idx = 0 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1619 self._layers.append(new_layer) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1620 return 0 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1621 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1622 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1623 # 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
|
1624 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1625 next_group = layer_group.next() |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1626 while next_group: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1627 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
|
1628 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1629 for vlayer in self._layers: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1630 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
|
1631 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
|
1632 # 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
|
1633 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
|
1634 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1635 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
|
1636 self._layers[idx].idx = idx |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1637 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1638 return new_layer.idx |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1639 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1640 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1641 next_group = next_group.next() |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1642 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1643 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1644 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1645 # 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
|
1646 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1647 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
|
1648 while tail_group: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1649 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
|
1650 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1651 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
|
1652 # it is after last layer group. |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1653 new_layer.idx = len(self._layers) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1654 self._layers.append(new_layer) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1655 return new_layer.idx |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1656 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1657 tail_group = tail_group.next() |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1658 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1659 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1660 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
|
1661 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1662 ## \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
|
1663 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1664 def rm_layer(self, layer_idx): |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1665 layers = self._layers |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1666 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1667 layer = self._layers[layer_idx] |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1668 for scene_node in layer.scenes: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1669 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
|
1670 try: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1671 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
|
1672 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
|
1673 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
|
1674 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1675 except: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1676 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1677 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1678 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
|
1679 scene_node.parent().removeChild(scene_node) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1680 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1681 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1682 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1683 del layers[layer_idx] |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1684 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1685 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
|
1686 layers[idx].idx = idx |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1687 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1688 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1689 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1690 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
|
1691 layer = self._layers[layer_idx] |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1692 return layer.group |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1693 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1694 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
|
1695 layer = self._layers[layer_idx] |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1696 return layer.scenes |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1697 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1698 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
|
1699 layer = self._layers[layer_idx] |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1700 try: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1701 data = layer.data |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1702 except: |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1703 return None |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1704 return data |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1705 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1706 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
|
1707 layer = self._layers[layer_idx] |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1708 layer.data = data |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1709 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1710 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1711 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
|
1712 layer = self._layers[layer_idx] |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1713 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1714 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
|
1715 gid = self.new_id() |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1716 dup_group.setAttribute('id', gid) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1717 dup_group.setAttribute('inkscape:label', 'dup') |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1718 dup_group.setAttribute('sodipodi:insensitive', '1') |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1719 dup_group.setAttribute('style', '') |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1720 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1721 layer.group.appendChild(dup_group) |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1722 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1723 return dup_group |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1724 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1725 ## \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
|
1726 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1727 # \return -1 for error. |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1728 # |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1729 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
|
1730 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
|
1731 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
|
1732 return layer_idx |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1733 pass |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1734 return -1 |
ac61d86987af
Move more code to layers_parser
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
1735 |
1354
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1352
diff
changeset
|
1736 def reset_layers(self): |
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1352
diff
changeset
|
1737 self._layers[:] = [] |
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1352
diff
changeset
|
1738 self.parse_all_layers() |
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1352
diff
changeset
|
1739 pass |
1352
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1740 pass |
9164a0782ba7
Refactory layer_parser out from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1350
diff
changeset
|
1741 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1742 ## \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
|
1743 # |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1744 # 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
|
1745 # 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
|
1746 # 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
|
1747 # |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
1748 @composite |
1342
972d749b9656
Move component_manager to a separated object.
Thinker K.F. Li <thinker@codemud.net>
parents:
1340
diff
changeset
|
1749 class domview(domview_monitor): |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1750 use_traits = (component_manager, layers_parser, FSM_manager) |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
1751 |
1348
22a79dcbaec6
Change structure of provide_traits and method_map_traits
Thinker K.F. Li <thinker@codemud.net>
parents:
1345
diff
changeset
|
1752 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
|
1753 '_start_component_manager'} |
1345
e0400a2b7c35
Use trait instead of mixin for component_manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1344
diff
changeset
|
1754 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1755 # 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
|
1756 _doc = None |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1757 _root = None |
1463
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1758 # Required by component_manager and FSM_manager |
5ff744b981fb
FSM manager and data types
Thinker K.F. Li <thinker@codemud.net>
parents:
1459
diff
changeset
|
1759 _cur_comp = None |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1760 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1761 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
|
1762 super(domview, self).__init__() |
1302
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
1763 self._metadata_node = None |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
1764 # |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
1765 # Following two variables would be changed by class |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
1766 # component_manager to switch components and timelines. |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
1767 # |
1302
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
1768 self._scenes_node = None |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
1769 self._layers_parent = None |
1323
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
1770 self._layers = [] |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1771 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1772 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1773 ## \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
|
1774 # |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1775 def _init_metadata(self): |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
1776 self._layers_parent = self._root |
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
1777 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1778 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
|
1779 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
|
1780 break |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1781 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1782 else: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1783 raise RuntimeError, \ |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1784 '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
|
1785 |
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
1786 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
|
1787 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1788 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
|
1789 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
|
1790 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
|
1791 break |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1792 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1793 else: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1794 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
|
1795 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
|
1796 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
|
1797 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
|
1798 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
|
1799 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
|
1800 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
|
1801 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
|
1802 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1803 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1804 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1805 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
|
1806 self._doc = doc |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1807 self._root = root |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1808 |
1315
fcff6978f9bf
User can switch components.
Thinker K.F. Li <thinker@codemud.net>
parents:
1310
diff
changeset
|
1809 self._init_metadata() |
1302
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
1810 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
|
1811 self._start_component_manager() |
1354
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1352
diff
changeset
|
1812 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
|
1813 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
|
1814 |
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
|
1815 def reset(self): |
1302
c53331c55a23
Refactory domview to more clear responsibilities
Thinker K.F. Li <thinker@codemud.net>
parents:
1301
diff
changeset
|
1816 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
|
1817 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
|
1818 pass |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1819 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1820 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
|
1821 s = "" |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1822 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
|
1823 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
|
1824 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1825 return s |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1826 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1827 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
|
1828 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
|
1829 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
|
1830 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
|
1831 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1832 print " " * l * 2,"/>" |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1833 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1834 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1835 ## \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
|
1836 # |
1247
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1837 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
|
1838 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
|
1839 ref=None): |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1840 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
|
1841 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
|
1842 doc = self._doc |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1843 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1844 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
|
1845 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
|
1846 if start != end: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1847 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
|
1848 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1849 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
|
1850 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
|
1851 if ref: |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1852 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
|
1853 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1854 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1855 scenes_node.appendChild(scene_node) |
1247
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1856 |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1857 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
|
1858 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1859 return scene_node |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1860 |
1262
2f861eea1214
Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents:
1260
diff
changeset
|
1861 ## \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
|
1862 # |
2f861eea1214
Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents:
1260
diff
changeset
|
1863 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
|
1864 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
|
1865 pass |
2f861eea1214
Make domview_ui manages scenes and layers found by checker
Thinker K.F. Li <thinker@codemud.net>
parents:
1260
diff
changeset
|
1866 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1867 ## \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
|
1868 # |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1869 # 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
|
1870 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
|
1871 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
|
1872 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
|
1873 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
|
1874 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1875 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
|
1876 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
|
1877 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1878 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
|
1879 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
|
1880 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1881 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
|
1882 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
|
1883 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1884 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1885 |
1256
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1886 ## \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
|
1887 # |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1888 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
|
1889 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
|
1890 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
|
1891 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1892 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
|
1893 for layer in self._layers: |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1894 try: |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1895 layer.scenes.remove(scene_node) |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1896 except ValueError: # not in the list |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1897 pass |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1898 else: |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1899 break |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
1900 pass |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1901 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1902 |
1256
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1903 ## \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
|
1904 # |
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1905 # 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
|
1906 # 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
|
1907 # |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1908 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
|
1909 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
|
1910 try: |
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1911 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
|
1912 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
|
1913 # Inkscape. |
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1914 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
|
1915 pass |
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1916 except: |
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1917 pass |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1918 |
1256
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1919 try: |
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1920 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
|
1921 except: |
8755415b5e99
More check for remvoing scene and scene group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
1922 pass |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1923 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1924 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1925 ## \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
|
1926 # |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1927 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
|
1928 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
|
1929 doc = self._doc |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1930 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1931 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
|
1932 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
|
1933 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
|
1934 scene_group.setAttribute("inkscape:groupmode", "layer") |
1299
6949e2b6cae2
Add unlink clone checker.
Thinker K.F. Li <thinker@codemud.net>
parents:
1298
diff
changeset
|
1935 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
|
1936 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1937 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
|
1938 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1939 return scene_group |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1940 |
1259
df474448364e
Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents:
1256
diff
changeset
|
1941 ## \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
|
1942 # |
df474448364e
Add find_layer_from_group() for domview_ui
Thinker K.F. Li <thinker@codemud.net>
parents:
1256
diff
changeset
|
1943 # \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
|
1944 # |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1945 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
|
1946 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
|
1947 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
|
1948 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
|
1949 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
|
1950 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
|
1951 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1952 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1953 return -1, None |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1954 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1955 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
|
1956 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
|
1957 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
|
1958 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
|
1959 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
|
1960 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
|
1961 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1962 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
|
1963 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
|
1964 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1965 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1966 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1967 |
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
|
1968 ## \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
|
1969 # |
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
|
1970 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
|
1971 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
|
1972 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
|
1973 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1974 ## \brief Remove frames |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1975 # |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1976 # - 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
|
1977 # - 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
|
1978 # |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1979 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
|
1980 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
|
1981 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1982 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
|
1983 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
|
1984 start, end, tween_type = \ |
1274
a4d3838264dd
Make public APIs being public for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1270
diff
changeset
|
1985 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
|
1986 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1987 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
|
1988 continue |
1286
922d1caf6632
Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1285
diff
changeset
|
1989 |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1990 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
|
1991 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
|
1992 start=(start - num), |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1993 end=(end - num)) |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1994 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
|
1995 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
|
1996 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1997 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1998 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1999 |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
2000 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
|
2001 return self._maxframe |
1246
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
2002 |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
2003 ## \brief Copy children of a group. |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
2004 # |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
2005 # 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
|
2006 # |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
2007 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
|
2008 # Search for the duplicated group |
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
2009 doc = self._doc |
1286
922d1caf6632
Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1285
diff
changeset
|
2010 |
922d1caf6632
Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1285
diff
changeset
|
2011 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
|
2012 |
1247
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
2013 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
|
2014 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
|
2015 new_gids = set() |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
2016 for old_node in old_nodes: |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
2017 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
|
2018 new_node = new_nodes.next() |
1247
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
2019 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
|
2020 |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
2021 # |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
2022 # 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
|
2023 # 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
|
2024 # 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
|
2025 # 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
|
2026 # 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
|
2027 # |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
2028 gid = self.new_id() |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
2029 while gid in new_gids: |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
2030 gid = self.new_id() |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
2031 pass |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
2032 new_gids.add(gid) |
45e9566ea5c0
Fix bugs of inserting/removing frames.
Thinker K.F. Li <thinker@codemud.net>
parents:
1246
diff
changeset
|
2033 new_node.setAttribute('id', gid) |
1246
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
2034 pass |
1286
922d1caf6632
Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1285
diff
changeset
|
2035 |
922d1caf6632
Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1285
diff
changeset
|
2036 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
|
2037 dup_group.removeChild(child) # prevent from crash |
1298 | 2038 dst_group.appendChild(child) |
1286
922d1caf6632
Revert to changeset #0442ae9c2ac2 for domview.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1285
diff
changeset
|
2039 pass |
1246
42c4874c8d1e
Move _duplicate_group to domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
1244
diff
changeset
|
2040 pass |
1291
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
2041 |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
2042 ## \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
|
2043 # |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
2044 # 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
|
2045 # and append nodes to the desitnate group. |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
2046 # |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
2047 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
|
2048 doc = self._doc |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
2049 |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
2050 for src_child in src_group.childList(): |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
2051 src_child_id = src_child.getAttribute('id') |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
2052 dst_child_id = self.new_id() |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
2053 |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
2054 dst_child = doc.createElement('svg:use') |
1294 | 2055 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
|
2056 dst_child.setAttribute('xlink:href', '#' + src_child_id) |
1294 | 2057 dst_child.setAttribute('ns0:duplicate-src', src_child_id) |
1295 | 2058 dst_group.appendChild(dst_child) |
1291
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
2059 pass |
a3e04b3f2a8c
Add clone function for domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1286
diff
changeset
|
2060 pass |
1323
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2061 |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2062 ## \brief To test a graphic node. |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2063 # |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2064 # 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
|
2065 # 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
|
2066 # scene group. |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2067 def is_graph_node(self, node): |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2068 try: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2069 mode = node.getAttribute('inkscape:groupmode') |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2070 except: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2071 pass |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2072 else: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2073 if mode == 'layer': |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2074 return False |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2075 pass |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2076 |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2077 try: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2078 label = node.geteAttribute('inkscape:label') |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2079 except: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2080 pass |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2081 else: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2082 return False |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2083 |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2084 try: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2085 scene_group = node.geteAttribute('scene_group') |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2086 except: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2087 pass |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2088 else: |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2089 if scene_group == 'true': |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2090 return False |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2091 pass |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2092 |
ffbbd3aa218d
Make a component from a group.
Thinker K.F. Li <thinker@codemud.net>
parents:
1322
diff
changeset
|
2093 return True |
1243
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
2094 pass |
d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
2095 |