Skip to content

Commit

Permalink
Move UrlText's enable/disable logic to separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
pylbrecht committed Jul 3, 2024
1 parent ef9b3aa commit 857ff9e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
6 changes: 3 additions & 3 deletions qutebrowser/mainwindow/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,14 +528,14 @@ def _connect_signals(self):
self.status.tabindex.on_tab_index_changed)

self.tabbed_browser.cur_url_changed.connect(
self.status.url.set_url)
self.status.url.widget.set_url)
self.tabbed_browser.cur_url_changed.connect(functools.partial(
self.status.backforward.widget.on_tab_cur_url_changed,
tabs=self.tabbed_browser))
self.tabbed_browser.cur_link_hovered.connect(
self.status.url.set_hover_url)
self.status.url.widget.set_hover_url)
self.tabbed_browser.cur_load_status_changed.connect(
self.status.url.on_load_status_changed)
self.status.url.widget.on_load_status_changed)

self.tabbed_browser.cur_search_match_changed.connect(
self.status.search_match.set_match)
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 @@ -181,7 +181,7 @@ def __init__(self, *, win_id, private, parent=None):

self.search_match = searchmatch.SearchMatch()

self.url = url.UrlText()
self.url = url.UrlText(widget=url.UrlTextWidget())
self.percentage = percentage.Percentage()
self.backforward = backforward.Backforward(widget=backforward.BackforwardWidget())
self.tabindex = tabindex.TabIndex()
Expand Down Expand Up @@ -268,7 +268,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, self.percentage,
for widget in [self.url.widget, self.percentage,
self.backforward.widget, self.tabindex,
self.keystring, self.prog, self.clock, *self._text_widgets]:
assert isinstance(widget, QWidget)
Expand Down Expand Up @@ -416,7 +416,7 @@ def on_mode_left(self, old_mode, new_mode):
@pyqtSlot(browsertab.AbstractTab)
def on_tab_changed(self, tab):
"""Notify sub-widgets when the tab has been changed."""
self.url.on_tab_changed(tab)
self.url.widget.on_tab_changed(tab)
self.prog.on_tab_changed(tab)
self.percentage.on_tab_changed(tab)
self.backforward.widget.on_tab_changed(tab)
Expand Down
14 changes: 13 additions & 1 deletion qutebrowser/mainwindow/statusbar/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import enum

from qutebrowser.qt.core import pyqtSlot, pyqtProperty, QUrl
from qutebrowser.qt.widgets import QWidget

from qutebrowser.mainwindow.statusbar import textbase
from qutebrowser.config import stylesheet
Expand All @@ -28,7 +29,7 @@ class UrlType(enum.Enum):
normal = enum.auto()


class UrlText(textbase.TextBase):
class UrlTextWidget(textbase.TextBase):

"""URL displayed in the statusbar.
Expand Down Expand Up @@ -169,3 +170,14 @@ def on_tab_changed(self, tab):
self._normal_url = ''
self.on_load_status_changed(tab.load_status())
self._update_url()


class UrlText:

Check warning on line 175 in qutebrowser/mainwindow/statusbar/url.py

View workflow job for this annotation

GitHub Actions / linters (pylint)

Missing class docstring

Check warning on line 175 in qutebrowser/mainwindow/statusbar/url.py

View workflow job for this annotation

GitHub Actions / linters (flake8)

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

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

def disable(self):
self.widget.hide()
2 changes: 1 addition & 1 deletion tests/unit/mainwindow/statusbar/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@pytest.fixture
def url_widget(qtbot, monkeypatch, config_stub):
"""Fixture providing a Url widget."""
widget = url.UrlText()
widget = url.UrlTextWidget()
qtbot.add_widget(widget)
assert not widget.isVisible()
return widget
Expand Down

0 comments on commit 857ff9e

Please sign in to comment.