Coverage for qutebrowser/misc/miscwidgets.py : 67%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014-2018 Florian Bruhin (The Compiler) <mail@qutebrowser.org> # # 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/>.
QStyleOption, QStyle, QLayout, QApplication)
"""A mixin to give a QLineEdit a minimal look and nicer repr()."""
self.setStyleSheet(""" QLineEdit { border: 0px; padding-left: 1px; background-color: transparent; } """) self.setAttribute(Qt.WA_MacShowFocusRect, False)
"""Override keyPressEvent to paste primary selection on Shift + Ins.""" if e.key() == Qt.Key_Insert and e.modifiers() == Qt.ShiftModifier: try: text = utils.get_clipboard(selection=True, fallback=True) except utils.ClipboardError: e.ignore() else: e.accept() self.insert(text) return super().keyPressEvent(e)
def __repr__(self): return utils.get_repr(self)
"""A QLineEdit with a history and prompt chars.
Attributes: history: The command history object. _validator: The current command validator. _promptlen: The length of the current prompt. """
def __repr__(self): return utils.get_repr(self, text=self.text())
def on_text_edited(self, _text): """Slot for textEdited. Stop history browsing."""
def __on_cursor_position_changed(self, _old, new): """Prevent the cursor moving to the prompt.
We use __ here to avoid accidentally overriding it in subclasses. """
"""Set the current prompt to text.
This updates the validator, and makes sure the user can't move the cursor behind the prompt. """
"""Override home so it works properly with our cursor restriction."""
"""Validator to prevent the : from getting deleted.
Attributes: prompt: The current prompt. """
"""Override QValidator::validate.
Args: string: The string to validate. pos: The current cursor position.
Return: A tuple (status, string, pos) as a QValidator should. """ else:
"""A "fold" widget with an arrow to show/hide details.
Attributes: _folded: Whether the widget is currently folded or not. _hbox: The HBoxLayout the arrow/label are in. _arrow: The FoldArrow widget.
Signals: toggled: Emitted when the widget was folded/unfolded. arg 0: bool, if the contents are currently visible. """
super().__init__(parent) self._folded = True self._hbox = QHBoxLayout(self) self._hbox.setContentsMargins(0, 0, 0, 0) self._arrow = _FoldArrow() self._hbox.addWidget(self._arrow) label = QLabel(text) self._hbox.addWidget(label) self._hbox.addStretch()
"""Toggle the fold of the widget.""" self._folded = not self._folded self._arrow.fold(self._folded) self.toggled.emit(not self._folded)
"""Toggle the fold if the widget was pressed.
Args: e: The QMouseEvent. """ if e.button() == Qt.LeftButton: e.accept() self.toggle() else: super().mousePressEvent(e)
"""The arrow shown for the DetailFold widget.
Attributes: _folded: Whether the widget is currently folded or not. """
super().__init__(parent) self._folded = True
"""Fold/unfold the widget.
Args: folded: The new desired state. """ self._folded = folded self.update()
"""Paint the arrow.
Args: _paint: The QPaintEvent (unused). """ opt = QStyleOption() opt.initFrom(self) painter = QPainter(self) if self._folded: elem = QStyle.PE_IndicatorArrowRight else: elem = QStyle.PE_IndicatorArrowDown self.style().drawPrimitive(elem, opt, painter, self)
"""Return a sensible size.""" return QSize(8, 8)
"""A Qt layout which simply wraps a single widget.
This is used so the widget is hidden behind a defined API and can't easily be accidentally accessed. """
raise utils.Unreachable
raise utils.Unreachable
"""Wrap the given widget in the given container.""" objects.backend == usertypes.Backend.QtWebEngine and container.window() and container.window().windowHandle() and not container.window().windowHandle().isActive()): log.misc.debug("Calling QApplication::sync...") # WORKAROUND for: # https://bugreports.qt.io/browse/QTBUG-56652 # https://codereview.qt-project.org/#/c/176113/5//ALL,unified QApplication.sync()
"""A label telling the user this page is now fullscreen."""
background-color: rgba(50, 50, 50, 80%); color: white; border-radius: 20px; padding: 30px; """)
else:
geom = self.parentWidget().geometry() else:
"""Hide the widget after the given timeout."""
def _on_timeout(self): """Hide and delete the widget.""" |