Beispiel #1
0
class AdBlockIcon(E5ClickableLabel):
    """
    Class implementing the AdBlock icon for the main window status bar.
    """
    def __init__(self, parent):
        """
        Constructor
        
        @param parent reference to the parent widget (HelpWindow)
        """
        super(AdBlockIcon, self).__init__(parent)

        self.__mw = parent
        self.__menuAction = None
        self.__enabled = False

        self.setMaximumHeight(16)
        self.setCursor(Qt.PointingHandCursor)
        self.setToolTip(
            self.tr("AdBlock lets you block unwanted content on web pages."))

        self.clicked.connect(self.__showMenu)

    def setEnabled(self, enabled):
        """
        Public slot to set the enabled state.
        
        @param enabled enabled state (boolean)
        """
        self.__enabled = enabled
        if enabled:
            self.currentChanged()
        else:
            self.setPixmap(
                UI.PixmapCache.getPixmap("adBlockPlusDisabled16.png"))

    def __createMenu(self, menu=None):
        """
        Private slot to create the context menu.
        
        @param menu parent menu (QMenu)
        """
        if menu is None:
            menu = self.sender()
            if menu is None:
                return

        menu.clear()

        import Helpviewer.HelpWindow
        manager = Helpviewer.HelpWindow.HelpWindow.adBlockManager()

        if manager.isEnabled():
            menu.addAction(UI.PixmapCache.getIcon("adBlockPlusDisabled.png"),
                           self.tr("Disable AdBlock"),
                           self.__enableAdBlock).setData(False)
        else:
            menu.addAction(UI.PixmapCache.getIcon("adBlockPlus.png"),
                           self.tr("Enable AdBlock"),
                           self.__enableAdBlock).setData(True)
        menu.addSeparator()
        if manager.isEnabled() and \
           self.__mw.currentBrowser().page().url().host():
            if self.__isCurrentHostExcepted():
                menu.addAction(UI.PixmapCache.getIcon("adBlockPlus.png"),
                               self.tr("Remove AdBlock Exception"),
                               self.__setException).setData(False)
            else:
                menu.addAction(UI.PixmapCache.getIcon("adBlockPlusGreen.png"),
                               self.tr("Add AdBlock Exception"),
                               self.__setException).setData(True)
        menu.addAction(UI.PixmapCache.getIcon("adBlockPlusGreen.png"),
                       self.tr("AdBlock Exceptions..."),
                       manager.showExceptionsDialog)
        menu.addSeparator()
        menu.addAction(UI.PixmapCache.getIcon("adBlockPlus.png"),
                       self.tr("AdBlock Configuration..."), manager.showDialog)
        menu.addSeparator()

        entries = self.__mw.currentBrowser().page().getAdBlockedPageEntries()
        if entries:
            menu.addAction(self.tr(
                "Blocked URL (AdBlock Rule) - click to edit rule"))\
                .setEnabled(False)
            for entry in entries:
                address = entry.urlString()[-55:]
                actionText = self.tr("{0} with ({1})").format(
                    address, entry.rule.filter()).replace("&", "&&")
                act = menu.addAction(actionText, manager.showRule)
                act.setData(entry.rule)
        else:
            menu.addAction(self.tr("No content blocked")).setEnabled(False)

    def menuAction(self):
        """
        Public method to get a reference to the menu action.
        
        @return reference to the menu action (QAction)
        """
        if not self.__menuAction:
            self.__menuAction = QAction(self.tr("AdBlock"))
            self.__menuAction.setMenu(QMenu())
            self.__menuAction.menu().aboutToShow.connect(self.__createMenu)

        if self.__enabled:
            self.__menuAction.setIcon(
                UI.PixmapCache.getIcon("adBlockPlus.png"))
        else:
            self.__menuAction.setIcon(
                UI.PixmapCache.getIcon("adBlockPlusDisabled.png"))

        return self.__menuAction

    def __showMenu(self, pos):
        """
        Private slot to show the context menu.
        
        @param pos position the context menu should be shown (QPoint)
        """
        menu = QMenu()
        self.__createMenu(menu)
        menu.exec_(pos)

    def __enableAdBlock(self):
        """
        Private slot to enable or disable AdBlock.
        """
        act = self.sender()
        if act is not None:
            import Helpviewer.HelpWindow
            Helpviewer.HelpWindow.HelpWindow.adBlockManager().setEnabled(
                act.data())

    def __isCurrentHostExcepted(self):
        """
        Private method to check, if the host of the current browser is
        excepted.
        
        @return flag indicating an exception (boolean)
        """
        browser = self.__mw.currentBrowser()
        urlHost = browser.page().url().host()

        import Helpviewer.HelpWindow
        return urlHost and \
            Helpviewer.HelpWindow.HelpWindow.adBlockManager()\
            .isHostExcepted(urlHost)

    def currentChanged(self):
        """
        Public slot to handle a change of the current browser tab.
        """
        if self.__enabled:
            if self.__isCurrentHostExcepted():
                self.setPixmap(
                    UI.PixmapCache.getPixmap("adBlockPlusGreen16.png"))
            else:
                self.setPixmap(UI.PixmapCache.getPixmap("adBlockPlus16.png"))

    def __setException(self):
        """
        Private slot to add or remove the current host from the list of
        exceptions.
        """
        act = self.sender()
        if act is not None:
            import Helpviewer.HelpWindow
            urlHost = self.__mw.currentBrowser().page().url().host()
            if act.data():
                Helpviewer.HelpWindow.HelpWindow.adBlockManager()\
                    .addException(urlHost)
            else:
                Helpviewer.HelpWindow.HelpWindow.adBlockManager()\
                    .removeException(urlHost)
            self.currentChanged()

    def sourceChanged(self, browser, url):
        """
        Public slot to handle URL changes.
        
        @param browser reference to the browser (HelpBrowser)
        @param url new URL (QUrl)
        """
        if browser == self.__mw.currentBrowser():
            self.currentChanged()
