def __init__(self, graph, destPort, sourcePort): super(EdgeTracer, self).__init__() # show a faux copy of the delete menu menu = QtWidgets.QMenu() menu.addAction("Delete") # position of pipe end based on port type bindout_y = 5 bindin_y = -1 p1 = self.mapFromItem(sourcePort, 3.5, bindin_y) p2 = self.mapFromItem(destPort, 3.5, bindout_y) pos = graph.mapToGlobal(graph.mapFromScene((p1 - p2) / 2 + p2)) # render the menu without executing it try: # PyQt4 menupixmap = QtGui.QPixmap().grabWidget(menu) except AttributeError: menupixmap = menu.grab() # QtGui.QPixmap().grabWidget(menu) # round edges #mask = menupixmap.createMaskFromColor(QtGui.QColor(255, 255, 255), QtCore.Qt.MaskOutColor) #p = QtGui.QPainter(menupixmap) #p.setRenderHint(QtGui.QPainter.Antialiasing) #p.drawRoundedRect(0,0,menupixmap.width(),menupixmap.height(), 5,5) #p.drawPixmap(menupixmap.rect(), mask, mask.rect()) #p.end() # display the menu image (as a dummy menu as its being built) # TODO: this could probably be moved to the FauxMenu self._tracer = QtWidgets.QLabel() self._tracer.setWindowFlags(QtCore.Qt.Tool | QtCore.Qt.FramelessWindowHint) self._tracer.move(pos) self._tracer.setPixmap(menupixmap) self._tracer.show() self._tracer.raise_() # draw a faux selected line line = QtCore.QLineF(p1, p2) self.setPen( QtGui.QPen(QtGui.QColor(QtCore.Qt.red), 2, QtCore.Qt.DashLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)) self.setLine(line) self.setZValue(0) # cleanup both menu item and line by removing from scene (parent). self._timer = QtCore.QTimer() self._timer.singleShot(300, lambda: graph.scene().removeItem(self))
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)
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)