EricFileDialog eric7

Thu, 01 Feb 2024 15:44:36 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 01 Feb 2024 15:44:36 +0100
branch
eric7
changeset 10537
cd0fd14d09d5
parent 10536
9ffc1d79d3d8
child 10538
decb03459cd4

EricFileDialog
- Harmonized the API of the module level functions.

src/eric7/EricWidgets/EricFileDialog.py file | annotate | diff | comparison | revisions
src/eric7/Plugins/PluginWizardQFileDialog.py file | annotate | diff | comparison | revisions
src/eric7/Plugins/WizardPlugins/FileDialogWizard/FileDialogWizardDialog.py file | annotate | diff | comparison | revisions
--- a/src/eric7/EricWidgets/EricFileDialog.py	Thu Feb 01 13:30:35 2024 +0100
+++ b/src/eric7/EricWidgets/EricFileDialog.py	Thu Feb 01 15:44:36 2024 +0100
@@ -31,8 +31,8 @@
 
     @param filterStr Qt file filter
     @type str
-    @param initialFilter initial filter
-    @type str
+    @param initialFilter initial filter (defaults to "")
+    @type str (optional)
     @return the rearranged Qt file filter
     @rtype str
     """
@@ -51,27 +51,29 @@
 ###########################################################################
 
 
-def getOpenFileName(parent=None, caption="", directory="", filterStr="", options=None):
+def getOpenFileName(
+    parent=None, caption="", directory="", filterStr="", initialFilter="", options=None
+):
     """
     Module function to get the name of a file for opening it.
 
-    @param parent parent widget of the dialog
-    @type QWidget
-    @param caption window title of the dialog
-    @type str
-    @param directory working directory of the dialog
-    @type str
-    @param filterStr filter string for the dialog
-    @type str
-    @param options various options for the dialog
-    @type QFileDialog.Options
+    @param parent parent widget of the dialog (defaults to None)
+    @type QWidget (optional)
+    @param caption window title of the dialog (defaults to "")
+    @type str (optional)
+    @param directory working directory of the dialog (defaults to "")
+    @type str (optional)
+    @param filterStr filter string for the dialog (defaults to "")
+    @type str (optional)
+    @param initialFilter initial filter for the dialog (defaults to "")
+    @type str (optional)
+    @param options various options for the dialog (defaults to None)
+    @type QFileDialog.Options ((optional)
     @return name of file to be opened
     @rtype str
     """
-    if options is None:
-        options = QFileDialog.Option(0)
-    return QFileDialog.getOpenFileName(
-        parent, caption, directory, filterStr, "", options
+    return getOpenFileNameAndFilter(
+        parent, caption, directory, filterStr, initialFilter, options
     )[0]
 
 
@@ -82,18 +84,18 @@
     Module function to get the name of a file for opening it and the selected
     file name filter.
 
-    @param parent parent widget of the dialog
-    @type QWidget
-    @param caption window title of the dialog
-    @type str
-    @param directory working directory of the dialog
-    @type str
-    @param filterStr filter string for the dialog
-    @type str
-    @param initialFilter initial filter for the dialog
-    @type str
-    @param options various options for the dialog
-    @type QFileDialog.Options
+    @param parent parent widget of the dialog (defaults to None)
+    @type QWidget (optional)
+    @param caption window title of the dialog (defaults to "")
+    @type str (optional)
+    @param directory working directory of the dialog (defaults to "")
+    @type str (optional)
+    @param filterStr filter string for the dialog (defaults to "")
+    @type str (optional)
+    @param initialFilter initial filter for the dialog (defaults to "")
+    @type str (optional)
+    @param options various options for the dialog (defaults to None)
+    @type QFileDialog.Options ((optional)
     @return name of file to be opened and selected filter
     @rtype tuple of (str, str)
     """
@@ -105,27 +107,29 @@
     )
 
 
-def getOpenFileNames(parent=None, caption="", directory="", filterStr="", options=None):
+def getOpenFileNames(
+    parent=None, caption="", directory="", filterStr="", initialFilter="", options=None
+):
     """
     Module function to get a list of names of files for opening.
 
-    @param parent parent widget of the dialog
-    @type QWidget
-    @param caption window title of the dialog
-    @type str
-    @param directory working directory of the dialog
-    @type str
-    @param filterStr filter string for the dialog
-    @type str
-    @param options various options for the dialog
-    @type QFileDialog.Options
+    @param parent parent widget of the dialog (defaults to None)
+    @type QWidget (optional)
+    @param caption window title of the dialog (defaults to "")
+    @type str (optional)
+    @param directory working directory of the dialog (defaults to "")
+    @type str (optional)
+    @param filterStr filter string for the dialog (defaults to "")
+    @type str (optional)
+    @param initialFilter initial filter for the dialog (defaults to "")
+    @type str (optional)
+    @param options various options for the dialog (defaults to None)
+    @type QFileDialog.Options ((optional)
     @return list of file names to be opened
     @rtype list of str
     """
