Stop using self.sender() in signalfilter, connect signals to mainframe
This commit is contained in:
parent
8757f016cb
commit
98edd45fee
3
doc/BUGS
3
doc/BUGS
@ -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
|
||||
|
@ -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))
|
||||
|
@ -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):
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user