コード例 #1
0
    def _create_key_event(self, event_type, event):
        if self.enable_window.focus_owner is None:
            focus_owner = self.enable_window.component
        else:
            focus_owner = self.enable_window.focus_owner

        if focus_owner is None:
            return

        if event_type == 'character':
            key = event
            if not key:
                return None
        else:
            key_code = event[0]
            if key_code in KEY_MAP:
                key = KEY_MAP.get(key_code)
            else:
                key = key_code

        return KeyEvent(event_type=event_type,
                        character=key,
                        alt_down=keys[key.LALT] | keys[key.RALT],
                        control_down=keys[key.LCTRL] | keys[key.RCTRL],
                        shift_down=keys[key.LSHIFT] | keys[key.RSHIFT],
                        x=self._mouse_x,
                        y=self._mouse_y,
                        window=self.enable_window)
コード例 #2
0
ファイル: base_window.py プロジェクト: toddrme2178/enable
    def _create_key_event(self, event_type, event):
        focus_owner = self.focus_owner

        if focus_owner is None:
            focus_owner = self.component

            if focus_owner is None:
                event.ignore()
                return None

        if event_type == 'character':
            key = six.text_type(event.text())
        else:
            # Convert the keypress to a standard enable key if possible, otherwise
            # to text.
            key_code = event.key()
            key = KEY_MAP.get(key_code)
            if key is None:
                key = six.unichr(key_code).lower()

        if not key:
            return None

        # Use the last-seen mouse position as the coordinates of this event.
        x, y = self.control.handler.last_mouse_pos

        modifiers = event.modifiers()

        return KeyEvent(event_type=event_type, character=key, x=x,
                        y=self._flip_y(y),
                        alt_down=bool(modifiers & QtCore.Qt.AltModifier),
                        shift_down=bool(modifiers & QtCore.Qt.ShiftModifier),
                        control_down=bool(modifiers & QtCore.Qt.ControlModifier),
                        event=event,
                        window=self)
コード例 #3
0
ファイル: testing.py プロジェクト: alexlib/enable
    def create_key_press(self,
                         key,
                         window=None,
                         alt_down=False,
                         control_down=False,
                         shift_down=False):
        """ Creates a KeyEvent for the given Key.

        Parameters
        ----------
        key : string
            The key of the event

        window : AbstractWindow, optional
            The enable AbstractWindow to associate with the event. Default
            is to create a mock class instance.

        alt_down : boolean, optional
            The key is pressed while `alt` is down. Default value is False.

        control_down : boolean, optional
            The key is pressed while `control` is down. Default value is
            False.

        shift_down : boolean, optional
            The key is pressed while `shift` is down. Default value is
            False.

        Returns
        -------
        key_event : KeyEvent
             The enable KEyEvent instance of the desired event ready to be
             passed to an enable Interactor.
        """
        key_event = KeyEvent(
            character=key,
            event_type="key_pressed",
            alt_down=alt_down,
            control_down=control_down,
            shift_down=shift_down,
        )
        if window is None:
            key_event.window = self.create_mock_window()
        else:
            key_event.window = window
        return key_event
コード例 #4
0
ファイル: testing.py プロジェクト: burnpanck/enable
    def create_key_press(self, key, window=None, alt_down=False,
                         control_down=False, shift_down=False):
        """ Creates a KeyEvent for the given Key.

        Parameters
        ----------
        key : string
            The key of the event

        window : AbstractWindow, optional
            The enable AbstractWindow to associate with the event. Default
            is to create a mock class instance.

        alt_down : boolean, optional
            The key is pressed while `alt` is down. Default value is False.

        control_down : boolean, optional
            The key is pressed while `control` is down. Default value is
            False.

        shift_down : boolean, optional
            The key is pressed while `shift` is down. Default value is
            False.

        Returns
        -------
        key_event : KeyEvent
             The enable KEyEvent instance of the desired event ready to be
             passed to an enable Interactor.

        """
        key_event = KeyEvent(character=key,
                             event_type='key_pressed',
                             alt_down=alt_down,
                             control_down=control_down,
                             shift_down=shift_down)
        if window is None:
            key_event.window = self.create_mock_window()
        else:
            key_event.window = window
        return key_event
コード例 #5
0
ファイル: plot_tools.py プロジェクト: reidmcy/uchicago-pyanno
    def wx_key_event_repackaging(key_event, gui_event):
        key_code = gui_event.GetKeyCode()
        if key_code in wx_constants.KEY_MAP:
            character = wx_constants.KEY_MAP[key_code]
        elif key_code == wx.WXK_COMMAND:
            character = 'Menu'
        else:
            character = chr(key_code).lower()

        return KeyEvent(event_type=key_event.event_type,
                        character=character,
                        x=key_event.x, y=key_event.y,
                        control_down=gui_event.ControlDown(),
                        shift_down=gui_event.ShiftDown(),
                        meta_down=gui_event.MetaDown(),
                        event=gui_event,
                        window=key_event.window)
コード例 #6
0
    def _create_key_event(self, event_type, event):
        """ Convert a GUI toolkit keyboard event into a KeyEvent.
        """
        if self.focus_owner is None:
            focus_owner = self.component
        else:
            focus_owner = self.focus_owner

        if focus_owner is not None:
            if event_type == "character":
                key = chr(event.GetUnicodeKey())
                if not key:
                    return None
            else:
                key_code = event.GetKeyCode()
                if key_code in KEY_MAP:
                    key = KEY_MAP.get(key_code)
                else:
                    key = chr(event.GetUnicodeKey()).lower()

            # Use the last-seen mouse coordinates instead of GetX/GetY due
            # to wx bug.
            x, y = self._last_mouse_pos

            # Someday when wx does this properly, we can use these instead:
            # x = event.GetX()
            # y = event.GetY()

            return KeyEvent(
                event_type=event_type,
                character=key,
                alt_down=event.AltDown(),
                control_down=event.ControlDown(),
                shift_down=event.ShiftDown(),
                x=x,
                y=self._flip_y(y),
                event=event,
                window=self,
            )
        else:
            event.Skip()

        return None