Mercurial > MadButterfly
comparison pyink/FSM_window.py @ 1500:65249f15138e
Show transition editor when user click on "Edit" menu item
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 04 May 2011 00:45:49 +0800 |
parents | 9a7332e28291 |
children | 4a57650bb926 |
comparison
equal
deleted
inserted
replaced
1499:9a7332e28291 | 1500:65249f15138e |
---|---|
159 def hide_error(self): | 159 def hide_error(self): |
160 error_dialog = self._error_dialog | 160 error_dialog = self._error_dialog |
161 error_dialog.hide() | 161 error_dialog.hide() |
162 pass | 162 pass |
163 | 163 |
164 def show_state_editor(self, state_name=''): | 164 def show_state_editor(self, state_name='', radius='30', entry_action=''): |
165 state_name_inp = self._state_name | 165 state_name_inp = self._state_name |
166 state_radius_inp = self._state_radius | 166 state_radius_inp = self._state_radius |
167 state_entry_action = self._state_entry_action | |
167 state_editor = self._state_editor | 168 state_editor = self._state_editor |
168 | 169 |
169 state_name_inp.set_text(state_name) | 170 state_name_inp.set_text(state_name) |
170 state_radius_inp.set_text('30') | 171 state_radius_inp.set_text(radius) |
172 state_entry_action.set_text(entry_action) | |
171 state_editor.show() | 173 state_editor.show() |
172 pass | 174 pass |
173 | 175 |
174 def hide_state_editor(self): | 176 def hide_state_editor(self): |
175 state_editor = self._state_editor | 177 state_editor = self._state_editor |
176 state_editor.hide() | 178 state_editor.hide() |
177 pass | 179 pass |
178 | 180 |
181 def show_transition_editor(self, cond='', action=''): | |
182 transition_cond = self._transition_cond | |
183 transition_action = self._transition_action | |
184 transition_editor = self._transition_editor | |
185 | |
186 transition_cond.set_text(cond) | |
187 transition_action.set_text(action) | |
188 transition_editor.show() | |
189 pass | |
190 | |
191 def hide_transition_editor(self): | |
192 transition_editor = self._transition_editor | |
193 transition_editor.hide() | |
194 pass | |
195 | |
179 def popup_state_menu(self): | 196 def popup_state_menu(self): |
180 menu = self._state_menu | 197 menu = self._state_menu |
181 menu.popup(None, None, None, 0, 0) | 198 menu.popup(None, None, None, 0, 0) |
182 pass | 199 pass |
183 | 200 |
250 | 267 |
251 def on_transition_apply_clicked(self, *args): | 268 def on_transition_apply_clicked(self, *args): |
252 pass | 269 pass |
253 | 270 |
254 def on_transition_cancel_clicked(self, *args): | 271 def on_transition_cancel_clicked(self, *args): |
272 transition_editor = self._transition_editor | |
273 transition_editor.hide() | |
255 pass | 274 pass |
256 | 275 |
257 def on_del_transition_activate(self, *args): | 276 def on_del_transition_activate(self, *args): |
258 pass | 277 pass |
259 | 278 |
381 return trn[1] | 400 return trn[1] |
382 | 401 |
383 @property | 402 @property |
384 def state(self): | 403 def state(self): |
385 return self._state | 404 return self._state |
405 | |
406 @property | |
407 def action(self): | |
408 domview = self._domview | |
409 state_name = self._state.state_name | |
410 trn_cond = self.trn_cond | |
411 trn = domview.get_transition(state_name, trn_cond) | |
412 return trn[2] | |
386 | 413 |
387 def draw(self, parent): | 414 def draw(self, parent): |
388 path = self.path | 415 path = self.path |
389 trn_g, path_node, arrow_node = self._draw_transition_real(parent, path) | 416 trn_g, path_node, arrow_node = self._draw_transition_real(parent, path) |
390 self.trn_g = trn_g | 417 self.trn_g = trn_g |
1000 window = self._window | 1027 window = self._window |
1001 window.ungrab_bg() | 1028 window.ungrab_bg() |
1002 window.grab_bg(stop_hint) | 1029 window.grab_bg(stop_hint) |
1003 pass | 1030 pass |
1004 | 1031 |
1005 def on_del_transition_activate(self, *args): | 1032 def _handle_del_transition(self, *args): |
1006 pass | 1033 pass |
1007 | 1034 |
1008 def on_edit_transition_activate(self, *args): | 1035 def _handle_edit_transition(self, *args): |
1036 trn = self._select_transition | |
1037 | |
1038 cond = trn.trn_cond | |
1039 action = trn.action or '' | |
1040 | |
1041 window = self._window | |
1042 window.show_transition_editor(cond, action) | |
1009 pass | 1043 pass |
1010 | 1044 |
1011 def _show_transition_menu(self, trn): | 1045 def _show_transition_menu(self, trn): |
1012 self._select_transition = trn | 1046 self._select_transition = trn |
1013 | 1047 |
1037 window.ungrab_all() | 1071 window.ungrab_all() |
1038 | 1072 |
1039 window.grab_bg(self.on_move_state_background) | 1073 window.grab_bg(self.on_move_state_background) |
1040 window.grab_state(self._handle_move_state_state) | 1074 window.grab_state(self._handle_move_state_state) |
1041 window.grab_transition(self._handle_transitoin_mouse_events) | 1075 window.grab_transition(self._handle_transitoin_mouse_events) |
1076 window.grab_edit_transition(self._handle_edit_transition) | |
1042 pass | 1077 pass |
1043 | 1078 |
1044 def deactivate(self): | 1079 def deactivate(self): |
1045 self._deselect_state() | 1080 self._deselect_state() |
1046 pass | 1081 pass |
1213 _leave_mode_cb = None | 1248 _leave_mode_cb = None |
1214 _move_state_mode = None | 1249 _move_state_mode = None |
1215 _add_state_mode = None | 1250 _add_state_mode = None |
1216 _state_mouse_event_handler = None | 1251 _state_mouse_event_handler = None |
1217 _add_transition_cb = None | 1252 _add_transition_cb = None |
1253 _edit_transition_cb = None | |
1218 _transition_mouse_event_handler = None | 1254 _transition_mouse_event_handler = None |
1219 | 1255 |
1220 def __init__(self, domview_ui, close_cb, destroy_cb): | 1256 def __init__(self, domview_ui, close_cb, destroy_cb): |
1221 super(FSM_window, self).__init__() | 1257 super(FSM_window, self).__init__() |
1222 | 1258 |
1319 self.ungrab_bg() | 1355 self.ungrab_bg() |
1320 self.ungrab_mouse() | 1356 self.ungrab_mouse() |
1321 self.ungrab_state() | 1357 self.ungrab_state() |
1322 self.ungrab_add_transition() | 1358 self.ungrab_add_transition() |
1323 self.ungrab_transition() | 1359 self.ungrab_transition() |
1360 self.ungrab_edit_transition() | |
1324 pass | 1361 pass |
1325 | 1362 |
1326 def on_state_mouse_event(self, state, evtype, button, x, y): | 1363 def on_state_mouse_event(self, state, evtype, button, x, y): |
1327 if self._state_mouse_event_handler: | 1364 if self._state_mouse_event_handler: |
1328 self._state_mouse_event_handler(state, evtype, button, x, y) | 1365 self._state_mouse_event_handler(state, evtype, button, x, y) |
1373 self._add_transition_cb = callback | 1410 self._add_transition_cb = callback |
1374 pass | 1411 pass |
1375 | 1412 |
1376 def ungrab_add_transition(self): | 1413 def ungrab_add_transition(self): |
1377 self._add_transition_cb = None | 1414 self._add_transition_cb = None |
1415 pass | |
1416 | |
1417 def grab_edit_transition(self, callback): | |
1418 assert self._edit_transition_cb is None | |
1419 self._edit_transition_cb = callback | |
1420 pass | |
1421 | |
1422 def ungrab_edit_transition(self): | |
1423 self._edit_transition_cb = None | |
1378 pass | 1424 pass |
1379 | 1425 |
1380 def _load_new_state(self, state_name): | 1426 def _load_new_state(self, state_name): |
1381 states = self._states | 1427 states = self._states |
1382 | 1428 |
1463 pass | 1509 pass |
1464 | 1510 |
1465 def on_add_transition_activate(self, *args): | 1511 def on_add_transition_activate(self, *args): |
1466 if self._add_transition_cb: | 1512 if self._add_transition_cb: |
1467 self._add_transition_cb(*args) | 1513 self._add_transition_cb(*args) |
1514 pass | |
1515 pass | |
1516 | |
1517 def on_edit_transition_activate(self, *args): | |
1518 if self._edit_transition_cb: | |
1519 self._edit_transition_cb(*args) | |
1468 pass | 1520 pass |
1469 pass | 1521 pass |
1470 | 1522 |
1471 def _install_test_data(self): | 1523 def _install_test_data(self): |
1472 self._init_layers() | 1524 self._init_layers() |