Wed, 07 Feb 2018 20:14:09 +0100
Continued removing the use of QObject.sender().
--- a/Helpviewer/HelpWebSearchWidget.py Wed Feb 07 18:57:46 2018 +0100 +++ b/Helpviewer/HelpWebSearchWidget.py Wed Feb 07 20:14:09 2018 +0100 @@ -241,7 +241,8 @@ engine = self.__openSearchManager.engine(engineName) action = OpenSearchEngineAction(engine, self.__enginesMenu) action.setData(engineName) - action.triggered.connect(self.__changeCurrentEngine) + action.triggered.connect( + lambda: self.__changeCurrentEngine(action)) self.__enginesMenu.addAction(action) if self.__openSearchManager.currentEngineName() == engineName: @@ -274,10 +275,11 @@ title = ct.title() action = self.__enginesMenu.addAction( - self.tr("Add '{0}'").format(title), - self.__addEngineFromUrl) + self.tr("Add '{0}'").format(title)) action.setData(url) action.setIcon(ct.icon()) + action.triggered.connect( + lambda: self.__addEngineFromUrl(action)) self.__enginesMenu.addSeparator() self.__enginesMenu.addAction(self.__mw.searchEnginesAction()) @@ -286,26 +288,28 @@ self.__enginesMenu.addAction(self.tr("Clear Recent Searches"), self.clear) - def __changeCurrentEngine(self): + def __changeCurrentEngine(self, action): """ Private slot to handle the selection of a search engine. + + @param action reference to the action that triggered + @type QAction """ - action = self.sender() - if action is not None: - name = action.data() - self.__openSearchManager.setCurrentEngineName(name) + name = action.data() + self.__openSearchManager.setCurrentEngineName(name) - def __addEngineFromUrl(self): + def __addEngineFromUrl(self, action): """ Private slot to add a search engine given its URL. + + @param action reference to the action that triggered + @type QAction """ - action = self.sender() - if action is not None: - url = action.data() - if not isinstance(url, QUrl): - return - - self.__openSearchManager.addEngine(url) + url = action.data() + if not isinstance(url, QUrl): + return + + self.__openSearchManager.addEngine(url) def __searchButtonClicked(self): """
--- a/Helpviewer/HelpWindow.py Wed Feb 07 18:57:46 2018 +0100 +++ b/Helpviewer/HelpWindow.py Wed Feb 07 20:14:09 2018 +0100 @@ -2488,7 +2488,8 @@ self, 'Configuration', True, fromEric=self.fromEric, displayMode=ConfigurationDialog.HelpBrowserMode) dlg.preferencesChanged.connect(self.preferencesChanged) - dlg.masterPasswordChanged.connect(self.masterPasswordChanged) + dlg.masterPasswordChanged.connect( + lambda old, new: self.masterPasswordChanged(old, new, local=True)) dlg.show() if self.__lastConfigurationPageName: dlg.showConfigurationPageByName(self.__lastConfigurationPageName) @@ -2531,16 +2532,20 @@ self.virustotalIpReportAct.setEnabled(True) self.virustotalDomainReportAct.setEnabled(True) - def masterPasswordChanged(self, oldPassword, newPassword): + def masterPasswordChanged(self, oldPassword, newPassword, local=False): """ Public slot to handle the change of the master password. - @param oldPassword current master password (string) - @param newPassword new master password (string) - """ - from Preferences.ConfigurationDialog import ConfigurationDialog + @param oldPassword current master password + @type str + @param newPassword new master password + @type str + @param local flag indicating being called from the local configuration + dialog + @type bool + """ self.passwordManager().masterPasswordChanged(oldPassword, newPassword) - if self.fromEric and isinstance(self.sender(), ConfigurationDialog): + if self.fromEric and local: # we were called from our local configuration dialog Preferences.convertPasswords(oldPassword, newPassword) Utilities.crypto.changeRememberedMaster(newPassword) @@ -3621,17 +3626,20 @@ feedsManager = self.feedsManager() feedsManager.openUrl.connect(self.openUrl) feedsManager.newUrl.connect(self.openUrlNewTab) - feedsManager.rejected.connect(self.__feedsManagerClosed) + feedsManager.rejected.connect( + lambda fm: self.__feedsManagerClosed(fm)) feedsManager.show() - def __feedsManagerClosed(self): + def __feedsManagerClosed(self, feedsManager): """ Private slot to handle closing the feeds manager dialog. - """ - feedsManager = self.sender() + + @param feedsManager reference to the feeds manager object + @type FeedsManager + """ feedsManager.openUrl.disconnect(self.openUrl) feedsManager.newUrl.disconnect(self.openUrlNewTab) - feedsManager.rejected.disconnect(self.__feedsManagerClosed) + feedsManager.rejected.disconnect() def __showSiteinfoDialog(self): """
--- a/Helpviewer/OpenSearch/OpenSearchEngine.py Wed Feb 07 18:57:46 2018 +0100 +++ b/Helpviewer/OpenSearch/OpenSearchEngine.py Wed Feb 07 20:14:09 2018 +0100 @@ -364,17 +364,16 @@ reply = self.__networkAccessManager.get( QNetworkRequest(QUrl.fromEncoded(self._imageUrl.encode("utf-8")))) - reply.finished.connect(self.__imageObtained) + reply.finished.connect(lambda: self.__imageObtained(reply)) self.__replies.append(reply) - def __imageObtained(self): + def __imageObtained(self, reply): """ Private slot to receive the image of the engine. + + @param reply reference to the network reply + @type QNetworkReply """ - reply = self.sender() - if reply is None: - return - response = reply.readAll() reply.close()
--- a/Helpviewer/OpenSearch/OpenSearchManager.py Wed Feb 07 18:57:46 2018 +0100 +++ b/Helpviewer/OpenSearch/OpenSearchManager.py Wed Feb 07 20:14:09 2018 +0100 @@ -173,7 +173,7 @@ from Helpviewer.HelpWindow import HelpWindow reply = HelpWindow.networkAccessManager().get(QNetworkRequest(url)) - reply.finished.connect(self.__engineFromUrlAvailable) + reply.finished.connect(lambda: self.__engineFromUrlAvailable(reply)) reply.setParent(self) self.__replies.append(reply) @@ -410,14 +410,13 @@ """Searches on: {1}</p>""").format(engine.name(), host)) return res - def __engineFromUrlAvailable(self): + def __engineFromUrlAvailable(self, reply): """ Private slot to add a search engine from the net. + + @param reply reference to the network reply + @type QNetworkReply """ - reply = self.sender() - if reply is None: - return - if reply.error() != QNetworkReply.NoError: reply.close() if reply in self.__replies:
--- a/Helpviewer/PersonalInformationManager/PersonalInformationManager.py Wed Feb 07 18:57:46 2018 +0100 +++ b/Helpviewer/PersonalInformationManager/PersonalInformationManager.py Wed Feb 07 20:14:09 2018 +0100 @@ -143,9 +143,9 @@ for key, info in sorted(self.__allInfo.items()): if info: - act = submenu.addAction( - self.__translations[key], self.__insertData) + act = submenu.addAction(self.__translations[key]) act.setData(info) + act.triggered.connect(lambda: self.__insertData(act)) submenu.addSeparator() submenu.addAction(self.tr("Edit Personal Information"), @@ -154,12 +154,14 @@ menu.addMenu(submenu) menu.addSeparator() - def __insertData(self): + def __insertData(self, act): """ Private slot to insert the selected personal information. + + @param act reference to the action that triggered + @type QAction """ - act = self.sender() - if not self.__element or self.__element.isNull() or act is None: + if not self.__element or self.__element.isNull(): return info = act.data()
--- a/Helpviewer/SiteInfo/SiteInfoDialog.py Wed Feb 07 18:57:46 2018 +0100 +++ b/Helpviewer/SiteInfo/SiteInfoDialog.py Wed Feb 07 20:14:09 2018 +0100 @@ -225,31 +225,34 @@ return menu = QMenu() - act = menu.addAction( - self.tr("Copy Image Location to Clipboard"), - self.__copyAction) + act = menu.addAction(self.tr("Copy Image Location to Clipboard")) act.setData(itm.text(1)) - act = menu.addAction( - self.tr("Copy Image Name to Clipboard"), - self.__copyAction) + act.triggered.connect(lambda: self.__copyAction(act)) + act = menu.addAction(self.tr("Copy Image Name to Clipboard")) act.setData(itm.text(0)) + act.triggered.connect(lambda: self.__copyAction(act)) menu.addSeparator() - act = menu.addAction(self.tr("Save Image"), self.__saveImage) + act = menu.addAction(self.tr("Save Image")) act.setData(self.imagesTree.indexOfTopLevelItem(itm)) + act.triggered.connect(lambda: self.__saveImage(act)) menu.exec_(QCursor.pos()) - def __copyAction(self): + def __copyAction(self, act): """ Private slot to copy the image URL or the image name to the clipboard. + + @param act reference to the action that triggered + @type QAction """ - act = self.sender() QApplication.clipboard().setText(act.data()) - def __saveImage(self): + def __saveImage(self, act): """ Private slot to save the selected image to disk. + + @param act reference to the action that triggered + @type QAction """ - act = self.sender() index = act.data() itm = self.imagesTree.topLevelItem(index) if itm is None:
--- a/Helpviewer/SpeedDial/SpeedDial.py Wed Feb 07 18:57:46 2018 +0100 +++ b/Helpviewer/SpeedDial/SpeedDial.py Wed Feb 07 20:14:09 2018 +0100 @@ -316,7 +316,8 @@ thumbnailer = PageThumbnailer(self) thumbnailer.setUrl(QUrl.fromEncoded(url.encode("utf-8"))) thumbnailer.setLoadTitle(loadTitle) - thumbnailer.thumbnailCreated.connect(self.__thumbnailCreated) + thumbnailer.thumbnailCreated.connect( + lambda imag: self.__thumbnailCreated(imag, thumbnailer)) self.__thumbnailers.append(thumbnailer) thumbnailer.start() @@ -388,48 +389,47 @@ """ return self.__speedDialSize - def __thumbnailCreated(self, image): + def __thumbnailCreated(self, image, thumbnailer): """ Private slot to handle the creation of a thumbnail image. - @param image thumbnail image (QPixmap) + @param image thumbnail image + @type QPixmap + @param thumbnailer reference to the page thumbnailer + @type PageThumbnailer """ - from .PageThumbnailer import PageThumbnailer - thumbnailer = self.sender() - if not isinstance(thumbnailer, PageThumbnailer) or \ - thumbnailer not in self.__thumbnailers: - return - - loadTitle = thumbnailer.loadTitle() - title = thumbnailer.title() - url = thumbnailer.url().toString() - fileName = self.__imageFileName(url) - - if image.isNull(): - fileName = "qrc:icons/brokenPage.png" - title = self.tr("Unable to load") - loadTitle = True - page = self.pageForUrl(thumbnailer.url()) - page.broken = True - else: - if not image.save(fileName): - qWarning( - "SpeedDial.__thumbnailCreated: Cannot save thumbnail" - " to {0}".format(fileName)) + if thumbnailer in self.__thumbnailers: + loadTitle = thumbnailer.loadTitle() + title = thumbnailer.title() + url = thumbnailer.url().toString() + fileName = self.__imageFileName(url) - fileName = QUrl.fromLocalFile(fileName).toString() - - self.__regenerateScript = True - - for frame in self.__cleanFrames(): - frame.evaluateJavaScript("setImageToUrl('{0}', '{1}');".format( - url, fileName)) - if loadTitle: - frame.evaluateJavaScript("setTitleToUrl('{0}', '{1}');".format( - url, Utilities.html_uencode(title))) - - thumbnailer.deleteLater() - self.__thumbnailers.remove(thumbnailer) + if image.isNull(): + fileName = "qrc:icons/brokenPage.png" + title = self.tr("Unable to load") + loadTitle = True + page = self.pageForUrl(thumbnailer.url()) + page.broken = True + else: + if not image.save(fileName): + qWarning( + "SpeedDial.__thumbnailCreated: Cannot save thumbnail" + " to {0}".format(fileName)) + + fileName = QUrl.fromLocalFile(fileName).toString() + + self.__regenerateScript = True + + for frame in self.__cleanFrames(): + frame.evaluateJavaScript("setImageToUrl('{0}', '{1}');".format( + url, fileName)) + if loadTitle: + frame.evaluateJavaScript( + "setTitleToUrl('{0}', '{1}');".format( + url, Utilities.html_uencode(title))) + + thumbnailer.deleteLater() + self.__thumbnailers.remove(thumbnailer) def __cleanFrames(self): """
--- a/Helpviewer/UserAgent/UserAgentMenu.py Wed Feb 07 18:57:46 2018 +0100 +++ b/Helpviewer/UserAgent/UserAgentMenu.py Wed Feb 07 20:14:09 2018 +0100 @@ -107,11 +107,13 @@ else: HelpWebPage().setUserAgent(userAgent) - def __changeUserAgent(self): + def __changeUserAgent(self, act): """ Private slot to change the user agent. + + @param act reference to the action that triggered + @type QAction """ - act = self.sender() if self.__url: self.__manager.setUserAgentForUrl(self.__url, act.data()) else: @@ -157,7 +159,7 @@ act.setToolTip(userAgent) act.setCheckable(True) act.setChecked(userAgent == currentUserAgentString) - act.triggered.connect(self.__changeUserAgent) + act.triggered.connect(lambda: self.__changeUserAgent(act)) if menuStack: menuStack[-1].addAction(act) else:
--- a/Helpviewer/VirusTotal/VirusTotalApi.py Wed Feb 07 18:57:46 2018 +0100 +++ b/Helpviewer/VirusTotal/VirusTotalApi.py Wed Feb 07 20:14:09 2018 +0100 @@ -127,17 +127,20 @@ import Helpviewer.HelpWindow nam = Helpviewer.HelpWindow.HelpWindow.networkAccessManager() reply = nam.post(request, params) - reply.finished.connect(self.__checkServiceKeyValidityFinished) + reply.finished.connect( + lambda: self.__checkServiceKeyValidityFinished(reply)) self.__replies.append(reply) - def __checkServiceKeyValidityFinished(self): + def __checkServiceKeyValidityFinished(self, reply): """ Private slot to determine the result of the service key validity check. + + @param reply reference to the network reply + @type QNetworkReply """ res = False msg = "" - reply = self.sender() if reply.error() == QNetworkReply.NoError: res = True elif reply.error() == self.ServiceCode_InvalidKey: @@ -168,11 +171,13 @@ reply.finished.connect(self.__submitUrlFinished) self.__replies.append(reply) - def __submitUrlFinished(self): + def __submitUrlFinished(self, reply): """ Private slot to determine the result of the URL scan submission. + + @param reply reference to the network reply + @type QNetworkReply """ - reply = self.sender() if reply.error() == QNetworkReply.NoError: result = json.loads(str(reply.readAll(), "utf-8")) if result["response_code"] == self.ServiceResult_ItemPresent: @@ -211,12 +216,14 @@ reply.finished.connect(self.__getUrlScanReportUrlFinished) self.__replies.append(reply) - def __getUrlScanReportUrlFinished(self): + def __getUrlScanReportUrlFinished(self, reply): """ Private slot to determine the result of the URL scan report URL request. + + @param reply reference to the network reply + @type QNetworkReply """ - reply = self.sender() if reply.error() == QNetworkReply.NoError: result = json.loads(str(reply.readAll(), "utf-8")) if "filescan_id" in result and result["filescan_id"] is not None: @@ -243,12 +250,14 @@ reply.finished.connect(self.__getFileScanReportUrlFinished) self.__replies.append(reply) - def __getFileScanReportUrlFinished(self): + def __getFileScanReportUrlFinished(self, reply): """ Private slot to determine the result of the file scan report URL request. + + @param reply reference to the network reply + @type QNetworkReply """ - reply = self.sender() if reply.error() == QNetworkReply.NoError: result = json.loads(str(reply.readAll(), "utf-8")) self.fileScanReport.emit(result["permalink"]) @@ -284,11 +293,13 @@ reply.finished.connect(self.__getIpAddressReportFinished) self.__replies.append(reply) - def __getIpAddressReportFinished(self): + def __getIpAddressReportFinished(self, reply): """ Private slot to process the IP address report data. + + @param reply reference to the network reply + @type QNetworkReply """ - reply = self.sender() if reply.error() == QNetworkReply.NoError: result = json.loads(str(reply.readAll(), "utf-8")) if result["response_code"] == 0: @@ -343,14 +354,16 @@ import Helpviewer.HelpWindow nam = Helpviewer.HelpWindow.HelpWindow.networkAccessManager() reply = nam.get(request) - reply.finished.connect(self.__getDomainReportFinished) + reply.finished.connect(lambda: self.__getDomainReportFinished(reply)) self.__replies.append(reply) - def __getDomainReportFinished(self): + def __getDomainReportFinished(self, reply): """ Private slot to process the IP address report data. + + @param reply reference to the network reply + @type QNetworkReply """ - reply = self.sender() if reply.error() == QNetworkReply.NoError: result = json.loads(str(reply.readAll(), "utf-8")) if result["response_code"] == 0:
--- a/WebBrowser/OpenSearch/OpenSearchEngine.py Wed Feb 07 18:57:46 2018 +0100 +++ b/WebBrowser/OpenSearch/OpenSearchEngine.py Wed Feb 07 20:14:09 2018 +0100 @@ -348,17 +348,16 @@ reply = self.__networkAccessManager.get( QNetworkRequest(QUrl.fromEncoded(self._imageUrl.encode("utf-8")))) - reply.finished.connect(self.__imageObtained) + reply.finished.connect(lambda: self.__imageObtained(reply)) self.__replies.append(reply) - def __imageObtained(self): + def __imageObtained(self, reply): """ Private slot to receive the image of the engine. + + @param reply reference to the network reply + @type QNetworkReply """ - reply = self.sender() - if reply is None: - return - response = reply.readAll() reply.close()
--- a/WebBrowser/OpenSearch/OpenSearchManager.py Wed Feb 07 18:57:46 2018 +0100 +++ b/WebBrowser/OpenSearch/OpenSearchManager.py Wed Feb 07 20:14:09 2018 +0100 @@ -175,7 +175,7 @@ from WebBrowser.WebBrowserWindow import WebBrowserWindow reply = WebBrowserWindow.networkManager().get(QNetworkRequest(url)) - reply.finished.connect(self.__engineFromUrlAvailable) + reply.finished.connect(lambda: self.__engineFromUrlAvailable(reply)) reply.setParent(self) self.__replies.append(reply) @@ -473,14 +473,13 @@ """Searches on: {1}</p>""").format(engine.name(), host)) return res - def __engineFromUrlAvailable(self): + def __engineFromUrlAvailable(self, reply): """ Private slot to add a search engine from the net. + + @param reply reference to the network reply + @type QNetworkReply """ - reply = self.sender() - if reply is None: - return - if reply.error() != QNetworkReply.NoError: reply.close() if reply in self.__replies:
--- a/WebBrowser/PersonalInformationManager/PersonalInformationManager.py Wed Feb 07 18:57:46 2018 +0100 +++ b/WebBrowser/PersonalInformationManager/PersonalInformationManager.py Wed Feb 07 20:14:09 2018 +0100 @@ -153,9 +153,9 @@ for key, info in sorted(self.__allInfo.items()): if info: - act = submenu.addAction( - self.__translations[key], self.__insertData) + act = submenu.addAction(self.__translations[key]) act.setData(info) + act.triggered.connect(lambda: self.__insertData(act)) submenu.addSeparator() submenu.addAction(self.tr("Edit Personal Information"), @@ -164,17 +164,16 @@ menu.addMenu(submenu) menu.addSeparator() - def __insertData(self): + def __insertData(self, act): """ Private slot to insert the selected personal information. + + @param act reference to the action that triggered + @type QAction """ if self.__view is None or self.__clickedPos.isNull(): return - act = self.sender() - if act is None: - return - info = act.data() info = info.replace('"', '\\"')
--- a/WebBrowser/Session/SessionManager.py Wed Feb 07 18:57:46 2018 +0100 +++ b/WebBrowser/Session/SessionManager.py Wed Feb 07 20:14:09 2018 +0100 @@ -14,7 +14,7 @@ from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QObject, QTimer, QDir, \ QFile, QFileInfo, QFileSystemWatcher, QByteArray, QDateTime -from PyQt5.QtWidgets import QMenu, QAction, QActionGroup, QApplication, \ +from PyQt5.QtWidgets import QActionGroup, QApplication, \ QInputDialog, QLineEdit, QDialog, QDialogButtonBox, QLabel, QComboBox, \ QVBoxLayout @@ -352,33 +352,35 @@ self.sessionsMetaDataChanged.emit() @pyqtSlot() - def aboutToShowSessionsMenu(self): + def aboutToShowSessionsMenu(self, menu): """ Public slot to populate the sessions selection menu. + + @param menu reference to the menu about to be shown + @type QMenu """ - menu = self.sender() - if isinstance(menu, QMenu): - menu.clear() - - actionGroup = QActionGroup(menu) - sessions = self.sessionMetaData(includeBackups=False) - for session in sessions: - act = menu.addAction(session.name) - act.setCheckable(True) - act.setChecked(session.isActive) - act.setData(session.filePath) - actionGroup.addAction(act) - act.triggered.connect(self.__sessionActTriggered) + menu.clear() + + actionGroup = QActionGroup(menu) + sessions = self.sessionMetaData(includeBackups=False) + for session in sessions: + act = menu.addAction(session.name) + act.setCheckable(True) + act.setChecked(session.isActive) + act.setData(session.filePath) + actionGroup.addAction(act) + act.triggered.connect(lambda: self.__sessionActTriggered(act)) @pyqtSlot() - def __sessionActTriggered(self): + def __sessionActTriggered(self, act): """ Private slot to handle the menu selection of a session. + + @param act reference to the action that triggered + @type QAction """ - act = self.sender() - if isinstance(act, QAction): - path = act.data() - self.switchToSession(path) + path = act.data() + self.switchToSession(path) def openSession(self, sessionFilePath, flags=0): """
--- a/WebBrowser/SiteInfo/SiteInfoDialog.py Wed Feb 07 18:57:46 2018 +0100 +++ b/WebBrowser/SiteInfo/SiteInfoDialog.py Wed Feb 07 20:14:09 2018 +0100 @@ -236,30 +236,34 @@ return menu = QMenu() - menu.addAction( - self.tr("Copy Image Location to Clipboard"), - self.__copyAction).setData(itm.text(1)) - menu.addAction( - self.tr("Copy Image Name to Clipboard"), - self.__copyAction).setData(itm.text(0)) + act = menu.addAction(self.tr("Copy Image Location to Clipboard")) + act.setData(itm.text(1)) + act.triggered.connect(lambda: self.__copyAction(act)) + act = menu.addAction(self.tr("Copy Image Name to Clipboard")) + act.setData(itm.text(0)) + act.triggered.connect(lambda: self.__copyAction(act)) menu.addSeparator() - menu.addAction( - self.tr("Save Image"), - self.__saveImage).setData(self.imagesTree.indexOfTopLevelItem(itm)) + act = menu.addAction(self.tr("Save Image")) + act.setData(self.imagesTree.indexOfTopLevelItem(itm)) + act.triggered.connect(lambda: self.__saveImage(act)) menu.exec_(self.imagesTree.viewport().mapToGlobal(pos)) - def __copyAction(self): + def __copyAction(self, act): """ Private slot to copy the image URL or the image name to the clipboard. + + @param act reference to the action that triggered + @type QAction """ - act = self.sender() QApplication.clipboard().setText(act.data()) - def __saveImage(self): + def __saveImage(self, act): """ Private slot to save the selected image to disk. + + @param act reference to the action that triggered + @type QAction """ - act = self.sender() index = act.data() itm = self.imagesTree.topLevelItem(index) if itm is None:
--- a/WebBrowser/SpeedDial/SpeedDial.py Wed Feb 07 18:57:46 2018 +0100 +++ b/WebBrowser/SpeedDial/SpeedDial.py Wed Feb 07 20:14:09 2018 +0100 @@ -323,7 +323,8 @@ thumbnailer = PageThumbnailer(self) thumbnailer.setUrl(QUrl.fromEncoded(url.encode("utf-8"))) thumbnailer.setLoadTitle(loadTitle) - thumbnailer.thumbnailCreated.connect(self.__thumbnailCreated) + thumbnailer.thumbnailCreated.connect( + lambda imag: self.__thumbnailCreated(imag, thumbnailer)) self.__thumbnailers.append(thumbnailer) thumbnailer.start() @@ -385,43 +386,41 @@ """ return self.__speedDialSize - def __thumbnailCreated(self, image): + def __thumbnailCreated(self, image, thumbnailer): """ Private slot to handle the creation of a thumbnail image. - @param image thumbnail image (QPixmap) + @param image thumbnail image + @type QPixmap + @param thumbnailer reference to the page thumbnailer + @type PageThumbnailer """ - from .PageThumbnailer import PageThumbnailer - thumbnailer = self.sender() - if not isinstance(thumbnailer, PageThumbnailer) or \ - thumbnailer not in self.__thumbnailers: - return - - loadTitle = thumbnailer.loadTitle() - title = thumbnailer.title() - url = thumbnailer.url().toString() - fileName = self.__imageFileName(url) - - if image.isNull(): - fileName = "qrc:icons/brokenPage.png" - title = self.tr("Unable to load") - page = self.pageForUrl(thumbnailer.url()) - page.broken = True - else: - if not image.save(fileName, "PNG"): - qWarning( - "SpeedDial.__thumbnailCreated: Cannot save thumbnail" - " to {0}".format(fileName)) - - self.__regenerateScript = True - thumbnailer.deleteLater() - self.__thumbnailers.remove(thumbnailer) - - if loadTitle: - self.pageTitleLoaded.emit(url, title) - - self.thumbnailLoaded.emit( - url, pixmapToDataUrl(QPixmap(fileName)).toString()) + if thumbnailer in self.__thumbnailers: + loadTitle = thumbnailer.loadTitle() + title = thumbnailer.title() + url = thumbnailer.url().toString() + fileName = self.__imageFileName(url) + + if image.isNull(): + fileName = "qrc:icons/brokenPage.png" + title = self.tr("Unable to load") + page = self.pageForUrl(thumbnailer.url()) + page.broken = True + else: + if not image.save(fileName, "PNG"): + qWarning( + "SpeedDial.__thumbnailCreated: Cannot save thumbnail" + " to {0}".format(fileName)) + + self.__regenerateScript = True + thumbnailer.deleteLater() + self.__thumbnailers.remove(thumbnailer) + + if loadTitle: + self.pageTitleLoaded.emit(url, title) + + self.thumbnailLoaded.emit( + url, pixmapToDataUrl(QPixmap(fileName)).toString()) def __escapeTitle(self, title): """
--- a/WebBrowser/SpellCheck/ManageDictionariesDialog.py Wed Feb 07 18:57:46 2018 +0100 +++ b/WebBrowser/SpellCheck/ManageDictionariesDialog.py Wed Feb 07 20:14:09 2018 +0100 @@ -194,7 +194,8 @@ request.setAttribute(QNetworkRequest.CacheLoadControlAttribute, QNetworkRequest.AlwaysNetwork) reply = WebBrowserWindow.networkManager().get(request) - reply.finished.connect(self.__listFileDownloaded) + reply.finished.connect( + lambda: self.__listFileDownloaded(reply)) reply.downloadProgress.connect(self.__downloadProgress) self.__replies.append(reply) else: @@ -206,10 +207,13 @@ """ from {0}.</p><p>Error: {1}</p>""" ).format(url, self.tr("Computer is offline."))) - def __listFileDownloaded(self): + def __listFileDownloaded(self, reply): """ Private method called, after the dictionaries list file has been downloaded from the Internet. + + @param reply reference to the network reply + @type QNetworkReply """ self.__refreshButton.setEnabled(True) self.__cancelButton.setEnabled(False) @@ -217,7 +221,6 @@ self.downloadProgress.setValue(0) - reply = self.sender() if reply in self.__replies: self.__replies.remove(reply) reply.deleteLater() @@ -382,7 +385,8 @@ request.setAttribute(QNetworkRequest.CacheLoadControlAttribute, QNetworkRequest.AlwaysNetwork) reply = WebBrowserWindow.networkManager().get(request) - reply.finished.connect(self.__installDictionary) + reply.finished.connect( + lambda: self.__installDictionary(reply)) reply.downloadProgress.connect(self.__downloadProgress) self.__replies.append(reply) else: @@ -398,11 +402,13 @@ self.__installationFinished() - def __installDictionary(self): + def __installDictionary(self, reply): """ Private slot to install the downloaded dictionary. + + @param reply reference to the network reply + @type QNetworkReply """ - reply = self.sender() if reply in self.__replies: self.__replies.remove(reply) reply.deleteLater()
--- a/WebBrowser/TabManager/TabManagerWidget.py Wed Feb 07 18:57:46 2018 +0100 +++ b/WebBrowser/TabManager/TabManagerWidget.py Wed Feb 07 20:14:09 2018 +0100 @@ -403,18 +403,18 @@ self.__waitForRefresh = False @pyqtSlot() - def __processActions(self): + def __processActions(self, act): """ Private slot to process the actions. + + @param act reference to the action that triggered + @type QAction """ - if self.sender() is None: - return - self.__refreshBlocked = True selectedBrowsers = collections.defaultdict(list) - command = self.sender().objectName() + command = act.objectName() for index in range(self.__tree.topLevelItemCount()): winItem = self.__tree.topLevelItem(index) @@ -522,14 +522,16 @@ menu.addSeparator() if self.__isBrowserSelected(): - menu.addAction( + act = menu.addAction( UI.PixmapCache.getIcon("bookmark22.png"), - self.tr("&Bookmark checked tabs"), - self.__processActions).setObjectName("bookmarkSelection") - menu.addAction( + self.tr("&Bookmark checked tabs")) + act.setObjectName("bookmarkSelection") + act.triggered.connect(lambda: self.__processActions(act)) + act = menu.addAction( UI.PixmapCache.getIcon("tabClose.png"), - self.tr("&Close checked tabs"), - self.__processActions).setObjectName("closeSelection") + self.tr("&Close checked tabs")) + act.setObjectName("closeSelection") + act.triggered.connect(lambda: self.__processActions(act)) menu.exec_(self.__tree.viewport().mapToGlobal(pos)) @@ -560,21 +562,22 @@ icon.setPixmap( UI.PixmapCache.getPixmap("tabManager.png").scaled(16, 16)) icon.setToolTip(self.tr("Show Tab Manager")) - icon.clicked.connect(self.raiseTabManager) + icon.clicked.connect(lambda: self.raiseTabManager(icon)) return icon - def raiseTabManager(self): + def raiseTabManager(self, icon): """ Public slot to show the tab manager. + + @param icon reference to the clicked icon + @type E5ClickableLabel or QAction """ window = None - icon = self.sender() - if icon: - if isinstance(icon, E5ClickableLabel): - window = icon.window() - elif isinstance(icon, QAction): - window = icon.parentWidget() + if isinstance(icon, E5ClickableLabel): + window = icon.window() + elif isinstance(icon, QAction): + window = icon.parentWidget() if window is not None: titleBarHeight = self.style().pixelMetric(QStyle.PM_TitleBarHeight)
--- a/WebBrowser/UserAgent/UserAgentMenu.py Wed Feb 07 18:57:46 2018 +0100 +++ b/WebBrowser/UserAgent/UserAgentMenu.py Wed Feb 07 20:14:09 2018 +0100 @@ -107,11 +107,13 @@ else: WebBrowserPage.setUserAgent(userAgent) - def __changeUserAgent(self): + def __changeUserAgent(self, act): """ Private slot to change the user agent. + + @param act reference to the action that triggered + @type QAction """ - act = self.sender() if self.__url: self.__manager.setUserAgentForUrl(self.__url, act.data()) else: @@ -157,7 +159,7 @@ act.setToolTip(userAgent) act.setCheckable(True) act.setChecked(userAgent == currentUserAgentString) - act.triggered.connect(self.__changeUserAgent) + act.triggered.connect(lambda: self.__changeUserAgent(act)) if menuStack: menuStack[-1].addAction(act) else:
--- a/WebBrowser/VirusTotal/VirusTotalApi.py Wed Feb 07 18:57:46 2018 +0100 +++ b/WebBrowser/VirusTotal/VirusTotalApi.py Wed Feb 07 20:14:09 2018 +0100 @@ -127,17 +127,20 @@ nam = WebBrowser.WebBrowserWindow.WebBrowserWindow\ .networkManager() reply = nam.post(request, params) - reply.finished.connect(self.__checkServiceKeyValidityFinished) + reply.finished.connect( + lambda: self.__checkServiceKeyValidityFinished(reply)) self.__replies.append(reply) - def __checkServiceKeyValidityFinished(self): + def __checkServiceKeyValidityFinished(self, reply): """ Private slot to determine the result of the service key validity check. + + @param reply reference to the network reply + @type QNetworkReply """ res = False msg = "" - reply = self.sender() if reply.error() == QNetworkReply.NoError: res = True elif reply.error() == self.ServiceCode_InvalidKey: @@ -169,11 +172,13 @@ reply.finished.connect(self.__submitUrlFinished) self.__replies.append(reply) - def __submitUrlFinished(self): + def __submitUrlFinished(self, reply): """ Private slot to determine the result of the URL scan submission. + + @param reply reference to the network reply + @type QNetworkReply """ - reply = self.sender() if reply.error() == QNetworkReply.NoError: result = json.loads(str(reply.readAll(), "utf-8")) if result["response_code"] == self.ServiceResult_ItemPresent: @@ -213,12 +218,14 @@ reply.finished.connect(self.__getUrlScanReportUrlFinished) self.__replies.append(reply) - def __getUrlScanReportUrlFinished(self): + def __getUrlScanReportUrlFinished(self, reply): """ - Private slot to determine the result of the URL scan report URL + Private slot to determine the result of the URL scan report URL. + + @param reply reference to the network reply + @type QNetworkReply request. """ - reply = self.sender() if reply.error() == QNetworkReply.NoError: result = json.loads(str(reply.readAll(), "utf-8")) if "filescan_id" in result and result["filescan_id"] is not None: @@ -246,12 +253,14 @@ reply.finished.connect(self.__getFileScanReportUrlFinished) self.__replies.append(reply) - def __getFileScanReportUrlFinished(self): + def __getFileScanReportUrlFinished(self, reply): """ Private slot to determine the result of the file scan report URL request. + + @param reply reference to the network reply + @type QNetworkReply """ - reply = self.sender() if reply.error() == QNetworkReply.NoError: result = json.loads(str(reply.readAll(), "utf-8")) self.fileScanReport.emit(result["permalink"]) @@ -284,11 +293,13 @@ reply.finished.connect(self.__getIpAddressReportFinished) self.__replies.append(reply) - def __getIpAddressReportFinished(self): + def __getIpAddressReportFinished(self, reply): """ Private slot to process the IP address report data. + + @param reply reference to the network reply + @type QNetworkReply """ - reply = self.sender() if reply.error() == QNetworkReply.NoError: result = json.loads(str(reply.readAll(), "utf-8")) if result["response_code"] == 0: @@ -340,14 +351,16 @@ nam = WebBrowser.WebBrowserWindow.WebBrowserWindow\ .networkManager() reply = nam.get(request) - reply.finished.connect(self.__getDomainReportFinished) + reply.finished.connect(lambda: self.__getDomainReportFinished(reply)) self.__replies.append(reply) - def __getDomainReportFinished(self): + def __getDomainReportFinished(self, reply): """ Private slot to process the IP address report data. + + @param reply reference to the network reply + @type QNetworkReply """ - reply = self.sender() if reply.error() == QNetworkReply.NoError: result = json.loads(str(reply.readAll(), "utf-8")) if result["response_code"] == 0:
--- a/WebBrowser/WebBrowserWebSearchWidget.py Wed Feb 07 18:57:46 2018 +0100 +++ b/WebBrowser/WebBrowserWebSearchWidget.py Wed Feb 07 20:14:09 2018 +0100 @@ -248,7 +248,8 @@ engine = self.__openSearchManager.engine(engineName) action = OpenSearchEngineAction(engine, self.__enginesMenu) action.setData(engineName) - action.triggered.connect(self.__changeCurrentEngine) + action.triggered.connect( + lambda: self.__changeCurrentEngine(action)) self.__enginesMenu.addAction(action) if self.__openSearchManager.currentEngineName() == engineName: @@ -280,10 +281,11 @@ title = cb.title() action = self.__enginesMenu.addAction( - self.tr("Add '{0}'").format(title), - self.__addEngineFromUrl) + self.tr("Add '{0}'").format(title)) action.setData(url) action.setIcon(cb.icon()) + action.triggered.connect( + lambda: self.__addEngineFromUrl(action)) self.__enginesMenu.addSeparator() self.__enginesMenu.addAction(self.__mw.searchEnginesAction()) @@ -292,26 +294,28 @@ self.__enginesMenu.addAction(self.tr("Clear Recent Searches"), self.clear) - def __changeCurrentEngine(self): + def __changeCurrentEngine(self, action): """ Private slot to handle the selection of a search engine. + + @param action reference to the action that triggered + @type QAction """ - action = self.sender() - if action is not None: - name = action.data() - self.__openSearchManager.setCurrentEngineName(name) + name = action.data() + self.__openSearchManager.setCurrentEngineName(name) - def __addEngineFromUrl(self): + def __addEngineFromUrl(self, action): """ Private slot to add a search engine given its URL. + + @param action reference to the action that triggered + @type QAction """ - action = self.sender() - if action is not None: - url = action.data() - if not isinstance(url, QUrl): - return - - self.__openSearchManager.addEngine(url) + url = action.data() + if not isinstance(url, QUrl): + return + + self.__openSearchManager.addEngine(url) def __searchButtonClicked(self): """
--- a/WebBrowser/WebBrowserWindow.py Wed Feb 07 18:57:46 2018 +0100 +++ b/WebBrowser/WebBrowserWindow.py Wed Feb 07 20:14:09 2018 +0100 @@ -1914,7 +1914,8 @@ """<p>Shows the tab manager window.</p>""" )) if not self.__initShortcutsOnly: - self.showTabManagerAct.triggered.connect(self.__showTabManager) + self.showTabManagerAct.triggered.connect( + lambda: self.__showTabManager(self.showTabManagerAct)) self.__actions.append(self.showTabManagerAct) self.showSessionsManagerAct = E5Action( @@ -2002,7 +2003,8 @@ if not self.isPrivate(): sessionsMenu = menu.addMenu(self.tr("Sessions")) sessionsMenu.aboutToShow.connect( - self.sessionManager().aboutToShowSessionsMenu) + lambda: self.sessionManager().aboutToShowSessionsMenu( + sessionsMenu)) menu.addAction(self.showSessionsManagerAct) menu.addSeparator() if self.saveAsAct is not None: @@ -2189,7 +2191,8 @@ if not self.isPrivate(): sessionsMenu = self.__superMenu.addMenu(self.tr("Sessions")) sessionsMenu.aboutToShow.connect( - self.sessionManager().aboutToShowSessionsMenu) + lambda: self.sessionManager().aboutToShowSessionsMenu( + sessionsMenu)) self.__superMenu.addAction(self.showSessionsManagerAct) self.__superMenu.addSeparator() @@ -3222,7 +3225,8 @@ self, 'Configuration', True, fromEric=self.__fromEric, displayMode=ConfigurationDialog.WebBrowserMode) dlg.preferencesChanged.connect(self.preferencesChanged) - dlg.masterPasswordChanged.connect(self.masterPasswordChanged) + dlg.masterPasswordChanged.connect( + lambda old, new: self.masterPasswordChanged(old, new, local=True)) dlg.show() if self.__lastConfigurationPageName: dlg.showConfigurationPageByName(self.__lastConfigurationPageName) @@ -3290,16 +3294,20 @@ self.sessionManager().preferencesChanged() - def masterPasswordChanged(self, oldPassword, newPassword): + def masterPasswordChanged(self, oldPassword, newPassword, local=False): """ Public slot to handle the change of the master password. - @param oldPassword current master password (string) - @param newPassword new master password (string) - """ - from Preferences.ConfigurationDialog import ConfigurationDialog + @param oldPassword current master password + @type str + @param newPassword new master password + @type str + @param local flag indicating being called from the local configuration + dialog + @type bool + """ self.passwordManager().masterPasswordChanged(oldPassword, newPassword) - if self.__fromEric and isinstance(self.sender(), ConfigurationDialog): + if self.__fromEric and local: # we were called from our local configuration dialog Preferences.convertPasswords(oldPassword, newPassword) Utilities.crypto.changeRememberedMaster(newPassword) @@ -4071,11 +4079,14 @@ return cls._tabManager - def __showTabManager(self): + def __showTabManager(self, act): """ Private method to show the tab manager window. - """ - self.tabManager().raiseTabManager() + + @param act reference to the act that triggered + @type QAction + """ + self.tabManager().raiseTabManager(act) @classmethod def mainWindow(cls): @@ -4448,20 +4459,23 @@ feedsManager.newBackgroundTab.connect(self.openUrlNewBackgroundTab) feedsManager.newWindow.connect(self.openUrlNewWindow) feedsManager.newPrivateWindow.connect(self.openUrlNewPrivateWindow) - feedsManager.rejected.connect(self.__feedsManagerClosed) + feedsManager.rejected.connect( + lambda fm: self.__feedsManagerClosed(fm)) feedsManager.show() - def __feedsManagerClosed(self): + def __feedsManagerClosed(self, feedsManager): """ Private slot to handle closing the feeds manager dialog. - """ - feedsManager = self.sender() + + @param feedsManager reference to the feeds manager object + @type FeedsManager + """ feedsManager.openUrl.disconnect(self.openUrl) feedsManager.newTab.disconnect(self.openUrlNewTab) feedsManager.newBackgroundTab.disconnect(self.openUrlNewBackgroundTab) feedsManager.newWindow.disconnect(self.openUrlNewWindow) feedsManager.newPrivateWindow.disconnect(self.openUrlNewPrivateWindow) - feedsManager.rejected.disconnect(self.__feedsManagerClosed) + feedsManager.rejected.disconnect() def __showSiteinfoDialog(self): """