diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index 5fdf48924f3..f16b7acd36f 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -523,7 +523,7 @@ def _connect_signals(self): self.status.prog.on_load_started) self.tabbed_browser.cur_scroll_perc_changed.connect( - self.status.percentage.widget.set_perc) + self.status.percentage.set_perc) self.tabbed_browser.widget.tab_index_changed.connect( self.status.tabindex.on_tab_index_changed) diff --git a/qutebrowser/mainwindow/statusbar/bar.py b/qutebrowser/mainwindow/statusbar/bar.py index f11b82e461b..0acf5696f30 100644 --- a/qutebrowser/mainwindow/statusbar/bar.py +++ b/qutebrowser/mainwindow/statusbar/bar.py @@ -411,7 +411,7 @@ def on_tab_changed(self, tab): """Notify sub-widgets when the tab has been changed.""" self.url.widget.on_tab_changed(tab) self.prog.on_tab_changed(tab) - self.percentage.widget.on_tab_changed(tab) + self.percentage.on_tab_changed(tab) self.backforward.on_tab_changed(tab) self.maybe_hide() assert tab.is_private == self._color_flags.private diff --git a/qutebrowser/mainwindow/statusbar/percentage.py b/qutebrowser/mainwindow/statusbar/percentage.py index eb699b1600a..531cc04018c 100644 --- a/qutebrowser/mainwindow/statusbar/percentage.py +++ b/qutebrowser/mainwindow/statusbar/percentage.py @@ -5,7 +5,7 @@ """Scroll percentage displayed in the statusbar.""" from qutebrowser.mainwindow.statusbar.item import StatusBarItem -from qutebrowser.qt.core import pyqtSlot, Qt +from qutebrowser.qt.core import Qt from qutebrowser.mainwindow.statusbar import textbase from qutebrowser.misc import throttle @@ -17,23 +17,20 @@ class PercentageWidget(textbase.TextBaseWidget): """Reading percentage displayed in the statusbar.""" def __init__(self, parent=None): - """Constructor. Set percentage to 0%.""" super().__init__(parent, elidemode=Qt.TextElideMode.ElideNone) + + +class Percentage(StatusBarItem): + def __init__(self, widget: PercentageWidget): + """Constructor. Set percentage to 0%.""" + super().__init__(widget) self._strings = self._calc_strings() - self._set_text = throttle.Throttle(self.setText, 100, parent=self) + self._set_text = throttle.Throttle(self.widget.setText, 100, parent=self.widget) self.set_perc(0, 0) def set_raw(self): self._strings = self._calc_strings(raw=True) - def _calc_strings(self, raw=False): - """Pre-calculate strings for the statusbar.""" - fmt = '[{:02}]' if raw else '[{:02}%]' - strings = {i: fmt.format(i) for i in range(1, 100)} - strings.update({0: '[top]', 100: '[bot]'}) - return strings - - @pyqtSlot(int, int) def set_perc(self, x, y): """Setter to be used as a Qt slot. @@ -48,7 +45,9 @@ def on_tab_changed(self, tab): """Update scroll position when tab changed.""" self.set_perc(*tab.scroller.pos_perc()) - -class Percentage(StatusBarItem): - def set_raw(self): - self.widget.set_raw() + def _calc_strings(self, raw=False): + """Pre-calculate strings for the statusbar.""" + fmt = '[{:02}]' if raw else '[{:02}%]' + strings = {i: fmt.format(i) for i in range(1, 100)} + strings.update({0: '[top]', 100: '[bot]'}) + return strings diff --git a/tests/unit/mainwindow/statusbar/test_percentage.py b/tests/unit/mainwindow/statusbar/test_percentage.py index 0532f75cac6..59326f3170c 100644 --- a/tests/unit/mainwindow/statusbar/test_percentage.py +++ b/tests/unit/mainwindow/statusbar/test_percentage.py @@ -6,16 +6,16 @@ import pytest -from qutebrowser.mainwindow.statusbar.percentage import PercentageWidget +from qutebrowser.mainwindow.statusbar.percentage import Percentage, PercentageWidget @pytest.fixture def percentage(qtbot): """Fixture providing a Percentage widget.""" - widget = PercentageWidget() + widget = Percentage(widget=PercentageWidget()) # Force immediate update of percentage widget widget._set_text.set_delay(-1) - qtbot.add_widget(widget) + qtbot.add_widget(widget.widget) return widget @@ -44,7 +44,7 @@ def test_percentage_text(percentage, y, raw, expected): if raw: percentage.set_raw() percentage.set_perc(x=None, y=y) - assert percentage.text() == expected + assert percentage.widget.text() == expected def test_tab_change(percentage, fake_web_tab): @@ -52,4 +52,4 @@ def test_tab_change(percentage, fake_web_tab): percentage.set_perc(x=None, y=10) tab = fake_web_tab(scroll_pos_perc=(0, 20)) percentage.on_tab_changed(tab) - assert percentage.text() == '[20%]' + assert percentage.widget.text() == '[20%]'