Mercurial > MadButterfly
annotate pyink/FSM_window.py @ 1478:6fe773e62b2a
Add state to FSM.
- Add a state if user left-click on the background of FSM window.
- pop a dialog that user can specify name and radius of the new state.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 25 Apr 2011 17:52:51 +0800 |
parents | eddec4543761 |
children | 92a8497d0361 |
rev | line source |
---|---|
1456
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1 import gtk |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
2 import os |
1458
59b90d7fcf57
Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents:
1457
diff
changeset
|
3 import data_monitor |
1456
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
4 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
5 class FSM_window_base(object): |
1478 | 6 _state_editor = None |
7 _state_name = None | |
8 _state_radius = None | |
9 | |
10 _error_dialog = None | |
11 _error_dialog_label = None | |
12 | |
1456
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
13 def __init__(self): |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
14 super(FSM_window_base, self).__init__() |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
15 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
16 dirname = os.path.dirname(__file__) |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
17 fname = os.path.join(dirname, 'FSM_window.glade') |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
18 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
19 builder = gtk.Builder() |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
20 builder.add_from_file(fname) |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
21 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
22 main_win = builder.get_object("FSM_main_win") |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
23 view_box = builder.get_object("view_box") |
1478 | 24 |
25 state_editor = builder.get_object("state_editor") | |
26 state_name = builder.get_object('state_name') | |
27 state_radius = builder.get_object('state_radius') | |
28 | |
29 error_dialog = builder.get_object('error_dialog') | |
30 error_dialog_label = builder.get_object('error_dialog_label') | |
1456
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
31 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
32 builder.connect_signals(self) |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
33 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
34 self._builder = builder |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
35 self._main_win = main_win |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
36 self._view_box = view_box |
1478 | 37 |
38 self._state_editor = state_editor | |
39 self._state_name = state_name | |
40 self._state_radius = state_radius | |
41 | |
42 self._error_dialog = error_dialog | |
43 self._error_dialog_label = error_dialog_label | |
44 pass | |
45 | |
46 def show_error(self, msg): | |
47 error_dialog = self._error_dialog | |
48 error_dialog_label = self._error_dialog_label | |
49 | |
50 error_dialog_label.set_text(msg) | |
51 error_dialog.show() | |
52 pass | |
53 | |
54 def hide_error(self): | |
55 error_dialog = self._error_dialog | |
56 error_dialog.hide() | |
57 pass | |
58 | |
59 def show_state_editor(self, state_name=''): | |
60 state_name_inp = self._state_name | |
61 state_radius_inp = self._state_radius | |
62 state_editor = self._state_editor | |
63 | |
64 state_name_inp.set_text(state_name) | |
65 state_radius_inp.set_text('30') | |
66 state_editor.show() | |
67 pass | |
68 | |
69 def hide_state_editor(self): | |
70 state_editor = self._state_editor | |
71 state_editor.hide() | |
1456
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
72 pass |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
73 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
74 def show(self): |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
75 self._main_win.show() |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
76 pass |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
77 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
78 def hide(self): |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
79 self._main_win.hide() |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
80 pass |
1478 | 81 |
82 def gtk_widget_hide(self, widget, event, *data): | |
83 widget.hide() | |
84 return True | |
1456
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
85 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
86 def on_start_state_activate(self, *args): |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
87 pass |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
88 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
89 def on_rename_state_activate(self, *args): |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
90 pass |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
91 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
92 def on_remove_state_activate(self, *args): |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
93 pass |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
94 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
95 def on_zoom_out_clicked(self, *args): |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
96 pass |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
97 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
98 def on_zoom_in_clicked(self, *args): |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
99 pass |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
100 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
101 def on_move_state_toggled(self, *args): |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
102 pass |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
103 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
104 def on_add_state_toggled(self, *args): |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
105 pass |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
106 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
107 def on_close_window_activate(self, *args): |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
108 pass |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
109 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
110 def on_FSM_main_win_destroy_event(self, *args): |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
111 pass |
1478 | 112 |
113 def on_state_apply_clicked(self, *args): | |
114 pass | |
115 | |
116 def on_state_cancel_clicked(self, *args): | |
117 state_editor = self._state_editor | |
118 state_editor.hide() | |
119 pass | |
120 | |
121 def on_error_dialog_ok_clicked(self, *args): | |
122 error_dialog = self._error_dialog | |
123 error_dialog.hide() | |
124 pass | |
1456
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
125 pass |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
126 |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
127 class FSM_transition(object): |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
128 _doc = None |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
129 _domview = None |
1476
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
130 _fsm_layer = None |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
131 _control_layer = None |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
132 _state = None |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
133 trn_cond = None |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
134 trn_g = None |
1473
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
135 _arrow_node = None |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
136 _path_node = None |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
137 |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
138 def __init__(self, trn_cond): |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
139 self.trn_cond = trn_cond |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
140 pass |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
141 |
1476
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
142 def init(self, doc, domview, state, fsm_layer, control_layer): |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
143 self._doc = doc |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
144 self._domview = domview |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
145 self._state = state |
1476
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
146 self._fsm_layer = fsm_layer |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
147 self._control_layer = control_layer |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
148 pass |
1473
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
149 |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
150 @staticmethod |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
151 def _update_graph(path, arrow_node, path_node): |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
152 import math |
1473
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
153 |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
154 path_txt = 'M %f,%f C %f,%f %f,%f %f,%f' % tuple(path) |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
155 path_node.setAttribute('d', path_txt) |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
156 path_node.setAttribute('style', 'stroke: #000000; stroke-width: 1; ' |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
157 'fill: none') |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
158 |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
159 # c0 c1 c2 c3 of cubic curve |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
160 c3 = (path[6], path[7]) |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
161 c2 = (path[4], path[5]) |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
162 c23_v = (c3[0] - c2[0], c3[1] - c2[1]) |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
163 c23_len = math.sqrt(c23_v[0] * c23_v[0] + c23_v[1] * c23_v[1]) |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
164 adir = (c23_v[0] / c23_len, c23_v[1] / c23_len) # arrow direction |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
165 odir = (-adir[1], adir[0]) # othogonal direction |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
166 arrow_pts = (c3[0], c3[1], |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
167 -adir[0] * 10 + odir[0] * 4, -adir[1] * 10 + odir[1] * 4, |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
168 -odir[0] * 8, -odir[1] * 8) |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
169 arrow_txt = 'M %f,%f l %f,%f l %f,%f z' % arrow_pts |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
170 arrow_node.setAttribute('d', arrow_txt) |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
171 arrow_node.setAttribute('style', 'stroke: #000000; stroke-width: 1; ' |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
172 'fill: #000000') |
1473
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
173 pass |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
174 |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
175 def _draw_transition_real(self, parent, path): |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
176 doc = self._doc |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
177 |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
178 trn_g = doc.createElement('svg:g') |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
179 |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
180 path_node = doc.createElement('svg:path') |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
181 arrow_node = doc.createElement('svg:path') |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
182 self._update_graph(path, arrow_node, path_node) |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
183 |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
184 trn_g.appendChild(path_node) |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
185 trn_g.appendChild(arrow_node) |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
186 |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
187 parent.appendChild(trn_g) |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
188 |
1473
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
189 return trn_g, path_node, arrow_node |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
190 |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
191 @property |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
192 def path(self): |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
193 domview = self._domview |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
194 state_name = self._state.state_name |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
195 trn_cond = self.trn_cond |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
196 trn = domview.get_transition(state_name, trn_cond) |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
197 return trn[3] |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
198 |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
199 def draw(self, parent): |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
200 path = self.path |
1473
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
201 trn_g, arrow_node, path_node = self._draw_transition_real(parent, path) |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
202 self.trn_g = trn_g |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
203 self._arrow_node = arrow_node |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
204 self._path_node = path_node |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
205 pass |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
206 |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
207 def clear(self): |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
208 trn_g = self.trn_g |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
209 parent = trn_g.parent() |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
210 parent.removeChild(trn_g) |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
211 pass |
1474
697ebfa9dc47
Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1473
diff
changeset
|
212 |
697ebfa9dc47
Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1473
diff
changeset
|
213 def update(self): |
697ebfa9dc47
Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1473
diff
changeset
|
214 path = self.path |
697ebfa9dc47
Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1473
diff
changeset
|
215 arrow_node = self._arrow_node |
697ebfa9dc47
Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1473
diff
changeset
|
216 path_node = self._path_node |
697ebfa9dc47
Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1473
diff
changeset
|
217 self._update_graph(path, arrow_node, path_node) |
697ebfa9dc47
Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1473
diff
changeset
|
218 pass |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
219 pass |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
220 |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
221 class FSM_state(object): |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
222 _doc = None |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
223 _domview = None |
1476
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
224 _fsm_layer = None |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
225 _control_layer = None |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
226 state_name = None |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
227 state_g = None |
1473
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
228 _text_node = None |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
229 _circle_node = None |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
230 transitions = None |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
231 |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
232 def __init__(self, state_name): |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
233 self.state_name = state_name |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
234 self.transitions = {} |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
235 pass |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
236 |
1476
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
237 def init(self, doc, domview, fsm_layer, control_layer): |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
238 self._doc = doc |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
239 self._domview = domview |
1476
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
240 self._fsm_layer = fsm_layer |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
241 self._control_layer = control_layer |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
242 pass |
1473
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
243 |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
244 @staticmethod |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
245 def _update_graph(text_node, text_content, circle_node, |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
246 state_name, r, x, y): |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
247 circle_node.setAttribute('r', str(r)) |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
248 circle_node.setAttribute('cx', str(x)) |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
249 circle_node.setAttribute('cy', str(y)) |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
250 circle_node.setAttribute('style', 'stroke: #000000; stroke-width: 1; ' |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
251 'fill: #ffffff') |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
252 |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
253 text_node.setAttribute('font-size', '16') |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
254 text_node.setAttribute('style', 'stroke: #000000; fill: #000000') |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
255 |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
256 text_content.setContent(state_name) |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
257 |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
258 tx, ty, tw, th = text_node.getBBox() |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
259 text_node.setAttribute('x', str(x - tw / 2)) |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
260 text_node.setAttribute('y', str(y + th / 2)) |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
261 pass |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
262 |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
263 def _draw_state_real(self, parent, state_name, r, x, y): |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
264 doc = self._doc |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
265 |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
266 state_g = doc.createElement('svg:g') |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
267 |
1473
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
268 text = doc.createElement('svg:text') |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
269 circle = doc.createElement('svg:circle') |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
270 text_content = doc.createTextNode(state_name) |
1473
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
271 |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
272 text.appendChild(text_content) |
1473
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
273 state_g.appendChild(circle) |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
274 state_g.appendChild(text) |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
275 parent.appendChild(state_g) |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
276 |
1473
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
277 self._update_graph(text, text_content, circle, state_name, r, x, y) |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
278 |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
279 return state_g, text, text_content, circle |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
280 |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
281 @property |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
282 def r(self): |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
283 domview = self._domview |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
284 state_name = self.state_name |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
285 r = domview.get_state_r(state_name) |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
286 return r |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
287 |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
288 @property |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
289 def xy(self): |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
290 domview = self._domview |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
291 state_name = self.state_name |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
292 xy = domview.get_state_xy(state_name) |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
293 return xy |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
294 |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
295 @property |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
296 def all_transitions(self): |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
297 domview = self._domview |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
298 state_name = self.state_name |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
299 conds = domview.all_transitions(state_name) |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
300 return conds |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
301 |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
302 def draw(self, parent): |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
303 domview = self._domview |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
304 state_name = self.state_name |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
305 |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
306 r = self.r |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
307 x, y = self.xy |
1473
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
308 state_g, text_node, text_content, circle_node = \ |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
309 self._draw_state_real(parent, state_name, r, x, y) |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
310 self.state_g = state_g |
1473
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
311 self._text_node = text_node |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
312 self._text_content = text_content |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
313 self._circle_node = circle_node |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
314 |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
315 for trn_cond in self.all_transitions: |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
316 trn = FSM_transition(trn_cond) |
1476
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
317 trn.init(self._doc, domview, self, |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
318 self._fsm_layer, self._control_layer) |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
319 trn.draw(parent) |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
320 self.transitions[trn_cond] = trn |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
321 pass |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
322 pass |
1473
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
323 |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
324 def clear(self): |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
325 state_g = self.state_g |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
326 parent = state_g.parent() |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
327 parent.removeChild(state_g) |
e807ad5aeb91
Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1472
diff
changeset
|
328 pass |
1474
697ebfa9dc47
Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1473
diff
changeset
|
329 |
697ebfa9dc47
Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1473
diff
changeset
|
330 def update(self): |
697ebfa9dc47
Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1473
diff
changeset
|
331 text_node = self._text_node |
697ebfa9dc47
Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1473
diff
changeset
|
332 text_content = self._text_content |
697ebfa9dc47
Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1473
diff
changeset
|
333 circle_node = self._circle_node |
697ebfa9dc47
Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1473
diff
changeset
|
334 state_name = self.state_name |
697ebfa9dc47
Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1473
diff
changeset
|
335 r = self.r |
697ebfa9dc47
Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1473
diff
changeset
|
336 x, y = self.xy |
697ebfa9dc47
Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1473
diff
changeset
|
337 self._update_graph(text_node, text_content, circle_node, |
697ebfa9dc47
Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1473
diff
changeset
|
338 r, x, y) |
697ebfa9dc47
Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1473
diff
changeset
|
339 pass |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
340 pass |
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
341 |
1456
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
342 class FSM_window(FSM_window_base): |
1458
59b90d7fcf57
Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents:
1457
diff
changeset
|
343 __metaclass__ = data_monitor.data_monitor |
59b90d7fcf57
Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents:
1457
diff
changeset
|
344 __data_monitor_prefix__ = 'on_' |
1476
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
345 |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
346 _background = None |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
347 _fsm_layer = None |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
348 _control_layer = None |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
349 width = 1024 |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
350 height = 768 |
1478 | 351 |
352 _grab_hdl = None | |
353 _bg_hdl = None | |
354 | |
355 _saved_x = 0 | |
356 _saved_y = 0 | |
1458
59b90d7fcf57
Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents:
1457
diff
changeset
|
357 |
59b90d7fcf57
Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents:
1457
diff
changeset
|
358 def __init__(self, domview_ui, close_cb, destroy_cb): |
1456
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
359 super(FSM_window, self).__init__() |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
360 |
1458
59b90d7fcf57
Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents:
1457
diff
changeset
|
361 self._locker = domview_ui |
1467
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1458
diff
changeset
|
362 |
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1458
diff
changeset
|
363 self._domview = domview_ui |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
364 self._states = {} |
1458
59b90d7fcf57
Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents:
1457
diff
changeset
|
365 |
1457
416a18409603
Show an empty document in SVG viewer widget
Thinker K.F. Li <thinker@codemud.net>
parents:
1456
diff
changeset
|
366 self._close_cb = close_cb # callback to close editor window (hide) |
416a18409603
Show an empty document in SVG viewer widget
Thinker K.F. Li <thinker@codemud.net>
parents:
1456
diff
changeset
|
367 self._destroy_cb = destroy_cb # callback to destroy editor window |
1456
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
368 pass |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
369 |
1476
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
370 def _init_layers(self): |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
371 doc = self._doc() |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
372 root = self._root() |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
373 |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
374 root.setAttribute('inkscape:groupmode', 'layer') |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
375 |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
376 background = doc.createElement('svg:rect') |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
377 background.setAttribute('x', '0') |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
378 background.setAttribute('y', '0') |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
379 background.setAttribute('width', str(self.width)) |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
380 background.setAttribute('height', str(self.height)) |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
381 background.setAttribute('style', 'fill: #ffffff') |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
382 root.appendChild(background) |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
383 self._background = background |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
384 |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
385 fsm_layer = doc.createElement('svg:g') |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
386 fsm_layer.setAttribute('inkscape:groupmode', 'layer') |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
387 root.appendChild(fsm_layer) |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
388 self._fsm_layer = fsm_layer |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
389 |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
390 control_layer = doc.createElement('svg:g') |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
391 control_layer.setAttribute('inkscape:groupmode', 'layer') |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
392 root.appendChild(control_layer) |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
393 self._control_layer = control_layer |
1478 | 394 |
395 self.grab_bg(self.on_add_state_background) | |
1476
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
396 pass |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
397 |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
398 def _doc(self): |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
399 view_widget = self._view_widget |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
400 view = view_widget.view |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
401 doc = view.doc().rdoc |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
402 return doc |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
403 |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
404 def _root(self): |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
405 doc = self._doc() |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
406 root = doc.root() |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
407 return root |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
408 |
1478 | 409 def _translate_xy(self, x, y): |
410 return x, y | |
411 | |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
412 def _clear_view(self): |
1476
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
413 if not self._background: |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
414 self._init_layers() |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
415 return |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
416 |
1476
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
417 children = [child for child in self._fsm_layer.childList()] + \ |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
418 [child for child in self._control_layer.childList()] |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
419 for child in children: |
1476
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
420 parent = child.parent() |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
421 parent.removeChild(child) |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
422 pass |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
423 |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
424 self._states = {} |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
425 pass |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
426 |
1478 | 427 def _draw_state_domview(self, state_name): |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
428 domview = self._domview |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
429 doc = self._doc() |
1476
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
430 fsm_layer = self._fsm_layer |
1472
7cb7abb5063b
Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents:
1471
diff
changeset
|
431 |
1478 | 432 state = FSM_state(state_name) |
433 state.init(doc, domview, self._fsm_layer, self._control_layer) | |
434 self._states[state_name] = state | |
435 | |
436 state.draw(fsm_layer) | |
437 pass | |
438 | |
439 def _update_view(self): | |
440 self._clear_view() | |
441 | |
442 domview = self._domview | |
443 | |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
444 state_names = domview.all_state_names() |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
445 for state_name in state_names: |
1478 | 446 self._draw_state_domview(state_name) |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
447 pass |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
448 pass |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
449 |
1456
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
450 def set_svg_view(self, view): |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
451 self._view_box.add(view) |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
452 self._view_widget = view |
1456
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
453 pass |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
454 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
455 def on_close_window_activate(self, *args): |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
456 self._close_cb() |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
457 pass |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
458 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
459 def on_FSM_main_win_destroy_event(self, *args): |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
460 self._destroy_cb() |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
461 pass |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
462 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
463 def on_FSM_main_win_delete_event(self, *args): |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
464 self._destroy_cb() |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
465 pass |
1467
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1458
diff
changeset
|
466 |
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1458
diff
changeset
|
467 def on_add_state_toggled(self, *args): |
1478 | 468 self.ungrab_bg() |
469 self.grab_bg(self.on_add_state_background) | |
470 pass | |
471 | |
472 def on_move_state_toggled(self, *args): | |
473 self.ungrab_bg() | |
474 self.grab_bg(self.on_move_state_background) | |
475 pass | |
476 | |
477 def on_add_state_background(self, item, evtype, buttons, x, y): | |
478 import pybInkscape | |
479 | |
480 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE and \ | |
481 buttons == 1: | |
482 self._saved_x = x | |
483 self._saved_y = y | |
484 self.show_state_editor() | |
485 pass | |
486 pass | |
487 | |
488 def on_move_state_background(self, item, evtype, buttons, x, y): | |
489 pass | |
490 | |
491 def on_state_apply_clicked(self, *args): | |
492 import traceback | |
493 | |
494 domview = self._domview | |
495 x, y = self._translate_xy(self._saved_x, self._saved_y) | |
496 | |
497 state_name = self._state_name.get_text() | |
498 r_txt = self._state_radius.get_text() | |
499 try: | |
500 r = float(r_txt) | |
501 except ValueError: | |
502 traceback.print_exc() | |
503 self.show_error('Invalid value: "%s" is not a valid value ' | |
504 'for radius.' % (r_txt)) | |
505 return | |
506 | |
507 try: | |
508 domview.add_state(state_name) | |
509 except: | |
510 traceback.print_exc() | |
511 self.show_error('Invalid state name: "%s" is existing' % | |
512 (state_name)) | |
513 return | |
514 domview.set_state_xy(state_name, x, y) | |
515 domview.set_state_r(state_name, r) | |
516 | |
517 self._draw_state_domview(state_name) | |
518 | |
519 self.hide_state_editor() | |
1475
8c6078c17f2d
Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents:
1474
diff
changeset
|
520 pass |
8c6078c17f2d
Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents:
1474
diff
changeset
|
521 |
8c6078c17f2d
Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents:
1474
diff
changeset
|
522 def _install_test_data(self): |
1476
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
523 self._init_layers() |
eddec4543761
Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents:
1475
diff
changeset
|
524 |
1467
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1458
diff
changeset
|
525 domview = self._domview |
1469
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
526 |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
527 view = self._view_widget.view |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
528 doc = view.doc() |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
529 rdoc = doc.rdoc |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
530 root_node = doc.root().repr |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
531 |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
532 line_node = rdoc.createElement('svg:line') |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
533 line_node.setAttribute('x1', '10') |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
534 line_node.setAttribute('y1', '10') |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
535 line_node.setAttribute('x2', '100') |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
536 line_node.setAttribute('y2', '100') |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
537 line_node.setAttribute('style', 'stroke: #000000; stroke-width:2') |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
538 |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
539 root_node.appendChild(line_node) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
540 |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
541 def show_msg(*args, **kws): |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
542 print 'mouse_event' |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
543 print args |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
544 pass |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
545 print 'before connect' |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
546 hdl_id = line_node.spitem.connect('mouse-event', show_msg) |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
547 print hdl_id |
c1e70540541c
Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents:
1467
diff
changeset
|
548 |
1471
055845649807
Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1469
diff
changeset
|
549 state1 = 'state 1' |
055845649807
Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1469
diff
changeset
|
550 domview.add_state(state1) |
055845649807
Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1469
diff
changeset
|
551 domview.set_state_r(state1, 50) |
055845649807
Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1469
diff
changeset
|
552 domview.set_state_xy(state1, 200, 100) |
055845649807
Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1469
diff
changeset
|
553 state2 = 'state 2' |
055845649807
Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1469
diff
changeset
|
554 domview.add_state(state2) |
055845649807
Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1469
diff
changeset
|
555 domview.set_state_r(state2, 30) |
055845649807
Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1469
diff
changeset
|
556 domview.set_state_xy(state2, 300, 100) |
055845649807
Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1469
diff
changeset
|
557 domview.add_transition(state1, 'event1', state2) |
055845649807
Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1469
diff
changeset
|
558 domview.set_transition_path(state1, 'event1', (200, 150, |
055845649807
Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1469
diff
changeset
|
559 240, 180, |
055845649807
Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1469
diff
changeset
|
560 260, 180, |
055845649807
Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents:
1469
diff
changeset
|
561 300, 130)) |
1467
6927debad4ee
Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents:
1458
diff
changeset
|
562 pass |
1475
8c6078c17f2d
Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents:
1474
diff
changeset
|
563 |
8c6078c17f2d
Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents:
1474
diff
changeset
|
564 def show(self): |
8c6078c17f2d
Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents:
1474
diff
changeset
|
565 self._install_test_data() |
8c6078c17f2d
Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents:
1474
diff
changeset
|
566 self._install_test_data = lambda: None |
8c6078c17f2d
Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents:
1474
diff
changeset
|
567 self._update_view() |
8c6078c17f2d
Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents:
1474
diff
changeset
|
568 super(FSM_window, self).show() |
8c6078c17f2d
Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents:
1474
diff
changeset
|
569 pass |
1478 | 570 |
571 def grab_mouse(self, callback): | |
572 assert self._grab_hdl is None | |
573 | |
574 root = self._root() | |
575 root.setAttribute('inkscape:groupmode', '') | |
576 self._grab_hdl = root.spitem.connect('mouse-event', callback) | |
577 pass | |
578 | |
579 def ungrab_mouse(self): | |
580 if not self._grab_hdl: | |
581 return | |
582 | |
583 root = self._root() | |
584 root.spitem.disconnect(self._grab_hdl) | |
585 self._grab_hdl = None | |
586 root.setAttribute('inkscape:groupmode', 'layer') | |
587 pass | |
588 | |
589 def grab_bg(self, callback): | |
590 assert self._bg_hdl is None | |
591 assert self._background | |
592 | |
593 background = self._background | |
594 bg_hdl = background.spitem.connect('mouse-event', callback) | |
595 self._bg_hdl = bg_hdl | |
596 pass | |
597 | |
598 def ungrab_bg(self): | |
599 if not self._bg_hdl: | |
600 return | |
601 | |
602 background = self._background | |
603 bg_hdl = self._bg_hdl | |
604 background.spitem.disconnect(bg_hdl) | |
605 self._bg_hdl = None | |
606 pass | |
1456
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
607 pass |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
608 |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
609 if __name__ == '__main__': |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
610 win = FSM_window() |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
611 win._main_win.connect('destroy', gtk.main_quit) |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
612 win.show() |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
613 gtk.main() |
894a4bf35fe6
Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
614 pass |