Merge 1d711d2347 into 7e3df43463
This commit is contained in:
commit
de55184b20
|
|
@ -2203,6 +2203,7 @@ statusbar.widgets:
|
|||
- tabs: "Current active tab, e.g. `2`."
|
||||
- keypress: "Display pressed keys when composing a vi command."
|
||||
- progress: "Progress bar for the current page loading."
|
||||
- progress_ascii: "ASCII Progress bar for the current page loading."
|
||||
- 'text:foo': "Display the static text after the colon, `foo` in the example."
|
||||
- clock: "Display current time. The format can be changed by adding a
|
||||
format string via `clock:...`. For supported format strings, see
|
||||
|
|
|
|||
|
|
@ -523,6 +523,11 @@ class MainWindow(QWidget):
|
|||
self.tabbed_browser.cur_load_started.connect(
|
||||
self.status.prog.on_load_started)
|
||||
|
||||
self.tabbed_browser.cur_progress.connect(
|
||||
self.status.prog_ascii.on_load_progress)
|
||||
self.tabbed_browser.cur_load_started.connect(
|
||||
self.status.prog_ascii.on_load_started)
|
||||
|
||||
self.tabbed_browser.cur_scroll_perc_changed.connect(
|
||||
self.status.percentage.set_perc)
|
||||
self.tabbed_browser.widget.tab_index_changed.connect(
|
||||
|
|
|
|||
|
|
@ -15,8 +15,9 @@ from qutebrowser.config import config, stylesheet
|
|||
from qutebrowser.keyinput import modeman
|
||||
from qutebrowser.utils import usertypes, log, objreg, utils
|
||||
from qutebrowser.mainwindow.statusbar import (backforward, command, progress,
|
||||
keystring, percentage, url,
|
||||
tabindex, textbase, clock, searchmatch)
|
||||
progress_ascii, keystring, percentage,
|
||||
url, tabindex, textbase, clock,
|
||||
searchmatch)
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
|
|
@ -127,6 +128,7 @@ class StatusBar(QWidget):
|
|||
percentage: The Percentage widget in the statusbar.
|
||||
url: The UrlText widget in the statusbar.
|
||||
prog: The Progress widget in the statusbar.
|
||||
prog_ascii: The ASCII Progress widget in the statusbar.
|
||||
cmd: The Command widget in the statusbar.
|
||||
search_match: The SearchMatch widget in the statusbar.
|
||||
_hbox: The main QHBoxLayout.
|
||||
|
|
@ -189,6 +191,7 @@ class StatusBar(QWidget):
|
|||
self.tabindex = tabindex.TabIndex()
|
||||
self.keystring = keystring.KeyString()
|
||||
self.prog = progress.Progress(self)
|
||||
self.prog_ascii = progress_ascii.Progress(self)
|
||||
self.clock = clock.Clock()
|
||||
self._text_widgets = []
|
||||
self._draw_widgets()
|
||||
|
|
@ -215,6 +218,8 @@ class StatusBar(QWidget):
|
|||
return self.keystring
|
||||
elif key == 'progress':
|
||||
return self.prog
|
||||
elif key == 'progress_ascii':
|
||||
return self.prog_ascii
|
||||
elif key == 'search_match':
|
||||
return self.search_match
|
||||
elif key.startswith('text:'):
|
||||
|
|
@ -248,7 +253,7 @@ class StatusBar(QWidget):
|
|||
|
||||
if segment == 'scroll_raw':
|
||||
widget.set_raw()
|
||||
elif segment in ('history', 'progress'):
|
||||
elif segment in ('history', 'progress', 'progress_ascii'):
|
||||
widget.enabled = True
|
||||
if tab:
|
||||
widget.on_tab_changed(tab)
|
||||
|
|
@ -272,9 +277,10 @@ class StatusBar(QWidget):
|
|||
# Start with widgets hidden and show them when needed
|
||||
for widget in [self.url, self.percentage,
|
||||
self.backforward, self.tabindex,
|
||||
self.keystring, self.prog, self.clock, *self._text_widgets]:
|
||||
self.keystring, self.prog, self.prog_ascii,
|
||||
self.clock, *self._text_widgets]:
|
||||
assert isinstance(widget, QWidget)
|
||||
if widget in [self.prog, self.backforward]:
|
||||
if widget in [self.prog, self.backforward, self.prog_ascii]:
|
||||
widget.enabled = False # type: ignore[attr-defined]
|
||||
widget.hide()
|
||||
self._hbox.removeWidget(widget)
|
||||
|
|
@ -421,6 +427,7 @@ class StatusBar(QWidget):
|
|||
"""Notify sub-widgets when the tab has been changed."""
|
||||
self.url.on_tab_changed(tab)
|
||||
self.prog.on_tab_changed(tab)
|
||||
self.prog_ascii.on_tab_changed(tab)
|
||||
self.percentage.on_tab_changed(tab)
|
||||
self.backforward.on_tab_changed(tab)
|
||||
self.maybe_hide()
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class Progress(QProgressBar):
|
|||
|
||||
@pyqtSlot()
|
||||
def on_load_started(self):
|
||||
"""Clear old error and show progress, used as slot to loadStarted."""
|
||||
"""Reset the value, and show the bar if enabled. Used as slot to loadStarted."""
|
||||
self.setValue(0)
|
||||
self.setVisible(self.enabled)
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,93 @@
|
|||
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||
|
||||
# Copyright 2014-2021 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
"""The progress bar in the statusbar."""
|
||||
|
||||
from PyQt5.QtCore import pyqtSlot, QSize
|
||||
from PyQt5.QtWidgets import QLabel, QSizePolicy
|
||||
|
||||
from qutebrowser.config import stylesheet
|
||||
from qutebrowser.utils import utils, usertypes
|
||||
|
||||
|
||||
class Progress(QLabel):
|
||||
|
||||
"""The ascii progress bar part of the status bar."""
|
||||
|
||||
STYLESHEET = """
|
||||
QLabel {
|
||||
font: {{ conf.fonts.statusbar }};
|
||||
}
|
||||
"""
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
stylesheet.set_register(self)
|
||||
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
|
||||
self.enabled = False
|
||||
self.chunks = 10
|
||||
self.value = 0
|
||||
self.update_bar(self.value)
|
||||
self.hide()
|
||||
|
||||
def __repr__(self):
|
||||
return utils.get_repr(self, value=self.value)
|
||||
|
||||
def update_bar(self, val: int) -> None:
|
||||
"""Update the value of the progress bar."""
|
||||
self.value = val
|
||||
c = self.value//self.chunks
|
||||
bar = f"{'=' * (c - 1)}{'>' * (c > 0)}{' '*(self.chunks - c)}"
|
||||
self.setText(f"[{bar}]")
|
||||
|
||||
@pyqtSlot()
|
||||
def on_load_started(self):
|
||||
"""Reset the value, and show the bar if enabled. Used as slot to loadStarted."""
|
||||
self.update_bar(0)
|
||||
self.setVisible(self.enabled)
|
||||
|
||||
@pyqtSlot(int)
|
||||
def on_load_progress(self, value: int) -> None:
|
||||
"""Hide the statusbar when loading finished.
|
||||
|
||||
We use this instead of loadFinished because we sometimes get
|
||||
loadStarted and loadProgress(100) without loadFinished from Qt.
|
||||
|
||||
WORKAROUND for https://bugreports.qt.io/browse/QTBUG-65223
|
||||
"""
|
||||
self.update_bar(value)
|
||||
if value == 100:
|
||||
self.hide()
|
||||
|
||||
def on_tab_changed(self, tab):
|
||||
"""Set the correct value when the current tab changed."""
|
||||
self.update_bar(tab.progress())
|
||||
if self.enabled and tab.load_status() == usertypes.LoadStatus.loading:
|
||||
self.show()
|
||||
else:
|
||||
self.hide()
|
||||
|
||||
def sizeHint(self):
|
||||
"""Set the height to the text height."""
|
||||
width = super().sizeHint().width()
|
||||
height = self.fontMetrics().height()
|
||||
return QSize(width, height)
|
||||
|
||||
def minimumSizeHint(self):
|
||||
return self.sizeHint()
|
||||
Loading…
Reference in New Issue