# HG changeset patch # User Thinker K.F. Li # Date 1304441149 -28800 # Node ID 65249f15138e2f8d6947aed498746fc8b0f0b3f4 # Parent 9a7332e282912572e277818a0e3a767302474d44 Show transition editor when user click on "Edit" menu item diff -r 9a7332e28291 -r 65249f15138e pyink/FSM_window.py --- a/pyink/FSM_window.py Tue May 03 13:09:43 2011 +0800 +++ b/pyink/FSM_window.py Wed May 04 00:45:49 2011 +0800 @@ -161,13 +161,15 @@ error_dialog.hide() pass - def show_state_editor(self, state_name=''): + def show_state_editor(self, state_name='', radius='30', entry_action=''): state_name_inp = self._state_name state_radius_inp = self._state_radius + state_entry_action = self._state_entry_action state_editor = self._state_editor state_name_inp.set_text(state_name) - state_radius_inp.set_text('30') + state_radius_inp.set_text(radius) + state_entry_action.set_text(entry_action) state_editor.show() pass @@ -176,6 +178,21 @@ state_editor.hide() pass + def show_transition_editor(self, cond='', action=''): + transition_cond = self._transition_cond + transition_action = self._transition_action + transition_editor = self._transition_editor + + transition_cond.set_text(cond) + transition_action.set_text(action) + transition_editor.show() + pass + + def hide_transition_editor(self): + transition_editor = self._transition_editor + transition_editor.hide() + pass + def popup_state_menu(self): menu = self._state_menu menu.popup(None, None, None, 0, 0) @@ -252,6 +269,8 @@ pass def on_transition_cancel_clicked(self, *args): + transition_editor = self._transition_editor + transition_editor.hide() pass def on_del_transition_activate(self, *args): @@ -384,6 +403,14 @@ def state(self): return self._state + @property + def action(self): + domview = self._domview + state_name = self._state.state_name + trn_cond = self.trn_cond + trn = domview.get_transition(state_name, trn_cond) + return trn[2] + def draw(self, parent): path = self.path trn_g, path_node, arrow_node = self._draw_transition_real(parent, path) @@ -1002,10 +1029,17 @@ window.grab_bg(stop_hint) pass - def on_del_transition_activate(self, *args): + def _handle_del_transition(self, *args): pass - def on_edit_transition_activate(self, *args): + def _handle_edit_transition(self, *args): + trn = self._select_transition + + cond = trn.trn_cond + action = trn.action or '' + + window = self._window + window.show_transition_editor(cond, action) pass def _show_transition_menu(self, trn): @@ -1039,6 +1073,7 @@ window.grab_bg(self.on_move_state_background) window.grab_state(self._handle_move_state_state) window.grab_transition(self._handle_transitoin_mouse_events) + window.grab_edit_transition(self._handle_edit_transition) pass def deactivate(self): @@ -1215,6 +1250,7 @@ _add_state_mode = None _state_mouse_event_handler = None _add_transition_cb = None + _edit_transition_cb = None _transition_mouse_event_handler = None def __init__(self, domview_ui, close_cb, destroy_cb): @@ -1321,6 +1357,7 @@ self.ungrab_state() self.ungrab_add_transition() self.ungrab_transition() + self.ungrab_edit_transition() pass def on_state_mouse_event(self, state, evtype, button, x, y): @@ -1377,6 +1414,15 @@ self._add_transition_cb = None pass + def grab_edit_transition(self, callback): + assert self._edit_transition_cb is None + self._edit_transition_cb = callback + pass + + def ungrab_edit_transition(self): + self._edit_transition_cb = None + pass + def _load_new_state(self, state_name): states = self._states @@ -1468,6 +1514,12 @@ pass pass + def on_edit_transition_activate(self, *args): + if self._edit_transition_cb: + self._edit_transition_cb(*args) + pass + pass + def _install_test_data(self): self._init_layers()