comparison pyink/FSM_window.py @ 1506:f185a9d23a30

_FSM_popup handles edit state
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 09 May 2011 17:13:43 +0800
parents 7b8e67b2391b
children bebf73ee38c8
comparison
equal deleted inserted replaced
1505:7b8e67b2391b 1506:f185a9d23a30
166 state_radius_inp = self._state_radius 166 state_radius_inp = self._state_radius
167 state_entry_action = self._state_entry_action 167 state_entry_action = self._state_entry_action
168 state_editor = self._state_editor 168 state_editor = self._state_editor
169 169
170 state_name_inp.set_text(state_name) 170 state_name_inp.set_text(state_name)
171 state_radius_inp.set_text(radius) 171 state_radius_inp.set_text(str(radius))
172 state_entry_action.set_text(entry_action) 172 state_entry_action.set_text(entry_action or '')
173 state_editor.show() 173 state_editor.show()
174 pass 174 pass
175 175
176 def hide_state_editor(self): 176 def hide_state_editor(self):
177 state_editor = self._state_editor 177 state_editor = self._state_editor
741 def xy(self): 741 def xy(self):
742 domview = self._domview 742 domview = self._domview
743 state_name = self.state_name 743 state_name = self.state_name
744 xy = domview.get_state_xy(state_name) 744 xy = domview.get_state_xy(state_name)
745 return xy 745 return xy
746
747 @property
748 def entry_action(self):
749 domview = self._domview
750 state_name = self.state_name
751 entry_action = domview.get_state_entry_action(state_name)
752 return entry_action
746 753
747 @property 754 @property
748 def all_transitions(self): 755 def all_transitions(self):
749 domview = self._domview 756 domview = self._domview
750 state_name = self.state_name 757 state_name = self.state_name
982 # 989 #
983 def _handle_state_mouse_events(self, state, evtype, button, x, y): 990 def _handle_state_mouse_events(self, state, evtype, button, x, y):
984 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_PRESS and \ 991 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_PRESS and \
985 button == 3: 992 button == 3:
986 self._show_state_menu(state) 993 self._show_state_menu(state)
994 self._select.select_state(state)
987 elif evtype == pybInkscape.PYSPItem.PYB_EVENT_MOUSE_ENTER: 995 elif evtype == pybInkscape.PYSPItem.PYB_EVENT_MOUSE_ENTER:
988 state.start_hint() 996 state.start_hint()
989 elif evtype == pybInkscape.PYSPItem.PYB_EVENT_MOUSE_LEAVE: 997 elif evtype == pybInkscape.PYSPItem.PYB_EVENT_MOUSE_LEAVE:
990 state.stop_hint() 998 state.stop_hint()
991 pass 999 pass
1117 1125
1118 window.hide_transition_editor() 1126 window.hide_transition_editor()
1119 pass 1127 pass
1120 1128
1121 def _handle_edit_state(self, *args): 1129 def _handle_edit_state(self, *args):
1130 select = self._select
1131 state = select.selected_state
1132 name = state.state_name
1133 r = state.r
1134 entry_action = state.entry_action
1135
1136 window = self._window
1137 window.show_state_editor(name, r, entry_action)
1138 pass
1139
1140 def _handle_state_change(self):
1141 window = self._window
1142 domview = self._domview
1143 select = self._select
1144
1145 state_name_txt = window._state_name
1146 state_radius_txt = window._state_radius
1147 state_entry_action_txt = window._state_entry_action
1148
1149 state_name = state_name_txt.get_text()
1150 state_radius = state_radius_txt.get_text()
1151 state_entry_action = state_entry_action_txt.get_text()
1152
1153 state_radius_i = int(state_radius)
1154
1155 state = select.selected_state
1156 old_state_name = state.state_name
1157 if old_state_name != state_name:
1158 domview.rename_state(old_state_name, state_name)
1159 state.state_name = state_name
1160 pass
1161
1162 domview.set_state_r(state_name, state_radius_i)
1163 domview.set_state_entry_action(state_name, state_entry_action)
1164
1165 state.update()
1166
1167 window.hide_state_editor()
1168 select.deselect()
1122 pass 1169 pass
1123 1170
1124 def popup_install_handler(self): 1171 def popup_install_handler(self):
1125 window = self._window 1172 window = self._window
1126 1173
1127 window.grab_add_transition(self._handle_add_transition) 1174 window.grab_add_transition(self._handle_add_transition)
1128 window.grab_edit_transition(self._handle_edit_transition) 1175 window.grab_edit_transition(self._handle_edit_transition)
1129 window.grab_edit_state(self._handle_edit_state) 1176 window.grab_edit_state(self._handle_edit_state)
1130 window.grab_transition_apply(self._handle_transition_apply) 1177 window.grab_transition_apply(self._handle_transition_apply)
1178 window.grab_state_apply(self._handle_state_change)
1131 pass 1179 pass
1132 pass 1180 pass
1133 1181
1134 1182
1135 class _FSM_move_state_mode(object): 1183 class _FSM_move_state_mode(object):
1415 self._locker = domview_ui 1463 self._locker = domview_ui
1416 1464
1417 self._select = select_man 1465 self._select = select_man
1418 pass 1466 pass
1419 1467
1420 def handle_new_state(self): 1468 def _handle_add_new_state(self):
1421 import traceback 1469 import traceback
1422 1470
1423 domview = self._domview 1471 domview = self._domview
1424 window = self._window 1472 window = self._window
1425 x, y = window._translate_xy(self._saved_x, self._saved_y) 1473 x, y = window._translate_xy(self._saved_x, self._saved_y)
1536 window = self._window 1584 window = self._window
1537 1585
1538 window._emit_leave_mode() 1586 window._emit_leave_mode()
1539 window.ungrab_all() 1587 window.ungrab_all()
1540 1588
1541 window.ungrab_bg()
1542 window.grab_bg(self._handle_add_state_background) 1589 window.grab_bg(self._handle_add_state_background)
1543 window.grab_state(self._handle_state_mouse_events) 1590 window.grab_state(self._handle_state_mouse_events)
1591 window.grab_state_apply(self._handle_add_new_state)
1544 pass 1592 pass
1545 1593
1546 def deactivate(self): 1594 def deactivate(self):
1547 if self._select_state: 1595 if self._select_state:
1548 self._select_state.hide_selected() 1596 self._select_state.hide_selected()
1575 _add_transition_cb = None 1623 _add_transition_cb = None
1576 _edit_transition_cb = None 1624 _edit_transition_cb = None
1577 _transition_apply_cb = None 1625 _transition_apply_cb = None
1578 _transition_mouse_event_handler = None 1626 _transition_mouse_event_handler = None
1579 _edit_state_cb = None 1627 _edit_state_cb = None
1628 _state_apply_cb = None
1580 1629
1581 _grab_stack = None 1630 _grab_stack = None
1582 1631
1583 _select = None 1632 _select = None
1584 1633
1695 self.ungrab_add_transition() 1744 self.ungrab_add_transition()
1696 self.ungrab_transition() 1745 self.ungrab_transition()
1697 self.ungrab_edit_transition() 1746 self.ungrab_edit_transition()
1698 self.ungrab_edit_state() 1747 self.ungrab_edit_state()
1699 self.ungrab_transition_apply() 1748 self.ungrab_transition_apply()
1749 self.ungrab_state_apply()
1700 pass 1750 pass
1701 1751
1702 def save_grabs(self): 1752 def save_grabs(self):
1703 save = (self._bg_mouse_event_cb, 1753 save = (self._bg_mouse_event_cb,
1704 self._state_mouse_event_handler, 1754 self._state_mouse_event_handler,
1705 self._transition_mouse_event_handler, 1755 self._transition_mouse_event_handler,
1706 self._add_transition_cb, 1756 self._add_transition_cb,
1707 self._edit_transition_cb, 1757 self._edit_transition_cb,
1708 self._transition_apply_cb, 1758 self._transition_apply_cb,
1709 self._edit_state_cb) 1759 self._edit_state_cb,
1760 self._state_apply_cb)
1710 return save 1761 return save
1711 1762
1712 def restore_grabs(self, save): 1763 def restore_grabs(self, save):
1713 self._bg_mouse_event_cb, \ 1764 self._bg_mouse_event_cb, \
1714 self._state_mouse_event_handler, \ 1765 self._state_mouse_event_handler, \
1715 self._transition_mouse_event_handler, \ 1766 self._transition_mouse_event_handler, \
1716 self._add_transition_cb, \ 1767 self._add_transition_cb, \
1717 self._edit_transition_cb, \ 1768 self._edit_transition_cb, \
1718 self._transition_apply_cb, \ 1769 self._transition_apply_cb, \
1719 self._edit_state_cb \ 1770 self._edit_state_cb, \
1771 self._state_apply_cb \
1720 = save 1772 = save
1721 pass 1773 pass
1722 1774
1723 ## \brief Push current setting of grab handles into the stack. 1775 ## \brief Push current setting of grab handles into the stack.
1724 # 1776 #
1811 self._edit_state_cb = callback 1863 self._edit_state_cb = callback
1812 pass 1864 pass
1813 1865
1814 def ungrab_edit_state(self): 1866 def ungrab_edit_state(self):
1815 self._edit_state_cb = None 1867 self._edit_state_cb = None
1868 pass
1869
1870 def grab_state_apply(self, callback):
1871 assert self._state_apply_cb is None
1872 self._state_apply_cb = callback
1873 pass
1874
1875 def ungrab_state_apply(self):
1876 self._state_apply_cb = None
1816 pass 1877 pass
1817 1878
1818 def _load_new_state(self, state_name): 1879 def _load_new_state(self, state_name):
1819 states = self._states 1880 states = self._states
1820 1881
1895 mode.activate() 1956 mode.activate()
1896 self._set_leave_mode_cb(lambda: mode.deactivate()) 1957 self._set_leave_mode_cb(lambda: mode.deactivate())
1897 pass 1958 pass
1898 1959
1899 def on_state_apply_clicked(self, *args): 1960 def on_state_apply_clicked(self, *args):
1900 self._add_state_mode.handle_new_state() 1961 if self._state_apply_cb:
1962 self._state_apply_cb()
1963 pass
1901 pass 1964 pass
1902 1965
1903 def on_add_transition_activate(self, *args): 1966 def on_add_transition_activate(self, *args):
1904 if self._add_transition_cb: 1967 if self._add_transition_cb:
1905 self._add_transition_cb(*args) 1968 self._add_transition_cb(*args)