diff -r 3c605ab5a8c7 -r 183220dc5492 src/eric7/Plugins/WizardPlugins/FileDialogWizard/FileDialogWizardDialog.py --- a/src/eric7/Plugins/WizardPlugins/FileDialogWizard/FileDialogWizardDialog.py Sun Jul 17 12:21:39 2022 +0200 +++ b/src/eric7/Plugins/WizardPlugins/FileDialogWizard/FileDialogWizardDialog.py Sun Jul 17 15:33:33 2022 +0200 @@ -9,7 +9,7 @@ import os -from PyQt6.QtCore import pyqtSlot, QUrl +from PyQt6.QtCore import pyqtSlot, QCoreApplication, QUrl from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QFileDialog, QButtonGroup from EricWidgets.EricCompleters import EricFileCompleter, EricDirCompleter @@ -27,12 +27,28 @@ EricFileDialog or QFileDialog code generator. """ + EricTypes = ( + ( + QCoreApplication.translate("FileDialogWizardDialog", "eric (String)"), + "eric_string", + ), + ( + QCoreApplication.translate("FileDialogWizardDialog", "eric (Path)"), + "eric_pathlib", + ), + ) + PyQtTypes = ( + ("PyQt5", "pyqt5"), + ("PyQt6", "pyqt6"), + ) + def __init__(self, dialogVariant, parent=None): """ Constructor @param dialogVariant variant of the file dialog to be generated - (-1 = EricFileDialog, 0 = unknown, 5 = PyQt5, 6 = PyQt6) + (-2 = EricFileDialog (pathlib.Path based), -1 = EricFileDialog (string + based), 0 = unknown, 5 = PyQt5, 6 = PyQt6) @type int @param parent parent widget @type QWidget @@ -61,13 +77,19 @@ self.__typeButtonsGroup.idClicked.connect(self.__toggleInitialFilterAndResult) self.__toggleInitialFilterAndResult(1) - if self.__dialogVariant == -1: - self.pyqtComboBox.addItems(["eric"]) + if self.__dialogVariant < 0: + for name, type_ in FileDialogWizardDialog.EricTypes: + self.pyqtComboBox.addItem(name, type_) self.setWindowTitle(self.tr("EricFileDialog Wizard")) - self.pyqtComboBox.setCurrentIndex(0) - self.pyqtComboBox.setEnabled(False) + if self.__dialogVariant == -1: + self.pyqtComboBox.setCurrentIndex(0) + elif self.__dialogVariant == -2: + self.pyqtComboBox.setCurrentIndex(1) + else: + self.pyqtComboBox.setCurrentIndex(0) else: - self.pyqtComboBox.addItems(["PyQt5", "PyQt6"]) + for name, type_ in FileDialogWizardDialog.PyQtTypes: + self.pyqtComboBox.addItem(name, type_) self.setWindowTitle(self.tr("QFileDialog Wizard")) if self.__dialogVariant == 5: self.pyqtComboBox.setCurrentIndex(0) @@ -111,17 +133,17 @@ @param index index of the current item @type int """ - txt = self.pyqtComboBox.itemText(index) - self.rfOpenFile.setEnabled(txt == "eric") - self.rfOpenFiles.setEnabled(txt == "eric") - self.rfSaveFile.setEnabled(txt == "eric") + txt = self.pyqtComboBox.itemData(index) + self.rfOpenFile.setEnabled(txt.startswith("eric_")) + self.rfOpenFiles.setEnabled(txt.startswith("eric_")) + self.rfSaveFile.setEnabled(txt.startswith("eric_")) - self.rOpenFileUrl.setEnabled(txt in ["PyQt5", "PyQt6"]) - self.rOpenFileUrls.setEnabled(txt in ["PyQt5", "PyQt6"]) - self.rSaveFileUrl.setEnabled(txt in ["PyQt5", "PyQt6"]) - self.rDirectoryUrl.setEnabled(txt in ["PyQt5", "PyQt6"]) + self.rOpenFileUrl.setEnabled(txt in ["pyqt5", "pyqt6"]) + self.rOpenFileUrls.setEnabled(txt in ["pyqt5", "pyqt6"]) + self.rSaveFileUrl.setEnabled(txt in ["pyqt5", "pyqt6"]) + self.rDirectoryUrl.setEnabled(txt in ["pyqt5", "pyqt6"]) - if txt in ["PyQt5", "PyQt6"]: + if txt in ["pyqt5", "pyqt6"]: if self.rfOpenFile.isChecked(): self.rOpenFile.setChecked(True) elif self.rfOpenFiles.isChecked(): @@ -138,8 +160,10 @@ if self.rDirectoryUrl.isChecked(): self.rDirectory.setChecked(True) - if txt == "eric": + if txt == "eric_string": self.__dialogVariant = -1 + elif txt == "eric_pathlib": + self.__dialogVariant = -2 elif txt == "PyQt5": self.__dialogVariant = 5 elif txt == "PyQt6": @@ -312,7 +336,7 @@ @param checkedId id of the clicked button (integer) """ - enable = (self.__dialogVariant in (-1,) and checkedId in [11, 12, 13]) or ( + enable = (self.__dialogVariant in (-1, -2) and checkedId in [11, 12, 13]) or ( self.__dialogVariant in (5, 6) and checkedId in [1, 2, 3, 21, 22, 23] ) @@ -357,14 +381,16 @@ self.rSaveFile, self.rfSaveFile, ]: - nameVariable = "fileName" + nameVariable = "filePath" if self.__dialogVariant == -2 else "fileName" elif self.__typeButtonsGroup.checkedButton() in [ self.rOpenFiles, self.rfOpenFiles, ]: - nameVariable = "fileNames" + nameVariable = ( + "filePaths" if self.__dialogVariant == -2 else "fileNames" + ) elif self.__typeButtonsGroup.checkedButton() == self.rDirectory: - nameVariable = "dirName" + nameVariable = "dirPath" if self.__dialogVariant == -2 else "dirName" else: nameVariable = "res" filterVariable = self.eFilterVariable.text() @@ -384,7 +410,7 @@ else: filterVariable = ", " + filterVariable - if self.__dialogVariant == -1: + if self.__dialogVariant in (-1, -2): dialogType = "EricFileDialog" optionStr = "" else: @@ -397,12 +423,25 @@ or self.rfOpenFile.isChecked() or self.rOpenFileUrl.isChecked() ): + # + # getOpenFile... + # if self.rOpenFile.isChecked(): - code += "getOpenFileName({0}{1}".format(os.linesep, istring) + method = ( + "getOpenFilePath" + if self.__dialogVariant == -2 + else "getOpenFileName" + ) + code += "{0}({1}{2}".format(method, os.linesep, istring) elif self.rOpenFileUrl.isChecked(): code += "getOpenFileUrl({0}{1}".format(os.linesep, istring) else: - code += "getOpenFileNameAndFilter({0}{1}".format(os.linesep, istring) + method = ( + "getOpenFilePathAndFilter" + if self.__dialogVariant == -2 + else "getOpenFileNameAndFilter" + ) + code += "{0}({1}{2}".format(method, os.linesep, istring) code += "{0},{1}{2}".format(parent, os.linesep, istring) if not self.eCaption.text(): code += '"",{0}{1}'.format(os.linesep, istring) @@ -460,12 +499,25 @@ or self.rfOpenFiles.isChecked() or self.rOpenFileUrls.isChecked() ): + # + # getOpenFile...s + # if self.rOpenFiles.isChecked(): - code += "getOpenFileNames({0}{1}".format(os.linesep, istring) + method = ( + "getOpenFilePaths" + if self.__dialogVariant == -2 + else "getOpenFileNames" + ) + code += "{0}({1}{2}".format(method, os.linesep, istring) elif self.rOpenFileUrls.isChecked(): code += "getOpenFileUrls({0}{1}".format(os.linesep, istring) else: - code += "getOpenFileNamesAndFilter({0}{1}".format(os.linesep, istring) + method = ( + "getOpenFilePathsAndFilter" + if self.__dialogVariant == -2 + else "getOpenFileNamesAndFilter" + ) + code += "{0}({1}{2}".format(method, os.linesep, istring) code += "{0},{1}{2}".format(parent, os.linesep, istring) if not self.eCaption.text(): code += '"",{0}{1}'.format(os.linesep, istring) @@ -523,12 +575,25 @@ or self.rfSaveFile.isChecked() or self.rSaveFileUrl.isChecked() ): + # + # getSaveFile... + # if self.rSaveFile.isChecked(): - code += "getSaveFileName({0}{1}".format(os.linesep, istring) + method = ( + "getSaveFilePath" + if self.__dialogVariant == -2 + else "getSaveFileName" + ) + code += "{0}({1}{2}".format(method, os.linesep, istring) elif self.rSaveFileUrl.isChecked(): code += "getSaveFileUrl({0}{1}".format(os.linesep, istring) else: - code += "getSaveFileNameAndFilter({0}{1}".format(os.linesep, istring) + method = ( + "getSaveFilePathAndFilter" + if self.__dialogVariant == -2 + else "getSaveFileNameAndFilter" + ) + code += "{0}({1}{2}".format(method, os.linesep, istring) code += "{0},{1}{2}".format(parent, os.linesep, istring) if not self.eCaption.text(): code += '"",{0}{1}'.format(os.linesep, istring) @@ -592,7 +657,12 @@ code += "{0}){0}".format(estring) elif self.rDirectory.isChecked() or self.rDirectoryUrl.isChecked(): if self.rDirectory.isChecked(): - code += "getExistingDirectory({0}{1}".format(os.linesep, istring) + method = ( + "getExistingDirectoryPath" + if self.__dialogVariant == -2 + else "getExistingDirectory" + ) + code += "{0}({1}{2}".format(method, os.linesep, istring) else: code += "getExistingDirectoryUrl({0}{1}".format(os.linesep, istring) code += "{0},{1}{2}".format(parent, os.linesep, istring)