--- a/eric7/Project/ProjectSourcesBrowser.py Mon Aug 23 19:30:32 2021 +0200 +++ b/eric7/Project/ProjectSourcesBrowser.py Mon Aug 23 19:42:53 2021 +0200 @@ -14,6 +14,7 @@ from PyQt6.QtWidgets import QDialog, QInputDialog, QMenu from EricWidgets import EricMessageBox +from EricWidgets.EricApplication import ericApp from UI.BrowserModel import ( BrowserFileItem, BrowserClassItem, BrowserMethodItem, @@ -139,6 +140,24 @@ self.tr("Load Diagram..."), self.__loadDiagram) self.graphicsMenu.aboutToShow.connect(self.__showContextMenuGraphics) + self.__startMenu = QMenu(self.tr("Start"), self) + self.__startMenu.addAction( + UI.PixmapCache.getIcon("runScript"), + self.tr('Run Script...'), + self.__contextMenuRunScript) + self.__startMenu.addAction( + UI.PixmapCache.getIcon("debugScript"), + self.tr('Debug Script...'), + self.__contextMenuDebugScript) + self.__startMenu.addAction( + UI.PixmapCache.getIcon("profileScript"), + self.tr('Profile Script...'), + self.__contextMenuProfileScript) + self.__startMenu.addAction( + UI.PixmapCache.getIcon("coverageScript"), + self.tr('Coverage run of Script...'), + self.__contextMenuCoverageScript) + self.unittestAction = self.sourceMenu.addAction( self.tr('Run unittest...'), self.handleUnittest) self.sourceMenu.addSeparator() @@ -165,6 +184,8 @@ self.sourceMenu.addSeparator() self.sourceMenuActions["Show"] = self.sourceMenu.addMenu(self.menuShow) self.sourceMenu.addSeparator() + self.__startAct = self.sourceMenu.addMenu(self.__startMenu) + self.sourceMenu.addSeparator() self.sourceMenu.addAction( self.tr('Copy Path to Clipboard'), self._copyToClipboard) self.sourceMenu.addSeparator() @@ -677,6 +698,15 @@ """ ProjectBaseBrowser._showContextMenu(self, self.sourceMenu) + itm = self.model().item(self.currentIndex()) + if itm: + try: + self.__startAct.setEnabled(itm.isPython3File()) + except AttributeError: + self.__startAct.setEnabled(False) + else: + self.__startAct.setEnabled(False) + self.showMenu.emit("Main", self.sourceMenu) def __showContextMenuMulti(self): @@ -1154,3 +1184,35 @@ if loadedDiagram.load(): self.loadedDiagram = loadedDiagram self.loadedDiagram.show(fromFile=True) + + ########################################################################### + ## Methods for the Start submenu + ########################################################################### + + def __contextMenuRunScript(self): + """ + Private method to run the editor script. + """ + fn = self.model().item(self.currentIndex()).fileName() + ericApp().getObject("DebugUI").doRun(False, script=fn) + + def __contextMenuDebugScript(self): + """ + Private method to debug the editor script. + """ + fn = self.model().item(self.currentIndex()).fileName() + ericApp().getObject("DebugUI").doDebug(False, script=fn) + + def __contextMenuProfileScript(self): + """ + Private method to profile the editor script. + """ + fn = self.model().item(self.currentIndex()).fileName() + ericApp().getObject("DebugUI").doProfile(False, script=fn) + + def __contextMenuCoverageScript(self): + """ + Private method to run a coverage test of the editor script. + """ + fn = self.model().item(self.currentIndex()).fileName() + ericApp().getObject("DebugUI").doCoverage(False, script=fn)