コード例 #1
0
    def generateNodeSearchActions(self, txt, menu, mousemenu):

        # user query
        txt = txt.lower()

        # NODE SEARCH
        # search using txt string
        sortedMods = []
        if len(txt) > 2:  # match anywhere in name
            for node in list(self._known_GPI_nodes.values()):
                if node.name.lower().find(txt) > -1:
                    sortedMods.append(node)
        else:  # only match from start of name
            for node in list(self._known_GPI_nodes.values()):
                if node.name.lower().startswith(txt):
                    sortedMods.append(node)
        sortedMods = sorted(sortedMods, key=lambda x: x.name.lower())

        # create actions and add them to the menu
        for node in sortedMods:

            a = QtWidgets.QAction(node.name+" (" + node.thrd_sec + ")", self._parent, statusTip="Click to instantiate the \'"+str(node.name)+"\' node.")
            s = {'subsig': node}

            # The way this signal is connected, the
            # s-dict is fully copied which is required to pass the correct
            # mod name.
            a.triggered.connect(partial(self.addNodeAndCloseMouseMenu,
                                        s=s, searchmenu=menu,
                                        mousemenu=mousemenu))
            menu.addAction(a)


        # NETWORK SEARCH
        # search using txt string
        if True:
            sortedMods= []
            if len(txt) > 2:
                for net in list(self._known_GPI_networks.values()):
                    if net.name.lower().find(txt) > -1:
                        sortedMods.append(net)

            else:
                for net in list(self._known_GPI_networks.values()):
                    if net.name.lower().startswith(txt):
                        sortedMods.append(net)
            sortedMods = sorted(sortedMods, key=lambda x: x.name.lower())

            if len(sortedMods):
                menu.addSeparator()

            # create actions and add them to the menu
            for net in sortedMods:
                a = QtWidgets.QAction(net.name+" (net) (" + net.thrd_sec + ")", self._parent, statusTip="Click to instantiate the \'"+str(net.name)+"\' network.")
                s = {'sig': 'load', 'subsig': 'net', 'path': net.fullpath}
                a.triggered.connect(partial(self.addNodeAndCloseMouseMenu,
                                            s=s, searchmenu=menu,
                                            mousemenu=mousemenu))
                menu.addAction(a)
コード例 #2
0
    def generateLibMenus(self):
        # default menu if no libraries are found
        numnodes = len(list(self._known_GPI_nodes.keys()))
        if numnodes == 0:
            self._lib_menus['No Nodes Found'] = QtWidgets.QMenu('No Nodes Found')
            buf = 'Check your ~/.gpirc for the correct LIB_DIRS.'
            act = QtWidgets.QAction(buf, self._parent, triggered = self.openLIBDIRSHelp)
            self._lib_menus['No Nodes Found'].addAction(act)

            for m in sorted(list(self._lib_menus.keys()), key=lambda x: x.lower()):
                mm = self._lib_menus[m]
                mm.setTearOffEnabled(False)
                self._lib_menu.append(mm)

            return

        # NODE MENU
        # setup libs using node id. ex: core.mathematics.sum
        # the ids of
        for k in sorted(self._known_GPI_nodes.keys(), key=lambda x: x.lower()):
            node = self._known_GPI_nodes.get(k)
            if node.third not in self._lib_menus:
                #self._lib_menus[node.third] = QtWidgets.QMenu(node.third.capitalize())
                self._lib_menus[node.third] = QtWidgets.QMenu(node.third)
                self._lib_menus[node.third].setTearOffEnabled(True)

            if node.thrd_sec not in self._lib_second:
                self._lib_second[node.thrd_sec] = QtWidgets.QMenu(node.second)
                self._lib_second[node.thrd_sec].setTearOffEnabled(True)
                ma = self._lib_menus[node.third].addMenu(self._lib_second[node.thrd_sec])

            sm = self._lib_second[node.thrd_sec]

            # TODO: try setting up hotkeys/shortcuts for specific nodes
            a = QtWidgets.QAction(node.name, self._parent, statusTip="Click to instantiate the \'"+str(node.name)+"\' node.")
            s = {'subsig': node}
            a.triggered.connect(partial(self._parent.addNodeRun, sig=s))
            sm.addAction(a)

        # NETWORK MENU
        for sm in list(self._lib_second.values()):
            sm.addSeparator()

        for k in sorted(list(self._known_GPI_networks.keys()), key=lambda x: x.lower()):
            net = self._known_GPI_networks.get(k)
            if net.third not in self._lib_menus:
                #self._lib_menus[net.third] = QtWidgets.QMenu(net.third.capitalize())
                self._lib_menus[net.third] = QtWidgets.QMenu(net.third)
                self._lib_menus[net.third].setTearOffEnabled(True)

            if net.thrd_sec not in self._lib_second:
                self._lib_second[net.thrd_sec] = QtWidgets.QMenu(net.second)
                self._lib_second[net.thrd_sec].setTearOffEnabled(True)
                self._lib_menus[net.third].addMenu(self._lib_second[node.thrd_sec])

            sm = self._lib_second[net.thrd_sec]
            a = QtWidgets.QAction(net.name + ' (net)', self._parent, statusTip="Click to instantiate the \'"+str(net.name)+"\' network.")
            s = {'sig': 'load', 'subsig': 'net', 'path': net.fullpath}
            a.triggered.connect(partial(self._parent.addNodeRun, sig=s))
            sm.addAction(a)

        for m in sorted(list(self._lib_menus.keys()), key=lambda x: x.lower()):
            mm = self._lib_menus[m]
            mm.setTearOffEnabled(True)
            self._lib_menu.append(mm)
