Mercurial > MadButterfly
comparison pyink/FSM_window.py @ 1508:62001d2c89f6
Make _FSM_add_state_mode to use _FSM_popup
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 09 May 2011 19:25:38 +0800 |
parents | bebf73ee38c8 |
children | 4a2402ac34dd |
comparison
equal
deleted
inserted
replaced
1507:bebf73ee38c8 | 1508:62001d2c89f6 |
---|---|
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='', radius='30', entry_action=''): | 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_entry_action = self._state_entry_action |
168 state_editor = self._state_editor | 168 state_editor = self._state_editor |
169 | 169 |
1148 | 1148 |
1149 state_name = state_name_txt.get_text() | 1149 state_name = state_name_txt.get_text() |
1150 state_radius = state_radius_txt.get_text() | 1150 state_radius = state_radius_txt.get_text() |
1151 state_entry_action = state_entry_action_txt.get_text() | 1151 state_entry_action = state_entry_action_txt.get_text() |
1152 | 1152 |
1153 state_radius_i = int(state_radius) | 1153 state_radius_f = float(state_radius) |
1154 | 1154 |
1155 state = select.selected_state | 1155 state = select.selected_state |
1156 old_state_name = state.state_name | 1156 old_state_name = state.state_name |
1157 if old_state_name != state_name: | 1157 if old_state_name != state_name: |
1158 domview.rename_state(old_state_name, state_name) | 1158 domview.rename_state(old_state_name, state_name) |
1159 state.state_name = state_name | 1159 state.state_name = state_name |
1160 pass | 1160 pass |
1161 | 1161 |
1162 domview.set_state_r(state_name, state_radius_i) | 1162 domview.set_state_r(state_name, state_radius_f) |
1163 domview.set_state_entry_action(state_name, state_entry_action) | 1163 domview.set_state_entry_action(state_name, state_entry_action) |
1164 | 1164 |
1165 state.update() | 1165 state.update() |
1166 | 1166 |
1167 window.hide_state_editor() | 1167 window.hide_state_editor() |
1422 | 1422 |
1423 window.ungrab_bg() | 1423 window.ungrab_bg() |
1424 window.grab_bg(self._handle_move_state_background) | 1424 window.grab_bg(self._handle_move_state_background) |
1425 window.grab_state(self._handle_move_state_state) | 1425 window.grab_state(self._handle_move_state_state) |
1426 window.grab_transition(self._handle_transitoin_mouse_events) | 1426 window.grab_transition(self._handle_transitoin_mouse_events) |
1427 #window.grab_edit_transition(self._handle_edit_transition) | |
1428 #window.grab_transition_apply(self._handle_transition_apply) | |
1429 | 1427 |
1430 self._popup.popup_install_handler() | 1428 self._popup.popup_install_handler() |
1431 pass | 1429 pass |
1432 | 1430 |
1433 def deactivate(self): | 1431 def deactivate(self): |
1451 _saved_y = 0 | 1449 _saved_y = 0 |
1452 | 1450 |
1453 _select_state = None | 1451 _select_state = None |
1454 _candidate_state = None | 1452 _candidate_state = None |
1455 | 1453 |
1454 _popup = None | |
1456 _select = None | 1455 _select = None |
1457 | 1456 |
1458 def __init__(self, window, domview_ui, select_man): | 1457 def __init__(self, window, domview_ui, select_man): |
1459 super(_FSM_add_state_mode, self).__init__() | 1458 super(_FSM_add_state_mode, self).__init__() |
1460 | 1459 |
1461 self._window = window | 1460 self._window = window |
1462 self._domview = domview_ui | 1461 self._domview = domview_ui |
1463 self._locker = domview_ui | 1462 self._locker = domview_ui |
1464 | 1463 |
1465 self._select = select_man | 1464 self._select = select_man |
1465 self._popup = _FSM_popup(window, domview_ui, select_man) | |
1466 pass | 1466 pass |
1467 | 1467 |
1468 def _handle_add_new_state(self): | 1468 def _handle_add_new_state(self): |
1469 import traceback | 1469 import traceback |
1470 | 1470 |
1497 window.hide_state_editor() | 1497 window.hide_state_editor() |
1498 pass | 1498 pass |
1499 | 1499 |
1500 def _handle_add_state_background(self, item, evtype, button, x, y): | 1500 def _handle_add_state_background(self, item, evtype, button, x, y): |
1501 window = self._window | 1501 window = self._window |
1502 select = self._select | |
1502 | 1503 |
1503 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE and \ | 1504 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE and \ |
1504 button == 1: | 1505 button == 1: |
1505 self._saved_x = x | 1506 self._saved_x = x |
1506 self._saved_y = y | 1507 self._saved_y = y |
1508 select.deselect() | |
1507 window.show_state_editor() | 1509 window.show_state_editor() |
1508 pass | 1510 pass |
1509 pass | 1511 pass |
1510 | 1512 |
1511 def _stop_select_target(self): | 1513 ## \brief Dispatching state apply event to _FSM_popup or this class. |
1512 self.deactivate() | 1514 # |
1513 self.activate() | 1515 # When user change properties of a state, this event is deliveried to |
1514 pass | 1516 # _FSM_popup. Otherwise, dispatch the event to this class. |
1515 | 1517 # |
1516 def _handle_select_transition_target(self, state, evtype, button, x, y): | 1518 def _handle_state_apply(self): |
1517 if self._candidate_state != state and self._select_state != state: | 1519 select = self._select |
1518 if self._candidate_state: | 1520 if select.selected_state: |
1519 self._candidate_state.hide_selected() | 1521 # selected the state while user request to edit a state. |
1520 pass | 1522 popup = self._popup |
1521 self._candidate_state = state | 1523 popup._handle_state_change() |
1522 state.show_selected() | 1524 else: |
1523 pass | 1525 # deselected while user click on bg to add a new state. |
1524 | 1526 self._handle_add_new_state() |
1525 if evtype != pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE: | |
1526 return | |
1527 if button != 1: | |
1528 return | |
1529 | |
1530 if state == self._select_state: | |
1531 self._stop_select_target() | |
1532 return | |
1533 | |
1534 window = self._window | |
1535 fsm_layer = window._fsm_layer | |
1536 | |
1537 target_state = state | |
1538 target_name = target_state.state_name | |
1539 src_state = self._select_state | |
1540 src_name = src_state.state_name | |
1541 cond = '' | |
1542 | |
1543 domview = self._domview | |
1544 domview.add_transition(src_name, cond, target_name) | |
1545 src_state.add_transition(fsm_layer, cond) | |
1546 | |
1547 trn = src_state.transitions[cond] | |
1548 window._install_transition_event_handler(trn) | |
1549 | |
1550 self._stop_select_target() | |
1551 pass | |
1552 | |
1553 def _handle_add_transition(self, *args): | |
1554 def restore_bg(item, evtype, *args): | |
1555 if evtype != pybInkscape.PYSPItem.PYB_EVENT_BUTTON_PRESS: | |
1556 if self._candidate_state: | |
1557 self._candidate_state.hide_selected() | |
1558 self._candidate_state = None | |
1559 pass | |
1560 return | |
1561 self._stop_select_target() | |
1562 pass | |
1563 | |
1564 window = self._window | |
1565 window.ungrab_bg() | |
1566 window.grab_bg(restore_bg) | |
1567 | |
1568 window.ungrab_state() | |
1569 window.grab_state(self._handle_select_transition_target) | |
1570 self._select_state.show_selected() | |
1571 pass | |
1572 | |
1573 def _handle_state_mouse_events(self, state, evtype, button, x, y): | |
1574 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE and \ | |
1575 button == 3: | |
1576 self._select_state = state | |
1577 | |
1578 window = self._window | |
1579 window.popup_state_menu() | |
1580 pass | 1527 pass |
1581 pass | 1528 pass |
1582 | 1529 |
1583 def activate(self): | 1530 def activate(self): |
1584 window = self._window | 1531 window = self._window |
1585 | 1532 |
1586 window._emit_leave_mode() | 1533 window._emit_leave_mode() |
1587 window.ungrab_all() | 1534 window.ungrab_all() |
1588 | 1535 |
1589 window.grab_bg(self._handle_add_state_background) | 1536 window.grab_bg(self._handle_add_state_background) |
1590 window.grab_state(self._handle_state_mouse_events) | 1537 |
1591 window.grab_state_apply(self._handle_add_new_state) | 1538 # |
1539 # Install event handlers for _FSM_popup | |
1540 # | |
1541 window.grab_state(self._popup._handle_state_mouse_events) | |
1542 window.grab_transition(self._popup._handle_transition_mouse_events) | |
1543 self._popup.popup_install_handler() | |
1544 | |
1545 # | |
1546 # Workaround to make state apply events dispatched to right | |
1547 # place according history of user actions. | |
1548 # | |
1549 # see _handle_state_apply() | |
1550 # | |
1551 window.ungrab_state_apply() | |
1552 window.grab_state_apply(self._handle_state_apply) | |
1592 pass | 1553 pass |
1593 | 1554 |
1594 def deactivate(self): | 1555 def deactivate(self): |
1595 if self._select_state: | 1556 if self._select_state: |
1596 self._select_state.hide_selected() | 1557 self._select_state.hide_selected() |