FileDialog
Added in version 4.10.
Superclasses: Object
A GtkFileDialog
object collects the arguments that
are needed to present a file chooser dialog to the
user, such as a title for the dialog and whether it
should be modal.
The dialog is shown with open
,
save
, etc. These APIs follow the
GIO async pattern, and the result can be obtained by calling
the corresponding finish function, for example
open_finish
.
Constructors
- class FileDialog
- classmethod new() FileDialog
Creates a new
GtkFileDialog
object.Added in version 4.10.
Methods
- class FileDialog
-
- get_default_filter() FileFilter | None
Gets the filter that will be selected by default in the file chooser dialog.
Added in version 4.10.
- get_filters() ListModel | None
Gets the filters that will be offered to the user in the file chooser dialog.
Added in version 4.10.
- get_initial_file() File | None
Gets the file that will be initially selected in the file chooser dialog.
Added in version 4.10.
- get_initial_folder() File | None
Gets the folder that will be set as the initial folder in the file chooser dialog.
Added in version 4.10.
- get_initial_name() str | None
Gets the name for the file that should be initially set.
Added in version 4.10.
- get_modal() bool
Returns whether the file chooser dialog blocks interaction with the parent window while it is presented.
Added in version 4.10.
- get_title() str
Returns the title that will be shown on the file chooser dialog.
Added in version 4.10.
- open(parent: Window | None = None, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None
This function initiates a file selection operation by presenting a file chooser dialog to the user.
The
callback
will be called when the dialog is dismissed. It should callopen_finish
to obtain the result.Added in version 4.10.
- Parameters:
parent – the parent
GtkWindow
cancellable – a
GCancellable
to cancel the operationcallback – a callback to call when the operation is complete
user_data – data to pass to
callback
- open_finish(result: AsyncResult) File | None
Finishes the
open
call and returns the resulting file.Added in version 4.10.
- Parameters:
result – a
GAsyncResult
- open_multiple(parent: Window | None = None, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None
This function initiates a multi-file selection operation by presenting a file chooser dialog to the user.
The file chooser will initially be opened in the directory
initial_folder
.The
callback
will be called when the dialog is dismissed. It should callopen_multiple_finish
to obtain the result.Added in version 4.10.
- Parameters:
parent – the parent
GtkWindow
cancellable – a
GCancellable
to cancel the operationcallback – a callback to call when the operation is complete
user_data – data to pass to
callback
- open_multiple_finish(result: AsyncResult) ListModel | None
Finishes the
open
call and returns the resulting files in aGListModel
.Added in version 4.10.
- Parameters:
result – a
GAsyncResult
- save(parent: Window | None = None, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None
This function initiates a file save operation by presenting a file chooser dialog to the user.
The
callback
will be called when the dialog is dismissed. It should callsave_finish
to obtain the result.Added in version 4.10.
- Parameters:
parent – the parent
GtkWindow
cancellable – a
GCancellable
to cancel the operationcallback – a callback to call when the operation is complete
user_data – data to pass to
callback
- save_finish(result: AsyncResult) File | None
Finishes the
save
call and returns the resulting file.Added in version 4.10.
- Parameters:
result – a
GAsyncResult
- select_folder(parent: Window | None = None, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None
This function initiates a directory selection operation by presenting a file chooser dialog to the user.
If you pass
initial_folder
, the file chooser will initially be opened in the parent directory of that folder, otherwise, it will be in the directoryinitial_folder
.The
callback
will be called when the dialog is dismissed. It should callselect_folder_finish
to obtain the result.Added in version 4.10.
- Parameters:
parent – the parent
GtkWindow
cancellable – a
GCancellable
to cancel the operationcallback – a callback to call when the operation is complete
user_data – data to pass to
callback
- select_folder_finish(result: AsyncResult) File | None
Finishes the
select_folder
call and returns the resulting file.Added in version 4.10.
- Parameters:
result – a
GAsyncResult
- select_multiple_folders(parent: Window | None = None, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None
This function initiates a multi-directory selection operation by presenting a file chooser dialog to the user.
The file chooser will initially be opened in the directory
initial_folder
.The
callback
will be called when the dialog is dismissed. It should callselect_multiple_folders_finish
to obtain the result.Added in version 4.10.
- Parameters:
parent – the parent
GtkWindow
cancellable – a
GCancellable
to cancel the operationcallback – a callback to call when the operation is complete
user_data – data to pass to
callback
- select_multiple_folders_finish(result: AsyncResult) ListModel | None
Finishes the
select_multiple_folders
call and returns the resulting files in aGListModel
.Added in version 4.10.
- Parameters:
result – a
GAsyncResult
- set_accept_label(accept_label: str | None = None) None
Sets the label shown on the file chooser’s accept button.
Leaving the accept label unset or setting it as
NULL
will fall back to a default label, depending on what API is used to launch the file dialog.Added in version 4.10.
- Parameters:
accept_label – the new accept label
- set_default_filter(filter: FileFilter | None = None) None
Sets the filter that will be selected by default in the file chooser dialog.
If set to
None
, the first item infilters
will be used as the default filter. If that list is empty, the dialog will be unfiltered.Added in version 4.10.
- Parameters:
filter – a
GtkFileFilter
- set_filters(filters: ListModel | None = None) None
Sets the filters that will be offered to the user in the file chooser dialog.
Added in version 4.10.
- Parameters:
filters – a
GListModel
ofGtkFileFilters
- set_initial_file(file: File | None = None) None
Sets the file that will be initially selected in the file chooser dialog.
This function is a shortcut for calling both
set_initial_folder()
andset_initial_name()
with the directory and name offile
respectively.Added in version 4.10.
- Parameters:
file – a
GFile
- set_initial_folder(folder: File | None = None) None
Sets the folder that will be set as the initial folder in the file chooser dialog.
Added in version 4.10.
- Parameters:
folder – a
GFile
- set_initial_name(name: str | None = None) None
Sets the name for the file that should be initially set. For saving dialogs, this will usually be pre-entered into the name field.
If a file with this name already exists in the directory set via
initial_folder
, the dialog should preselect it.Added in version 4.10.
- Parameters:
name – a UTF8 string
Properties
- class FileDialog
-
- props.default_filter: FileFilter
The default filter, that is, the filter that is initially active in the file chooser dialog.
If the default filter is
None
, the first filter offilters
is used as the default filter. If that property contains no filter, the dialog will be unfiltered.If
filters
is notNone
, the default filter should be part of the list. If it is not, the dialog may choose to not make it available.Added in version 4.10.
- props.filters: ListModel
The list of filters.
See
default_filter
about how those two properties interact.Added in version 4.10.
- props.initial_file: File
The initial file, that is, the file that is initially selected in the file chooser dialog
This is a utility property that sets both
initial_folder
andinitial_name
.Added in version 4.10.
- props.initial_folder: File
The initial folder, that is, the directory that is initially opened in the file chooser dialog
Added in version 4.10.