class MyToolBarClass(QToolBar):

    signal_for_mainwindow = QtCore.pyqtSignal(str)

    def __init__(self):
        super().__init__()
        print(self)

        self.setOrientation(QtCore.Qt.Vertical)

        # self.open_action = QAction(QtGui.QIcon(), "TEST")

        # self.addAction(self.open_action)
        # self.addAction(QtGui.QIcon(), "TEST2")

        # font = QtGui.QFont()
        # font.setPointSize(30)
        # self.setFont(font)

        # self.setStyleSheet("""
        #                           QPushButton{
        #                               padding: 6px;
        #                               font-size: 22px;}
        #                     """)

        # self.setStyleSheet("""
        #                        QToolBar {
        #                     background: #eee;
        #                     padding: 0px;
        #                     border: 0px;}
        #
        #                          QAction{
        #                               padding: 6px;
        #                               font-size: 22px;}
        #
        #                         QPushButton{
        #                               padding: 6px;
        #                               font-size: 22px;}
        #
        #                         QToolButton{
        #                         background-color: #59f;
        #                         padding: 10px;}
        #
        #                     """)

        self.file_menu = QMenu('&File')
        self.file_menu_button = QPushButton("File")
        self.addWidget(self.file_menu_button)
        self.file_menu_button.setMenu(self.file_menu)

        self.load_file_action = QAction('Load file')
        self.file_menu.addAction(self.load_file_action)
        self.save_file_action = QAction('Save file')
        self.file_menu.addAction(self.save_file_action)

        # self.load_file_action.triggered.connect(lambda:self.load_file_act())
        # self.save_file_action.triggered.connect(lambda: self.save_file_act())

        self.manage_layout_menu = QMenu('&Manage layout')
        self.manage_layout_button = QPushButton("Manage \n Layout")
        self.addWidget(self.manage_layout_button)
        self.manage_layout_button.setMenu(self.manage_layout_menu)

        self.manage_layout_action_table = QAction('Table',
                                                  checkable=True,
                                                  checked=True)
        self.manage_layout_menu.addAction(self.manage_layout_action_table)
        # self.manage_layout_action_table.triggered.connect(self.manage_layout_checked_action)

        self.manage_layout_action_plot = QAction('Plot',
                                                 checkable=True,
                                                 checked=True)
        self.manage_layout_menu.addAction(self.manage_layout_action_plot)
        # self.manage_layout_action_plot.triggered.connect(self.manage_layout_checked_action)

        self.manage_layout_action_MLWidget = QAction('ML Widget',
                                                     checkable=True,
                                                     checked=True)
        self.manage_layout_menu.addAction(self.manage_layout_action_MLWidget)
        # self.manage_layout_action_MLWidget.triggered.connect(self.manage_layout_checked_action)

        self.manage_layout_action_right_table = QAction('Right Table',
                                                        checkable=True,
                                                        checked=True)
        self.manage_layout_menu.addAction(
            self.manage_layout_action_right_table)
        # self.manage_layout_action_right_table.triggered.connect(self.manage_layout_checked_action)

        self.manage_layout_action_preprocessing_widget = QAction(
            'Preprocessing Widget', checkable=True, checked=True)
        self.manage_layout_menu.addAction(
            self.manage_layout_action_preprocessing_widget)
        # self.manage_layout_action_preprocessing_widget.triggered.connect(self.manage_layout_checked_action)

        # ===============================================================

        self.set_layout_menu = QMenu('&Set layout')

        self.set_layout_button = QPushButton("Choose \n Layout")
        self.addWidget(self.set_layout_button)
        self.set_layout_button.setMenu(self.set_layout_menu)

        self.set_layout_action_data = QAction(QtGui.QIcon('icons/table.png'),
                                              'Data description')
        self.set_layout_menu.addAction(self.set_layout_action_data)

        self.set_layout_action_plot = QAction(QtGui.QIcon('icons/chart.png'),
                                              'Plotting')
        self.set_layout_menu.addAction(self.set_layout_action_plot)

        self.set_layout_action_ML = QAction(QtGui.QIcon('icons/computer.png'),
                                            'Machine Learning')
        self.set_layout_menu.addAction(self.set_layout_action_ML)

        # self.font = self.set_layout_menu.font()
        # self.font.setPointSize(16)
        # self.set_layout_menu.setFont(self.font)

        self.addSeparator()

        self.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)

    def update_tab(self, name):
        print('update tab')
        self.clear_toolbar()

        if name == 'Plotting':

            self.open_action = QAction(QtGui.QIcon(), "Plotting test")
            self.addAction(self.open_action)

        elif name == 'Data description':
            self.clear_table_action = QAction(
                QtGui.QIcon('icons/table--minus.png'), "Clear Table")

            self.description_table_action = QAction(QtGui.QIcon(''),
                                                    "Description Table")

            self.addAction(self.clear_table_action)
            self.addAction(self.description_table_action)

            self.clear_table_action.triggered.connect(self.clear_table_signal)
            self.description_table_action.triggered.connect(
                self.clear_table_signal)

            # print(self.addAction.menu())
            print(self.clear_table_action.menu())

        elif name == "Machine Learning":
            self.open_action = QAction(QtGui.QIcon(), "ML test")
            self.addAction(self.open_action)

    def clear_toolbar(self):
        to_delete = False
        for action in self.actions():
            if to_delete:
                self.removeAction(action)
            if action.isSeparator():
                to_delete = True

    def clear_table_signal(self):
        print('ct signal')
        sender_text = self.sender().text()
        print(self.sender())
        print(sender_text)
        self.signal_for_mainwindow.emit(sender_text)
