From a470bfc3f37cd15bd1acf3bbc077e9297a813492 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 11 Jul 2016 14:28:51 +0200 Subject: [PATCH] Get rid of url_text_changed signal Instead we simply use url_changed which (similar to Qt's urlChanged) simply has a QUrl argument. --- qutebrowser/browser/browsertab.py | 3 +- qutebrowser/browser/webengine/webenginetab.py | 2 +- qutebrowser/browser/webkit/webkittab.py | 2 +- qutebrowser/browser/webkit/webview.py | 4 --- qutebrowser/completion/models/miscmodels.py | 2 +- qutebrowser/mainwindow/mainwindow.py | 2 +- qutebrowser/mainwindow/statusbar/url.py | 8 ++--- qutebrowser/mainwindow/tabbedbrowser.py | 18 +++++----- tests/unit/mainwindow/statusbar/test_url.py | 35 ++++++++++++------- 9 files changed, 41 insertions(+), 35 deletions(-) diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index 96f4aa980..4515694b2 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -445,11 +445,10 @@ class AbstractTab(QWidget): load_progress = pyqtSignal(int) load_finished = pyqtSignal(bool) icon_changed = pyqtSignal(QIcon) - # FIXME:qtwebengine get rid of this altogether? - url_text_changed = pyqtSignal(str) title_changed = pyqtSignal(str) load_status_changed = pyqtSignal(str) new_tab_requested = pyqtSignal(QUrl) + url_changed = pyqtSignal(QUrl) shutting_down = pyqtSignal() def __init__(self, win_id, parent=None): diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index 3e331ee91..61ba16972 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -316,9 +316,9 @@ class WebEngineTab(browsertab.AbstractTab): page.loadProgress.connect(self._on_load_progress) page.loadStarted.connect(self._on_load_started) view.titleChanged.connect(self.title_changed) + view.urlChanged.connect(self.url_changed) page.loadFinished.connect(self._on_load_finished) page.certificate_error.connect(self._on_ssl_errors) # FIXME:qtwebengine stub this? # view.iconChanged.connect(self.icon_changed) # view.scroll.pos_changed.connect(self.scroll.perc_changed) - # view.url_text_changed.connect(self.url_text_changed) diff --git a/qutebrowser/browser/webkit/webkittab.py b/qutebrowser/browser/webkit/webkittab.py index 8edbb57bd..19c6f7836 100644 --- a/qutebrowser/browser/webkit/webkittab.py +++ b/qutebrowser/browser/webkit/webkittab.py @@ -520,7 +520,7 @@ class WebKitTab(browsertab.AbstractTab): frame.loadStarted.connect(self._on_load_started) view.scroll_pos_changed.connect(self.scroll.perc_changed) view.titleChanged.connect(self.title_changed) - view.url_text_changed.connect(self.url_text_changed) + view.urlChanged.connect(self.url_changed) view.shutting_down.connect(self.shutting_down) page.networkAccessManager().sslErrors.connect(self._on_ssl_errors) diff --git a/qutebrowser/browser/webkit/webview.py b/qutebrowser/browser/webkit/webview.py index faa3081c4..9b2da7353 100644 --- a/qutebrowser/browser/webkit/webview.py +++ b/qutebrowser/browser/webkit/webview.py @@ -56,7 +56,6 @@ class WebView(QWebView): arg 1: x-position in %. arg 2: y-position in %. linkHovered: QWebPages linkHovered signal exposed. - url_text_changed: Current URL string changed. mouse_wheel_zoom: Emitted when the page should be zoomed because the mousewheel was used with ctrl. arg 1: The angle delta of the wheel event (QPoint) @@ -65,7 +64,6 @@ class WebView(QWebView): scroll_pos_changed = pyqtSignal(int, int) linkHovered = pyqtSignal(str, str, str) - url_text_changed = pyqtSignal(str) shutting_down = pyqtSignal() mouse_wheel_zoom = pyqtSignal(QPoint) @@ -292,7 +290,6 @@ class WebView(QWebView): urlstr = url.toDisplayString() log.webview.debug("New title: {}".format(urlstr)) self.titleChanged.emit(urlstr) - self.url_text_changed.emit(url.toDisplayString()) self.load(url) if url.scheme() == 'qute': frame = self.page().mainFrame() @@ -318,7 +315,6 @@ class WebView(QWebView): If the URL is invalid, we just ignore it here. """ if url.isValid(): - self.url_text_changed.emit(url.toDisplayString()) if not self.title(): self.titleChanged.emit(self.url().toDisplayString()) diff --git a/qutebrowser/completion/models/miscmodels.py b/qutebrowser/completion/models/miscmodels.py index 8ef19b69f..d98da5b9b 100644 --- a/qutebrowser/completion/models/miscmodels.py +++ b/qutebrowser/completion/models/miscmodels.py @@ -183,7 +183,7 @@ class TabCompletionModel(base.BaseCompletionModel): window=win_id) for i in range(tabbed_browser.count()): tab = tabbed_browser.widget(i) - tab.url_text_changed.connect(self.rebuild) + tab.url_changed.connect(self.rebuild) tab.shutting_down.connect(self.delayed_rebuild) tabbed_browser.new_tab.connect(self.on_new_tab) objreg.get("app").new_window.connect(self.on_new_window) diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index e4539c44a..950375623 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -349,7 +349,7 @@ class MainWindow(QWidget): tabs.cur_load_started.connect(status.txt.on_load_started) tabs.current_tab_changed.connect(status.url.on_tab_changed) - tabs.cur_url_text_changed.connect(status.url.set_url) + tabs.cur_url_changed.connect(status.url.set_url) tabs.cur_link_hovered.connect(status.url.set_hover_url) tabs.cur_load_status_changed.connect(status.url.on_load_status_changed) diff --git a/qutebrowser/mainwindow/statusbar/url.py b/qutebrowser/mainwindow/statusbar/url.py index 2b5b52ed6..e4e1b4a3d 100644 --- a/qutebrowser/mainwindow/statusbar/url.py +++ b/qutebrowser/mainwindow/statusbar/url.py @@ -129,14 +129,14 @@ class UrlText(textbase.TextBase): self._normal_url_type = UrlType.normal self._update_url() - @pyqtSlot(str) - def set_url(self, s): + @pyqtSlot(QUrl) + def set_url(self, url): """Setter to be used as a Qt slot. Args: - s: The URL to set as string. + url: The URL to set as QUrl. """ - self._normal_url = s + self._normal_url = url.toDisplayString() self._normal_url_type = UrlType.normal self._update_url() diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 0cdaf8164..3418a635f 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -75,7 +75,7 @@ class TabbedBrowser(tabwidget.TabWidget): cur_load_finished: Current tab finished loading (load_finished) cur_statusbar_message: Current tab got a statusbar message (statusBarMessage) - cur_url_text_changed: Current URL text changed. + cur_url_changed: Current URL changed. cur_link_hovered: Link hovered in current tab (link_hovered) cur_scroll_perc_changed: Scroll percentage of current tab changed. arg 1: x-position in %. @@ -93,7 +93,7 @@ class TabbedBrowser(tabwidget.TabWidget): cur_load_started = pyqtSignal() cur_load_finished = pyqtSignal(bool) cur_statusbar_message = pyqtSignal(str) - cur_url_text_changed = pyqtSignal(str) + cur_url_changed = pyqtSignal(QUrl) cur_link_hovered = pyqtSignal(str) cur_scroll_perc_changed = pyqtSignal(int, int) cur_load_status_changed = pyqtSignal(str) @@ -184,12 +184,12 @@ class TabbedBrowser(tabwidget.TabWidget): tab.scroll.perc_changed.connect( self._filter.create(self.cur_scroll_perc_changed, tab)) tab.scroll.perc_changed.connect(self.on_scroll_pos_changed) - tab.url_text_changed.connect( - self._filter.create(self.cur_url_text_changed, tab)) + tab.url_changed.connect( + self._filter.create(self.cur_url_changed, tab)) tab.load_status_changed.connect( self._filter.create(self.cur_load_status_changed, tab)) - tab.url_text_changed.connect( - functools.partial(self.on_url_text_changed, tab)) + tab.url_changed.connect( + functools.partial(self.on_url_changed, tab)) # misc tab.title_changed.connect( functools.partial(self.on_title_changed, tab)) @@ -502,8 +502,8 @@ class TabbedBrowser(tabwidget.TabWidget): if idx == self.currentIndex(): self.update_window_title() - @pyqtSlot(browsertab.AbstractTab, str) - def on_url_text_changed(self, tab, url): + @pyqtSlot(browsertab.AbstractTab, QUrl) + def on_url_changed(self, tab, url): """Set the new URL as title if there's no title yet. Args: @@ -516,7 +516,7 @@ class TabbedBrowser(tabwidget.TabWidget): # We can get signals for tabs we already deleted... return if not self.page_title(idx): - self.set_page_title(idx, url) + self.set_page_title(idx, url.toDisplayString()) @pyqtSlot(browsertab.AbstractTab, QIcon) def on_icon_changed(self, tab, icon): diff --git a/tests/unit/mainwindow/statusbar/test_url.py b/tests/unit/mainwindow/statusbar/test_url.py index b147d7ab2..b901168c5 100644 --- a/tests/unit/mainwindow/statusbar/test_url.py +++ b/tests/unit/mainwindow/statusbar/test_url.py @@ -127,19 +127,30 @@ def test_on_tab_changed(url_widget, fake_web_tab, load_status, qurl): assert url_widget.text() == qurl.toDisplayString() -@pytest.mark.parametrize('url_text, load_status, expected_status', [ - ('http://abc123.com/this/awesome/url.html', usertypes.LoadStatus.success, - url.UrlType.success), - ('https://supersecret.gov/nsa/files.txt', usertypes.LoadStatus.success_https, - url.UrlType.success_https), - ('Th1$ i$ n0t @ n0rm@L uRL! P@n1c! <-->', usertypes.LoadStatus.error, - url.UrlType.error), - ('http://www.qutebrowser.org/CONTRIBUTING.html', usertypes.LoadStatus.loading, - url.UrlType.normal), - ('www.whatisthisurl.com', usertypes.LoadStatus.warn, url.UrlType.warn) +@pytest.mark.parametrize('qurl, load_status, expected_status', [ + ( + QUrl('http://abc123.com/this/awesome/url.html'), + usertypes.LoadStatus.success, + url.UrlType.success + ), + ( + QUrl('https://supersecret.gov/nsa/files.txt'), + usertypes.LoadStatus.success_https, + url.UrlType.success_https + ), + ( + QUrl('http://www.qutebrowser.org/CONTRIBUTING.html'), + usertypes.LoadStatus.loading, + url.UrlType.normal + ), + ( + QUrl('www.whatisthisurl.com'), + usertypes.LoadStatus.warn, + url.UrlType.warn + ), ]) -def test_normal_url(url_widget, url_text, load_status, expected_status): - url_widget.set_url(url_text) +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.set_hover_url(url_text) url_widget.set_hover_url("")