diff -r e075c8fe07fd -r df7edc29cbfb src/eric7/Debugger/StartDialog.py --- a/src/eric7/Debugger/StartDialog.py Tue Oct 31 09:23:05 2023 +0100 +++ b/src/eric7/Debugger/StartDialog.py Wed Nov 29 14:23:36 2023 +0100 @@ -7,6 +7,7 @@ Module implementing the Start Program dialog. """ +import enum import os from PyQt6.QtCore import Qt @@ -16,10 +17,23 @@ from eric7.EricWidgets.EricApplication import ericApp from eric7.EricWidgets.EricPathPicker import EricPathPickerModes +from .Ui_StartDialog import Ui_StartDialog -class StartDialog(QDialog): + +class StartDialogMode(enum.Enum): + """ + Class defining the various modes of the start dialog. """ - Class implementing the Start Program dialog. + + Debug = 0 + Run = 1 + Coverage = 2 + Profile = 3 + + +class StartDialog(QDialog, Ui_StartDialog): + """ + Class implementing the Start dialog. It implements a dialog that is used to start an application for debugging. It asks the user to enter @@ -34,14 +48,13 @@ argvList, wdList, envList, - exceptions, - unhandledExceptions, parent=None, - dialogType=0, + dialogMode=StartDialogMode.Debug, modfuncList=None, + autoClearShell=True, tracePython=False, - autoClearShell=True, autoContinue=True, + reportAllExceptions=False, enableMultiprocess=False, multiprocessNoDebugHistory=None, configOverride=None, @@ -63,31 +76,29 @@ @type list of str @param envList history list of environment parameter settings @type list of str - @param exceptions exception reporting flag - @type bool - @param unhandledExceptions flag indicating to always report unhandled exceptions - @type bool @param parent parent widget of this dialog @type QWidget - @param dialogType type of the start dialog + @param dialogMode mode of the start dialog <ul> - <li>0 = start debug dialog</li> - <li>1 = start run dialog</li> - <li>2 = start coverage dialog</li> - <li>3 = start profile dialog</li> + <li>StartDialogMode.Debug = start debug dialog</li> + <li>StartDialogMode.Run = start run dialog</li> + <li>StartDialogMode.Coverage = start coverage dialog</li> + <li>StartDialogMode.Profile = start profile dialog</li> </ul> - @type int (0 to 3) + @type StartDialogMode @param modfuncList history list of module functions @type list of str + @param autoClearShell flag indicating, that the interpreter window + should be cleared automatically + @type bool @param tracePython flag indicating if the Python library should be traced as well @type bool - @param autoClearShell flag indicating, that the interpreter window - should be cleared automatically - @type bool @param autoContinue flag indicating, that the debugger should not stop at the first executable line @type bool + @param reportAllExceptions flag indicating to report all exceptions + @type bool @param enableMultiprocess flag indicating the support for multi process debugging @type bool @@ -106,139 +117,124 @@ @type list of str """ super().__init__(parent) + self.setupUi(self) self.setModal(True) - self.dialogType = dialogType - if dialogType == 0: - from .Ui_StartDebugDialog import ( # __IGNORE_WARNING_I101__ - Ui_StartDebugDialog, - ) - - self.ui = Ui_StartDebugDialog() - elif dialogType == 1: - from .Ui_StartRunDialog import Ui_StartRunDialog # __IGNORE_WARNING_I101__ + self.__dialogMode = dialogMode + self.debugGroup.setVisible(self.__dialogMode == StartDialogMode.Debug) + self.coverageGroup.setVisible(self.__dialogMode == StartDialogMode.Coverage) + self.profileGroup.setVisible(self.__dialogMode == StartDialogMode.Profile) + # nothing special for 'Run' mode - self.ui = Ui_StartRunDialog() - elif dialogType == 2: - from .Ui_StartCoverageDialog import ( # __IGNORE_WARNING_I101__ - Ui_StartCoverageDialog, - ) - - self.ui = Ui_StartCoverageDialog() - elif dialogType == 3: - from .Ui_StartProfileDialog import ( # __IGNORE_WARNING_I101__ - Ui_StartProfileDialog, - ) - - self.ui = Ui_StartProfileDialog() - self.ui.setupUi(self) - - self.ui.venvComboBox.addItem("") + self.venvComboBox.addItem("") projectEnvironmentString = ( ericApp().getObject("DebugServer").getProjectEnvironmentString() ) if projectEnvironmentString: - self.ui.venvComboBox.addItem(projectEnvironmentString) - self.ui.venvComboBox.addItems( + self.venvComboBox.addItem(projectEnvironmentString) + self.venvComboBox.addItems( sorted(ericApp().getObject("VirtualEnvManager").getVirtualenvNames()) ) - self.ui.scriptnamePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) - self.ui.scriptnamePicker.setDefaultDirectory( + self.scriptnamePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) + self.scriptnamePicker.setDefaultDirectory( Preferences.getMultiProject("Workspace") ) - self.ui.scriptnamePicker.setInsertPolicy(QComboBox.InsertPolicy.InsertAtTop) - self.ui.scriptnamePicker.setSizeAdjustPolicy( + self.scriptnamePicker.setInsertPolicy(QComboBox.InsertPolicy.InsertAtTop) + self.scriptnamePicker.setSizeAdjustPolicy( QComboBox.SizeAdjustPolicy.AdjustToMinimumContentsLengthWithIcon ) - self.ui.scriptnamePicker.setFilters( + self.scriptnamePicker.setFilters( self.tr( "Python Files (*.py *.py3);;" "Python GUI Files (*.pyw *.pyw3);;" "All Files (*)" ) ) - self.ui.scriptnamePicker.setEnabled(not forProject) + self.scriptnamePicker.setEnabled(not forProject) - self.ui.workdirPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) - self.ui.workdirPicker.setDefaultDirectory( - Preferences.getMultiProject("Workspace") - ) - self.ui.workdirPicker.setInsertPolicy(QComboBox.InsertPolicy.InsertAtTop) - self.ui.workdirPicker.setSizeAdjustPolicy( + self.workdirPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) + self.workdirPicker.setDefaultDirectory(Preferences.getMultiProject("Workspace")) + self.workdirPicker.setInsertPolicy(QComboBox.InsertPolicy.InsertAtTop) + self.workdirPicker.setSizeAdjustPolicy( QComboBox.SizeAdjustPolicy.AdjustToMinimumContentsLengthWithIcon ) - self.clearButton = self.ui.buttonBox.addButton( + self.clearButton = self.buttonBox.addButton( self.tr("Clear Histories"), QDialogButtonBox.ButtonRole.ActionRole ) - self.editButton = self.ui.buttonBox.addButton( + self.editButton = self.buttonBox.addButton( self.tr("Edit History"), QDialogButtonBox.ButtonRole.ActionRole ) self.setWindowTitle(caption) - self.ui.cmdlineCombo.completer().setCaseSensitivity( + self.cmdlineCombo.completer().setCaseSensitivity( Qt.CaseSensitivity.CaseSensitive ) - self.ui.cmdlineCombo.clear() - self.ui.cmdlineCombo.addItems(argvList) + self.cmdlineCombo.lineEdit().setClearButtonEnabled(True) + self.cmdlineCombo.clear() + self.cmdlineCombo.addItems(argvList) if len(argvList) > 0: - self.ui.cmdlineCombo.setCurrentIndex(0) + self.cmdlineCombo.setCurrentIndex(0) - self.ui.workdirPicker.clear() - self.ui.workdirPicker.addItems(wdList) + self.workdirPicker.clear() + self.workdirPicker.addItems(wdList) if len(wdList) > 0: - self.ui.workdirPicker.setCurrentIndex(0) + self.workdirPicker.setCurrentIndex(0) - self.ui.environmentCombo.completer().setCaseSensitivity( + self.environmentCombo.completer().setCaseSensitivity( Qt.CaseSensitivity.CaseSensitive ) - self.ui.environmentCombo.clear() - self.ui.environmentCombo.addItems(envList) + self.environmentCombo.lineEdit().setClearButtonEnabled(True) + self.environmentCombo.clear() + self.environmentCombo.addItems(envList) - self.ui.exceptionCheckBox.setChecked(exceptions) - self.ui.unhandledExceptionCheckBox.setChecked(unhandledExceptions) - self.ui.clearShellCheckBox.setChecked(autoClearShell) - self.ui.consoleCheckBox.setEnabled( + self.clearShellCheckBox.setChecked(autoClearShell) + self.consoleCheckBox.setEnabled( Preferences.getDebugger("ConsoleDbgCommand") != "" ) - self.ui.consoleCheckBox.setChecked(False) + self.consoleCheckBox.setChecked(False) - venvIndex = max(0, self.ui.venvComboBox.findText(lastUsedVenvName)) - self.ui.venvComboBox.setCurrentIndex(venvIndex) - self.ui.globalOverrideGroup.setChecked(configOverride["enable"]) - self.ui.redirectCheckBox.setChecked(configOverride["redirect"]) + venvIndex = max(0, self.venvComboBox.findText(lastUsedVenvName)) + self.venvComboBox.setCurrentIndex(venvIndex) + self.globalOverrideGroup.setChecked(configOverride["enable"]) + self.redirectCheckBox.setChecked(configOverride["redirect"]) - self.ui.scriptnamePicker.addItems(scriptsList) - self.ui.scriptnamePicker.setText(scriptName) + self.scriptnamePicker.addItems(scriptsList) + self.scriptnamePicker.setText(scriptName) - if dialogType == 0: # start debug dialog + if dialogMode == StartDialogMode.Debug: enableMultiprocessGlobal = Preferences.getDebugger("MultiProcessEnabled") - self.ui.tracePythonCheckBox.setChecked(tracePython) - self.ui.tracePythonCheckBox.show() - self.ui.autoContinueCheckBox.setChecked(autoContinue) - self.ui.multiprocessGroup.setEnabled(enableMultiprocessGlobal) - self.ui.multiprocessGroup.setChecked( + self.tracePythonCheckBox.setChecked(tracePython) + self.tracePythonCheckBox.show() + self.autoContinueCheckBox.setChecked(autoContinue) + self.allExceptionsCheckBox.setChecked(reportAllExceptions) + self.multiprocessGroup.setEnabled(enableMultiprocessGlobal) + self.multiprocessGroup.setChecked( enableMultiprocess & enableMultiprocessGlobal ) - self.ui.multiprocessNoDebugCombo.clear() - self.ui.multiprocessNoDebugCombo.setToolTip( + self.multiprocessNoDebugCombo.clear() + self.multiprocessNoDebugCombo.setToolTip( self.tr( "Enter the list of programs or program patterns not to be" " debugged separated by '{0}'." ).format(os.pathsep) ) + self.multiprocessNoDebugCombo.lineEdit().setClearButtonEnabled(True) if multiprocessNoDebugHistory: - self.ui.multiprocessNoDebugCombo.completer().setCaseSensitivity( + self.multiprocessNoDebugCombo.completer().setCaseSensitivity( Qt.CaseSensitivity.CaseSensitive ) - self.ui.multiprocessNoDebugCombo.addItems(multiprocessNoDebugHistory) - self.ui.multiprocessNoDebugCombo.setCurrentIndex(0) + self.multiprocessNoDebugCombo.addItems(multiprocessNoDebugHistory) + self.multiprocessNoDebugCombo.setCurrentIndex(0) - if dialogType == 3: # start coverage or profile dialog - self.ui.eraseCheckBox.setChecked(True) + if dialogMode == StartDialogMode.Coverage: + self.eraseCoverageCheckBox.setChecked(True) - self.ui.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setFocus( + if dialogMode == StartDialogMode.Profile: + self.eraseProfileCheckBox.setChecked(True) + + self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setFocus( Qt.FocusReason.OtherFocusReason ) @@ -252,26 +248,25 @@ """ Private slot to enable/disable the OK button. """ - self.ui.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setDisabled( - self.ui.modFuncCombo.currentText() == "" + self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setDisabled( + self.modFuncCombo.currentText() == "" ) def getData(self): """ Public method to retrieve the data entered into this dialog. - @return a tuple of virtual environment, script name, argv, workdir, - environment, exceptions flag, unhandled exceptions flag, clear interpreter - flag and run in console flag - @rtype tuple of (str, str, str, str, str, bool, bool, bool, bool) + @return tuple containing the virtual environment, script name, argv, workdir, + environment, clear interpreter flag and run in console flag + @rtype tuple of (str, str, str, str, str, bool, bool) """ - cmdLine = self.ui.cmdlineCombo.currentText() - workdir = self.ui.workdirPicker.currentText(toNative=False) - environment = self.ui.environmentCombo.currentText() - venvName = self.ui.venvComboBox.currentText() + cmdLine = self.cmdlineCombo.currentText() + workdir = self.workdirPicker.currentText(toNative=False) + environment = self.environmentCombo.currentText() + venvName = self.venvComboBox.currentText() scriptName = ( - self.ui.scriptnamePicker.currentText() - if self.ui.scriptnamePicker.isEnabled() + self.scriptnamePicker.currentText() + if self.scriptnamePicker.isEnabled() else "" ) @@ -281,10 +276,8 @@ cmdLine, workdir, environment, - self.ui.exceptionCheckBox.isChecked(), - self.ui.unhandledExceptionCheckBox.isChecked(), - self.ui.clearShellCheckBox.isChecked(), - self.ui.consoleCheckBox.isChecked(), + self.clearShellCheckBox.isChecked(), + self.consoleCheckBox.isChecked(), ) def getGlobalOverrideData(self): @@ -297,8 +290,8 @@ @rtype dict """ return { - "enable": self.ui.globalOverrideGroup.isChecked(), - "redirect": self.ui.redirectCheckBox.isChecked(), + "enable": self.globalOverrideGroup.isChecked(), + "redirect": self.redirectCheckBox.isChecked(), } def getDebugData(self): @@ -306,22 +299,23 @@ Public method to retrieve the debug related data entered into this dialog. - @return a tuple of a flag indicating, if the Python library should be + @return tuple containing a flag indicating, if the Python library should be traced as well, a flag indicating, that the debugger should not - stop at the first executable line, a flag indicating to support - multi process debugging and a space separated list of programs not - to be debugged - @rtype tuple of (bool, bool, bool, str) + stop at the first executable line, a flag indicating to report all + exceptions, a flag indicating to support multi process debugging and a + space separated list of programs not to be debugged + @rtype tuple of (bool, bool, bool, bool, str) """ - if self.dialogType == 0: + if self.__dialogMode == StartDialogMode.Debug: return ( - self.ui.tracePythonCheckBox.isChecked(), - self.ui.autoContinueCheckBox.isChecked(), - self.ui.multiprocessGroup.isChecked(), - self.ui.multiprocessNoDebugCombo.currentText(), + self.tracePythonCheckBox.isChecked(), + self.autoContinueCheckBox.isChecked(), + self.allExceptionsCheckBox.isChecked(), + self.multiprocessGroup.isChecked(), + self.multiprocessNoDebugCombo.currentText(), ) else: - return (False, False, False, "") + return (False, False, False, False, "") def getCoverageData(self): """ @@ -331,8 +325,8 @@ @return flag indicating erasure of coverage info @rtype bool """ - if self.dialogType == 2: - return self.ui.eraseCheckBox.isChecked() + if self.__dialogMode == StartDialogMode.Coverage: + return self.eraseCoverageCheckBox.isChecked() else: return False @@ -344,8 +338,8 @@ @return flag indicating erasure of profiling info @rtype bool """ - if self.dialogType == 3: - return self.ui.eraseCheckBox.isChecked() + if self.__dialogMode == StartDialogMode.Profile: + return self.eraseProfileCheckBox.isChecked() else: return False @@ -357,26 +351,26 @@ self.__clearHistoryLists = True self.__historiesModified = False # clear catches it all - cmdLine = self.ui.cmdlineCombo.currentText() - workdir = self.ui.workdirPicker.currentText() - environment = self.ui.environmentCombo.currentText() - scriptName = self.ui.scriptnamePicker.currentText() + cmdLine = self.cmdlineCombo.currentText() + workdir = self.workdirPicker.currentText() + environment = self.environmentCombo.currentText() + scriptName = self.scriptnamePicker.currentText() - self.ui.cmdlineCombo.clear() - self.ui.workdirPicker.clear() - self.ui.environmentCombo.clear() - self.ui.scriptnamePicker.clear() + self.cmdlineCombo.clear() + self.workdirPicker.clear() + self.environmentCombo.clear() + self.scriptnamePicker.clear() - self.ui.cmdlineCombo.addItem(cmdLine) - self.ui.workdirPicker.addItem(workdir) - self.ui.environmentCombo.addItem(environment) - self.ui.scriptnamePicker.addItem("") - self.ui.scriptnamePicker.setCurrentText(scriptName) + self.cmdlineCombo.addItem(cmdLine) + self.workdirPicker.addItem(workdir) + self.environmentCombo.addItem(environment) + self.scriptnamePicker.addItem("") + self.scriptnamePicker.setCurrentText(scriptName) - if self.dialogType == 0: - noDebugList = self.ui.multiprocessNoDebugCombo.currentText() - self.ui.multiprocessNoDebugCombo.clear() - self.ui.multiprocessNoDebugCombo.addItem(noDebugList) + if self.__dialogMode == StartDialogMode.Debug: + noDebugList = self.multiprocessNoDebugCombo.currentText() + self.multiprocessNoDebugCombo.clear() + self.multiprocessNoDebugCombo.addItem(noDebugList) def __editHistory(self): """ @@ -393,14 +387,14 @@ ] widgets = [ None, - self.ui.scriptnamePicker, - self.ui.cmdlineCombo, - self.ui.workdirPicker, - self.ui.environmentCombo, + self.scriptnamePicker, + self.cmdlineCombo, + self.workdirPicker, + self.environmentCombo, ] - if self.dialogType == 0: + if self.__dialogMode == StartDialogMode.Debug: histories.append(self.tr("No Debug Programs")) - widgets.append(self.ui.multiprocessNoDebugCombo) + widgets.append(self.multiprocessNoDebugCombo) historyKind, ok = QInputDialog.getItem( self, self.tr("Edit History"), @@ -460,22 +454,22 @@ """ noDebugHistory = ( [ - self.ui.multiprocessNoDebugCombo.itemText(index) - for index in range(self.ui.multiprocessNoDebugCombo.count()) + self.multiprocessNoDebugCombo.itemText(index) + for index in range(self.multiprocessNoDebugCombo.count()) ] - if self.dialogType == 0 + if self.__dialogMode == StartDialogMode.Debug else None ) return ( - self.ui.scriptnamePicker.getPathItems(), + self.scriptnamePicker.getPathItems(), [ - self.ui.cmdlineCombo.itemText(index) - for index in range(self.ui.cmdlineCombo.count()) + self.cmdlineCombo.itemText(index) + for index in range(self.cmdlineCombo.count()) ], - self.ui.workdirPicker.getPathItems(), + self.workdirPicker.getPathItems(), [ - self.ui.environmentCombo.itemText(index) - for index in range(self.ui.environmentCombo.count()) + self.environmentCombo.itemText(index) + for index in range(self.environmentCombo.count()) ], noDebugHistory, )