Beispiel #3
0
class AdBlockIcon(E5ClickableLabel):
    """
    Class implementing the AdBlock icon for the main window status bar.
    """
    def __init__(self, parent):
        """
        Constructor
        
        @param parent reference to the parent widget (HelpWindow)
        """
        super(AdBlockIcon, self).__init__(parent)
        
        self.__mw = parent
        self.__menuAction = None
        self.__enabled = False
        
        self.setMaximumHeight(16)
        self.setCursor(Qt.PointingHandCursor)
        self.setToolTip(self.tr(
            "AdBlock lets you block unwanted content on web pages."))
        
        self.clicked.connect(self.__showMenu)
    
    def setEnabled(self, enabled):
        """
        Public slot to set the enabled state.
        
        @param enabled enabled state (boolean)
        """
        self.__enabled = enabled
        if enabled:
            self.currentChanged()
        else:
            self.setPixmap(
                UI.PixmapCache.getPixmap("adBlockPlusDisabled16.png"))
    
    def __createMenu(self, menu=None):
        """
        Private slot to create the context menu.
        
        @param menu parent menu (QMenu)
        """
        if menu is None:
            menu = self.sender()
            if menu is None:
                return
        
        menu.clear()
        
        import Helpviewer.HelpWindow
        manager = Helpviewer.HelpWindow.HelpWindow.adBlockManager()
        
        if manager.isEnabled():
            menu.addAction(
                UI.PixmapCache.getIcon("adBlockPlusDisabled.png"),
                self.tr("Disable AdBlock"),
                self.__enableAdBlock).setData(False)
        else:
            menu.addAction(
                UI.PixmapCache.getIcon("adBlockPlus.png"),
                self.tr("Enable AdBlock"),
                self.__enableAdBlock).setData(True)
        menu.addSeparator()
        if manager.isEnabled() and \
           self.__mw.currentBrowser().page().url().host():
            if self.__isCurrentHostExcepted():
                menu.addAction(
                    UI.PixmapCache.getIcon("adBlockPlus.png"),
                    self.tr("Remove AdBlock Exception"),
                    self.__setException).setData(False)
            else:
                menu.addAction(
                    UI.PixmapCache.getIcon("adBlockPlusGreen.png"),
                    self.tr("Add AdBlock Exception"),
                    self.__setException).setData(True)
        menu.addAction(
            UI.PixmapCache.getIcon("adBlockPlusGreen.png"),
            self.tr("AdBlock Exceptions..."), manager.showExceptionsDialog)
        menu.addSeparator()
        menu.addAction(
            UI.PixmapCache.getIcon("adBlockPlus.png"),
            self.tr("AdBlock Configuration..."), manager.showDialog)
        menu.addSeparator()
        
        entries = self.__mw.currentBrowser().page().getAdBlockedPageEntries()
        if entries:
            menu.addAction(self.tr(
                "Blocked URL (AdBlock Rule) - click to edit rule"))\
                .setEnabled(False)
            for entry in entries:
                address = entry.urlString()[-55:]
                actionText = self.tr("{0} with ({1})").format(
                    address, entry.rule.filter()).replace("&", "&&")
                act = menu.addAction(actionText, manager.showRule)
                act.setData(entry.rule)
        else:
            menu.addAction(self.tr("No content blocked")).setEnabled(False)
    
    def menuAction(self):
        """
        Public method to get a reference to the menu action.
        
        @return reference to the menu action (QAction)
        """
        if not self.__menuAction:
            self.__menuAction = QAction(self.tr("AdBlock"))
            self.__menuAction.setMenu(QMenu())
            self.__menuAction.menu().aboutToShow.connect(self.__createMenu)
        
        if self.__enabled:
            self.__menuAction.setIcon(
                UI.PixmapCache.getIcon("adBlockPlus.png"))
        else:
            self.__menuAction.setIcon(
                UI.PixmapCache.getIcon("adBlockPlusDisabled.png"))
        
        return self.__menuAction
    
    def __showMenu(self, pos):
        """
        Private slot to show the context menu.
        
        @param pos position the context menu should be shown (QPoint)
        """
        menu = QMenu()
        self.__createMenu(menu)
        menu.exec_(pos)
    
    def __enableAdBlock(self):
        """
        Private slot to enable or disable AdBlock.
        """
        act = self.sender()
        if act is not None:
            import Helpviewer.HelpWindow
            Helpviewer.HelpWindow.HelpWindow.adBlockManager().setEnabled(
                act.data())
    
    def __isCurrentHostExcepted(self):
        """
        Private method to check, if the host of the current browser is
        excepted.
        
        @return flag indicating an exception (boolean)
        """
        browser = self.__mw.currentBrowser()
        urlHost = browser.page().url().host()
        
        import Helpviewer.HelpWindow
        return urlHost and \
            Helpviewer.HelpWindow.HelpWindow.adBlockManager()\
            .isHostExcepted(urlHost)
    
    def currentChanged(self):
        """
        Public slot to handle a change of the current browser tab.
        """
        if self.__enabled:
            if self.__isCurrentHostExcepted():
                self.setPixmap(
                    UI.PixmapCache.getPixmap("adBlockPlusGreen16.png"))
            else:
                self.setPixmap(UI.PixmapCache.getPixmap("adBlockPlus16.png"))
    
    def __setException(self):
        """
        Private slot to add or remove the current host from the list of
        exceptions.
        """
        act = self.sender()
        if act is not None:
            import Helpviewer.HelpWindow
            urlHost = self.__mw.currentBrowser().page().url().host()
            if act.data():
                Helpviewer.HelpWindow.HelpWindow.adBlockManager()\
                    .addException(urlHost)
            else:
                Helpviewer.HelpWindow.HelpWindow.adBlockManager()\
                    .removeException(urlHost)
            self.currentChanged()
    
    def sourceChanged(self, browser, url):
        """
        Public slot to handle URL changes.
        
        @param browser reference to the browser (HelpBrowser)
        @param url new URL (QUrl)
        """
        if browser == self.__mw.currentBrowser():
            self.currentChanged()
