2014-06-19 09:04:37 +02:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
2015-01-03 15:51:31 +01:00
|
|
|
# Copyright 2014-2015 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
2014-04-23 16:57:12 +02:00
|
|
|
#
|
|
|
|
# This file is part of qutebrowser.
|
|
|
|
#
|
|
|
|
# qutebrowser is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# qutebrowser is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2015-01-09 20:14:50 +01:00
|
|
|
"""Mode manager singleton which handles the current keyboard mode."""
|
2014-04-23 16:57:12 +02:00
|
|
|
|
2014-09-29 10:43:06 +02:00
|
|
|
import functools
|
|
|
|
|
2014-04-25 06:22:01 +02:00
|
|
|
from PyQt5.QtGui import QWindow
|
2015-02-12 18:57:56 +01:00
|
|
|
from PyQt5.QtCore import pyqtSignal, Qt, QObject, QEvent
|
2014-06-19 11:16:54 +02:00
|
|
|
from PyQt5.QtWidgets import QApplication
|
2015-02-12 18:57:56 +01:00
|
|
|
from PyQt5.QtWebKitWidgets import QWebView
|
2014-04-23 16:57:12 +02:00
|
|
|
|
2014-09-28 00:18:57 +02:00
|
|
|
from qutebrowser.keyinput import modeparsers, keyparser
|
2014-08-26 19:10:14 +02:00
|
|
|
from qutebrowser.config import config
|
2014-08-26 20:48:39 +02:00
|
|
|
from qutebrowser.commands import cmdexc, cmdutils
|
2014-09-26 15:48:24 +02:00
|
|
|
from qutebrowser.utils import usertypes, log, objreg, utils
|
2014-04-24 16:53:16 +02:00
|
|
|
|
2014-04-23 16:57:12 +02:00
|
|
|
|
2014-09-25 18:45:16 +02:00
|
|
|
class NotInModeError(Exception):
|
|
|
|
|
|
|
|
"""Exception raised when we want to leave a mode we're not in."""
|
|
|
|
|
|
|
|
|
2014-09-28 22:13:14 +02:00
|
|
|
def init(win_id, parent):
|
2014-10-06 22:23:27 +02:00
|
|
|
"""Initialize the mode manager and the keyparsers for the given win_id."""
|
2014-09-28 00:18:57 +02:00
|
|
|
KM = usertypes.KeyMode # pylint: disable=invalid-name
|
2014-09-28 22:13:14 +02:00
|
|
|
modeman = ModeManager(win_id, parent)
|
|
|
|
objreg.register('mode-manager', modeman, scope='window', window=win_id)
|
2014-09-28 00:18:57 +02:00
|
|
|
keyparsers = {
|
2014-09-28 22:13:14 +02:00
|
|
|
KM.normal: modeparsers.NormalKeyParser(win_id, modeman),
|
|
|
|
KM.hint: modeparsers.HintKeyParser(win_id, modeman),
|
|
|
|
KM.insert: keyparser.PassthroughKeyParser(win_id, 'insert', modeman),
|
|
|
|
KM.passthrough: keyparser.PassthroughKeyParser(win_id, 'passthrough',
|
|
|
|
modeman),
|
|
|
|
KM.command: keyparser.PassthroughKeyParser(win_id, 'command', modeman),
|
|
|
|
KM.prompt: keyparser.PassthroughKeyParser(win_id, 'prompt', modeman,
|
2014-09-28 00:18:57 +02:00
|
|
|
warn=False),
|
2014-09-28 22:13:14 +02:00
|
|
|
KM.yesno: modeparsers.PromptKeyParser(win_id, modeman),
|
2014-09-28 00:18:57 +02:00
|
|
|
}
|
2014-09-28 22:13:14 +02:00
|
|
|
objreg.register('keyparsers', keyparsers, scope='window', window=win_id)
|
2014-09-29 10:43:06 +02:00
|
|
|
modeman.destroyed.connect(
|
|
|
|
functools.partial(objreg.delete, 'keyparsers', scope='window',
|
|
|
|
window=win_id))
|
2014-09-28 00:18:57 +02:00
|
|
|
modeman.register(KM.normal, keyparsers[KM.normal].handle)
|
|
|
|
modeman.register(KM.hint, keyparsers[KM.hint].handle)
|
|
|
|
modeman.register(KM.insert, keyparsers[KM.insert].handle, passthrough=True)
|
|
|
|
modeman.register(KM.passthrough, keyparsers[KM.passthrough].handle,
|
|
|
|
passthrough=True)
|
|
|
|
modeman.register(KM.command, keyparsers[KM.command].handle,
|
|
|
|
passthrough=True)
|
|
|
|
modeman.register(KM.prompt, keyparsers[KM.prompt].handle, passthrough=True)
|
|
|
|
modeman.register(KM.yesno, keyparsers[KM.yesno].handle)
|
2014-09-28 22:13:14 +02:00
|
|
|
return modeman
|
2014-09-28 00:18:57 +02:00
|
|
|
|
|
|
|
|
2014-09-28 22:13:14 +02:00
|
|
|
def _get_modeman(win_id):
|
|
|
|
"""Get a modemanager object."""
|
|
|
|
return objreg.get('mode-manager', scope='window', window=win_id)
|
2014-09-28 00:18:57 +02:00
|
|
|
|
2014-10-06 22:30:37 +02:00
|
|
|
|
2014-12-28 00:01:27 +01:00
|
|
|
def enter(win_id, mode, reason=None, only_if_normal=False):
|
2014-04-23 16:57:12 +02:00
|
|
|
"""Enter the mode 'mode'."""
|
2014-12-28 00:01:27 +01:00
|
|
|
_get_modeman(win_id).enter(mode, reason, only_if_normal)
|
2014-04-23 16:57:12 +02:00
|
|
|
|
|
|
|
|
2014-09-28 22:13:14 +02:00
|
|
|
def leave(win_id, mode, reason=None):
|
2014-04-24 06:44:58 +02:00
|
|
|
"""Leave the mode 'mode'."""
|
2014-09-28 22:13:14 +02:00
|
|
|
_get_modeman(win_id).leave(mode, reason)
|
2014-04-24 06:44:58 +02:00
|
|
|
|
|
|
|
|
2014-09-28 22:13:14 +02:00
|
|
|
def maybe_leave(win_id, mode, reason=None):
|
2014-04-24 16:03:16 +02:00
|
|
|
"""Convenience method to leave 'mode' without exceptions."""
|
|
|
|
try:
|
2014-09-28 22:13:14 +02:00
|
|
|
_get_modeman(win_id).leave(mode, reason)
|
2014-09-25 18:45:16 +02:00
|
|
|
except NotInModeError as e:
|
2014-09-16 08:20:19 +02:00
|
|
|
# This is rather likely to happen, so we only log to debug log.
|
2014-09-25 18:45:16 +02:00
|
|
|
log.modes.debug("{} (leave reason: {})".format(e, reason))
|
2014-04-24 16:03:16 +02:00
|
|
|
|
|
|
|
|
2014-09-28 22:13:14 +02:00
|
|
|
class EventFilter(QObject):
|
|
|
|
|
|
|
|
"""Event filter which passes the event to the corrent ModeManager."""
|
|
|
|
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
super().__init__(parent)
|
|
|
|
self._activated = True
|
|
|
|
|
|
|
|
def eventFilter(self, obj, event):
|
2014-09-28 22:23:37 +02:00
|
|
|
"""Forward events to the correct modeman."""
|
2014-09-28 22:13:14 +02:00
|
|
|
try:
|
2015-03-16 22:30:06 +01:00
|
|
|
if not self._activated:
|
|
|
|
return False
|
|
|
|
if event.type() not in [QEvent.KeyPress, QEvent.KeyRelease]:
|
|
|
|
# We're not interested in non-key-events so we pass them
|
|
|
|
# through.
|
|
|
|
return False
|
|
|
|
if not isinstance(obj, QWindow):
|
|
|
|
# We already handled this same event at some point earlier, so
|
|
|
|
# we're not interested in it anymore.
|
|
|
|
return False
|
|
|
|
if (QApplication.instance().activeWindow() not in
|
|
|
|
objreg.window_registry.values()):
|
|
|
|
# Some other window (print dialog, etc.) is focused so we pass
|
|
|
|
# the event through.
|
|
|
|
return False
|
|
|
|
try:
|
|
|
|
modeman = objreg.get('mode-manager', scope='window',
|
|
|
|
window='current')
|
|
|
|
return modeman.eventFilter(event)
|
|
|
|
except objreg.RegistryUnavailableError:
|
|
|
|
# No window available yet, or not a MainWindow
|
|
|
|
return False
|
2014-09-28 22:13:14 +02:00
|
|
|
except:
|
|
|
|
# If there is an exception in here and we leave the eventfilter
|
|
|
|
# activated, we'll get an infinite loop and a stack overflow.
|
|
|
|
self._activated = False
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
2014-04-23 16:57:12 +02:00
|
|
|
class ModeManager(QObject):
|
|
|
|
|
|
|
|
"""Manager for keyboard modes.
|
|
|
|
|
|
|
|
Attributes:
|
2014-04-24 06:59:39 +02:00
|
|
|
passthrough: A list of modes in which to pass through events.
|
2014-12-28 00:01:27 +01:00
|
|
|
mode: The mode we're currently in.
|
2014-09-28 22:13:14 +02:00
|
|
|
_win_id: The window ID of this ModeManager
|
2014-04-23 16:57:12 +02:00
|
|
|
_handlers: A dictionary of modes and their handlers.
|
2014-04-25 08:40:46 +02:00
|
|
|
_forward_unbound_keys: If we should forward unbound keys.
|
2014-04-25 09:20:19 +02:00
|
|
|
_releaseevents_to_pass: A list of keys where the keyPressEvent was
|
|
|
|
passed through, so the release event should as
|
|
|
|
well.
|
2014-04-23 17:56:36 +02:00
|
|
|
|
|
|
|
Signals:
|
|
|
|
entered: Emitted when a mode is entered.
|
2014-09-28 22:13:14 +02:00
|
|
|
arg1: The mode which has been entered.
|
|
|
|
arg2: The window ID of this mode manager.
|
2014-04-24 07:01:27 +02:00
|
|
|
left: Emitted when a mode is left.
|
2014-09-28 22:13:14 +02:00
|
|
|
arg1: The mode which has been left.
|
2014-12-08 20:18:55 +01:00
|
|
|
arg2: The new current mode.
|
|
|
|
arg3: The window ID of this mode manager.
|
2014-04-23 16:57:12 +02:00
|
|
|
"""
|
|
|
|
|
2014-09-28 22:13:14 +02:00
|
|
|
entered = pyqtSignal(usertypes.KeyMode, int)
|
2014-12-08 20:18:55 +01:00
|
|
|
left = pyqtSignal(usertypes.KeyMode, usertypes.KeyMode, int)
|
2014-04-23 17:56:36 +02:00
|
|
|
|
2014-09-28 22:13:14 +02:00
|
|
|
def __init__(self, win_id, parent=None):
|
2014-04-23 16:57:12 +02:00
|
|
|
super().__init__(parent)
|
2014-09-28 22:13:14 +02:00
|
|
|
self._win_id = win_id
|
2014-04-23 16:57:12 +02:00
|
|
|
self._handlers = {}
|
2014-04-24 06:59:39 +02:00
|
|
|
self.passthrough = []
|
2015-01-09 20:25:04 +01:00
|
|
|
self.mode = usertypes.KeyMode.normal
|
2014-04-25 09:20:19 +02:00
|
|
|
self._releaseevents_to_pass = []
|
2014-09-28 11:27:52 +02:00
|
|
|
self._forward_unbound_keys = config.get(
|
|
|
|
'input', 'forward-unbound-keys')
|
2014-10-18 19:50:10 +02:00
|
|
|
objreg.get('config').changed.connect(self.set_forward_unbound_keys)
|
2014-04-24 06:44:58 +02:00
|
|
|
|
2014-06-17 11:03:42 +02:00
|
|
|
def __repr__(self):
|
2014-12-28 00:01:27 +01:00
|
|
|
return utils.get_repr(self, mode=self.mode,
|
2014-09-26 15:48:24 +02:00
|
|
|
passthrough=self.passthrough)
|
2014-06-17 11:03:42 +02:00
|
|
|
|
2014-04-25 11:21:00 +02:00
|
|
|
def _eventFilter_keypress(self, event):
|
|
|
|
"""Handle filtering of KeyPress events.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
event: The KeyPress to examine.
|
|
|
|
|
|
|
|
Return:
|
|
|
|
True if event should be filtered, False otherwise.
|
|
|
|
"""
|
2014-12-28 00:01:27 +01:00
|
|
|
curmode = self.mode
|
2014-09-02 21:54:07 +02:00
|
|
|
handler = self._handlers[curmode]
|
|
|
|
if curmode != usertypes.KeyMode.insert:
|
2014-08-26 20:15:41 +02:00
|
|
|
log.modes.debug("got keypress in mode {} - calling handler "
|
2014-10-08 21:11:04 +02:00
|
|
|
"{}".format(curmode, utils.qualname(handler)))
|
2014-04-25 11:21:00 +02:00
|
|
|
handled = handler(event) if handler is not None else False
|
|
|
|
|
2014-06-25 15:25:24 +02:00
|
|
|
is_non_alnum = bool(event.modifiers()) or not event.text().strip()
|
2015-02-12 18:57:56 +01:00
|
|
|
focus_widget = QApplication.instance().focusWidget()
|
|
|
|
is_tab = event.key() in (Qt.Key_Tab, Qt.Key_Backtab)
|
2014-06-19 11:51:25 +02:00
|
|
|
|
2014-04-25 11:21:00 +02:00
|
|
|
if handled:
|
|
|
|
filter_this = True
|
2015-02-12 18:57:56 +01:00
|
|
|
elif is_tab and not isinstance(focus_widget, QWebView):
|
|
|
|
filter_this = True
|
2014-09-02 21:54:07 +02:00
|
|
|
elif (curmode in self.passthrough or
|
2014-06-19 11:51:25 +02:00
|
|
|
self._forward_unbound_keys == 'all' or
|
|
|
|
(self._forward_unbound_keys == 'auto' and is_non_alnum)):
|
2014-04-25 11:21:00 +02:00
|
|
|
filter_this = False
|
|
|
|
else:
|
|
|
|
filter_this = True
|
|
|
|
|
|
|
|
if not filter_this:
|
|
|
|
self._releaseevents_to_pass.append(event)
|
|
|
|
|
2014-09-02 21:54:07 +02:00
|
|
|
if curmode != usertypes.KeyMode.insert:
|
2014-08-26 20:15:41 +02:00
|
|
|
log.modes.debug("handled: {}, forward-unbound-keys: {}, "
|
2015-02-12 18:57:56 +01:00
|
|
|
"passthrough: {}, is_non_alnum: {}, is_tab {} --> "
|
|
|
|
"filter: {} (focused: {!r})".format(
|
2014-10-28 07:44:42 +01:00
|
|
|
handled, self._forward_unbound_keys,
|
2015-02-12 18:57:56 +01:00
|
|
|
curmode in self.passthrough, is_non_alnum,
|
|
|
|
is_tab, filter_this, focus_widget))
|
2014-04-25 11:21:00 +02:00
|
|
|
return filter_this
|
|
|
|
|
|
|
|
def _eventFilter_keyrelease(self, event):
|
|
|
|
"""Handle filtering of KeyRelease events.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
event: The KeyPress to examine.
|
|
|
|
|
|
|
|
Return:
|
|
|
|
True if event should be filtered, False otherwise.
|
|
|
|
"""
|
|
|
|
# handle like matching KeyPress
|
|
|
|
if event in self._releaseevents_to_pass:
|
|
|
|
# remove all occurences
|
|
|
|
self._releaseevents_to_pass = [
|
|
|
|
e for e in self._releaseevents_to_pass if e != event]
|
|
|
|
filter_this = False
|
|
|
|
else:
|
|
|
|
filter_this = True
|
2014-12-28 00:01:27 +01:00
|
|
|
if self.mode != usertypes.KeyMode.insert:
|
2014-08-26 20:15:41 +02:00
|
|
|
log.modes.debug("filter: {}".format(filter_this))
|
2014-04-25 11:21:00 +02:00
|
|
|
return filter_this
|
|
|
|
|
2014-04-23 23:22:34 +02:00
|
|
|
def register(self, mode, handler, passthrough=False):
|
2014-04-23 16:57:12 +02:00
|
|
|
"""Register a new mode.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
mode: The name of the mode.
|
|
|
|
handler: Handler for keyPressEvents.
|
2014-04-23 23:22:34 +02:00
|
|
|
passthrough: Whether to pass keybindings in this mode through to
|
|
|
|
the widgets.
|
2014-04-23 16:57:12 +02:00
|
|
|
"""
|
2014-08-26 19:10:14 +02:00
|
|
|
if not isinstance(mode, usertypes.KeyMode):
|
2014-07-29 00:23:20 +02:00
|
|
|
raise TypeError("Mode {} is no KeyMode member!".format(mode))
|
2014-04-23 16:57:12 +02:00
|
|
|
self._handlers[mode] = handler
|
2014-04-23 23:22:34 +02:00
|
|
|
if passthrough:
|
2014-04-24 06:59:39 +02:00
|
|
|
self.passthrough.append(mode)
|
2014-04-23 16:57:12 +02:00
|
|
|
|
2014-12-28 00:01:27 +01:00
|
|
|
def enter(self, mode, reason=None, only_if_normal=False):
|
2014-04-23 17:56:36 +02:00
|
|
|
"""Enter a new mode.
|
|
|
|
|
2014-04-24 06:44:58 +02:00
|
|
|
Args:
|
2014-07-28 22:40:58 +02:00
|
|
|
mode: The mode to enter as a KeyMode member.
|
2014-05-09 16:03:46 +02:00
|
|
|
reason: Why the mode was entered.
|
2014-12-28 00:01:27 +01:00
|
|
|
only_if_normal: Only enter the new mode if we're in normal mode.
|
2014-04-23 17:56:36 +02:00
|
|
|
"""
|
2014-08-26 19:10:14 +02:00
|
|
|
if not isinstance(mode, usertypes.KeyMode):
|
2014-07-29 00:23:20 +02:00
|
|
|
raise TypeError("Mode {} is no KeyMode member!".format(mode))
|
2014-08-26 20:15:41 +02:00
|
|
|
log.modes.debug("Entering mode {}{}".format(
|
2014-05-09 16:03:46 +02:00
|
|
|
mode, '' if reason is None else ' (reason: {})'.format(reason)))
|
2014-04-23 23:23:30 +02:00
|
|
|
if mode not in self._handlers:
|
|
|
|
raise ValueError("No handler for mode {}".format(mode))
|
2014-12-28 01:27:18 +01:00
|
|
|
prompt_modes = (usertypes.KeyMode.prompt, usertypes.KeyMode.yesno)
|
|
|
|
if self.mode == mode or (self.mode in prompt_modes and
|
|
|
|
mode in prompt_modes):
|
2014-12-28 00:01:27 +01:00
|
|
|
log.modes.debug("Ignoring request as we're in mode {} "
|
|
|
|
"already.".format(self.mode))
|
|
|
|
return
|
|
|
|
if self.mode != usertypes.KeyMode.normal:
|
|
|
|
if only_if_normal:
|
|
|
|
log.modes.debug("Ignoring request as we're in mode {} "
|
|
|
|
"and only_if_normal is set..".format(
|
|
|
|
self.mode))
|
|
|
|
return
|
|
|
|
log.modes.debug("Overriding mode {}.".format(self.mode))
|
|
|
|
self.left.emit(self.mode, mode, self._win_id)
|
|
|
|
self.mode = mode
|
2014-09-28 22:13:14 +02:00
|
|
|
self.entered.emit(mode, self._win_id)
|
2014-04-23 22:22:58 +02:00
|
|
|
|
2014-09-28 22:13:14 +02:00
|
|
|
@cmdutils.register(instance='mode-manager', hide=True, scope='window')
|
2014-07-28 22:40:58 +02:00
|
|
|
def enter_mode(self, mode):
|
2014-08-03 00:33:39 +02:00
|
|
|
"""Enter a key mode.
|
2014-07-28 22:40:58 +02:00
|
|
|
|
|
|
|
Args:
|
2014-08-03 00:33:39 +02:00
|
|
|
mode: The mode to enter.
|
2014-07-28 22:40:58 +02:00
|
|
|
"""
|
|
|
|
try:
|
2014-08-26 19:10:14 +02:00
|
|
|
m = usertypes.KeyMode[mode]
|
2014-07-28 22:40:58 +02:00
|
|
|
except KeyError:
|
2014-08-26 19:10:14 +02:00
|
|
|
raise cmdexc.CommandError("Mode {} does not exist!".format(mode))
|
2014-07-28 22:40:58 +02:00
|
|
|
self.enter(m, 'command')
|
|
|
|
|
2014-05-09 16:03:46 +02:00
|
|
|
def leave(self, mode, reason=None):
|
2014-08-03 00:33:39 +02:00
|
|
|
"""Leave a key mode.
|
2014-04-24 06:44:58 +02:00
|
|
|
|
|
|
|
Args:
|
2014-05-09 16:03:46 +02:00
|
|
|
mode: The name of the mode to leave.
|
|
|
|
reason: Why the mode was left.
|
2014-04-24 06:44:58 +02:00
|
|
|
"""
|
2014-12-28 00:01:27 +01:00
|
|
|
if self.mode != mode:
|
|
|
|
raise NotInModeError("Not in mode {}!".format(mode))
|
|
|
|
log.modes.debug("Leaving mode {}{}".format(
|
|
|
|
mode, '' if reason is None else ' (reason: {})'.format(reason)))
|
|
|
|
self.mode = usertypes.KeyMode.normal
|
|
|
|
self.left.emit(mode, self.mode, self._win_id)
|
2014-04-24 06:44:58 +02:00
|
|
|
|
2014-09-23 23:05:55 +02:00
|
|
|
@cmdutils.register(instance='mode-manager', name='leave-mode',
|
2014-09-28 22:13:14 +02:00
|
|
|
not_modes=[usertypes.KeyMode.normal], hide=True,
|
|
|
|
scope='window')
|
2014-04-24 23:09:12 +02:00
|
|
|
def leave_current_mode(self):
|
2014-04-25 11:21:00 +02:00
|
|
|
"""Leave the mode we're currently in."""
|
2014-12-28 00:01:27 +01:00
|
|
|
if self.mode == usertypes.KeyMode.normal:
|
2014-04-24 23:09:12 +02:00
|
|
|
raise ValueError("Can't leave normal mode!")
|
2014-12-28 00:01:27 +01:00
|
|
|
self.leave(self.mode, 'leave current')
|
2014-04-24 23:09:12 +02:00
|
|
|
|
2014-10-18 19:50:10 +02:00
|
|
|
@config.change_filter('input', 'forward-unbound-keys')
|
2014-09-28 11:27:52 +02:00
|
|
|
def set_forward_unbound_keys(self):
|
2014-04-25 08:40:46 +02:00
|
|
|
"""Update local setting when config changed."""
|
2014-09-28 11:27:52 +02:00
|
|
|
self._forward_unbound_keys = config.get(
|
|
|
|
'input', 'forward-unbound-keys')
|
2014-04-25 08:40:46 +02:00
|
|
|
|
2015-03-16 22:30:06 +01:00
|
|
|
def eventFilter(self, event):
|
2014-04-23 23:24:46 +02:00
|
|
|
"""Filter all events based on the currently set mode.
|
|
|
|
|
|
|
|
Also calls the real keypress handler.
|
2014-04-24 15:47:38 +02:00
|
|
|
|
2014-04-25 11:21:00 +02:00
|
|
|
Args:
|
|
|
|
event: The KeyPress to examine.
|
|
|
|
|
|
|
|
Return:
|
|
|
|
True if event should be filtered, False otherwise.
|
2014-04-23 23:24:46 +02:00
|
|
|
"""
|
2014-12-28 00:01:27 +01:00
|
|
|
if self.mode is None:
|
2014-04-24 21:29:28 +02:00
|
|
|
# We got events before mode is set, so just pass them through.
|
|
|
|
return False
|
2015-03-16 22:30:06 +01:00
|
|
|
if event.type() == QEvent.KeyPress:
|
2014-04-25 11:21:00 +02:00
|
|
|
return self._eventFilter_keypress(event)
|
2014-04-25 06:39:17 +02:00
|
|
|
else:
|
2014-04-25 11:21:00 +02:00
|
|
|
return self._eventFilter_keyrelease(event)
|