--- 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 """