Beispiel #4
0
class AdBlockIcon(E5ClickableLabel):
    """
    Class implementing the AdBlock icon for the main window status bar.
    """
    def __init__(self, parent):
        """
        Constructor
        
        @param parent reference to the parent widget
        @type WebBrowserWindow
        """
        super(AdBlockIcon, self).__init__(parent)

        self.__mw = parent
        self.__menuAction = None
        self.__enabled = False

        self.setMaximumHeight(16)
        self.setCursor(Qt.PointingHandCursor)
        self.setToolTip(
            self.tr("AdBlock lets you block unwanted content on web pages."))

        self.clicked.connect(self.__showMenu)

    def setEnabled(self, enabled):
        """
        Public slot to set the enabled state.
        
        @param enabled enabled state
        @type bool
        """
        self.__enabled = enabled
        if enabled:
            self.currentChanged()
        else:
            self.setPixmap(
                UI.PixmapCache.getPixmap("adBlockPlusDisabled16.png"))

    def __createMenu(self, menu):
        """
        Private slot to create the context menu.
        
        @param menu parent menu
        @type QMenu
        """
        menu.clear()

        manager = self.__mw.adBlockManager()

        if manager.isEnabled():
            act = menu.addAction(
                UI.PixmapCache.getIcon("adBlockPlusDisabled.png"),
                self.tr("Disable AdBlock"))
            act.setData(False)
            act.triggered.connect(lambda: self.__enableAdBlock(act))
        else:
            act = menu.addAction(UI.PixmapCache.getIcon("adBlockPlus.png"),
                                 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():
                act = menu.addAction(UI.PixmapCache.getIcon("adBlockPlus.png"),
                                     self.tr("Remove AdBlock Exception"))
                act.setData(False)
                act.triggered.connect(lambda: self.__setException(act))
            else:
                act = menu.addAction(
                    UI.PixmapCache.getIcon("adBlockPlusGreen.png"),
                    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)
        menu.addSeparator()
        menu.addAction(UI.PixmapCache.getIcon("adBlockPlus.png"),
                       self.tr("AdBlock Configuration..."), manager.showDialog)

    def menuAction(self):
        """
        Public method to get a reference to the menu action.
        
        @return reference to the menu action
        @rtype QAction
        """
        if not self.__menuAction:
            self.__menuAction = QAction(self.tr("AdBlock"), self)
            self.__menuAction.setMenu(QMenu())
            self.__menuAction.menu().aboutToShow.connect(
                lambda: self.__createMenu(self.__menuAction.menu()))

        if self.__enabled:
            self.__menuAction.setIcon(
                UI.PixmapCache.getIcon("adBlockPlus.png"))
        else:
            self.__menuAction.setIcon(
                UI.PixmapCache.getIcon("adBlockPlusDisabled.png"))

        return self.__menuAction

    def __showMenu(self, pos):
        """
        Private slot to show the context menu.
        
        @param pos position the context menu should be shown
        @type QPoint
        """
        menu = QMenu()
        self.__createMenu(menu)
        menu.exec_(pos)

    def __enableAdBlock(self, act):
        """
        Private slot to enable or disable AdBlock.
        
        @param act reference to the action
        @type QAction
        """
        self.__mw.adBlockManager().setEnabled(act.data())

    def __isCurrentHostExcepted(self):
        """
        Private method to check, if the host of the current browser is
        excepted.
        
        @return flag indicating an exception
        @rtype bool
        """
        browser = self.__mw.currentBrowser()
        if browser is None:
            return False

        urlHost = browser.page().url().host()

        return (urlHost and self.__mw.adBlockManager().isHostExcepted(urlHost))

    def currentChanged(self):
        """
        Public slot to handle a change of the current browser tab.
        """
        if self.__enabled:
            if self.__isCurrentHostExcepted():
                self.setPixmap(
                    UI.PixmapCache.getPixmap("adBlockPlusGreen16.png"))
            else:
                self.setPixmap(UI.PixmapCache.getPixmap("adBlockPlus16.png"))

    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
        """
        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):
        """
        Public slot to handle URL changes.
        
        @param browser reference to the browser
        @type WebBrowserView
        @param url new URL
        @type QUrl
        """
        if browser == self.__mw.currentBrowser():
            self.currentChanged()