comparison pyink/FSM_window.py @ 1491:06c101bba830

Hint user to select transition target
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 01 May 2011 00:09:56 +0800
parents 3f107ceee9c1
children 6616530c4180
comparison
equal deleted inserted replaced
1490:3f107ceee9c1 1491:06c101bba830
687 687
688 _saved_x = 0 688 _saved_x = 0
689 _saved_y = 0 689 _saved_y = 0
690 690
691 _select_state = None 691 _select_state = None
692 _candidate_state = None
692 693
693 def __init__(self, window, domview_ui): 694 def __init__(self, window, domview_ui):
694 super(_FSM_add_state_mode, self).__init__() 695 super(_FSM_add_state_mode, self).__init__()
695 696
696 self._window = window 697 self._window = window
739 self._saved_y = y 740 self._saved_y = y
740 window.show_state_editor() 741 window.show_state_editor()
741 pass 742 pass
742 pass 743 pass
743 744
745 def _stop_select_target(self):
746 self.deactivate()
747 self.activate()
748 pass
749
744 def _handle_select_transition_target(self, state, evtype, button, x, y): 750 def _handle_select_transition_target(self, state, evtype, button, x, y):
751 if self._candidate_state != state and self._select_state != state:
752 if self._candidate_state:
753 self._candidate_state.hide_selected()
754 pass
755 self._candidate_state = state
756 state.show_selected()
757 pass
758
745 if evtype != pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE: 759 if evtype != pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE:
746 return 760 return
747 if button != 1: 761 if button != 1:
748 return 762 return
749 763
750 if state == self._select_state: 764 if state == self._select_state:
751 self.deactivate() 765 self._stop_select_target()
752 self.activate()
753 return 766 return
754 767
755 window = self._window 768 window = self._window
756 fsm_layer = window._fsm_layer 769 fsm_layer = window._fsm_layer
757 770
758 target_state = state 771 target_state = state
759 src_state = self._select_state 772 src_state = self._select_state
760 cond = '' 773 cond = ''
761 src_state.add_transition(fsm_layer, cond, target_state) 774 src_state.add_transition(fsm_layer, cond, target_state)
775
776 self._stop_select_target()
762 pass 777 pass
763 778
764 def _handle_add_transition(self, *args): 779 def _handle_add_transition(self, *args):
765 def restore_bg(item, evtype, *args): 780 def restore_bg(item, evtype, *args):
766 if evtype != pybInkscape.PYSPItem.PYB_EVENT_BUTTON_PRESS: 781 if evtype != pybInkscape.PYSPItem.PYB_EVENT_BUTTON_PRESS:
782 if self._candidate_state:
783 self._candidate_state.hide_selected()
784 self._candidate_state = None
785 pass
767 return 786 return
768 self.deactivate() 787 self._stop_select_target()
769 self.activate()
770 pass 788 pass
771 789
772 window = self._window 790 window = self._window
773 window.ungrab_bg() 791 window.ungrab_bg()
774 window.grab_bg(restore_bg) 792 window.grab_bg(restore_bg)
775 793
776 window.ungrab_state() 794 window.ungrab_state()
777 window.grab_state(self._handle_select_transition_target) 795 window.grab_state(self._handle_select_transition_target)
796 self._select_state.show_selected()
778 pass 797 pass
779 798
780 def _handle_state_mouse_events(self, state, evtype, button, x, y): 799 def _handle_state_mouse_events(self, state, evtype, button, x, y):
781 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE and \ 800 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE and \
782 button == 3: 801 button == 3:
797 window.grab_state(self._handle_state_mouse_events) 816 window.grab_state(self._handle_state_mouse_events)
798 window.grab_add_transition(self._handle_add_transition) 817 window.grab_add_transition(self._handle_add_transition)
799 pass 818 pass
800 819
801 def deactivate(self): 820 def deactivate(self):
821 if self._select_state:
822 self._select_state.hide_selected()
823 pass
824 if self._candidate_state:
825 self._candidate_state.hide_selected()
826 self._candidate_state = None
827 pass
802 pass 828 pass
803 pass 829 pass
804 830
805 class FSM_window(FSM_window_base): 831 class FSM_window(FSM_window_base):
806 __metaclass__ = data_monitor.data_monitor 832 __metaclass__ = data_monitor.data_monitor