comparison pyink/FSM_window.py @ 1504:d5b677831671

Make grab_bg() stackable
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 09 May 2011 00:27:10 +0800
parents 4d582306df85
children 7b8e67b2391b
comparison
equal deleted inserted replaced
1503:4d582306df85 1504:d5b677831671
1146 self._select = select_man 1146 self._select = select_man
1147 1147
1148 self._on_deactivate = [] 1148 self._on_deactivate = []
1149 pass 1149 pass
1150 1150
1151 def on_move_state_background(self, item, evtype, button, x, y): 1151 def _handle_move_state_background(self, item, evtype, button, x, y):
1152 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE: 1152 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE:
1153 self._select.deselect() 1153 self._select.deselect()
1154 pass 1154 pass
1155 pass 1155 pass
1156 1156
1222 1222
1223 state_name = state_src.state_name 1223 state_name = state_src.state_name
1224 cond = trn.trn_cond 1224 cond = trn.trn_cond
1225 domview.set_transition_path(state_name, cond, path) 1225 domview.set_transition_path(state_name, cond, path)
1226 1226
1227 select.control_transition(trn) 1227 trn.update()
1228 trn.show_control_points()
1228 pass 1229 pass
1229 1230
1230 def c1_start(): 1231 def c1_start():
1231 def relay_event(item, evtype, button, x, y): 1232 def relay_event(item, evtype, button, x, y):
1232 c1_dragger.mouse_event(evtype, button, x, y) 1233 c1_dragger.mouse_event(evtype, button, x, y)
1233 pass 1234 pass
1234 1235
1236 window.push_grabs()
1235 window.ungrab_bg() 1237 window.ungrab_bg()
1236 window.grab_bg(relay_event) 1238 window.grab_bg(relay_event)
1237 pass 1239 pass
1238 1240
1239 def c1_stop(rx, ry): 1241 def c1_stop(rx, ry):
1240 window.ungrab_bg() 1242 window.pop_grabs()
1241 window.grab_bg(self.on_move_state_background)
1242 pass 1243 pass
1243 1244
1244 def c2_update(rx, ry): 1245 def c2_update(rx, ry):
1245 nc2x = c2x + rx 1246 nc2x = c2x + rx
1246 nc2y = c2y + ry 1247 nc2y = c2y + ry
1257 1258
1258 state_name = state_src.state_name 1259 state_name = state_src.state_name
1259 cond = trn.trn_cond 1260 cond = trn.trn_cond
1260 domview.set_transition_path(state_name, cond, path) 1261 domview.set_transition_path(state_name, cond, path)
1261 1262
1262 select.control_transition(trn) 1263 trn.update()
1264 trn.show_control_points()
1263 pass 1265 pass
1264 1266
1265 def c2_start(): 1267 def c2_start():
1266 def relay_event(item, evtype, button, x, y): 1268 def relay_event(item, evtype, button, x, y):
1267 c2_dragger.mouse_event(evtype, button, x, y) 1269 c2_dragger.mouse_event(evtype, button, x, y)
1268 pass 1270 pass
1269 1271
1272 window.push_grabs()
1270 window.ungrab_bg() 1273 window.ungrab_bg()
1271 window.grab_bg(relay_event) 1274 window.grab_bg(relay_event)
1272 pass 1275 pass
1273 1276
1274 def c2_stop(rx, ry): 1277 def c2_stop(rx, ry):
1275 window.ungrab_bg() 1278 window.pop_grabs()
1276 window.grab_bg(self.on_move_state_background)
1277 pass 1279 pass
1278 1280
1279 c1_dragger = _dragger() 1281 c1_dragger = _dragger()
1280 c1_dragger.update = c1_update 1282 c1_dragger.update = c1_update
1281 c1_dragger.start_drag = c1_start 1283 c1_dragger.start_drag = c1_start
1327 # 1329 #
1328 def _hint_transition(self, trn): 1330 def _hint_transition(self, trn):
1329 def stop_hint(*args): 1331 def stop_hint(*args):
1330 trn.stop_hint() 1332 trn.stop_hint()
1331 window.ungrab_bg() 1333 window.ungrab_bg()
1332 window.grab_bg(self.on_move_state_background) 1334 window.grab_bg(self._handle_move_state_background)
1333 pass 1335 pass
1334 1336
1335 trn.start_hint() 1337 trn.start_hint()
1336 1338
1337 window = self._window 1339 window = self._window
1362 window._emit_leave_mode() 1364 window._emit_leave_mode()
1363 window._clear_leave_mode_cb() 1365 window._clear_leave_mode_cb()
1364 window.ungrab_all() 1366 window.ungrab_all()
1365 1367
1366 window.ungrab_bg() 1368 window.ungrab_bg()
1367 window.grab_bg(self.on_move_state_background) 1369 window.grab_bg(self._handle_move_state_background)
1368 window.grab_state(self._handle_move_state_state) 1370 window.grab_state(self._handle_move_state_state)
1369 window.grab_transition(self._handle_transitoin_mouse_events) 1371 window.grab_transition(self._handle_transitoin_mouse_events)
1370 #window.grab_edit_transition(self._handle_edit_transition) 1372 #window.grab_edit_transition(self._handle_edit_transition)
1371 #window.grab_transition_apply(self._handle_transition_apply) 1373 #window.grab_transition_apply(self._handle_transition_apply)
1372 1374
1438 window._load_new_state_incr(state_name) 1440 window._load_new_state_incr(state_name)
1439 1441
1440 window.hide_state_editor() 1442 window.hide_state_editor()
1441 pass 1443 pass
1442 1444
1443 def on_add_state_background(self, item, evtype, button, x, y): 1445 def _handle_add_state_background(self, item, evtype, button, x, y):
1444 window = self._window 1446 window = self._window
1445 1447
1446 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE and \ 1448 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE and \
1447 button == 1: 1449 button == 1:
1448 self._saved_x = x 1450 self._saved_x = x
1528 1530
1529 window._emit_leave_mode() 1531 window._emit_leave_mode()
1530 window.ungrab_all() 1532 window.ungrab_all()
1531 1533
1532 window.ungrab_bg() 1534 window.ungrab_bg()
1533 window.grab_bg(self.on_add_state_background) 1535 window.grab_bg(self._handle_add_state_background)
1534 window.grab_state(self._handle_state_mouse_events) 1536 window.grab_state(self._handle_state_mouse_events)
1535 pass 1537 pass
1536 1538
1537 def deactivate(self): 1539 def deactivate(self):
1538 if self._select_state: 1540 if self._select_state:
1556 height = 768 1558 height = 768
1557 1559
1558 _grab_mouse_hdl = None 1560 _grab_mouse_hdl = None
1559 _bg_hdl = None 1561 _bg_hdl = None
1560 1562
1563 _bg_mouse_event_cb = None
1561 _leave_mode_cb = None 1564 _leave_mode_cb = None
1562 _move_state_mode = None 1565 _move_state_mode = None
1563 _add_state_mode = None 1566 _add_state_mode = None
1564 _state_mouse_event_handler = None 1567 _state_mouse_event_handler = None
1565 _add_transition_cb = None 1568 _add_transition_cb = None
1614 1617
1615 control_layer = doc.createElement('svg:g') 1618 control_layer = doc.createElement('svg:g')
1616 control_layer.setAttribute('inkscape:groupmode', 'layer') 1619 control_layer.setAttribute('inkscape:groupmode', 'layer')
1617 root.appendChild(control_layer) 1620 root.appendChild(control_layer)
1618 self._control_layer = control_layer 1621 self._control_layer = control_layer
1622
1623 bg_hdl = background.spitem.connect('mouse-event',
1624 self.on_bg_mouse_events)
1625 self._bg_hdl = bg_hdl
1619 pass 1626 pass
1620 1627
1621 def _doc(self): 1628 def _doc(self):
1622 view_widget = self._view_widget 1629 view_widget = self._view_widget
1623 view = view_widget.view 1630 view = view_widget.view
1674 self._leave_mode_cb = None 1681 self._leave_mode_cb = None
1675 pass 1682 pass
1676 pass 1683 pass
1677 1684
1678 def ungrab_all(self): 1685 def ungrab_all(self):
1686 self.ungrab_bg()
1679 self.ungrab_state() 1687 self.ungrab_state()
1680 self.ungrab_add_transition() 1688 self.ungrab_add_transition()
1681 self.ungrab_transition() 1689 self.ungrab_transition()
1682 self.ungrab_edit_transition() 1690 self.ungrab_edit_transition()
1683 self.ungrab_edit_state() 1691 self.ungrab_edit_state()
1684 self.ungrab_transition_apply() 1692 self.ungrab_transition_apply()
1685 pass 1693 pass
1686 1694
1687 def save_grabs(self): 1695 def save_grabs(self):
1688 save = (self._state_mouse_event_handler, 1696 save = (self._bg_mouse_event_cb,
1697 self._state_mouse_event_handler,
1689 self._transition_mouse_event_handler, 1698 self._transition_mouse_event_handler,
1690 self._add_transition_cb, 1699 self._add_transition_cb,
1691 self._edit_transition_cb, 1700 self._edit_transition_cb,
1692 self._transition_apply_cb, 1701 self._transition_apply_cb,
1693 self._edit_state_cb) 1702 self._edit_state_cb)
1694 return save 1703 return save
1695 1704
1696 def restore_grabs(self, save): 1705 def restore_grabs(self, save):
1697 self._state_mouse_event_handler, \ 1706 self._bg_mouse_event_cb, \
1707 self._state_mouse_event_handler, \
1698 self._transition_mouse_event_handler, \ 1708 self._transition_mouse_event_handler, \
1699 self._add_transition_cb, \ 1709 self._add_transition_cb, \
1700 self._edit_transition_cb, \ 1710 self._edit_transition_cb, \
1701 self._transition_apply_cb, \ 1711 self._transition_apply_cb, \
1702 self._edit_state_cb \ 1712 self._edit_state_cb \
1703 = save 1713 = save
1704 pass 1714 pass
1705 1715
1716 ## \brief Push current setting of grab handles into the stack.
1717 #
1706 def push_grabs(self): 1718 def push_grabs(self):
1707 save = self.save_grabs() 1719 save = self.save_grabs()
1708 self._grab_stack.append(save) 1720 self._grab_stack.append(save)
1709 pass 1721 pass
1710 1722
1723 ## \brief Restore setting of grab handles from the stack.
1724 #
1711 def pop_grabs(self): 1725 def pop_grabs(self):
1712 save = self._grab_stack.pop() 1726 save = self._grab_stack.pop()
1713 self.restore_grabs(save) 1727 self.restore_grabs(save)
1714 pass 1728 pass
1715 1729
1969 root.spitem.disconnect(self._grab_mouse_hdl) 1983 root.spitem.disconnect(self._grab_mouse_hdl)
1970 self._grab_mouse_hdl = None 1984 self._grab_mouse_hdl = None
1971 root.setAttribute('inkscape:groupmode', 'layer') 1985 root.setAttribute('inkscape:groupmode', 'layer')
1972 pass 1986 pass
1973 1987
1988 def on_bg_mouse_events(self, item, evtype, button, x, y):
1989 if not self._bg_mouse_event_cb:
1990 return
1991
1992 self._bg_mouse_event_cb(item, evtype, button, x, y)
1993 pass
1994
1974 def grab_bg(self, callback): 1995 def grab_bg(self, callback):
1975 assert self._bg_hdl is None 1996 assert self._bg_mouse_event_cb is None
1976 assert self._background 1997
1977 1998 self._bg_mouse_event_cb = callback
1978 background = self._background
1979 bg_hdl = background.spitem.connect('mouse-event', callback)
1980 self._bg_hdl = bg_hdl
1981 pass 1999 pass
1982 2000
1983 def ungrab_bg(self): 2001 def ungrab_bg(self):
1984 if not self._bg_hdl: 2002 if not self._bg_mouse_event_cb:
1985 return 2003 return
1986 2004
1987 background = self._background 2005 self._bg_mouse_event_cb = None
1988 bg_hdl = self._bg_hdl
1989 background.spitem.disconnect(bg_hdl)
1990 self._bg_hdl = None
1991 pass 2006 pass
1992 pass 2007 pass
1993 2008
1994 if __name__ == '__main__': 2009 if __name__ == '__main__':
1995 win = FSM_window() 2010 win = FSM_window()