def _create_mouse_event(self, event): "Convert a GUI toolkit mouse event into a MouseEvent" if event is not None: x = event.GetX() y = event.GetY() self._last_mouse_pos = (x, y) mouse_wheel = ( (float(event.GetLinesPerAction()) * event.GetWheelRotation()) / (event.GetWheelDelta() or 1)) wheel_axis = MOUSE_WHEEL_AXIS_MAP[event.GetWheelAxis()] if wheel_axis == 'horizontal': mouse_wheel_delta = (mouse_wheel * 120 / 200., 0) else: mouse_wheel_delta = (0, mouse_wheel * 120 / 200.) # Note: The following code fixes a bug in wxPython that returns # 'mouse_wheel' events in screen coordinates, rather than window # coordinates: if float(wx.VERSION_STRING[:3]) < 2.8: if mouse_wheel != 0 and sys.platform == "win32": x, y = self.control.ScreenToClientXY(x, y) return MouseEvent( x=x, y=self._flip_y(y), alt_down=event.AltDown(), control_down=event.ControlDown(), shift_down=event.ShiftDown(), left_down=event.LeftIsDown(), middle_down=event.MiddleIsDown(), right_down=event.RightIsDown(), mouse_wheel=mouse_wheel, mouse_wheel_axis=wheel_axis, window=self, ) # If no event specified, make one up: x, y = wx.GetMousePosition() x, y = self.control.ScreenToClientXY(x, y) self._last_mouse_pos = (x, y) return MouseEvent(x=x, y=self._flip_y(y), alt_down=self.alt_pressed, control_down=self.ctrl_pressed, shift_down=self.shift_pressed, left_down=False, middle_down=False, right_down=False, mouse_wheel=0, window=self)
def _create_mouse_event(self, event): """ Convert a GUI toolkit mouse event into a MouseEvent """ if event is not None: x = event.GetX() y = event.GetY() self._last_mouse_pos = (x, y) mouse_wheel = (float(event.GetLinesPerAction()) * event.GetWheelRotation()) / (event.GetWheelDelta() or 1) wheel_axis = MOUSE_WHEEL_AXIS_MAP[event.GetWheelAxis()] if wheel_axis == "horizontal": mouse_wheel_delta = (mouse_wheel * 120 / 200.0, 0) else: mouse_wheel_delta = (0, mouse_wheel * 120 / 200.0) return MouseEvent( x=x, y=self._flip_y(y), alt_down=event.AltDown(), control_down=event.ControlDown(), shift_down=event.ShiftDown(), left_down=event.LeftIsDown(), middle_down=event.MiddleIsDown(), right_down=event.RightIsDown(), mouse_wheel=mouse_wheel, mouse_wheel_axis=wheel_axis, mouse_wheel_delta=mouse_wheel_delta, window=self, ) # If no event specified, make one up: x, y = wx.GetMousePosition() x, y = self.control.ScreenToClientXY(x, y) self._last_mouse_pos = (x, y) return MouseEvent( x=x, y=self._flip_y(y), alt_down=self.alt_pressed, control_down=self.ctrl_pressed, shift_down=self.shift_pressed, left_down=False, middle_down=False, right_down=False, mouse_wheel=0, window=self, )
def _create_mouse_event(self, event): # If the control no longer exists, don't send mouse event if self.control is None: return None # If the event (if there is one) doesn't contain the mouse position, # modifiers and buttons then get sensible defaults. try: x = event.x() y = event.y() modifiers = event.modifiers() buttons = event.buttons() except AttributeError: pos = self.control.mapFromGlobal(QtGui.QCursor.pos()) x = pos.x() y = pos.y() modifiers = 0 buttons = 0 self.control.handler.last_mouse_pos = (x, y) # A bit crap, because AbstractWindow was written with wx in mind, and # we treat wheel events like mouse events. if isinstance(event, QtGui.QWheelEvent): degrees_per_step = 15.0 if is_qt4: delta = event.delta() mouse_wheel = delta / float(8 * degrees_per_step) mouse_wheel_axis = MOUSE_WHEEL_AXIS_MAP[event.orientation()] if mouse_wheel_axis == 'horizontal': mouse_wheel_delta = (delta, 0) else: mouse_wheel_delta = (0, delta) else: delta = event.pixelDelta() mouse_wheel_delta = (delta.x(), delta.y()) if abs(mouse_wheel_delta[0]) > abs(mouse_wheel_delta[1]): mouse_wheel = mouse_wheel_delta[0] / float(8 * degrees_per_step) mouse_wheel_axis = 'horizontal' else: mouse_wheel = mouse_wheel_delta[1] / float(8 * degrees_per_step) mouse_wheel_axis = 'vertical' else: mouse_wheel = 0 mouse_wheel_delta = (0, 0) mouse_wheel_axis = 'vertical' return MouseEvent( x=x, y=self._flip_y(y), mouse_wheel=mouse_wheel, mouse_wheel_axis=mouse_wheel_axis, mouse_wheel_delta=mouse_wheel_delta, alt_down=bool(modifiers & QtCore.Qt.AltModifier), shift_down=bool(modifiers & QtCore.Qt.ShiftModifier), control_down=bool(modifiers & QtCore.Qt.ControlModifier), left_down=bool(buttons & QtCore.Qt.LeftButton), middle_down=bool(buttons & QtCore.Qt.MidButton), right_down=bool(buttons & QtCore.Qt.RightButton), window=self )
def _create_mouse_event(self, event): """ Convert a Pyglet mouse event into an Enable MouseEvent. Since Pyglet doesn't actually have a mouse event object like WX or Qt, PygletWindow actually does most of the work of creating an Enable MouseEvent when various things happen, and calls AbstractWindow._handle_mouse_event with that object. _handle_mouse_event() then calls this method with that object. AbstractWindow._on_window_leave() also calls this method. """ if event is not None: x = event.x y = event.y self._last_mouse_pos = (x, y) mouse = pyglet.window.mouse buttons = event.buttons if buttons is None: buttons = 0 return MouseEvent(x=x, y=y, alt_down=event.alt_pressed, control_down=event.ctrl_pressed, shift_down=event.shift_pressed, left_down=bool(mouse.LEFT & buttons), middle_down=bool(mouse.MIDDLE & buttons), right_down=bool(mouse.RIGHT & buttons), mouse_wheel=event.scroll_y, window=self) else: # If no event specified, make one up: x = self.control._mouse_x y = self.control._mouse_y self._last_mouse_pos = (x, y) return MouseEvent(x=x, y=y, alt_down=event.alt_pressed, control_down=event.ctrl_pressed, shift_down=event.shift_pressed, left_down=False, middle_down=False, right_down=False, mouse_wheel=0, window=self)
def create_mouse_event(self, **kwargs): """ Creates a MouseEvent() with the specified attributes. """ # provide defaults for all key shift states event_attributes = { # key shift states 'alt_down': False, 'control_down': False, 'shift_down': False, } event_attributes.update(**kwargs) event = MouseEvent(**event_attributes) return event
def create_mouse_event(self, **kwargs): """ Creates a MouseEvent() with the specified attributes. """ # provide defaults for all key shift states event_attributes = { # key shift states "alt_down": False, "control_down": False, "shift_down": False, "mouse_wheel": 0, "mouse_wheel_axis": "vertical", } event_attributes.update(**kwargs) event = MouseEvent(**event_attributes) return event
def _create_mouse_event(self, event): # If the control no longer exists, don't send mouse event if self.control is None: return None # If the event (if there is one) doesn't contain the mouse position, # modifiers and buttons then get sensible defaults. try: x = event.x() y = event.y() modifiers = event.modifiers() buttons = event.buttons() except AttributeError: pos = self.control.mapFromGlobal(QtGui.QCursor.pos()) x = pos.x() y = pos.y() modifiers = 0 buttons = 0 self.control.handler.last_mouse_pos = (x, y) # A bit crap, because AbstractWindow was written with wx in mind, and # we treat wheel events like mouse events. if isinstance(event, QtGui.QWheelEvent): delta = event.angleDelta() degrees_per_step = 15.0 mouse_wheel = delta / float(8 * degrees_per_step) else: mouse_wheel = 0 return MouseEvent(x=x, y=self._flip_y(y), mouse_wheel=mouse_wheel, alt_down=bool(modifiers & QtCore.Qt.AltModifier), shift_down=bool(modifiers & QtCore.Qt.ShiftModifier), control_down=bool(modifiers & QtCore.Qt.ControlModifier), left_down=bool(buttons & QtCore.Qt.LeftButton), middle_down=bool(buttons & QtCore.Qt.MidButton), right_down=bool(buttons & QtCore.Qt.RightButton), window=self)
warnings.warn("pyface.wx is unavailable", ImportWarning) clipboard = None PythonDropTarget = None # ----------------------------------------------------------------------------- # Constants: # ----------------------------------------------------------------------------- # Number of pixels to scroll at a time: scroll_incr = 16 # Reusable instance to avoid constructor/destructor overhead: wx_rect = wx.Rect(0, 0, 0, 0) # Default 'fake' start event for wxPython based drag operations: default_start_event = MouseEvent() # To conserve system resources, there is only one 'timer' per program: system_timer = None class EnableTimer(wx.Timer): """ This class maintains a 'work list' of scheduled components, where each item in the list has the form: [ component, interval, timer_pop_time ] """ def __init__(self): wx.Timer.__init__(self) self._work_list = [] def schedule(self, component, interval): """ Schedule a timer event for a specified component