def __createInspectorActionGroup(self, parent): """ Creates an action group with 'set inspector' actions for all installed inspector. """ actionGroup = QtWidgets.QActionGroup(parent) actionGroup.setExclusive(True) sortedItems = sorted(self.argosApplication.inspectorRegistry.items, key=lambda item: item.identifier) shortCutNr = 1 for item in sortedItems: logger.debug("item: {}".format(item.identifier)) setAndDrawFn = partial(self.setAndDrawInspectorById, item.identifier) action = QtWidgets.QAction(item.name, self, triggered=setAndDrawFn, checkable=True) action.setData(item.identifier) if shortCutNr <= 9 and "debug" not in item.identifier: # TODO: make configurable by the user action.setShortcut( QtGui.QKeySequence("Ctrl+{}".format(shortCutNr))) shortCutNr += 1 actionGroup.addAction(action) return actionGroup
def __createInspectorActionGroup(self, parent): """ Creates an action group with 'set inspector' actions for all installed inspector. """ actionGroup = QtWidgets.QActionGroup(parent) actionGroup.setExclusive(True) for item in self.argosApplication.inspectorRegistry.items: logger.debug("__createInspectorActionGroup item: {} {}".format(item.identifier, item._data)) setAndDrawFn = partial(self.setAndDrawInspectorById, item.identifier) action = QtWidgets.QAction(item.name, self, triggered=setAndDrawFn, checkable=True) action.setData(item.identifier) if item.shortCut: try: keySeq = QtGui.QKeySequence(item.shortCut.strip()) except Exception as ex: logger.warning("Unable to create short cut from: '{}".format(item.shortCut)) else: action.setShortcut(QtGui.QKeySequence(keySeq)) actionGroup.addAction(action) return actionGroup
def __setupMenus(self): """ Sets up the main menu. """ if True: # Don't use self.menuBar(), on OS-X this is not shared across windows. # See: http://qt-project.org/doc/qt-4.8/qmenubar.html#details # And:http://qt-project.org/doc/qt-4.8/qmainwindow.html#menuBar menuBar = QtWidgets.QMenuBar() # Make a menu without parent. self.setMenuBar(menuBar) else: menuBar = self.menuBar() ### File Menu ### fileMenu = menuBar.addMenu("&File") fileMenu.addAction("&New Window", self.cloneWindow, QtGui.QKeySequence("Ctrl+N")) fileMenu.addAction("Close &Window", self.close, QtGui.QKeySequence.Close) fileMenu.addSeparator() action = fileMenu.addAction("Browse Directory...", lambda: self.openFiles(fileMode = QtWidgets.QFileDialog.Directory)) action.setShortcut(QtGui.QKeySequence("Ctrl+B")) action = fileMenu.addAction("&Open Files...", lambda: self.openFiles(fileMode = QtWidgets.QFileDialog.ExistingFiles)) action.setShortcut(QtGui.QKeySequence("Ctrl+O")) self.openAsMenu = fileMenu.addMenu("Open As") self.openAsMenu.aboutToShow.connect(self._repopulateOpenAsMenu) self.openRecentMenu = fileMenu.addMenu("Open Recent") self.openRecentMenu.aboutToShow.connect(self._repopulateOpenRecentMenu) fileMenu.addSeparator() fileMenu.addSeparator() fileMenu.addAction("E&xit", self.argosApplication.quit, 'Ctrl+Q') ### View Menu ### self.viewMenu = menuBar.addMenu("&View") self.inspectorActionGroup = self.__createInspectorActionGroup(self) for action in self.inspectorActionGroup.actions(): self.viewMenu.addAction(action) self.viewMenu.addSeparator() self.panelsMenu = self.viewMenu.addMenu("&Panels") self.tableHeadersMenu = self.viewMenu.addMenu("&Table Headers") ### Config Menu ### self.configMenu = menuBar.addMenu("Configure") app = self.argosApplication action = self.configMenu.addAction("&File Format Plugins...", lambda: self.execPluginsDialog("File Formats", app.rtiRegistry)) if DEBUGGING: action.setShortcut(QtGui.QKeySequence("Ctrl+P")) action = self.configMenu.addAction("&Inspector Plugins...", lambda: self.execPluginsDialog("Inspectors", app.inspectorRegistry)) # if DEBUGGING: # action.setShortcut(QtGui.QKeySequence("Ctrl+P")) self.configMenu.addSeparator() self.configMenu.addAction( "Show Config Files...", lambda: self.openInExternalApp(argosConfigDirectory())) ### Window Menu ### self.windowMenu = menuBar.addMenu("&Window") # The action added to the menu in the repopulateWindowMenu method, which is called by # the ArgosApplication object every time a window is added or removed. self.activateWindowAction = QtWidgets.QAction( "Window #{}".format(self.windowNumber), self, triggered=self.activateAndRaise, checkable=True) if self.windowNumber <= 9: self.activateWindowAction.setShortcut(QtGui.QKeySequence( "Alt+{}".format(self.windowNumber))) ### Help Menu ### menuBar.addSeparator() helpMenu = menuBar.addMenu("&Help") helpMenu.addAction( "&Online Documentation...", lambda: self.openInWebBrowser("https://github.com/titusjan/argos#argos")) helpMenu.addSeparator() helpMenu.addAction( "Show Log Files...", lambda: self.openInExternalApp(argosLogDirectory())) helpMenu.addAction('&About...', self.about) if TESTING or DEBUGGING: helpMenu.addSeparator() helpMenu.addAction("&My Test", self.myTest, "Meta+T") helpMenu.addAction("&Test Walk Current", self.testWalkCurrentNode, "Meta+W") helpMenu.addAction("&Extensive Test Walk", self.testWalk, "Meta+E") helpMenu.addAction("Add Test Data", self.addTestData, "Meta+A")
def __setupMenus(self): """ Sets up the main menu. """ if True: # Don't use self.menuBar(), on OS-X this is not shared across windows. # See: http://qt-project.org/doc/qt-4.8/qmenubar.html#details # And:http://qt-project.org/doc/qt-4.8/qmainwindow.html#menuBar menuBar = QtWidgets.QMenuBar() # Make a menu without parent. self.setMenuBar(menuBar) else: menuBar = self.menuBar() ### File Menu ### fileMenu = menuBar.addMenu("&File") fileMenu.addAction("&New Window", self.cloneWindow, QtGui.QKeySequence("Ctrl+N")) fileMenu.addAction("Close &Window", self.close, QtGui.QKeySequence.Close) fileMenu.addSeparator() action = fileMenu.addAction( "Browse Directory...", lambda: self.openFiles(fileMode=QtWidgets.QFileDialog.Directory)) action.setShortcut(QtGui.QKeySequence("Ctrl+B")) action = fileMenu.addAction( "&Open Files...", lambda: self.openFiles( fileMode=QtWidgets.QFileDialog.ExistingFiles)) action.setShortcut(QtGui.QKeySequence("Ctrl+O")) openAsMenu = fileMenu.addMenu("Open As") for rtiRegItem in self.argosApplication.rtiRegistry.items: #rtiRegItem.tryImportClass() def createTrigger(): "Function to create a closure with the regItem" _rtiRegItem = rtiRegItem # keep reference in closure return lambda: self.openFiles( rtiRegItem=_rtiRegItem, fileMode=QtWidgets.QFileDialog.ExistingFiles, caption="Open {}".format(_rtiRegItem.name)) action = QtWidgets.QAction( "{}...".format(rtiRegItem.name), self, enabled= True, # Since this is only executed at start-up, it must be static #enabled=bool(rtiRegItem.successfullyImported), # TODO: make this work? triggered=createTrigger()) openAsMenu.addAction(action) fileMenu.addSeparator() # for action in self.repoWidget.repoTreeView.topLevelItemActionGroup.actions(): # fileMenu.addAction(action) # # for action in self.repoWidget.repoTreeView.currentItemActionGroup.actions(): # fileMenu.addAction(action) fileMenu.addSeparator() fileMenu.addAction("E&xit", self.argosApplication.closeAllWindows, QtGui.QKeySequence.Quit) ### View Menu ### self.viewMenu = menuBar.addMenu("&View") action = self.viewMenu.addAction("Installed &Plugins...", self.execPluginsDialog) action.setShortcut(QtGui.QKeySequence("Ctrl+P")) self.viewMenu.addSeparator() ### Inspector Menu ### self.execInspectorDialogAction = QtWidgets.QAction( "&Browse Inspectors...", self, triggered=self.execInspectorDialog) self.execInspectorDialogAction.setShortcut( QtGui.QKeySequence("Ctrl+i")) self.inspectorActionGroup = self.__createInspectorActionGroup(self) self.inspectorMenu = menuBar.addMenu("Inspector") addInspectorActionsToMenu(self.inspectorMenu, self.execInspectorDialogAction, self.inspectorActionGroup) ### Window Menu ### self.windowMenu = menuBar.addMenu("&Window") # The action added to the menu in the repopulateWindowMenu method, which is called by # the ArgosApplication object every time a window is added or removed. self.activateWindowAction = QtWidgets.QAction( "Window #{}".format(self.windowNumber), self, triggered=self.activateAndRaise, checkable=True) if self.windowNumber <= 9: self.activateWindowAction.setShortcut( QtGui.QKeySequence("Alt+{}".format(self.windowNumber))) ### Help Menu ### menuBar.addSeparator() helpMenu = menuBar.addMenu("&Help") helpMenu.addAction('&About...', self.about) if DEBUGGING: helpMenu.addSeparator() helpMenu.addAction("&Test", self.myTest, "Alt+T") helpMenu.addAction("Add Test Data", self.addTestData, "Alt+A") ### Context menu ### # Note that the dock-widgets have a Qt.PreventContextMenu context menu policy. # Therefor the context menu is only shown in the center widget. self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.showContextMenu)