diff options
author | Florian Bruhin <git@the-compiler.org> | 2014-07-16 11:07:05 +0200 |
---|---|---|
committer | Florian Bruhin <git@the-compiler.org> | 2014-07-16 11:07:05 +0200 |
commit | 98edd45fee22e31a91f79eb42c1d35522502bd56 (patch) | |
tree | 38836ed26c08a8e6c4f679751a2af404e73aca75 | |
parent | 8757f016cb846927b447c6cdc0f6c6f7a2a95135 (diff) | |
download | qutebrowser-98edd45fee22e31a91f79eb42c1d35522502bd56.tar.gz qutebrowser-98edd45fee22e31a91f79eb42c1d35522502bd56.zip |
Stop using self.sender() in signalfilter, connect signals to mainframe
-rw-r--r-- | doc/BUGS | 3 | ||||
-rw-r--r-- | qutebrowser/browser/signalfilter.py | 24 | ||||
-rw-r--r-- | qutebrowser/widgets/tabbedbrowser.py | 39 | ||||
-rw-r--r-- | qutebrowser/widgets/webview.py | 9 |
4 files changed, 41 insertions, 34 deletions
@@ -95,7 +95,8 @@ Bugs windows - ok is always True in WebPage:on_load_status_changed, even when an error page - is loaded. + is loaded (probably *because* we're loading the error page and that + succeeds). - When tabbar -> scroll-buttons is disabled and there are too many tabs, the window has a bigger size hint instead of tabs getting smaller than the diff --git a/qutebrowser/browser/signalfilter.py b/qutebrowser/browser/signalfilter.py index dd9f71ed7..cb073cce3 100644 --- a/qutebrowser/browser/signalfilter.py +++ b/qutebrowser/browser/signalfilter.py @@ -48,18 +48,22 @@ class SignalFilter(QObject): super().__init__(tabs) self._tabs = tabs - def create(self, signal): + def create(self, signal, tab): """Factory for partial _filter_signals functions. Args: signal: The pyqtSignal to filter. + tab: The WebView to create filters for. Return: A partial functon calling _filter_signals with a signal. """ - return partial(self._filter_signals, signal) + if not isinstance(tab, WebView): + raise ValueError("Tried to create filter for {} which is no " + "WebView!".format(tab)) + return partial(self._filter_signals, signal, tab) - def _filter_signals(self, signal, *args): + def _filter_signals(self, signal, tab, *args): """Filter signals and trigger TabbedBrowser signals if needed. Triggers signal if the original signal was sent from the _current_ tab @@ -70,24 +74,20 @@ class SignalFilter(QObject): Args: signal: The signal to emit if the sender was the current widget. + tab: The WebView which the filter belongs to. *args: The args to pass to the signal. Emit: The target signal if the sender was the current widget. """ - sender = self.sender() log_signal = signal_name(signal) not in self.BLACKLIST - if not isinstance(sender, WebView): - # BUG? This should never happen, but it does regularely... - logger.warning("Got signal {} by {} which is no tab!".format( - dbg_signal(signal, args), sender)) - return - if self._tabs.currentWidget() == sender: + tabidx = self._tabs.indexOf(tab) + if tabidx == self._tabs.currentIndex(): if log_signal: logger.debug("emitting: {} (tab {})".format( - dbg_signal(signal, args), self._tabs.indexOf(sender))) + dbg_signal(signal, args), tabidx)) signal.emit(*args) else: if log_signal: logger.debug("ignoring: {} (tab {})".format( - dbg_signal(signal, args), self._tabs.indexOf(sender))) + dbg_signal(signal, args), tabidx)) diff --git a/qutebrowser/widgets/tabbedbrowser.py b/qutebrowser/widgets/tabbedbrowser.py index eb284af3f..c23b138d2 100644 --- a/qutebrowser/widgets/tabbedbrowser.py +++ b/qutebrowser/widgets/tabbedbrowser.py @@ -150,35 +150,40 @@ class TabbedBrowser(TabWidget): def _connect_tab_signals(self, tab): """Set up the needed signals for tab.""" + page = tab.page() + frame = page.mainFrame() # filtered signals - tab.linkHovered.connect(self._filter.create(self.cur_link_hovered)) - tab.loadProgress.connect(self._filter.create(self.cur_progress)) - tab.loadFinished.connect(self._filter.create(self.cur_load_finished)) - tab.loadStarted.connect(self._filter.create(self.cur_load_started)) + tab.linkHovered.connect( + self._filter.create(self.cur_link_hovered, tab)) + tab.loadProgress.connect( + self._filter.create(self.cur_progress, tab)) + frame.loadFinished.connect( + self._filter.create(self.cur_load_finished, tab)) + frame.loadStarted.connect( + self._filter.create(self.cur_load_started, tab)) tab.statusBarMessage.connect( - self._filter.create(self.cur_statusbar_message)) + self._filter.create(self.cur_statusbar_message, tab)) tab.scroll_pos_changed.connect( - self._filter.create(self.cur_scroll_perc_changed)) + self._filter.create(self.cur_scroll_perc_changed, tab)) tab.url_text_changed.connect( - self._filter.create(self.cur_url_text_changed)) - tab.url_text_changed.connect(partial(self.on_url_text_changed, tab)) + self._filter.create(self.cur_url_text_changed, tab)) tab.load_status_changed.connect( - self._filter.create(self.cur_load_status_changed)) + self._filter.create(self.cur_load_status_changed, tab)) + tab.url_text_changed.connect(partial(self.on_url_text_changed, tab)) # hintmanager tab.hintmanager.hint_strings_updated.connect(self.hint_strings_updated) tab.hintmanager.download_get.connect(self.download_get) tab.hintmanager.openurl.connect(self.openurl) self.cur_load_started.connect(self.on_cur_load_started) # downloads - tab.page().unsupportedContent.connect(self.start_download) - tab.page().start_download.connect(self.start_download) + page.unsupportedContent.connect(self.start_download) + page.start_download.connect(self.start_download) # misc tab.titleChanged.connect(partial(self.on_title_changed, tab)) tab.iconChanged.connect(partial(self.on_icon_changed, tab)) - tab.page().mainFrame().loadStarted.connect(partial( - self.on_load_started, tab)) - tab.page().windowCloseRequested.connect(partial( - self.on_window_close_requested, tab)) + frame.loadStarted.connect(partial(self.on_load_started, tab)) + page.windowCloseRequested.connect( + partial(self.on_window_close_requested, tab)) def cntwidget(self, count=None): """Return a widget based on a count/idx. @@ -362,8 +367,8 @@ class TabbedBrowser(TabWidget): @pyqtSlot() def on_cur_load_started(self): """Leave insert/hint mode when loading started.""" - for mode in ('insert', 'hint'): - modeman.maybe_leave(mode, 'load started') + modeman.maybe_leave('insert', 'load started') + modeman.maybe_leave('hint', 'load started') @pyqtSlot(WebView, str) def on_title_changed(self, tab, text): diff --git a/qutebrowser/widgets/webview.py b/qutebrowser/widgets/webview.py index 89a2a4cbd..deb09437c 100644 --- a/qutebrowser/widgets/webview.py +++ b/qutebrowser/widgets/webview.py @@ -110,11 +110,11 @@ class WebView(QWebView): self.hintmanager = HintManager(self) self.hintmanager.mouse_event.connect(self.on_mouse_event) self.hintmanager.set_open_target.connect(self.set_force_open_target) - self.page().linkHovered.connect(self.linkHovered) - self.page().mainFrame().loadStarted.connect(self.on_load_started) - self.page().change_title.connect(self.titleChanged) + self._page.linkHovered.connect(self.linkHovered) + self._page.mainFrame().loadStarted.connect(self.on_load_started) + self._page.change_title.connect(self.titleChanged) self.urlChanged.connect(self.on_url_changed) - self.loadFinished.connect(self.on_load_finished) + self._page.mainFrame().loadFinished.connect(self.on_load_finished) self.loadProgress.connect(lambda p: setattr(self, 'progress', p)) self.page().statusBarMessage.connect( lambda msg: setattr(self, 'statusbar_message', msg)) @@ -355,6 +355,7 @@ class WebView(QWebView): try: # Avoid loading finished signal when stopping self.loadFinished.disconnect() + self.page().mainFrame().loadFinished.disconnect() except TypeError: log.destroy.exception("This should never happen.") self.stop() |