Fix lint/cleanup
This commit is contained in:
parent
b7440b1f79
commit
f437bc25bf
@ -20,7 +20,7 @@
|
||||
import logging
|
||||
|
||||
from qutebrowser.commands.exceptions import (ArgumentCountError,
|
||||
InvalidModeError)
|
||||
InvalidModeError)
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, QObject
|
||||
|
||||
@ -57,6 +57,8 @@ class Command(QObject):
|
||||
|
||||
def __init__(self, name, maxsplit, hide, nargs, count, desc, instance,
|
||||
handler, completion, modes, not_modes):
|
||||
# I really don't know how to solve this in a better way, I tried.
|
||||
# pylint: disable=too-many-arguments
|
||||
super().__init__()
|
||||
self.name = name
|
||||
self.maxsplit = maxsplit
|
||||
|
@ -23,8 +23,8 @@ from PyQt5.QtWebKitWidgets import QWebPage
|
||||
import qutebrowser.config.config as config
|
||||
import qutebrowser.commands.utils as cmdutils
|
||||
import qutebrowser.utils.message as message
|
||||
from qutebrowser.commands.exceptions import (ArgumentCountError,
|
||||
NoSuchCommandError, InvalidModeError)
|
||||
from qutebrowser.commands.exceptions import (
|
||||
ArgumentCountError, NoSuchCommandError, InvalidModeError)
|
||||
|
||||
|
||||
def split_cmdline(text):
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
"""KeyChainParser for "hint" mode."""
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, Qt
|
||||
from PyQt5.QtCore import pyqtSignal
|
||||
|
||||
from qutebrowser.keyinput.keyparser import CommandKeyParser
|
||||
|
||||
|
@ -108,6 +108,57 @@ class ModeManager(QObject):
|
||||
return None
|
||||
return self._mode_stack[-1]
|
||||
|
||||
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.
|
||||
"""
|
||||
handler = self._handlers[self.mode]
|
||||
logging.debug("KeyPress, calling handler {}".format(handler))
|
||||
self.key_pressed.emit(event)
|
||||
handled = handler(event) if handler is not None else False
|
||||
|
||||
if handled:
|
||||
filter_this = True
|
||||
elif self.mode in self.passthrough or self._forward_unbound_keys:
|
||||
filter_this = False
|
||||
else:
|
||||
filter_this = True
|
||||
|
||||
if not filter_this:
|
||||
self._releaseevents_to_pass.append(event)
|
||||
|
||||
logging.debug("handled: {}, forward_unbound_keys: {}, passthrough: {} "
|
||||
"--> filter: {}".format(handled,
|
||||
self._forward_unbound_keys,
|
||||
self.mode in self.passthrough,
|
||||
filter_this))
|
||||
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
|
||||
logging.debug("KeyRelease --> filter: {}".format(filter_this))
|
||||
return filter_this
|
||||
|
||||
def register(self, mode, handler, passthrough=False):
|
||||
"""Register a new mode.
|
||||
|
||||
@ -161,6 +212,7 @@ class ModeManager(QObject):
|
||||
@cmdutils.register(instance='modeman', name='leave_mode',
|
||||
not_modes=['normal'], hide=True)
|
||||
def leave_current_mode(self):
|
||||
"""Leave the mode we're currently in."""
|
||||
if self.mode == "normal":
|
||||
raise ValueError("Can't leave normal mode!")
|
||||
self.leave(self.mode)
|
||||
@ -172,18 +224,24 @@ class ModeManager(QObject):
|
||||
self._forward_unbound_keys = config.get('general',
|
||||
'forward_unbound_keys')
|
||||
|
||||
def eventFilter(self, obj, evt):
|
||||
def eventFilter(self, obj, event):
|
||||
"""Filter all events based on the currently set mode.
|
||||
|
||||
Also calls the real keypress handler.
|
||||
|
||||
Args:
|
||||
event: The KeyPress to examine.
|
||||
|
||||
Return:
|
||||
True if event should be filtered, False otherwise.
|
||||
|
||||
Emit:
|
||||
key_pressed: When a key was actually pressed.
|
||||
"""
|
||||
if self.mode is None:
|
||||
# We got events before mode is set, so just pass them through.
|
||||
return False
|
||||
typ = evt.type()
|
||||
typ = event.type()
|
||||
if typ not in [QEvent.KeyPress, QEvent.KeyRelease]:
|
||||
# We're not interested in non-key-events so we pass them through.
|
||||
return False
|
||||
@ -197,35 +255,7 @@ class ModeManager(QObject):
|
||||
logging.debug("Got event {} for {} in mode {}".format(
|
||||
debug.EVENTS[typ], obj.__class__.__name__, self.mode))
|
||||
|
||||
handler = self._handlers[self.mode]
|
||||
|
||||
if typ == QEvent.KeyPress:
|
||||
logging.debug("KeyPress, calling handler {}".format(handler))
|
||||
self.key_pressed.emit(evt)
|
||||
handled = handler(evt) if handler is not None else False
|
||||
|
||||
if handled:
|
||||
filter_this = True
|
||||
elif self.mode in self.passthrough or self._forward_unbound_keys:
|
||||
filter_this = False
|
||||
else:
|
||||
filter_this = True
|
||||
|
||||
if not filter_this:
|
||||
self._releaseevents_to_pass.append(evt)
|
||||
|
||||
logging.debug("handled: {}, forward_unbound_keys: {}, "
|
||||
"passthrough: {} --> filter: {}".format(
|
||||
handled, self._forward_unbound_keys,
|
||||
self.mode in self.passthrough, filter_this))
|
||||
return self._eventFilter_keypress(event)
|
||||
else:
|
||||
# KeyRelease, handle like matching KeyPress
|
||||
if evt in self._releaseevents_to_pass:
|
||||
# remove all occurences
|
||||
self._releaseevents_to_pass = [e for e in
|
||||
self._releaseevents_to_pass if e != evt]
|
||||
filter_this = False
|
||||
else:
|
||||
filter_this = True
|
||||
logging.debug("KeyRelease --> filter: {}".format(filter_this))
|
||||
return filter_this
|
||||
return self._eventFilter_keyrelease(event)
|
||||
|
@ -21,8 +21,6 @@ Module attributes:
|
||||
STARTCHARS: Possible chars for starting a commandline input.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
import qutebrowser.utils.message as message
|
||||
from qutebrowser.keyinput.keyparser import CommandKeyParser
|
||||
|
||||
@ -31,6 +29,8 @@ STARTCHARS = ":/?"
|
||||
|
||||
class NormalKeyParser(CommandKeyParser):
|
||||
|
||||
"""KeyParser for normalmode with added STARTCHARS detection."""
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent, supports_count=True, supports_chains=True)
|
||||
self.read_config('keybind')
|
||||
|
@ -19,9 +19,8 @@
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, pyqtProperty, Qt
|
||||
from PyQt5.QtWidgets import (QWidget, QLineEdit, QProgressBar, QLabel,
|
||||
QHBoxLayout, QStackedLayout, QSizePolicy,
|
||||
QShortcut)
|
||||
from PyQt5.QtGui import QPainter, QKeySequence, QValidator
|
||||
QHBoxLayout, QStackedLayout, QSizePolicy)
|
||||
from PyQt5.QtGui import QPainter, QValidator
|
||||
|
||||
import qutebrowser.keyinput.modes as modes
|
||||
import qutebrowser.commands.utils as cmdutils
|
||||
|
@ -345,7 +345,7 @@ class TabbedBrowser(TabWidget):
|
||||
|
||||
@pyqtSlot(str)
|
||||
def on_mode_left(self, mode):
|
||||
"""Focus tabs if command mode was left."""
|
||||
"""Give focus to tabs if command mode was left."""
|
||||
if mode == "command":
|
||||
self.setFocus()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user