From 0104490978f6ad42617ece83b001f55fd804267a Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 29 Nov 2018 19:44:48 +0100 Subject: [PATCH] Use enum values for load_status_changed --- qutebrowser/browser/browsertab.py | 4 ++-- qutebrowser/mainwindow/statusbar/url.py | 11 +++++------ qutebrowser/mainwindow/tabbedbrowser.py | 2 +- tests/unit/mainwindow/statusbar/test_url.py | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index 0625b218e..a53828af3 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -837,7 +837,7 @@ class AbstractTab(QWidget): load_finished = pyqtSignal(bool) icon_changed = pyqtSignal(QIcon) title_changed = pyqtSignal(str) - load_status_changed = pyqtSignal(str) + load_status_changed = pyqtSignal(usertypes.LoadStatus) new_tab_requested = pyqtSignal(QUrl) url_changed = pyqtSignal(QUrl) shutting_down = pyqtSignal() @@ -906,7 +906,7 @@ class AbstractTab(QWidget): raise TypeError("Type {} is no LoadStatus member!".format(val)) log.webview.debug("load status for {}: {}".format(repr(self), val)) self._load_status = val - self.load_status_changed.emit(val.name) + self.load_status_changed.emit(val) def send_event(self, evt: QEvent) -> None: """Send the given event to the underlying widget. diff --git a/qutebrowser/mainwindow/statusbar/url.py b/qutebrowser/mainwindow/statusbar/url.py index fda09d642..8ac258465 100644 --- a/qutebrowser/mainwindow/statusbar/url.py +++ b/qutebrowser/mainwindow/statusbar/url.py @@ -112,19 +112,18 @@ class UrlText(textbase.TextBase): self._urltype = UrlType.normal config.set_register_stylesheet(self, update=False) - @pyqtSlot(str) - def on_load_status_changed(self, status_str): + @pyqtSlot(usertypes.LoadStatus) + def on_load_status_changed(self, status): """Slot for load_status_changed. Sets URL color accordingly. Args: - status_str: The LoadStatus as string. + status: The usertypes.LoadStatus. """ - status = usertypes.LoadStatus[status_str] if status in [usertypes.LoadStatus.success, usertypes.LoadStatus.success_https, usertypes.LoadStatus.error, usertypes.LoadStatus.warn]: - self._normal_url_type = UrlType[status_str] + self._normal_url_type = UrlType[status.name] else: self._normal_url_type = UrlType.normal self._update_url() @@ -172,5 +171,5 @@ class UrlText(textbase.TextBase): self._normal_url = urlutils.safe_display_string(tab.url()) else: self._normal_url = '' - self.on_load_status_changed(tab.load_status().name) + self.on_load_status_changed(tab.load_status()) self._update_url() diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index d00d5d797..5530b0e37 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -102,7 +102,7 @@ class TabbedBrowser(QWidget): cur_url_changed = pyqtSignal(QUrl) cur_link_hovered = pyqtSignal(str) cur_scroll_perc_changed = pyqtSignal(int, int) - cur_load_status_changed = pyqtSignal(str) + cur_load_status_changed = pyqtSignal(usertypes.LoadStatus) cur_fullscreen_requested = pyqtSignal(bool) cur_caret_selection_toggled = pyqtSignal(bool) close_window = pyqtSignal() diff --git a/tests/unit/mainwindow/statusbar/test_url.py b/tests/unit/mainwindow/statusbar/test_url.py index bda51b504..801a71f0a 100644 --- a/tests/unit/mainwindow/statusbar/test_url.py +++ b/tests/unit/mainwindow/statusbar/test_url.py @@ -89,7 +89,7 @@ def test_set_url(url_widget, url_text, expected, which): def test_on_load_status_changed(url_widget, status, expected): """Test text when status is changed.""" url_widget.set_url(QUrl('www.example.com')) - url_widget.on_load_status_changed(status.name) + url_widget.on_load_status_changed(status) assert url_widget._urltype == expected @@ -139,7 +139,7 @@ def test_on_tab_changed(url_widget, fake_web_tab, load_status, qurl): ]) def test_normal_url(url_widget, qurl, load_status, expected_status): url_widget.set_url(qurl) - url_widget.on_load_status_changed(load_status.name) + url_widget.on_load_status_changed(load_status) url_widget.set_hover_url(qurl.toDisplayString()) url_widget.set_hover_url("") assert url_widget.text() == qurl.toDisplayString()