Simplify displaying text a lot.
This now only has one category of text, and displays it in a QStackedWidget with the Command.
This commit is contained in:
parent
ab87c8e8b9
commit
b03932400f
@ -107,7 +107,7 @@ class QuteBrowser(QApplication):
|
||||
self.setQuitOnLastWindowClosed(False)
|
||||
self.lastWindowClosed.connect(self.shutdown)
|
||||
self.mainwindow.tabs.keypress.connect(
|
||||
self.mainwindow.status.txt.clear_tmp)
|
||||
self.mainwindow.status.clear_tmp_text)
|
||||
self.mainwindow.tabs.keypress.connect(self.keyparser.handle)
|
||||
self.keyparser.set_cmd_text.connect(
|
||||
self.mainwindow.status.cmd.set_cmd_text)
|
||||
|
@ -72,8 +72,6 @@ class TabbedBrowser(TabWidget):
|
||||
cur_scroll_perc_changed: Scroll percentage of current tab changed.
|
||||
arg 1: x-position in %.
|
||||
arg 2: y-position in %.
|
||||
disp_tmp_msg: A temporary message should be shown in the statusbar.
|
||||
arg: The message to display as string.
|
||||
keypress: A key was pressed.
|
||||
arg: The QKeyEvent leading to the keypress.
|
||||
shutdown_complete: The shuttdown is completed.
|
||||
@ -92,7 +90,6 @@ class TabbedBrowser(TabWidget):
|
||||
cur_link_hovered = pyqtSignal(str, str, str)
|
||||
cur_scroll_perc_changed = pyqtSignal(int, int)
|
||||
set_cmd_text = pyqtSignal(str)
|
||||
disp_tmp_msg = pyqtSignal(str)
|
||||
keypress = pyqtSignal('QKeyEvent')
|
||||
shutdown_complete = pyqtSignal()
|
||||
quit = pyqtSignal()
|
||||
@ -516,7 +513,7 @@ class TabbedBrowser(TabWidget):
|
||||
url = urlutils.urlstring(self.currentWidget().url())
|
||||
mode = QClipboard.Selection if sel else QClipboard.Clipboard
|
||||
clip.setText(url, mode)
|
||||
self.disp_tmp_msg.emit('URL yanked to {}'.format(
|
||||
self.cur_statusbar_message.emit('URL yanked to {}'.format(
|
||||
'primary selection' if sel else 'clipboard'))
|
||||
|
||||
def cur_yank_title(self, sel=False):
|
||||
@ -535,7 +532,7 @@ class TabbedBrowser(TabWidget):
|
||||
title = self.tabText(self.currentIndex())
|
||||
mode = QClipboard.Selection if sel else QClipboard.Clipboard
|
||||
clip.setText(title, mode)
|
||||
self.disp_tmp_msg.emit('Title yanked to {}'.format(
|
||||
self.cur_statusbar_message.emit('Title yanked to {}'.format(
|
||||
'primary selection' if sel else 'clipboard'))
|
||||
|
||||
def switch_prev(self, count=1):
|
||||
|
@ -74,7 +74,6 @@ class MainWindow(QWidget):
|
||||
|
||||
self.status.resized.connect(self.completion.resize_to_bar)
|
||||
self.status.moved.connect(self.completion.move_to_bar)
|
||||
self.tabs.disp_tmp_msg.connect(self.status.txt.disp_tmp)
|
||||
self.tabs.resized.connect(self.completion.on_browser_resized)
|
||||
self.tabs.cur_progress.connect(self.status.prog.setValue)
|
||||
self.tabs.cur_load_finished.connect(lambda *args:
|
||||
@ -84,7 +83,7 @@ class MainWindow(QWidget):
|
||||
self.tabs.cur_load_started.connect(self.status.prog.on_load_started)
|
||||
self.tabs.cur_scroll_perc_changed.connect(
|
||||
self.status.percentage.set_perc)
|
||||
self.tabs.cur_statusbar_message.connect(self.status.txt.setText)
|
||||
self.tabs.cur_statusbar_message.connect(self.status.disp_tmp_text)
|
||||
self.tabs.cur_url_changed.connect(self.status.url.set_url)
|
||||
self.tabs.cur_link_hovered.connect(self.status.url.set_hover_url)
|
||||
self.status.cmd.esc_pressed.connect(self.tabs.setFocus)
|
||||
|
@ -21,7 +21,8 @@ import logging
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, pyqtProperty, Qt
|
||||
from PyQt5.QtWidgets import (QWidget, QLineEdit, QProgressBar, QLabel,
|
||||
QHBoxLayout, QSizePolicy, QShortcut)
|
||||
QHBoxLayout, QStackedLayout, QSizePolicy,
|
||||
QShortcut)
|
||||
from PyQt5.QtGui import QPainter, QKeySequence, QValidator
|
||||
|
||||
import qutebrowser.utils.config as config
|
||||
@ -41,6 +42,7 @@ class StatusBar(QWidget):
|
||||
url: The Url widget in the statusbar.
|
||||
prog: The Progress widget in the statusbar.
|
||||
_hbox: The main QHBoxLayout.
|
||||
_stack: The QStackedLayout with cmd/txt widgets.
|
||||
_error: If there currently is an error, accessed through the error
|
||||
property.
|
||||
_STYLESHEET: The stylesheet template.
|
||||
@ -87,11 +89,16 @@ class StatusBar(QWidget):
|
||||
self._hbox.setContentsMargins(0, 0, 0, 0)
|
||||
self._hbox.setSpacing(5)
|
||||
|
||||
self._stack = QStackedLayout()
|
||||
self._stack.setContentsMargins(0, 0, 0, 0)
|
||||
|
||||
self.cmd = _Command(self)
|
||||
self._hbox.addWidget(self.cmd)
|
||||
self._stack.addWidget(self.cmd)
|
||||
|
||||
self.txt = _Text(self)
|
||||
self._hbox.addWidget(self.txt)
|
||||
self._stack.addWidget(self.txt)
|
||||
|
||||
self._hbox.addLayout(self._stack)
|
||||
self._hbox.addStretch()
|
||||
|
||||
self.keystring = _KeyString(self)
|
||||
@ -106,6 +113,8 @@ class StatusBar(QWidget):
|
||||
self.prog = _Progress(self)
|
||||
self._hbox.addWidget(self.prog)
|
||||
|
||||
self.clear_tmp_text()
|
||||
|
||||
@pyqtProperty(bool)
|
||||
def error(self):
|
||||
"""Getter for self.error, so it can be used as Qt property."""
|
||||
@ -123,16 +132,44 @@ class StatusBar(QWidget):
|
||||
self._error = val
|
||||
self.setStyleSheet(config.get_stylesheet(self._STYLESHEET))
|
||||
|
||||
@pyqtSlot()
|
||||
def _show_tmp_text(self):
|
||||
"""Show temporary text instead of command widget."""
|
||||
self._stack.setCurrentWidget(self.txt)
|
||||
|
||||
@pyqtSlot()
|
||||
def _hide_tmp_text(self):
|
||||
"""Show command widget instead of temproary text."""
|
||||
self._stack.setCurrentWidget(self.cmd)
|
||||
|
||||
@pyqtSlot(str)
|
||||
def disp_error(self, text):
|
||||
"""Display an error in the statusbar."""
|
||||
self.error = True
|
||||
self.txt.error = text
|
||||
self.disp_tmp_text(text)
|
||||
|
||||
def clear_error(self):
|
||||
"""Clear a displayed error from the status bar."""
|
||||
self.error = False
|
||||
self.txt.error = ''
|
||||
|
||||
@pyqtSlot(str)
|
||||
def disp_tmp_text(self, txt):
|
||||
"""Display a temporary text.
|
||||
|
||||
Args:
|
||||
txt: The text to display, or an empty string to clear.
|
||||
|
||||
"""
|
||||
self.txt.setText(txt)
|
||||
if txt:
|
||||
self._show_tmp_text()
|
||||
else:
|
||||
self._hide_tmp_text()
|
||||
|
||||
@pyqtSlot()
|
||||
def clear_tmp_text(self):
|
||||
"""Clear a temporary text."""
|
||||
self.disp_tmp_text('')
|
||||
|
||||
def resizeEvent(self, e):
|
||||
"""Extend resizeEvent of QWidget to emit a resized signal afterwards.
|
||||
@ -347,16 +384,6 @@ class _Command(QLineEdit):
|
||||
self.hide_completion.emit()
|
||||
super().focusOutEvent(e)
|
||||
|
||||
def focusInEvent(self, e):
|
||||
"""Clear error message when the statusbar is focused.
|
||||
|
||||
Args:
|
||||
e: The QFocusEvent.
|
||||
|
||||
"""
|
||||
self._statusbar.clear_error()
|
||||
super().focusInEvent(e)
|
||||
|
||||
|
||||
class _CommandValidator(QValidator):
|
||||
|
||||
@ -475,60 +502,9 @@ class TextBase(QLabel):
|
||||
|
||||
class _Text(TextBase):
|
||||
|
||||
"""Text displayed in the statusbar.
|
||||
"""Text displayed in the statusbar."""
|
||||
|
||||
There are three types of texts which can be displayed:
|
||||
The current normal text displayed for a longer time,
|
||||
the current temporary text displayed until the next keystroke,
|
||||
the current error text displayed until statusbar is focused.
|
||||
|
||||
Attributes:
|
||||
normal: The text normally displayed, accessed via property normal.
|
||||
temporary: The temporary text, accessed via property temporary.
|
||||
error: The error text accessed via property error.
|
||||
_initialized: True when initialization is done, to avoid calling
|
||||
callback when still in __init__.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self._initialized = False
|
||||
self.normal = ''
|
||||
self.temporary = ''
|
||||
self.error = ''
|
||||
self._initialized = True
|
||||
self._update_text()
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
"""Override __setattr__ to call _update_text() if texts changed."""
|
||||
super().__setattr__(name, value)
|
||||
if name in ['normal', 'temporary', 'error'] and self._initialized:
|
||||
self._update_text()
|
||||
|
||||
def _update_text(self):
|
||||
"""Callback called when texts are updated. Display appropriate text."""
|
||||
for t in [self.error, self.temporary, self.normal]:
|
||||
if t:
|
||||
self.setText(t)
|
||||
break
|
||||
else:
|
||||
self.setText('')
|
||||
|
||||
@pyqtSlot(str)
|
||||
def disp_tmp(self, txt):
|
||||
"""Display a temporary text.
|
||||
|
||||
Args:
|
||||
txt: The text to display, or an empty string to clear.
|
||||
|
||||
"""
|
||||
self.temporary = txt
|
||||
|
||||
@pyqtSlot()
|
||||
def clear_tmp(self):
|
||||
"""Clear a temporary text."""
|
||||
self.temporary = ''
|
||||
pass
|
||||
|
||||
|
||||
class _KeyString(TextBase):
|
||||
|
Loading…
Reference in New Issue
Block a user