コード例 #3
0
ファイル: mainWindow.py プロジェクト: schudds/framework
    def createMenus(self):

        # STYLE
        #self.styleMenu = QtWidgets.QMenu("&Style", self)
        #ag = QtWidgets.QActionGroup(self.styleMenu, exclusive=True)
        #for s in QtWidgets.QStyleFactory.keys():  # get menu items based on keys
        #    a = ag.addAction(QtWidgets.QAction(s, self.styleMenu, checkable=True))
        #    self.styleMenu.addAction(a)
        #ag.selected.connect(self.changeStyle)
        #self.menuBar().addMenu(self.styleMenu)

        # FILE
        self.fileMenu = QtWidgets.QMenu("&File", self)
        fileMenu_newTab = QtWidgets.QAction("New Tab",
                                            self,
                                            shortcut="Ctrl+T",
                                            triggered=self.addNewCanvasTab)
        self.fileMenu.addAction(fileMenu_newTab)
        self.fileMenu.addAction("Create New Node", self.createNewNode)
        self.menuBar().addMenu(self.fileMenu)

        # CONFIG
        self.configMenu = QtWidgets.QMenu("&Config", self)
        self.configMenu.addAction(
            "Generate Config File (" + str(Config.configFilePath()) + ")",
            self.generateConfigFile)
        self.configMenu.addAction(
            "Generate User Library (" + str(Config.userLibPath()) + ")",
            self.generateUserLib)
        self.configMenu.addAction("Scan For New Nodes", self.rescanKnownLibs)

        #self.configMenu.addAction("Rescan Config File (" +
        #                          str(Config.configFilePath()) + ")",
        #                          Config.loadConfigFile)
        self.menuBar().addMenu(self.configMenu)

        # DEBUG
        self.debugMenu = QtWidgets.QMenu("&Debug")
        ag = QtWidgets.QActionGroup(self.debugMenu, exclusive=False)

        ## logger output sub-menu
        self.loggerMenu = self.debugMenu.addMenu("Logger Level")
        self._loglevel_debug_act = QtWidgets.QAction(
            "Debug",
            self,
            checkable=True,
            triggered=lambda: self.setLoggerLevel(logging.DEBUG))
        self._loglevel_info_act = QtWidgets.QAction(
            "Info",
            self,
            checkable=True,
            triggered=lambda: self.setLoggerLevel(logging.INFO))

        self._loglevel_node_act = QtWidgets.QAction(
            "Node",
            self,
            checkable=True,
            triggered=lambda: self.setLoggerLevel(logger.GPINODE))

        self._loglevel_warn_act = QtWidgets.QAction(
            "Warn",
            self,
            checkable=True,
            triggered=lambda: self.setLoggerLevel(logging.WARNING))
        self._loglevel_error_act = QtWidgets.QAction(
            "Error",
            self,
            checkable=True,
            triggered=lambda: self.setLoggerLevel(logging.ERROR))
        self._loglevel_critical_act = QtWidgets.QAction(
            "Critical",
            self,
            checkable=True,
            triggered=lambda: self.setLoggerLevel(logging.CRITICAL))
        self.loggerMenuGroup = QtWidgets.QActionGroup(self)
        self.loggerMenuGroup.addAction(self._loglevel_debug_act)
        self.loggerMenuGroup.addAction(self._loglevel_info_act)
        self.loggerMenuGroup.addAction(self._loglevel_node_act)
        self.loggerMenuGroup.addAction(self._loglevel_warn_act)
        self.loggerMenuGroup.addAction(self._loglevel_error_act)
        self.loggerMenuGroup.addAction(self._loglevel_critical_act)
        self.loggerMenu.addAction(self._loglevel_debug_act)
        self.loggerMenu.addAction(self._loglevel_info_act)
        self.loggerMenu.addAction(self._loglevel_node_act)
        self.loggerMenu.addAction(self._loglevel_warn_act)
        self.loggerMenu.addAction(self._loglevel_error_act)
        self.loggerMenu.addAction(self._loglevel_critical_act)

        # initialize the log level -default
        if Commands.logLevel():
            #self._loglevel_warn_act.setChecked(True)
            self.setLoggerLevel(Commands.logLevel())
            self.setLoggerLevelMenuCheckbox(Commands.logLevel())
        else:
            self._loglevel_warn_act.setChecked(True)
            self.setLoggerLevel(logging.WARNING)

        # console submenu
        #a = ag.addAction(QtWidgets.QAction("Console", self.debugMenu,
        #        checkable=False))
        #a.triggered.connect(self.console)
        #self.debugMenu.addAction(a)

        #a = ag.addAction(QtWidgets.QAction("Debug Info", self.debugMenu, checkable=True))
        #self.debugMenu.addAction(a)
        #ag.selected.connect(self.debugOptions)

        # DEBUG
        self.debugMenu.addAction("Print sys.paths", self.printSysPath)
        self.debugMenu.addAction("Print sys.modules", self.printSysModules)
        self.menuBar().addMenu(self.debugMenu)

        # WINDOW
        self.windowMenu = QtWidgets.QMenu("Window", self)
        self.windowMenu_closeAct = QtWidgets.QAction(
            "Close Node Menus (Current Tab)",
            self,
            shortcut="Ctrl+X",
            triggered=self.closeAllNodeMenus)
        self.windowMenu.addAction(self.windowMenu_closeAct)
        self.menuBar().addMenu(self.windowMenu)

        # HELP
        self.helpMenu = QtWidgets.QMenu("&Help", self)
        aboutAction = self.helpMenu.addAction("&About")
        aboutAction.triggered.connect(self.about)
        self.checkForUpdate = QtWidgets.QAction("Check For Updates...",
                                                self,
                                                triggered=self.openUpdater)
        self.checkForUpdate.setMenuRole(
            QtWidgets.QAction.ApplicationSpecificRole)
        self.helpMenu.addAction(self.checkForUpdate)
        self.helpMenu_openDocs = QtWidgets.QAction("Documentation",
                                                   self,
                                                   triggered=self.openWebsite)
        self.helpMenu.addAction(self.helpMenu_openDocs)
        self.helpMenu_openDocs = QtWidgets.QAction(
            "Examples", self, triggered=self.openExamplesFolder)
        self.helpMenu.addAction(self.helpMenu_openDocs)
        self.menuBar().addMenu(self.helpMenu)