diff -r 18fb5d765f3a -r 4c60a21ce6dd WebBrowser/AdBlock/AdBlockIcon.py --- a/WebBrowser/AdBlock/AdBlockIcon.py Tue Feb 06 19:21:00 2018 +0100 +++ b/WebBrowser/AdBlock/AdBlockIcon.py Wed Feb 07 18:57:46 2018 +0100 @@ -55,44 +55,43 @@ self.setPixmap( UI.PixmapCache.getPixmap("adBlockPlusDisabled16.png")) - def __createMenu(self, menu=None): + def __createMenu(self, menu): """ Private slot to create the context menu. @param menu parent menu @type QMenu """ - if menu is None: - menu = self.sender() - if menu is None: - return - menu.clear() manager = self.__mw.adBlockManager() if manager.isEnabled(): - menu.addAction( + act = menu.addAction( UI.PixmapCache.getIcon("adBlockPlusDisabled.png"), - self.tr("Disable AdBlock"), - self.__enableAdBlock).setData(False) + self.tr("Disable AdBlock")) + act.setData(False) + act.triggered.connect(lambda: self.__enableAdBlock(act)) else: - menu.addAction( + act = menu.addAction( UI.PixmapCache.getIcon("adBlockPlus.png"), - self.tr("Enable AdBlock"), - self.__enableAdBlock).setData(True) + self.tr("Enable AdBlock")) + act.setData(True) + act.triggered.connect(lambda: self.__enableAdBlock(act)) menu.addSeparator() if manager.isEnabled() and self.__mw.currentBrowser().url().host(): if self.__isCurrentHostExcepted(): - menu.addAction( + act = menu.addAction( UI.PixmapCache.getIcon("adBlockPlus.png"), - self.tr("Remove AdBlock Exception"), - self.__setException).setData(False) + self.tr("Remove AdBlock Exception")) + act.setData(False) + act.triggered.connect(lambda: self.__setException(act)) else: - menu.addAction( + act = menu.addAction( UI.PixmapCache.getIcon("adBlockPlusGreen.png"), - self.tr("Add AdBlock Exception"), - self.__setException).setData(True) + self.tr("Add AdBlock Exception")) + act.setData(True) + act.triggered.connect(lambda: self.__setException(act)) menu.addAction( UI.PixmapCache.getIcon("adBlockPlusGreen.png"), self.tr("AdBlock Exceptions..."), manager.showExceptionsDialog) @@ -111,7 +110,8 @@ if not self.__menuAction: self.__menuAction = QAction(self.tr("AdBlock"), self) self.__menuAction.setMenu(QMenu()) - self.__menuAction.menu().aboutToShow.connect(self.__createMenu) + self.__menuAction.menu().aboutToShow.connect( + lambda: self.__createMenu(self.__menuAction.menu())) if self.__enabled: self.__menuAction.setIcon( @@ -133,13 +133,14 @@ self.__createMenu(menu) menu.exec_(pos) - def __enableAdBlock(self): + def __enableAdBlock(self, act): """ Private slot to enable or disable AdBlock. + + @param act reference to the action + @type QAction """ - act = self.sender() - if act is not None: - self.__mw.adBlockManager().setEnabled(act.data()) + self.__mw.adBlockManager().setEnabled(act.data()) def __isCurrentHostExcepted(self): """ @@ -169,19 +170,20 @@ else: self.setPixmap(UI.PixmapCache.getPixmap("adBlockPlus16.png")) - def __setException(self): + def __setException(self, act): """ Private slot to add or remove the current host from the list of exceptions. + + @param act referenced to the action + @type QAction """ - act = self.sender() - if act is not None: - urlHost = self.__mw.currentBrowser().url().host() - if act.data(): - self.__mw.adBlockManager().addException(urlHost) - else: - self.__mw.adBlockManager().removeException(urlHost) - self.currentChanged() + urlHost = self.__mw.currentBrowser().url().host() + if act.data(): + self.__mw.adBlockManager().addException(urlHost) + else: + self.__mw.adBlockManager().removeException(urlHost) + self.currentChanged() def sourceChanged(self, browser, url): """