eric7/Debugger/DebugUI.py

branch
eric7
changeset 8529
569623270e29
parent 8524
595547ab8d6f
child 8568
890dfe038613
diff -r 2175f268ad9b -r 569623270e29 eric7/Debugger/DebugUI.py
--- a/eric7/Debugger/DebugUI.py	Sun Aug 22 19:59:18 2021 +0200
+++ b/eric7/Debugger/DebugUI.py	Mon Aug 23 17:59:09 2021 +0200
@@ -88,6 +88,8 @@
         # read the saved debug info values
         self.lastUsedVenvName = Preferences.Prefs.settings.value(
             'DebugInfo/VirtualEnvironment', '')
+        self.scriptsHistory = Preferences.toList(
+            Preferences.Prefs.settings.value('DebugInfo/ScriptsHistory'))
         self.argvHistory = Preferences.toList(
             Preferences.Prefs.settings.value('DebugInfo/ArgumentsHistory'))
         self.wdHistory = Preferences.toList(
@@ -634,13 +636,9 @@
 
         self.debugActGrp.setEnabled(False)
         self.dbgSetBpActGrp.setEnabled(False)
-        self.runAct.setEnabled(False)
         self.runProjectAct.setEnabled(False)
-        self.profileAct.setEnabled(False)
         self.profileProjectAct.setEnabled(False)
-        self.coverageAct.setEnabled(False)
         self.coverageProjectAct.setEnabled(False)
-        self.debugAct.setEnabled(False)
         self.debugProjectAct.setEnabled(False)
         self.restartAct.setEnabled(False)
         self.stopAct.setEnabled(False)
@@ -731,6 +729,28 @@
         
         return [starttb, debugtb]
 
+    def setScriptsHistory(self, scriptName, clearHistories=False,
+                          history=None):
+        """
+        Public slot to initialize the scripts history.
+        
+        @param scriptName script name
+        @type str
+        @param clearHistories flag indicating, that the list should
+            be cleared (defaults to False)
+        @type bool (optional)
+        @param history list of history entries to be set (defaults to None)
+        @type list of str (optional)
+        """
+        if clearHistories:
+            del self.scriptsHistory[1:]
+        elif history is not None:
+            self.scriptsHistory = history[:]
+        else:
+            if scriptName in self.scriptsHistory:
+                self.scriptsHistory.remove(scriptName)
+            self.scriptsHistory.insert(0, scriptName)
+
     def setArgvHistory(self, argsStr, clearHistories=False, history=None):
         """
         Public slot to initialize the argv history.
@@ -852,10 +872,6 @@
         Private slot to handle the closeProgram signal.
         """
         self.editorOpen = False
-        self.debugAct.setEnabled(False)
-        self.runAct.setEnabled(False)
-        self.profileAct.setEnabled(False)
-        self.coverageAct.setEnabled(False)
         self.debugActGrp.setEnabled(False)
         self.dbgSetBpActGrp.setEnabled(False)
         self.lastAction = -1
@@ -886,11 +902,6 @@
                 elif editor.isRubyFile():
                     cap = self.debugServer.getClientCapabilities('Ruby')
         
-            if not self.passive:
-                self.runAct.setEnabled(cap & HasInterpreter)
-                self.coverageAct.setEnabled(cap & HasCoverage)
-                self.profileAct.setEnabled(cap & HasProfiler)
-                self.debugAct.setEnabled(cap & HasDebugger)
             self.dbgSetBpActGrp.setEnabled(cap & HasDebugger)
             if editor.curLineHasBreakpoint():
                 self.dbgEditBpAct.setEnabled(True)
@@ -903,10 +914,6 @@
                 self.dbgNextBpAct.setEnabled(False)
                 self.dbgPrevBpAct.setEnabled(False)
         else:
-            self.runAct.setEnabled(False)
-            self.coverageAct.setEnabled(False)
-            self.profileAct.setEnabled(False)
-            self.debugAct.setEnabled(False)
             self.dbgSetBpActGrp.setEnabled(False)
         
     def __cursorChanged(self, editor):
@@ -963,12 +970,15 @@
         """
         Public method to clear the various debug histories.
         """
+        self.scriptsHistory = []
         self.argvHistory = []
         self.wdHistory = []
         self.envHistory = []
         self.multiprocessNoDebugHistory = []
         
         Preferences.Prefs.settings.setValue(
+            'DebugInfo/ScriptsHistory', self.scriptsHistory)
+        Preferences.Prefs.settings.setValue(
             'DebugInfo/ArgumentsHistory', self.argvHistory)
         Preferences.Prefs.settings.setValue(
             'DebugInfo/WorkingDirectoryHistory', self.wdHistory)
@@ -985,6 +995,7 @@
         Public method to perform shutdown actions.
         """
         # Just save the 10 most recent entries
+        del self.scriptsHistory[10:]
         del self.argvHistory[10:]
         del self.wdHistory[10:]
         del self.envHistory[10:]
@@ -992,6 +1003,8 @@
         Preferences.Prefs.settings.setValue(
             'DebugInfo/VirtualEnvironment', self.lastUsedVenvName)
         Preferences.Prefs.settings.setValue(
+            'DebugInfo/ScriptsHistory', self.scriptsHistory)
+        Preferences.Prefs.settings.setValue(
             'DebugInfo/ArgumentsHistory', self.argvHistory)
         Preferences.Prefs.settings.setValue(
             'DebugInfo/WorkingDirectoryHistory', self.wdHistory)
@@ -1689,21 +1702,24 @@
         """
         Private slot to handle the coverage of script action.
         """
-        self.__doCoverage(False)
+        self.doCoverage(False)
         
     def __coverageProject(self):
         """
         Private slot to handle the coverage of project action.
         """
         self.__compileChangedProjectFiles()
-        self.__doCoverage(True)
+        self.doCoverage(True)
         
-    def __doCoverage(self, runProject):
+    def doCoverage(self, runProject, script=""):
         """
-        Private method to handle the coverage actions.
+        Public method to handle the coverage actions.
         
         @param runProject flag indicating coverage of the current project
             (True) or script (false)
+        @type bool
+        @param script name of a script (optional)
+        @type str
         """
         from .StartDialog import StartDialog
         
@@ -1717,14 +1733,24 @@
             if runProject else
             self.tr("Coverage of Script")
         )
+        if runProject:
+            scriptName = self.project.getMainScript(True)
+        elif script:
+            scriptName = script
+        elif self.lastDebuggedFile:
+            scriptName = self.lastDebuggedFile
+        else:
+            scriptName = ""
         dlg = StartDialog(
             cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory,
             self.envHistory, self.exceptions, self.ui, 2,
             autoClearShell=self.autoClearShell,
-            configOverride=self.overrideGlobalConfig)
+            configOverride=self.overrideGlobalConfig,
+            forProject=runProject, scriptName=scriptName,
+            scriptsList=self.scriptsHistory)
         if dlg.exec() == QDialog.DialogCode.Accepted:
-            (lastUsedVenvName, argv, wd, env, exceptions, clearShell,
-             console) = dlg.getData()
+            (lastUsedVenvName, scriptName, argv, wd, env, exceptions,
+             clearShell, console) = dlg.getData()
             configOverride = dlg.getGlobalOverrideData()
             eraseCoverage = dlg.getCoverageData()
             
@@ -1755,20 +1781,25 @@
                 self.lastStartAction = 6
                 self.clientType = self.project.getProjectLanguage()
             else:
-                editor = self.viewmanager.activeWindow()
-                if editor is None:
-                    return
-                
-                if (
-                    not self.viewmanager.checkDirty(
-                        editor, Preferences.getDebugger("Autosave")) or
-                    editor.getFileName() is None
-                ):
-                    return
+                if scriptName:
+                    fn = scriptName
+                    self.clientType = "Python3"
+                else:
+                    # run current editor
+                    editor = self.viewmanager.activeWindow()
+                    if editor is None:
+                        return
                     
-                fn = editor.getFileName()
+                    if (
+                        not self.viewmanager.checkDirty(
+                            editor, Preferences.getDebugger("Autosave")) or
+                        editor.getFileName() is None
+                    ):
+                        return
+                        
+                    fn = editor.getFileName()
+                    self.clientType = editor.determineFileType()
                 self.lastStartAction = 5
-                self.clientType = editor.determineFileType()
                 
             # save the filename for use by the restart method
             self.lastDebuggedFile = fn
@@ -1779,6 +1810,7 @@
             
             # This moves any previous occurrence of these arguments to the head
             # of the list.
+            self.setScriptsHistory(scriptName)
             self.setArgvHistory(argv)
             self.setWdHistory(wd)
             self.setEnvHistory(env)
@@ -1820,12 +1852,15 @@
                 self.stopAct.setEnabled(True)
         
         if dlg.clearHistories():
+            self.setScriptsHistory("", clearHistories=True)
             self.setArgvHistory("", clearHistories=True)
             self.setWdHistory("", clearHistories=True)
             self.setEnvHistory("", clearHistories=True)
             self.setMultiprocessNoDebugHistory("", clearHistories=True)
         elif dlg.historiesModified():
-            argvHistory, wdHistory, envHistory, _ = dlg.getHistories()
+            (scriptsHistory, argvHistory, wdHistory, envHistory,
+             _) = dlg.getHistories()
+            self.setScriptsHistory("", history=scriptsHistory)
             self.setArgvHistory("", history=argvHistory)
             self.setWdHistory("", history=wdHistory)
             self.setEnvHistory("", history=envHistory)
@@ -1834,21 +1869,24 @@
         """
         Private slot to handle the profile script action.
         """
-        self.__doProfile(False)
+        self.doProfile(False)
         
     def __profileProject(self):
         """
         Private slot to handle the profile project action.
         """
         self.__compileChangedProjectFiles()
-        self.__doProfile(True)
+        self.doProfile(True)
         
-    def __doProfile(self, runProject):
+    def doProfile(self, runProject, script=""):
         """
-        Private method to handle the profile actions.
+        Public method to handle the profile actions.
         
         @param runProject flag indicating profiling of the current project
             (True) or script (False)
+        @type bool
+        @param script name of a script (optional)
+        @type str
         """
         from .StartDialog import StartDialog
         
@@ -1862,14 +1900,24 @@
             if runProject else
             self.tr("Profile of Script")
         )
+        if runProject:
+            scriptName = self.project.getMainScript(True)
+        elif script:
+            scriptName = script
+        elif self.lastDebuggedFile:
+            scriptName = self.lastDebuggedFile
+        else:
+            scriptName = ""
         dlg = StartDialog(
             cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory,
             self.envHistory, self.exceptions, self.ui, 3,
             autoClearShell=self.autoClearShell,
-            configOverride=self.overrideGlobalConfig)
+            configOverride=self.overrideGlobalConfig,
+            forProject=runProject, scriptName=scriptName,
+            scriptsList=self.scriptsHistory)
         if dlg.exec() == QDialog.DialogCode.Accepted:
-            (lastUsedVenvName, argv, wd, env, exceptions, clearShell,
-             console) = dlg.getData()
+            (lastUsedVenvName, scriptName, argv, wd, env, exceptions,
+             clearShell, console) = dlg.getData()
             configOverride = dlg.getGlobalOverrideData()
             eraseTimings = dlg.getProfilingData()
             
@@ -1900,20 +1948,25 @@
                 self.lastStartAction = 8
                 self.clientType = self.project.getProjectLanguage()
             else:
-                editor = self.viewmanager.activeWindow()
-                if editor is None:
-                    return
-                
-                if (
-                    not self.viewmanager.checkDirty(
-                        editor, Preferences.getDebugger("Autosave")) or
-                    editor.getFileName() is None
-                ):
-                    return
+                if scriptName:
+                    fn = scriptName
+                    self.clientType = "Python3"
+                else:
+                    # run current editor
+                    editor = self.viewmanager.activeWindow()
+                    if editor is None:
+                        return
                     
-                fn = editor.getFileName()
+                    if (
+                        not self.viewmanager.checkDirty(
+                            editor, Preferences.getDebugger("Autosave")) or
+                        editor.getFileName() is None
+                    ):
+                        return
+                        
+                    fn = editor.getFileName()
+                    self.clientType = editor.determineFileType()
                 self.lastStartAction = 7
-                self.clientType = editor.determineFileType()
                 
             # save the filename for use by the restart method
             self.lastDebuggedFile = fn
@@ -1924,6 +1977,7 @@
             
             # This moves any previous occurrence of these arguments to the head
             # of the list.
+            self.setScriptsHistory(scriptName)
             self.setArgvHistory(argv)
             self.setWdHistory(wd)
             self.setEnvHistory(env)
@@ -1965,12 +2019,15 @@
                 self.stopAct.setEnabled(True)
         
         if dlg.clearHistories():
+            self.setScriptsHistory("", clearHistories=True)
             self.setArgvHistory("", clearHistories=True)
             self.setWdHistory("", clearHistories=True)
             self.setEnvHistory("", clearHistories=True)
             self.setMultiprocessNoDebugHistory("", clearHistories=True)
         elif dlg.historiesModified():
-            argvHistory, wdHistory, envHistory, _ = dlg.getHistories()
+            (scriptsHistory, argvHistory, wdHistory, envHistory,
+             _) = dlg.getHistories()
+            self.setScriptsHistory("", history=scriptsHistory)
             self.setArgvHistory("", history=argvHistory)
             self.setWdHistory("", history=wdHistory)
             self.setEnvHistory("", history=envHistory)
@@ -1979,21 +2036,24 @@
         """
         Private slot to handle the run script action.
         """
-        self.__doRun(False)
+        self.doRun(False)
         
     def __runProject(self):
         """
         Private slot to handle the run project action.
         """
         self.__compileChangedProjectFiles()
-        self.__doRun(True)
+        self.doRun(True)
         
-    def __doRun(self, runProject):
+    def doRun(self, runProject, script=""):
         """
-        Private method to handle the run actions.
+        Public method to handle the run actions.
         
         @param runProject flag indicating running the current project (True)
                 or script (False)
+        @type bool
+        @param script name of a script (optional)
+        @type str
         """
         from .StartDialog import StartDialog
         
@@ -2007,14 +2067,24 @@
             if runProject else
             self.tr("Run Script")
         )
+        if runProject:
+            scriptName = self.project.getMainScript(True)
+        elif script:
+            scriptName = script
+        elif self.lastDebuggedFile:
+            scriptName = self.lastDebuggedFile
+        else:
+            scriptName = ""
         dlg = StartDialog(
             cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory,
             self.envHistory, self.exceptions, self.ui, 1,
             autoClearShell=self.autoClearShell,
-            configOverride=self.overrideGlobalConfig)
+            configOverride=self.overrideGlobalConfig,
+            forProject=runProject, scriptName=scriptName,
+            scriptsList=self.scriptsHistory)
         if dlg.exec() == QDialog.DialogCode.Accepted:
-            (lastUsedVenvName, argv, wd, env, exceptions, clearShell,
-             console) = dlg.getData()
+            (lastUsedVenvName, scriptName, argv, wd, env, exceptions,
+             clearShell, console) = dlg.getData()
             configOverride = dlg.getGlobalOverrideData()
             
             if runProject:
@@ -2044,22 +2114,27 @@
                 self.lastStartAction = 4
                 self.clientType = self.project.getProjectLanguage()
             else:
-                editor = self.viewmanager.activeWindow()
-                if editor is None:
-                    return
-                
-                if (
-                    not self.viewmanager.checkDirty(
-                        editor,
-                        Preferences.getDebugger("Autosave")) or
-                    editor.getFileName() is None
-                ):
-                    return
+                if scriptName:
+                    fn = scriptName
+                    self.clientType = "Python3"
+                else:
+                    # run current editor
+                    editor = self.viewmanager.activeWindow()
+                    if editor is None:
+                        return
                     
-                fn = editor.getFileName()
+                    if (
+                        not self.viewmanager.checkDirty(
+                            editor,
+                            Preferences.getDebugger("Autosave")) or
+                        editor.getFileName() is None
+                    ):
+                        return
+                    
+                    fn = editor.getFileName()
+                    self.clientType = editor.determineFileType()
                 self.lastStartAction = 3
-                self.clientType = editor.determineFileType()
-                
+            
             # save the filename for use by the restart method
             self.lastDebuggedFile = fn
             self.restartAct.setEnabled(True)
@@ -2069,6 +2144,7 @@
             
             # This moves any previous occurrence of these arguments to the head
             # of the list.
+            self.setScriptsHistory(scriptName)
             self.setArgvHistory(argv)
             self.setWdHistory(wd)
             self.setEnvHistory(env)
@@ -2106,12 +2182,15 @@
                 self.stopAct.setEnabled(True)
         
         if dlg.clearHistories():
+            self.setScriptsHistory("", clearHistories=True)
             self.setArgvHistory("", clearHistories=True)
             self.setWdHistory("", clearHistories=True)
             self.setEnvHistory("", clearHistories=True)
             self.setMultiprocessNoDebugHistory("", clearHistories=True)
         elif dlg.historiesModified():
-            argvHistory, wdHistory, envHistory, _ = dlg.getHistories()
+            (scriptsHistory, argvHistory, wdHistory, envHistory,
+             _) = dlg.getHistories()
+            self.setScriptsHistory("", history=scriptsHistory)
             self.setArgvHistory("", history=argvHistory)
             self.setWdHistory("", history=wdHistory)
             self.setEnvHistory("", history=envHistory)
@@ -2120,21 +2199,24 @@
         """
         Private slot to handle the debug script action.
         """
-        self.__doDebug(False)
+        self.doDebug(False)
         
     def __debugProject(self):
         """
         Private slot to handle the debug project action.
         """
         self.__compileChangedProjectFiles()
-        self.__doDebug(True)
+        self.doDebug(True)
         
-    def __doDebug(self, debugProject):
+    def doDebug(self, debugProject, script=""):
         """
-        Private method to handle the debug actions.
+        Public method to handle the debug actions.
         
         @param debugProject flag indicating debugging the current project
             (True) or script (False)
+        @type bool
+        @param script name of a script (optional)
+        @type str
         """
         from .StartDialog import StartDialog
         
@@ -2148,6 +2230,14 @@
             if debugProject else
             self.tr("Debug Script")
         )
+        if debugProject:
+            scriptName = self.project.getMainScript(True)
+        elif script:
+            scriptName = script
+        elif self.lastDebuggedFile:
+            scriptName = self.lastDebuggedFile
+        else:
+            scriptName = ""
         dlg = StartDialog(
             cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory,
             self.envHistory, self.exceptions, self.ui, 0,
@@ -2155,10 +2245,12 @@
             autoContinue=self.autoContinue,
             enableMultiprocess=self.enableMultiprocess,
             multiprocessNoDebugHistory=self.multiprocessNoDebugHistory,
-            configOverride=self.overrideGlobalConfig)
+            configOverride=self.overrideGlobalConfig,
+            forProject=debugProject, scriptName=scriptName,
+            scriptsList=self.scriptsHistory)
         if dlg.exec() == QDialog.DialogCode.Accepted:
-            (lastUsedVenvName, argv, wd, env, exceptions, clearShell,
-             console) = dlg.getData()
+            (lastUsedVenvName, scriptName, argv, wd, env, exceptions,
+             clearShell, console) = dlg.getData()
             configOverride = dlg.getGlobalOverrideData()
             (tracePython, autoContinue, enableMultiprocess,
              multiprocessNoDebug) = dlg.getDebugData()
@@ -2193,20 +2285,25 @@
                 self.lastStartAction = 2
                 self.clientType = self.project.getProjectLanguage()
             else:
-                editor = self.viewmanager.activeWindow()
-                if editor is None:
-                    return
-                
-                if (
-                    not self.viewmanager.checkDirty(
-                        editor, Preferences.getDebugger("Autosave")) or
-                    editor.getFileName() is None
-                ):
-                    return
+                if scriptName:
+                    fn = scriptName
+                    self.clientType = "Python3"
+                else:
+                    # debug current editor
+                    editor = self.viewmanager.activeWindow()
+                    if editor is None:
+                        return
                     
-                fn = editor.getFileName()
+                    if (
+                        not self.viewmanager.checkDirty(
+                            editor, Preferences.getDebugger("Autosave")) or
+                        editor.getFileName() is None
+                    ):
+                        return
+                        
+                    fn = editor.getFileName()
+                    self.clientType = editor.determineFileType()
                 self.lastStartAction = 1
-                self.clientType = editor.determineFileType()
             
             # save the filename for use by the restart method
             self.lastDebuggedFile = fn
@@ -2217,6 +2314,7 @@
             
             # This moves any previous occurrence of these arguments to the head
             # of the list.
+            self.setScriptsHistory(scriptName)
             self.setArgvHistory(argv)
             self.setWdHistory(wd)
             self.setEnvHistory(env)
@@ -2282,13 +2380,15 @@
                     self.stopAct.setEnabled(True)
         
         if dlg.clearHistories():
+            self.setScriptsHistory("", clearHistories=True)
             self.setArgvHistory("", clearHistories=True)
             self.setWdHistory("", clearHistories=True)
             self.setEnvHistory("", clearHistories=True)
             self.setMultiprocessNoDebugHistory("", clearHistories=True)
         elif dlg.historiesModified():
-            (argvHistory, wdHistory, envHistory,
+            (scriptsHistory, argvHistory, wdHistory, envHistory,
              noDebugHistory) = dlg.getHistories()
+            self.setScriptsHistory("", history=scriptsHistory)
             self.setArgvHistory("", history=argvHistory)
             self.setWdHistory("", history=wdHistory)
             self.setEnvHistory("", history=envHistory)

eric ide

mercurial