def on_button_press(self, event): """Handle button press events. If the (mouse) button is pressed on top of a Handle (item.Handle), that handle is grabbed and can be dragged around. """ if not event.get_button()[1] == 1: # left mouse button return False view = self.view item, handle = HandleFinder(view.hovered_item, view).get_handle_at_point( (event.x, event.y)) # Handle must be the end handle of a connection if not handle or not isinstance( item, ConnectionView) or handle not in item.end_handles(): return False if handle is item.from_handle(): self._start_port_v = item.from_port else: self._start_port_v = item.to_port self._parent_state_v = item.parent self._end_handle = handle if isinstance(item, TransitionView): self._is_transition = True self._connection_v = item return True
def on_button_press(self, event): """Handle button press events. If the (mouse) button is pressed on top of a Handle (item.Handle), that handle is grabbed and can be dragged around. """ if not event.get_button()[1] == 1: # left mouse button return False view = self.view if isinstance(view.hovered_item, StateView): distance = view.hovered_item.border_width / 2. item, handle = HandleFinder(view.hovered_item, view).get_handle_at_point( (event.x, event.y), distance) else: item, handle = HandleFinder(view.hovered_item, view).get_handle_at_point( (event.x, event.y)) if not handle: return False # Only move ports when the MOVE_PORT_MODIFIER key is pressed if isinstance(item, (StateView, PortView)) and \ handle in [port.handle for port in item.get_all_ports()] and \ not (event.get_state()[1] & constants.MOVE_PORT_MODIFIER): return False # Do not move from/to handles of connections (only their waypoints) if isinstance(item, ConnectionView) and handle in item.end_handles( include_waypoints=True): return False if handle: view.hovered_item = item self.motion_handle = None self.grab_handle(item, handle) return True