# HG changeset patch # User Thinker K.F. Li # Date 1304148165 -28800 # Node ID 757c5626d15db85c7520e4f26b737bb7a49a0f9a # Parent 3aba29609607e388d06133dac144198e26c605b7 Show context menu for states diff -r 3aba29609607 -r 757c5626d15d pyink/FSM_window.glade --- a/pyink/FSM_window.glade Sat Apr 30 11:18:44 2011 +0800 +++ b/pyink/FSM_window.glade Sat Apr 30 15:22:45 2011 +0800 @@ -471,4 +471,34 @@ error_dialog_ok + + True + + + True + Add a transition to the state + Add Transition + True + + + + + + True + Delete selecting state + Del State + True + + + + + + True + Edit properties of the state. + Edit State + True + + + + diff -r 3aba29609607 -r 757c5626d15d pyink/FSM_window.py --- a/pyink/FSM_window.py Sat Apr 30 11:18:44 2011 +0800 +++ b/pyink/FSM_window.py Sat Apr 30 15:22:45 2011 +0800 @@ -3,12 +3,17 @@ import data_monitor class FSM_window_base(object): + _add_state_button = None + _move_state_button = None + _state_editor = None _state_name = None _state_radius = None _error_dialog = None _error_dialog_label = None + + _state_menu = None def __init__(self): super(FSM_window_base, self).__init__() @@ -31,6 +36,8 @@ error_dialog = builder.get_object('error_dialog') error_dialog_label = builder.get_object('error_dialog_label') + state_menu = builder.get_object('state_menu') + builder.connect_signals(self) self._builder = builder @@ -45,6 +52,8 @@ self._error_dialog = error_dialog self._error_dialog_label = error_dialog_label + + self._state_menu = state_menu pass def show_error(self, msg): @@ -75,6 +84,11 @@ state_editor.hide() pass + def popup_state_menu(self): + menu = self._state_menu + menu.popup(None, None, None, 0, 0) + pass + def show(self): self._main_win.show() self._add_state_button.set_active(True) @@ -127,6 +141,15 @@ error_dialog = self._error_dialog error_dialog.hide() pass + + def on_add_transition_activate(self, *args): + pass + + def on_del_state_activate(self, *args): + pass + + def on_edit_state_activate(self, *args): + pass pass class FSM_transition(object): @@ -511,7 +534,7 @@ self._locker = domview_ui pass - def on_move_state_background(self, item, evtype, buttons, x, y): + def on_move_state_background(self, item, evtype, button, x, y): pass def _select_state(self, state): @@ -529,13 +552,13 @@ self._selected_state = None pass - def handle_move_state_state(self, state, evtype, buttons, x, y): + def handle_move_state_state(self, state, evtype, button, x, y): import pybInkscape window = self._window states = window._states - def moving_state(item, evtype, buttons, x, y): + def moving_state(item, evtype, button, x, y): if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE: window.ungrab_mouse() pass @@ -551,7 +574,8 @@ window = self._window - if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_PRESS: + if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_PRESS and \ + button == 1: start_x = x start_y = y orign_state_x, orign_state_y = state.xy @@ -560,7 +584,8 @@ window.grab_mouse(moving_state) pass - if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE: + if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE and \ + button == 1: window.ungrab_mouse() pass pass @@ -630,19 +655,29 @@ window.hide_state_editor() pass - def on_add_state_background(self, item, evtype, buttons, x, y): + def on_add_state_background(self, item, evtype, button, x, y): import pybInkscape window = self._window if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE and \ - buttons == 1: + button == 1: self._saved_x = x self._saved_y = y window.show_state_editor() pass pass + def _handle_state_mouse_events(self, state, evtype, button, x, y): + import pybInkscape + + if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE and \ + button == 3: + window = self._window + window.popup_state_menu() + pass + pass + def activate(self): window = self._window @@ -650,6 +685,7 @@ window.ungrab_all() window.grab_bg(self.on_add_state_background) + window.grab_state(self._handle_state_mouse_events) pass def deactivate(self): @@ -777,15 +813,15 @@ self.ungrab_state() pass - def on_state_mouse_event(self, state, evtype, buttons, x, y): + def on_state_mouse_event(self, state, evtype, button, x, y): if self._state_mouse_event_handler: - self._state_mouse_event_handler(state, evtype, buttons, x, y) + self._state_mouse_event_handler(state, evtype, button, x, y) pass pass def _install_state_event_handler(self, state): - def mouse_event_handler(item, evtype, buttons, x, y): - self.on_state_mouse_event(state, evtype, buttons, x, y) + def mouse_event_handler(item, evtype, button, x, y): + self.on_state_mouse_event(state, evtype, button, x, y) pass state.grab(mouse_event_handler) pass