Skip to content

Commit

Permalink
Move Percentage's enable/disable logic to separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
pylbrecht committed Jul 6, 2024
1 parent 37cef07 commit 5a4254d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion qutebrowser/mainwindow/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def _connect_signals(self):
self.status.prog.widget.on_load_started)

self.tabbed_browser.cur_scroll_perc_changed.connect(
self.status.percentage.set_perc)
self.status.percentage.widget.set_perc)
self.tabbed_browser.widget.tab_index_changed.connect(
self.status.tabindex.on_tab_index_changed)

Expand Down
6 changes: 3 additions & 3 deletions qutebrowser/mainwindow/statusbar/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def __init__(self, *, win_id, private, parent=None):
self.search_match = searchmatch.SearchMatch()

self.url = url.UrlText(widget=url.UrlTextWidget())
self.percentage = percentage.Percentage()
self.percentage = percentage.Percentage(widget=percentage.PercentageWidget())
self.backforward = backforward.Backforward(widget=backforward.BackforwardWidget())
self.tabindex = tabindex.TabIndex()
self.keystring = keystring.KeyString()
Expand Down Expand Up @@ -275,7 +275,7 @@ def _draw_widgets(self):
def _clear_widgets(self):
"""Clear widgets before redrawing them."""
# Start with widgets hidden and show them when needed
for widget in [self.url.widget, self.percentage,
for widget in [self.url.widget, self.percentage.widget,
self.backforward.widget, self.tabindex,
self.keystring, self.prog.widget, self.clock, *self._text_widgets]:
assert isinstance(widget, QWidget)
Expand Down Expand Up @@ -425,7 +425,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.widget.on_tab_changed(tab)
self.percentage.on_tab_changed(tab)
self.percentage.widget.on_tab_changed(tab)
self.backforward.widget.on_tab_changed(tab)
self.maybe_hide()
assert tab.is_private == self._color_flags.private
Expand Down
14 changes: 13 additions & 1 deletion qutebrowser/mainwindow/statusbar/percentage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
"""Scroll percentage displayed in the statusbar."""

from qutebrowser.qt.core import pyqtSlot, Qt
from qutebrowser.qt.widgets import QWidget

Check warning on line 8 in qutebrowser/mainwindow/statusbar/percentage.py

View workflow job for this annotation

GitHub Actions / linters (pylint)

Unused QWidget imported from qutebrowser.qt.widgets

from qutebrowser.mainwindow.statusbar import textbase
from qutebrowser.misc import throttle
from qutebrowser.utils import utils


class Percentage(textbase.TextBase):
class PercentageWidget(textbase.TextBase):

"""Reading percentage displayed in the statusbar."""

Expand Down Expand Up @@ -46,3 +47,14 @@ def set_perc(self, x, y):
def on_tab_changed(self, tab):
"""Update scroll position when tab changed."""
self.set_perc(*tab.scroller.pos_perc())


class Percentage:

Check warning on line 52 in qutebrowser/mainwindow/statusbar/percentage.py

View workflow job for this annotation

GitHub Actions / linters (pylint)

Missing class docstring

Check warning on line 52 in qutebrowser/mainwindow/statusbar/percentage.py

View workflow job for this annotation

GitHub Actions / linters (flake8)

Missing docstring in public class
def __init__(self, widget: PercentageWidget):
self.widget = widget

def enable(self):
self.widget.show()

def disable(self):
self.widget.hide()
4 changes: 2 additions & 2 deletions tests/unit/mainwindow/statusbar/test_percentage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

import pytest

from qutebrowser.mainwindow.statusbar.percentage import Percentage
from qutebrowser.mainwindow.statusbar.percentage import PercentageWidget


@pytest.fixture
def percentage(qtbot):
"""Fixture providing a Percentage widget."""
widget = Percentage()
widget = PercentageWidget()
# Force immediate update of percentage widget
widget._set_text.set_delay(-1)
qtbot.add_widget(widget)
Expand Down

0 comments on commit 5a4254d

Please sign in to comment.