--- a/PipxInterface/PipxAppStartDialog.py Tue Jun 25 17:58:25 2024 +0200 +++ b/PipxInterface/PipxAppStartDialog.py Tue Jun 25 17:59:15 2024 +0200 @@ -9,11 +9,12 @@ import shlex from PyQt6.QtCore import QCoreApplication, QProcess, Qt, QTimer, pyqtSlot -from PyQt6.QtWidgets import QAbstractButton, QDialog, QDialogButtonBox +from PyQt6.QtWidgets import QAbstractButton, QComboBox, QDialog, QDialogButtonBox from eric7 import Preferences from eric7.EricGui import EricPixmapCache from eric7.EricWidgets import EricMessageBox +from eric7.EricWidgets.EricPathPicker import EricPathPickerModes from .Ui_PipxAppStartDialog import Ui_PipxAppStartDialog @@ -24,12 +25,14 @@ to execute the app. """ - def __init__(self, app, parent=None): + def __init__(self, app, plugin, parent=None): """ Constructor @param app path of the application to be executed @type str + @param plugin reference to the plug-in object + @type PluginPipxInterface @param parent reference to the parent widget (defaults to None) @type QWidget (optional) """ @@ -38,11 +41,18 @@ self.executeButton.setIcon(EricPixmapCache.getIcon("start")) + self.workdirPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) + self.workdirPicker.setInsertPolicy(QComboBox.InsertPolicy.InsertAtTop) + + self.__plugin = plugin + self.__process = None self.appLabel.setText(app) self.errorGroup.hide() + self.__populateWorkDirs() + self.parametersEdit.returnPressed.connect(self.on_executeButton_clicked) def closeEvent(self, e): @@ -117,6 +127,12 @@ self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setEnabled(True) self.executeButton.setEnabled(False) + # clear output of last run + self.resultbox.clear() + self.errors.clear() + self.errorGroup.hide() + + workdir = self.workdirPicker.text() command = self.parametersEdit.text() args = shlex.split(command) @@ -124,6 +140,9 @@ self.__process.finished.connect(self.__procFinished) self.__process.readyReadStandardOutput.connect(self.__readStdout) self.__process.readyReadStandardError.connect(self.__readStderr) + if os.path.isdir(workdir) or workdir == "": + self.__populateWorkDirs(workdir) + self.__process.setWorkingDirectory(workdir) self.__process.start(self.appLabel.text(), args) procStarted = self.__process.waitForStarted(5000) if not procStarted: @@ -180,3 +199,26 @@ self.errors.ensureCursorVisible() QCoreApplication.processEvents() + + def __populateWorkDirs(self, mostRecent=None): + """ + Private method to populate the working directory selector. + + @param mostRecent most recently used working directory + @type str + """ + workDirList = self.__plugin.getPreferences("RecentAppWorkdirs") + if mostRecent is not None: + if mostRecent in workDirList: + # push it to the beginning of the list + workDirList.remove(mostRecent) + workDirList.insert(0, mostRecent) + workDirList = workDirList[ + : self.__plugin.getPreferences("MaxRecentAppWorkdirs") + ] + self.__plugin.setPreferences("RecentAppWorkdirs", workDirList) + + self.workdirPicker.clear() + self.workdirPicker.addItems(workDirList) + if len(workDirList) > 0: + self.workdirPicker.setCurrentIndex(0)