summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2023-06-09 14:19:38 +0200
committerFlorian Bruhin <me@the-compiler.org>2023-06-09 14:19:38 +0200
commit0fe03ae475441c7f9579f924e03df52e53fea943 (patch)
tree7360668dbdba218eb4d1e495cd96d89455ead0f9
parent2c61ec38b81c0022e448f18c643df0335e27388c (diff)
downloadqutebrowser-0fe03ae475441c7f9579f924e03df52e53fea943.tar.gz
qutebrowser-0fe03ae475441c7f9579f924e03df52e53fea943.zip
Inline misc.MinimalLineEdit into statusbar.command.Command
Ever since 33088588d959b903a9c088a13d5bfad7862c72a5, misc.MinimalLineEdit is only used in statusbar.command.Command. Having it separated into a mixin makes a lot of things more complicated, and also needs pylint ignores and a hand-written superclass __init__. This commit inlines it into statusbar.command.Command, which makes everything a lot simpler. It also avoids triggering a segfault in Python 3.12.0b2: https://github.com/qutebrowser/qutebrowser/issues/7727#issuecomment-1583144545 https://www.riverbankcomputing.com/pipermail/pyqt/2023-June/045325.html
-rw-r--r--qutebrowser/mainwindow/statusbar/command.py30
-rw-r--r--qutebrowser/misc/miscwidgets.py35
2 files changed, 24 insertions, 41 deletions
diff --git a/qutebrowser/mainwindow/statusbar/command.py b/qutebrowser/mainwindow/statusbar/command.py
index df85d0dfa..925ade795 100644
--- a/qutebrowser/mainwindow/statusbar/command.py
+++ b/qutebrowser/mainwindow/statusbar/command.py
@@ -33,7 +33,7 @@ from qutebrowser.utils import usertypes, log, objreg, message, utils
from qutebrowser.config import config
-class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
+class Command(misc.CommandLineEdit):
"""The commandline part of the statusbar.
@@ -63,8 +63,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
def __init__(self, *, win_id: int,
private: bool,
parent: QWidget = None) -> None:
- misc.CommandLineEdit.__init__(self, parent=parent)
- misc.MinimalLineEditMixin.__init__(self)
+ super().__init__(parent)
self._win_id = win_id
if not private:
command_history = objreg.get('command-history')
@@ -77,6 +76,17 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
self.textChanged.connect(self.updateGeometry)
self.textChanged.connect(self._incremental_search)
+ self.setStyleSheet(
+ """
+ QLineEdit {
+ border: 0px;
+ padding-left: 1px;
+ background-color: transparent;
+ }
+ """
+ )
+ self.setAttribute(Qt.WidgetAttribute.WA_MacShowFocusRect, False)
+
def _handle_search(self) -> bool:
"""Check if the currently entered text is a search, and if so, run it.
@@ -253,7 +263,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
super().setText(text)
def keyPressEvent(self, e: QKeyEvent) -> None:
- """Override keyPressEvent to ignore Return key presses.
+ """Override keyPressEvent to ignore Return key presses, and add Shift-Ins.
If this widget is focused, we are in passthrough key mode, and
Enter/Shift+Enter/etc. will cause QLineEdit to think it's finished
@@ -264,10 +274,16 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
e.accept()
modeman.leave(self._win_id, usertypes.KeyMode.command,
'prefix deleted')
- return
- if e.key() == Qt.Key.Key_Return:
+ elif e.key() == Qt.Key.Key_Return:
e.ignore()
- return
+ elif e.key() == Qt.Key.Key_Insert and e.modifiers() == Qt.KeyboardModifier.ShiftModifier:
+ try:
+ text = utils.get_clipboard(selection=True, fallback=True)
+ except utils.ClipboardError:
+ e.ignore()
+ else:
+ e.accept()
+ self.insert(text)
else:
super().keyPressEvent(e)
diff --git a/qutebrowser/misc/miscwidgets.py b/qutebrowser/misc/miscwidgets.py
index 5d56f7fcf..82d5ac5a5 100644
--- a/qutebrowser/misc/miscwidgets.py
+++ b/qutebrowser/misc/miscwidgets.py
@@ -33,39 +33,6 @@ from qutebrowser.browser import inspector
from qutebrowser.keyinput import keyutils, modeman
-class MinimalLineEditMixin:
-
- """A mixin to give a QLineEdit a minimal look and nicer repr()."""
-
- def __init__(self):
- self.setStyleSheet( # type: ignore[attr-defined]
- """
- QLineEdit {
- border: 0px;
- padding-left: 1px;
- background-color: transparent;
- }
- """
- )
- self.setAttribute( # type: ignore[attr-defined]
- Qt.WidgetAttribute.WA_MacShowFocusRect, False)
-
- def keyPressEvent(self, e):
- """Override keyPressEvent to paste primary selection on Shift + Ins."""
- if e.key() == Qt.Key.Key_Insert and e.modifiers() == Qt.KeyboardModifier.ShiftModifier:
- try:
- text = utils.get_clipboard(selection=True, fallback=True)
- except utils.ClipboardError:
- e.ignore()
- else:
- e.accept()
- self.insert(text) # type: ignore[attr-defined]
- return
- super().keyPressEvent(e) # type: ignore[misc]
-
- def __repr__(self):
- return utils.get_repr(self)
-
class CommandLineEdit(QLineEdit):
@@ -77,7 +44,7 @@ class CommandLineEdit(QLineEdit):
_promptlen: The length of the current prompt.
"""
- def __init__(self, *, parent=None):
+ def __init__(self, parent=None):
super().__init__(parent)
self.history = cmdhistory.History(parent=self)
self._validator = _CommandValidator(self)