Use currying instead of self.sender() where applicable
This commit is contained in:
parent
c6d875f8df
commit
177e2945b6
@ -365,19 +365,19 @@ class Application(QApplication):
|
||||
# statusbar
|
||||
# FIXME some of these probably only should be triggered on mainframe
|
||||
# loadStarted.
|
||||
tabs.currentChanged.connect(status.prog.on_tab_changed)
|
||||
tabs.current_tab_changed.connect(status.prog.on_tab_changed)
|
||||
tabs.cur_progress.connect(status.prog.setValue)
|
||||
tabs.cur_load_finished.connect(status.prog.hide)
|
||||
tabs.cur_load_started.connect(status.prog.on_load_started)
|
||||
|
||||
tabs.currentChanged.connect(status.percentage.on_tab_changed)
|
||||
tabs.current_tab_changed.connect(status.percentage.on_tab_changed)
|
||||
tabs.cur_scroll_perc_changed.connect(status.percentage.set_perc)
|
||||
|
||||
tabs.currentChanged.connect(status.txt.on_tab_changed)
|
||||
tabs.current_tab_changed.connect(status.txt.on_tab_changed)
|
||||
tabs.cur_statusbar_message.connect(status.txt.on_statusbar_message)
|
||||
tabs.cur_load_started.connect(status.txt.on_load_started)
|
||||
|
||||
tabs.currentChanged.connect(status.url.on_tab_changed)
|
||||
tabs.current_tab_changed.connect(status.url.on_tab_changed)
|
||||
tabs.cur_url_text_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)
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
import os
|
||||
import os.path
|
||||
from functools import partial
|
||||
from collections import deque
|
||||
|
||||
from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject, QTimer
|
||||
@ -347,8 +348,8 @@ class DownloadManager(QObject):
|
||||
suggested_filename)
|
||||
logger.debug("fetch: {} -> {}".format(reply.url(), suggested_filepath))
|
||||
download = DownloadItem(reply)
|
||||
download.finished.connect(self.on_finished)
|
||||
download.data_changed.connect(self.on_data_changed)
|
||||
download.finished.connect(partial(self.on_finished, download))
|
||||
download.data_changed.connect(partial(self.on_data_changed, download))
|
||||
download.error.connect(self.on_error)
|
||||
download.basename = suggested_filename
|
||||
self.download_about_to_be_added.emit(len(self.downloads) + 1)
|
||||
@ -365,19 +366,19 @@ class DownloadManager(QObject):
|
||||
download.cancelled.connect(q.abort)
|
||||
message.instance().question.emit(q, False)
|
||||
|
||||
@pyqtSlot()
|
||||
def on_finished(self):
|
||||
@pyqtSlot(DownloadItem)
|
||||
def on_finished(self, download):
|
||||
"""Remove finished download."""
|
||||
logger.debug("on_finished: {}".format(self.sender()))
|
||||
idx = self.downloads.index(self.sender())
|
||||
logger.debug("on_finished: {}".format(download))
|
||||
idx = self.downloads.index(download)
|
||||
self.download_about_to_be_finished.emit(idx)
|
||||
del self.downloads[idx]
|
||||
self.download_finished.emit()
|
||||
|
||||
@pyqtSlot()
|
||||
def on_data_changed(self):
|
||||
@pyqtSlot(DownloadItem)
|
||||
def on_data_changed(self, download):
|
||||
"""Emit data_changed signal when download data changed."""
|
||||
idx = self.downloads.index(self.sender())
|
||||
idx = self.downloads.index(download)
|
||||
self.data_changed.emit(idx)
|
||||
|
||||
@pyqtSlot(str)
|
||||
|
@ -47,7 +47,6 @@ class Percentage(TextBase):
|
||||
self.setText('[{:2}%]'.format(y))
|
||||
|
||||
@pyqtSlot(int)
|
||||
def on_tab_changed(self, idx):
|
||||
def on_tab_changed(self, tab):
|
||||
"""Update scroll position when tab changed."""
|
||||
tab = self.sender().widget(idx)
|
||||
self.set_perc(*tab.scroll_pos)
|
||||
|
@ -60,9 +60,8 @@ class Progress(QProgressBar):
|
||||
self.show()
|
||||
|
||||
@pyqtSlot(int)
|
||||
def on_tab_changed(self, idx):
|
||||
def on_tab_changed(self, tab):
|
||||
"""Set the correct value when the current tab changed."""
|
||||
tab = self.sender().widget(idx)
|
||||
self.setValue(tab.progress)
|
||||
if tab.load_status == LoadStatus.loading:
|
||||
self.show()
|
||||
|
@ -100,9 +100,8 @@ class Text(TextBase):
|
||||
self.jstext = ''
|
||||
|
||||
@pyqtSlot(int)
|
||||
def on_tab_changed(self, idx):
|
||||
def on_tab_changed(self, tab):
|
||||
"""Set the correct jstext when the current tab changed."""
|
||||
tab = self.sender().widget(idx)
|
||||
self.jstext = tab.statusbar_message
|
||||
|
||||
@pyqtSlot(str, str)
|
||||
|
@ -180,9 +180,8 @@ class Url(TextBase):
|
||||
self.hover_url = None
|
||||
|
||||
@pyqtSlot(int)
|
||||
def on_tab_changed(self, idx):
|
||||
def on_tab_changed(self, tab):
|
||||
"""Update URL if the tab changed."""
|
||||
tab = self.sender().widget(idx)
|
||||
self.hover_url = None
|
||||
self.normal_url = tab.url_text
|
||||
status = LoadStatus[tab.load_status]
|
||||
|
@ -74,6 +74,7 @@ class TabbedBrowser(TabWidget):
|
||||
arg: The new size.
|
||||
start_download: Emitted when any tab wants to start downloading
|
||||
something.
|
||||
current_tab_changed: The current tab changed to the emitted WebView.
|
||||
"""
|
||||
|
||||
cur_progress = pyqtSignal(int)
|
||||
@ -90,6 +91,7 @@ class TabbedBrowser(TabWidget):
|
||||
quit = pyqtSignal()
|
||||
resized = pyqtSignal('QRect')
|
||||
got_cmd = pyqtSignal(str)
|
||||
current_tab_changed = pyqtSignal(WebView)
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
@ -147,7 +149,7 @@ class TabbedBrowser(TabWidget):
|
||||
self._filter.create(self.cur_scroll_perc_changed))
|
||||
tab.url_text_changed.connect(
|
||||
self._filter.create(self.cur_url_text_changed))
|
||||
tab.url_text_changed.connect(self.on_url_text_changed)
|
||||
tab.url_text_changed.connect(partial(self.on_url_text_changed, tab))
|
||||
tab.load_status_changed.connect(
|
||||
self._filter.create(self.cur_load_status_changed))
|
||||
# hintmanager
|
||||
@ -157,8 +159,8 @@ class TabbedBrowser(TabWidget):
|
||||
tab.page().unsupportedContent.connect(self.start_download)
|
||||
tab.page().start_download.connect(self.start_download)
|
||||
# misc
|
||||
tab.titleChanged.connect(self.on_title_changed)
|
||||
tab.iconChanged.connect(self.on_icon_changed)
|
||||
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(
|
||||
@ -332,37 +334,45 @@ class TabbedBrowser(TabWidget):
|
||||
"""
|
||||
self.setTabIcon(self.indexOf(tab), EmptyTabIcon())
|
||||
|
||||
@pyqtSlot(str)
|
||||
def on_title_changed(self, text):
|
||||
@pyqtSlot(WebView, str)
|
||||
def on_title_changed(self, tab, text):
|
||||
"""Set the title of a tab.
|
||||
|
||||
Slot for the titleChanged signal of any tab.
|
||||
|
||||
Args:
|
||||
tab: The WebView where the title was changed.
|
||||
text: The text to set.
|
||||
"""
|
||||
log.webview.debug("title changed to '{}'".format(text))
|
||||
if text:
|
||||
self.setTabText(self.indexOf(self.sender()), text)
|
||||
self.setTabText(self.indexOf(tab), text)
|
||||
else:
|
||||
log.webview.debug("ignoring title change")
|
||||
|
||||
@pyqtSlot(str)
|
||||
def on_url_text_changed(self, url):
|
||||
"""Set the new URL as title if there's no title yet."""
|
||||
idx = self.indexOf(self.sender())
|
||||
@pyqtSlot(WebView, str)
|
||||
def on_url_text_changed(self, tab, url):
|
||||
"""Set the new URL as title if there's no title yet.
|
||||
|
||||
Args:
|
||||
tab: The WebView where the title was changed.
|
||||
url: The new URL.
|
||||
"""
|
||||
idx = self.indexOf(tab)
|
||||
if not self.tabText(idx):
|
||||
self.setTabText(idx, url)
|
||||
|
||||
@pyqtSlot()
|
||||
def on_icon_changed(self):
|
||||
@pyqtSlot(WebView)
|
||||
def on_icon_changed(self, tab):
|
||||
"""Set the icon of a tab.
|
||||
|
||||
Slot for the iconChanged signal of any tab.
|
||||
|
||||
Args:
|
||||
tab: The WebView where the title was changed.
|
||||
"""
|
||||
if not config.get('tabbar', 'show-favicons'):
|
||||
return
|
||||
tab = self.sender()
|
||||
self.setTabIcon(self.indexOf(tab), tab.icon())
|
||||
|
||||
@pyqtSlot(str)
|
||||
@ -378,6 +388,7 @@ class TabbedBrowser(TabWidget):
|
||||
tab = self.widget(idx)
|
||||
self.last_focused = self.now_focused
|
||||
self.now_focused = tab
|
||||
self.current_tab_changed.emit(tab)
|
||||
|
||||
def resizeEvent(self, e):
|
||||
"""Extend resizeEvent of QWidget to emit a resized signal afterwards.
|
||||
|
Loading…
Reference in New Issue
Block a user