-    if options is None:
-        options = QFileDialog.Option(0)
-    return QFileDialog.getOpenFileNames(
-        parent, caption, directory, filterStr, "", options
+    return getOpenFileNamesAndFilter(
+        parent, caption, directory, filterStr, initialFilter, options
     )[0]
 
 
@@ -136,18 +140,18 @@
     Module function to get a list of names of files for opening and the
     selected file name filter.
 
-    @param parent parent widget of the dialog
-    @type QWidget
-    @param caption window title of the dialog
-    @type str
-    @param directory working directory of the dialog
-    @type str
-    @param filterStr filter string for the dialog
-    @type str
-    @param initialFilter initial filter for the dialog
-    @type str
-    @param options various options for the dialog
-    @type QFileDialog.Options
+    @param parent parent widget of the dialog (defaults to None)
+    @type QWidget (optional)
+    @param caption window title of the dialog (defaults to "")
+    @type str (optional)
+    @param directory working directory of the dialog (defaults to "")
+    @type str (optional)
+    @param filterStr filter string for the dialog (defaults to "")
+    @type str (optional)
+    @param initialFilter initial filter for the dialog (defaults to "")
+    @type str (optional)
+    @param options various options for the dialog (defaults to None)
+    @type QFileDialog.Options ((optional)
     @return list of file names to be opened and selected filter
     @rtype tuple of (list of str, str)
     """
@@ -165,16 +169,16 @@
     """
     Module function to get the names of files and directories for opening.
 
-    @param parent parent widget of the dialog
-    @type QWidget
-    @param caption window title of the dialog
-    @type str
-    @param directory working directory of the dialog
-    @type str
-    @param filterStr filter string for the dialog
-    @type str
-    @param options various options for the dialog
-    @type QFileDialog.Options
+    @param parent parent widget of the dialog (defaults to None)
+    @type QWidget (optional)
+    @param caption window title of the dialog (defaults to "")
+    @type str (optional)
+    @param directory working directory of the dialog (defaults to "")
+    @type str (optional)
+    @param filterStr filter string for the dialog (defaults to "")
+    @type str (optional)
+    @param options various options for the dialog (defaults to None)
+    @type QFileDialog.Options ((optional)
     @return names of the selected files and folders
     @rtype list of str
     """
@@ -185,27 +189,29 @@
     )
 
 
-def getSaveFileName(parent=None, caption="", directory="", filterStr="", options=None):
+def getSaveFileName(
+    parent=None, caption="", directory="", filterStr="", initialFilter="", options=None
+):
     """
     Module function to get the name of a file for saving.
 
-    @param parent parent widget of the dialog
-    @type QWidget
-    @param caption window title of the dialog
-    @type str
-    @param directory working directory of the dialog
-    @type str
-    @param filterStr filter string for the dialog
-    @type str
-    @param options various options for the dialog
-    @type QFileDialog.Options
+    @param parent parent widget of the dialog (defaults to None)
+    @type QWidget (optional)
+    @param caption window title of the dialog (defaults to "")
+    @type str (optional)
+    @param directory working directory of the dialog (defaults to "")
+    @type str (optional)
+    @param filterStr filter string for the dialog (defaults to "")
+    @type str (optional)
+    @param initialFilter initial filter for the dialog (defaults to "")
+    @type str (optional)
+    @param options various options for the dialog (defaults to None)
+    @type QFileDialog.Options ((optional)
     @return name of file to be saved
     @rtype str
     """
-    if options is None:
-        options = QFileDialog.Option(0)
-    return QFileDialog.getSaveFileName(
-        parent, caption, directory, filterStr, "", options
+    return getSaveFileNameAndFilter(
+        parent, caption, directory, filterStr, initialFilter, options
     )[0]
 
 
@@ -216,18 +222,18 @@
     Module function to get the name of a file for saving and the selected file name
     filter.
 
-    @param parent parent widget of the dialog
-    @type QWidget
-    @param caption window title of the dialog
-    @type str
-    @param directory working directory of the dialog
-    @type str
-    @param filterStr filter string for the dialog
-    @type str
-    @param initialFilter initial filter for the dialog
-    @type str
-    @param options various options for the dialog
-    @type QFileDialog.Options
+    @param parent parent widget of the dialog (defaults to None)
+    @type QWidget (optional)
+    @param caption window title of the dialog (defaults to "")
+    @type str (optional)
+    @param directory working directory of the dialog (defaults to "")
+    @type str (optional)
+    @param filterStr filter string for the dialog (defaults to "")
+    @type str (optional)
+    @param initialFilter initial filter for the dialog (defaults to "")
+    @type str (optional)
+    @param options various options for the dialog (defaults to None)
+    @type QFileDialog.Options ((optional)
     @return name of file to be saved and selected filte
     @rtype tuple of (str, str)
     """
@@ -245,14 +251,15 @@
     """
     Module function to get the name of a directory.
 
-    @param parent parent widget of the dialog
-    @type QWidget
-    @param caption window title of the dialog
-    @type str
-    @param directory working directory of the dialog
-    @type str
-    @param options various options for the dialog
-    @type QFileDialog.Options
+    @param parent parent widget of the dialog (defaults to None)
+    @type QWidget (optional)
+    @param caption window title of the dialog (defaults to "")
+    @type str (optional)
+    @param directory working directory of the dialog (defaults to "")
+    @type str (optional)
+    @param options various options for the dialog (defaults to
+        QFileDialog.Option.ShowDirsOnly)
+    @type QFileDialog.Options ((optional)
     @return name of selected directory
     @rtype str
     """
@@ -266,29 +273,30 @@
 ###########################################################################
 
 
-def getOpenFilePath(parent=None, caption="", directory="", filterStr="", options=None):
+def getOpenFilePath(
+    parent=None, caption="", directory="", filterStr="", initialFilter="", options=None
+):
     """
     Module function to get the path of a file for opening it.
 
-    @param parent parent widget of the dialog
-    @type QWidget
-    @param caption window title of the dialog
-    @type str
-    @param directory working directory of the dialog
-    @type str or pathlib.Path
-    @param filterStr filter string for the dialog
-    @type str
-    @param options various options for the dialog
-    @type QFileDialog.Options
+    @param parent parent widget of the dialog (defaults to None)
+    @type QWidget (optional)
+    @param caption window title of the dialog (defaults to "")
+    @type str (optional)
+    @param directory working directory of the dialog (defaults to "")
+    @type str or pathlib.Path (optional)
+    @param filterStr filter string for the dialog (defaults to "")
+    @type str (optional)
+    @param initialFilter initial filter for the dialog (defaults to "")
+    @type str (optional)
+    @param options various options for the dialog (defaults to None)
+    @type QFileDialog.Options ((optional)
     @return path of file to be opened
     @rtype pathlib.Path
     """
-    if options is None:
-        options = QFileDialog.Option(0)
-    filename = QFileDialog.getOpenFileName(
-        parent, caption, str(directory), filterStr, "", options
+    return getOpenFilePathAndFilter(
+        parent, caption, directory, filterStr, initialFilter, options
     )[0]
-    return pathlib.Path(filename)
 
 
 def getOpenFilePathAndFilter(
@@ -298,18 +306,18 @@
     Module function to get the path of a file for opening it and the selected
     file name filter.
 
-    @param parent parent widget of the dialog
-    @type QWidget
-    @param caption window title of the dialog
-    @type str
-    @param directory working directory of the dialog
-    @type str or pathlib.Path
-    @param filterStr filter string for the dialog
-    @type str
-    @param initialFilter initial filter for the dialog
-    @type str
-    @param options various options for the dialog
-    @type QFileDialog.Options
+    @param parent parent widget of the dialog (defaults to None)
+    @type QWidget (optional)
+    @param caption window title of the dialog (defaults to "")
+    @type str (optional)
+    @param directory working directory of the dialog (defaults to "")
+    @type str or pathlib.Path (optional)
+    @param filterStr filter string for the dialog (defaults to "")
+    @type str (optional)
+    @param initialFilter initial filter for the dialog (defaults to "")
+    @type str (optional)
+    @param options various options for the dialog (defaults to None)
+    @type QFileDialog.Options ((optional)
     @return path of file to be opened and selected filter
     @rtype tuple of (pathlib.Path, str)
     """
@@ -322,29 +330,30 @@
     return pathlib.Path(filename), selectedFilter
 
 
-def getOpenFilePaths(parent=None, caption="", directory="", filterStr="", options=None):
+def getOpenFilePaths(
+    parent=None, caption="", directory="", filterStr="", initialFilter="", options=None
+):
     """
     Module function to get a list of paths of files for opening.
 
-    @param parent parent widget of the dialog
-    @type QWidget
-    @param caption window title of the dialog
-    @type str
-    @param directory working directory of the dialog
-    @type str or pathlib.Path
-    @param filterStr filter string for the dialog
-    @type str
-    @param options various options for the dialog
-    @type QFileDialog.Options
+    @param parent parent widget of the dialog (defaults to None)
+    @type QWidget (optional)
+    @param caption window title of the dialog (defaults to "")
+    @type str (optional)
+    @param directory working directory of the dialog (defaults to "")
+    @type str or pathlib.Path (optional)
+    @param filterStr filter string for the dialog (defaults to "")
+    @type str (optional)
+    @param initialFilter initial filter for the dialog (defaults to "")
+    @type str (optional)
+    @param options various options for the dialog (defaults to None)
+    @type QFileDialog.Options ((optional)
     @return list of file paths to be opened
     @rtype list of pathlib.Path
     """
-    if options is None:
-        options = QFileDialog.Option(0)
-    filenames = QFileDialog.getOpenFileNames(
-        parent, caption, str(directory), filterStr, "", options
+    return getOpenFilPathsAndFilter(
+        parent, caption, directory, filterStr, initialFilter, options
     )[0]
-    return [pathlib.Path(f) for f in filenames]
 
 
 def getOpenFilPathsAndFilter(
@@ -354,18 +363,18 @@
     Module function to get a list of paths of files for opening and the
     selected file name filter.
 
-    @param parent parent widget of the dialog
-    @type QWidget
-    @param caption window title of the dialog
-    @type str
-    @param directory working directory of the dialog
-    @type str or pathlib.Path
-    @param filterStr filter string for the dialog
-    @type str
-    @param initialFilter initial filter for the dialog
-    @type str
-    @param options various options for the dialog
-    @type QFileDialog.Options
+    @param parent parent widget of the dialog (defaults to None)
+    @type QWidget (optional)
+    @param caption window title of the dialog (defaults to "")
+    @type str (optional)
+    @param directory working directory of the dialog (defaults to "")
+    @type str or pathlib.Path (optional)
+    @param filterStr filter string for the dialog (defaults to "")
+    @type str (optional)
+    @param initialFilter initial filter for the dialog (defaults to "")
+    @type str (optional)
+    @param options various options for the dialog (defaults to None)
+    @type QFileDialog.Options ((optional)
     @return list of file paths to be opened and selected filter
     @rtype tuple of (list of pathlib.Path, str)
     """
@@ -384,16 +393,16 @@
     """
     Module function to get the paths of files and directories for opening.
 
-    @param parent parent widget of the dialog
-    @type QWidget
-    @param caption window title of the dialog
-    @type str
-    @param directory working directory of the dialog
-    @type str or pathlib.Path
-    @param filterStr filter string for the dialog
-    @type str
-    @param options various options for the dialog
-    @type QFileDialog.Options
+    @param parent parent widget of the dialog (defaults to None)
+    @type QWidget (optional)
+    @param caption window title of the dialog (defaults to "")
+    @type str (optional)
+    @param directory working directory of the dialog (defaults to "")
+    @type str or pathlib.Path (optional)
+    @param filterStr filter string for the dialog (defaults to "")
+    @type str (optional)
+    @param options various options for the dialog (defaults to None)
+    @type QFileDialog.Options ((optional)
     @return paths of the selected files and folders
     @rtype list of pathlib.Path
     """
@@ -404,29 +413,30 @@
     )
 
 
-def getSaveFilePath(parent=None, caption="", directory="", filterStr="", options=None):
+def getSaveFilePath(
+    parent=None, caption="", directory="", filterStr="", initialFilter="", options=None
+):
     """
     Module function to get the path of a file for saving.
 
-    @param parent parent widget of the dialog
-    @type QWidget
-    @param caption window title of the dialog
-    @type str
-    @param directory working directory of the dialog
-    @type str or pathlib.Path
-    @param filterStr filter string for the dialog
-    @type str
-    @param options various options for the dialog
-    @type QFileDialog.Options
+    @param parent parent widget of the dialog (defaults to None)
+    @type QWidget (optional)
+    @param caption window title of the dialog (defaults to "")
+    @type str (optional)
+    @param directory working directory of the dialog (defaults to "")
+    @type str or pathlib.Path (optional)
+    @param filterStr filter string for the dialog (defaults to "")
+    @type str (optional)
+    @param initialFilter initial filter for the dialog (defaults to "")
+    @type str (optional)
+    @param options various options for the dialog (defaults to None)
+    @type QFileDialog.Options ((optional)
     @return path of file to be saved
     @rtype pathlib.Path
     """
-    if options is None:
-        options = QFileDialog.Option(0)
-    filename = QFileDialog.getSaveFileName(
-        parent, caption, str(directory), filterStr, "", options
+    return getSaveFilePathAndFilter(
+        parent, caption, str(directory), filterStr, initialFilter, options
     )[0]
-    return pathlib.Path(filename)
 
 
 def getSaveFilePathAndFilter(
@@ -436,18 +446,18 @@
     Module function to get the path of a file for saving and the selected
     file name filter.
 
-    @param parent parent widget of the dialog
-    @type QWidget
-    @param caption window title of the dialog
-    @type str
-    @param directory working directory of the dialog
-    @type str or pathlib.Path
-    @param filterStr filter string for the dialog
-    @type str
-    @param initialFilter initial filter for the dialog
-    @type str
-    @param options various options for the dialog
-    @type QFileDialog.Options
+    @param parent parent widget of the dialog (defaults to None)
+    @type QWidget (optional)
+    @param caption window title of the dialog (defaults to "")
+    @type str (optional)
+    @param directory working directory of the dialog (defaults to "")
+    @type str or pathlib.Path (optional)
+    @param filterStr filter string for the dialog (defaults to "")
+    @type str (optional)
+    @param initialFilter initial filter for the dialog (defaults to "")
+    @type str (optional)
+    @param options various options for the dialog (defaults to None)
+    @type QFileDialog.Options ((optional)
     @return path of file to be saved and selected filte
     @rtype tuple of (pathlib.Path, str)
     """
@@ -466,14 +476,15 @@
     """
     Module function to get the path of a directory.
 
-    @param parent parent widget of the dialog
-    @type QWidget
-    @param caption window title of the dialog
-    @type str
-    @param directory working directory of the dialog
-    @type str or pathlib.Path
-    @param options various options for the dialog
-    @type QFileDialog.Options
+    @param parent parent widget of the dialog (defaults to None)
+    @type QWidget (optional)
+    @param caption window title of the dialog (defaults to "")
+    @type str (optional)
+    @param directory working directory of the dialog (defaults to "")
+    @type str or pathlib.Path (optional)
+    @param options various options for the dialog (defaults to
+        QFileDialog.Option.ShowDirsOnly)
+    @type QFileDialog.Options ((optional)
     @return path of selected directory
     @rtype pathlib.Path
     """
--- a/src/eric7/Plugins/PluginWizardQFileDialog.py	Thu Feb 01 13:30:35 2024 +0100
+++ b/src/eric7/Plugins/PluginWizardQFileDialog.py	Thu Feb 01 15:44:36 2024 +0100
@@ -98,7 +98,7 @@
                 """ inserted at the current cursor position.</p>"""
             )
         )
-        self.qFileDialogAction.triggered.connect(self.__handleQFileDialog)
+        self.qFileDialogAction.triggered.connect(lambda: self.__handle("QFileDialog"))
 
         self.ericFileDialogAction = EricAction(
             self.tr("EricFileDialog Wizard"),
@@ -117,7 +117,9 @@
                 """ inserted at the current cursor position.</p>"""
             )
         )
-        self.ericFileDialogAction.triggered.connect(self.__handleEricFileDialog)
+        self.ericFileDialogAction.triggered.connect(
+            lambda: self.__handle("EricFileDialog")
+        )
 
         self.__ui.addEricActions(
             [self.qFileDialogAction, self.ericFileDialogAction], "wizards"
@@ -198,15 +200,3 @@
                 editor.beginUndoAction()
                 editor.insertAt(code, line, index)
                 editor.endUndoAction()
-
-    def __handleQFileDialog(self):
-        """
-        Private slot to handle the wizard QFileDialog action.
-        """
-        self.__handle("QFileDialog")
-
-    def __handleEricFileDialog(self):
-        """
-        Private slot to handle the wizard EricFileDialog action.
-        """
-        self.__handle("EricFileDialog")
--- a/src/eric7/Plugins/WizardPlugins/FileDialogWizard/FileDialogWizardDialog.py	Thu Feb 01 13:30:35 2024 +0100
+++ b/src/eric7/Plugins/WizardPlugins/FileDialogWizard/FileDialogWizardDialog.py	Thu Feb 01 15:44:36 2024 +0100
@@ -31,7 +31,7 @@
             "eric_string",
         ),
         (
-            QCoreApplication.translate("FileDialogWizardDialog", "eric (Path)"),
+            QCoreApplication.translate("FileDialogWizardDialog", "eric (pathlib.Path)"),
             "eric_pathlib",
         ),
     )
@@ -317,9 +317,9 @@
         @param checkedId id of the clicked button
         @type int
         """
-        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]
-        )
+        enable = (
+            self.__dialogVariant in (-1, -2) and checkedId in [1, 2, 3, 11, 12, 13]
+        ) or (self.__dialogVariant in (5, 6) and checkedId in [1, 2, 3, 21, 22, 23])
 
         self.lInitialFilter.setEnabled(enable)
         self.eInitialFilter.setEnabled(enable)
@@ -459,16 +459,15 @@
                 else:
                     fmt = 'self.tr("{0}")'
                 code += fmt.format(self.eFilters.text())
-            if self.rfOpenFile.isChecked() or self.__dialogVariant in (5, 6):
-                if self.eInitialFilter.text() == "":
-                    initialFilter = "None"
+            if self.eInitialFilter.text() == "":
+                initialFilter = "None"
+            else:
+                if self.cInitialFilter.isChecked():
+                    fmt = "{0}"
                 else:
-                    if self.cInitialFilter.isChecked():
-                        fmt = "{0}"
-                    else:
-                        fmt = 'self.tr("{0}")'
-                    initialFilter = fmt.format(self.eInitialFilter.text())
-                code += ",{0}{1}{2}".format(os.linesep, istring, initialFilter)
+                    fmt = 'self.tr("{0}")'
+                initialFilter = fmt.format(self.eInitialFilter.text())
+            code += ",{0}{1}{2}".format(os.linesep, istring, initialFilter)
             if not self.cSymlinks.isChecked():
                 code += ",{0}{1}{2}{3}.DontResolveSymlinks".format(
                     os.linesep, istring, dialogType, optionStr
@@ -535,16 +534,15 @@
                 else:
                     fmt = 'self.tr("{0}")'
                 code += fmt.format(self.eFilters.text())
-            if self.rfOpenFiles.isChecked() or self.__dialogVariant in (5, 6):
-                if self.eInitialFilter.text() == "":
-                    initialFilter = "None"
+            if self.eInitialFilter.text() == "":
+                initialFilter = "None"
+            else:
+                if self.cInitialFilter.isChecked():
+                    fmt = "{0}"
                 else:
-                    if self.cInitialFilter.isChecked():
-                        fmt = "{0}"
-                    else:
-                        fmt = 'self.tr("{0}")'
-                    initialFilter = fmt.format(self.eInitialFilter.text())
-                code += ",{0}{1}{2}".format(os.linesep, istring, initialFilter)
+                    fmt = 'self.tr("{0}")'
+                initialFilter = fmt.format(self.eInitialFilter.text())
+            code += ",{0}{1}{2}".format(os.linesep, istring, initialFilter)
             if not self.cSymlinks.isChecked():
                 code += ",{0}{1}{2}{3}.DontResolveSymlinks".format(
                     os.linesep, istring, dialogType, optionStr
@@ -611,16 +609,15 @@
                 else:
                     fmt = 'self.tr("{0}")'
                 code += fmt.format(self.eFilters.text())
-            if self.rfSaveFile.isChecked() or self.__dialogVariant in (5, 6):
-                if self.eInitialFilter.text() == "":
-                    initialFilter = "None"
+            if self.eInitialFilter.text() == "":
+                initialFilter = "None"
+            else:
+                if self.cInitialFilter.isChecked():
+                    fmt = "{0}"
                 else:
-                    if self.cInitialFilter.isChecked():
-                        fmt = "{0}"
-                    else:
-                        fmt = 'self.tr("{0}")'
-                    initialFilter = fmt.format(self.eInitialFilter.text())
-                code += ",{0}{1}{2}".format(os.linesep, istring, initialFilter)
+                    fmt = 'self.tr("{0}")'
+                initialFilter = fmt.format(self.eInitialFilter.text())
+            code += ",{0}{1}{2}".format(os.linesep, istring, initialFilter)
             if (not self.cSymlinks.isChecked()) or (
                 not self.cConfirmOverwrite.isChecked()
             ):

eric ide

mercurial