diff -r e9e7eca7efee -r bf71ee032bb4 src/eric7/EricWidgets/EricDirFileDialog.py --- a/src/eric7/EricWidgets/EricDirFileDialog.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/EricWidgets/EricDirFileDialog.py Wed Jul 13 14:55:47 2022 +0200 @@ -15,13 +15,14 @@ class EricDirFileDialog(QFileDialog): """ Derived QFileDialog to select files and directories simultaneously. - + For this purpose the none native file dialog is used. """ + def __init__(self, parent=None, caption="", directory="", filterStr=""): """ Constructor - + @param parent parent widget of the dialog @type QWidget @param caption window title of the dialog @@ -32,15 +33,15 @@ @type str """ self.__selectedFilesFolders = [] - + super().__init__(parent, caption, directory, filterStr) self.setFileMode(QFileDialog.FileMode.ExistingFiles) - + @pyqtSlot() def exec(self): """ Public slot to finalize initialization and start the event loop. - + @return accepted or rejected @rtype QDialog.DialogCode """ @@ -48,11 +49,10 @@ self.__fileNameEdit = self.findChild(QLineEdit) self.directoryEntered.connect(self.on_directoryEntered) self.__tree = self.findChild(QTreeView) - self.__tree.selectionModel().selectionChanged.connect( - self.on_selectionChanged) - + self.__tree.selectionModel().selectionChanged.connect(self.on_selectionChanged) + return QFileDialog.exec(self) - + @pyqtSlot() def accept(self): """ @@ -61,32 +61,33 @@ # Avoid to close the dialog if only return is pressed if not self.__openBtn.isEnabled(): return - + self.__selectedFilesFolders = [ x.data(QFileSystemModel.Roles.FilePathRole) for x in self.__tree.selectionModel().selectedIndexes() - if x.column() == 0] - + if x.column() == 0 + ] + self.hide() - + @pyqtSlot(str) def on_directoryEntered(self, directory): """ Private slot to reset selections if another directory was entered. - + @param directory name of the directory entered @type str """ self.__tree.selectionModel().clear() self.__fileNameEdit.clear() self.__openBtn.setEnabled(False) - + @pyqtSlot(QItemSelection, QItemSelection) def on_selectionChanged(self, selected, deselected): """ Private method to determine the selected files and folders and update the line edit. - + @param selected newly selected entries @type QItemSelection @param deselected deselected entries @@ -95,12 +96,15 @@ selectedItems = self.__tree.selectionModel().selectedIndexes() if self.__tree.rootIndex() in selectedItems or selectedItems == []: return - - selectedFiles = [x.data(QFileSystemModel.Roles.FileNameRole) - for x in selectedItems if x.column() == 0] + + selectedFiles = [ + x.data(QFileSystemModel.Roles.FileNameRole) + for x in selectedItems + if x.column() == 0 + ] enteredFiles = self.__fileNameEdit.text().split('"') enteredFiles = [x.strip() for x in enteredFiles if x.strip()] - + # Check if there is a directory in the selection. Then update the # lineEdit. for selectedFile in selectedFiles: @@ -110,13 +114,14 @@ txt = '"{0}"'.format(txt) self.__fileNameEdit.setText(txt) break - + @staticmethod - def getOpenFileAndDirNames(parent=None, caption="", directory="", - filterStr="", options=None): + def getOpenFileAndDirNames( + parent=None, caption="", directory="", filterStr="", options=None + ): """ Static method to get the names of files and directories for opening it. - + @param parent parent widget of the dialog @type QWidget @param caption window title of the dialog @@ -136,5 +141,5 @@ dlg = EricDirFileDialog(parent, caption, directory, filterStr) dlg.setOptions(options) dlg.exec() - + return dlg.__selectedFilesFolders