Example #1
0
    def __add_action(self,
                     texts: Sequence[str],
                     handler: IntentHandler = None,
                     icon: ResourceIcon = None,
                     shortcut: int = None,
                     toolbar: QGroupBox = None):
        """
        Adds an action to the menu.
        
        :param texts:           Path to menu item 
        :param handler:      Action to perform 
        :param icon:            Menu icon
        :param shortcut:        Shortcut key
        :param toolbar:         Toolbar to a shortcut button to
        """
        menu = self.__add_menu(texts[:-1])
        final = texts[-1]

        if final == "-":
            menu.addSeparator()

            if toolbar:
                lay: QHBoxLayout = toolbar.layout()
                fra = QFrame()
                fra.setMinimumWidth(16)
                fra.setFrameShape(QFrame.VLine)
                fra.setFrameShadow(QFrame.Sunken)
                lay.addWidget(fra)
            return
        elif final == "r":
            self.__add_recent(menu)
            return

        action = QAction()
        text = texts[-1]
        if "&" not in text:
            text = "&" + text
        action.setText(text)

        if handler is not None:
            if icon is None and handler.icon is not None:
                action.setIcon(handler.icon.icon())

            exec_ = _ActEnact(self.gui_actions, handler)
            action.triggered[bool].connect(exec_.execute)
            self.keep_alive.append(exec_)
            action.TAG_visualiser = handler

        if icon is not None:
            action.setIcon(icon.icon())

        if shortcut is not None:
            action.setShortcut(QKeySequence(shortcut))
            self.frm_main.addAction(action)

        self.keep_alive.append(action)
        menu.addAction(action)

        if toolbar:
            lay: QHBoxLayout = toolbar.layout()
            btn = self.__make_button()
            btn.setDefaultAction(action)
            lay.addWidget(btn)