Gtk.FileDialog

g GObject.Object GObject.Object Gtk.FileDialog Gtk.FileDialog GObject.Object->Gtk.FileDialog

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new ()

get_accept_label ()

get_default_filter ()

get_filters ()

get_initial_file ()

get_initial_folder ()

get_initial_name ()

get_modal ()

get_title ()

open (parent, cancellable, callback, *user_data)

open_finish (result)

open_multiple (parent, cancellable, callback, *user_data)

open_multiple_finish (result)

save (parent, cancellable, callback, *user_data)

save_finish (result)

select_folder (parent, cancellable, callback, *user_data)

select_folder_finish (result)

select_multiple_folders (parent, cancellable, callback, *user_data)

select_multiple_folders_finish (result)

set_accept_label (accept_label)

set_default_filter (filter)

set_filters (filters)

set_initial_file (file)

set_initial_folder (folder)

set_initial_name (name)

set_modal (modal)

set_title (title)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

accept-label

str

r/w/en

default-filter

Gtk.FileFilter

r/w/en

filters

Gio.ListModel

r/w/en

initial-file

Gio.File

r/w/en

initial-folder

Gio.File

r/w/en

initial-name

str

r/w/en

modal

bool

r/w/en

title

str

r/w/en

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class Gtk.FileDialog(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

Gtk.FileDialogClass

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 [method`Gtk`.FileDialog.open], [method`Gtk`.FileDialog.save], etc. These APIs follow the GIO async pattern, and the result can be obtained by calling the corresponding finish function, for example [method`Gtk`.FileDialog.open_finish].

New in version 4.10.

classmethod new()[source]
Returns:

the new GtkFileDialog

Return type:

Gtk.FileDialog

Creates a new GtkFileDialog object.

New in version 4.10.

get_accept_label()[source]
Returns:

the label shown on the file chooser’s accept button.

Return type:

str or None

New in version 4.10.

get_default_filter()[source]
Returns:

the current filter

Return type:

Gtk.FileFilter or None

Gets the filter that will be selected by default in the file chooser dialog.

New in version 4.10.

get_filters()[source]
Returns:

the filters, as a GListModel of GtkFileFilters

Return type:

Gio.ListModel or None

Gets the filters that will be offered to the user in the file chooser dialog.

New in version 4.10.

get_initial_file()[source]
Returns:

the file

Return type:

Gio.File or None

Gets the file that will be initially selected in the file chooser dialog.

New in version 4.10.

get_initial_folder()[source]
Returns:

the folder

Return type:

Gio.File or None

Gets the folder that will be set as the initial folder in the file chooser dialog.

New in version 4.10.

get_initial_name()[source]
Returns:

the name

Return type:

str or None

Gets the name for the file that should be initially set.

New in version 4.10.

get_modal()[source]
Returns:

TRUE if the file chooser dialog is modal

Return type:

bool

Returns whether the file chooser dialog blocks interaction with the parent window while it is presented.

New in version 4.10.

get_title()[source]
Returns:

the title

Return type:

str

Returns the title that will be shown on the file chooser dialog.

New in version 4.10.

open(parent, cancellable, callback, *user_data)[source]
Parameters:

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 call [method`Gtk`.FileDialog.open_finish] to obtain the result.

New in version 4.10.

open_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a GAsyncResult

Raises:

GLib.Error

Returns:

the file that was selected. Otherwise, NULL is returned and error is set

Return type:

Gio.File or None

Finishes the [method`Gtk`.FileDialog.open] call and returns the resulting file.

New in version 4.10.

open_multiple(parent, cancellable, callback, *user_data)[source]
Parameters:

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 [property`Gtk`.FileDialog:initial-folder].

The callback will be called when the dialog is dismissed. It should call [method`Gtk`.FileDialog.open_multiple_finish] to obtain the result.

New in version 4.10.

open_multiple_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a GAsyncResult

Raises:

GLib.Error

Returns:

the file that was selected, as a GListModel of GFiles. Otherwise, NULL is returned and error is set

Return type:

Gio.ListModel or None

Finishes the [method`Gtk`.FileDialog.open] call and returns the resulting files in a GListModel.

New in version 4.10.

save(parent, cancellable, callback, *user_data)[source]
Parameters:

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 call [method`Gtk`.FileDialog.save_finish] to obtain the result.

New in version 4.10.

save_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a GAsyncResult

Raises:

GLib.Error

Returns:

the file that was selected. Otherwise, NULL is returned and error is set

Return type:

Gio.File or None

Finishes the [method`Gtk`.FileDialog.save] call and returns the resulting file.

New in version 4.10.

select_folder(parent, cancellable, callback, *user_data)[source]
Parameters:

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 directory [property`Gtk`.FileDialog:initial-folder].

The callback will be called when the dialog is dismissed. It should call [method`Gtk`.FileDialog.select_folder_finish] to obtain the result.

New in version 4.10.

select_folder_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a GAsyncResult

Raises:

GLib.Error

Returns:

the file that was selected. Otherwise, NULL is returned and error is set

Return type:

Gio.File or None

Finishes the [method`Gtk`.FileDialog.select_folder] call and returns the resulting file.

New in version 4.10.

select_multiple_folders(parent, cancellable, callback, *user_data)[source]
Parameters:

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 [property`Gtk`.FileDialog:initial-folder].

The callback will be called when the dialog is dismissed. It should call [method`Gtk`.FileDialog.select_multiple_folders_finish] to obtain the result.

New in version 4.10.

select_multiple_folders_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a GAsyncResult

Raises:

GLib.Error

Returns:

the file that was selected, as a GListModel of GFiles. Otherwise, NULL is returned and error is set

Return type:

Gio.ListModel or None

Finishes the [method`Gtk`.FileDialog.select_multiple_folders] call and returns the resulting files in a GListModel.

New in version 4.10.

set_accept_label(accept_label)[source]
Parameters:

accept_label (str or None) – the new accept label

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.

New in version 4.10.

set_default_filter(filter)[source]
Parameters:

filter (Gtk.FileFilter or None) – a GtkFileFilter

Sets the filter that will be selected by default in the file chooser dialog.

If set to None, the first item in [property`Gtk`.FileDialog:filters] will be used as the default filter. If that list is empty, the dialog will be unfiltered.

New in version 4.10.

set_filters(filters)[source]
Parameters:

filters (Gio.ListModel or None) – a GListModel of GtkFileFilters

Sets the filters that will be offered to the user in the file chooser dialog.

New in version 4.10.

set_initial_file(file)[source]
Parameters:

file (Gio.File or None) – a GFile

Sets the file that will be initially selected in the file chooser dialog.

This function is a shortcut for calling both Gtk.FileDialog.set_initial_folder() and Gtk.FileDialog.set_initial_name() with the directory and name of file respectively.

New in version 4.10.

set_initial_folder(folder)[source]
Parameters:

folder (Gio.File or None) – a GFile

Sets the folder that will be set as the initial folder in the file chooser dialog.

New in version 4.10.

set_initial_name(name)[source]
Parameters:

name (str or None) – a UTF8 string

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 [property`Gtk`.FileDialog:initial-folder], the dialog should preselect it.

New in version 4.10.

set_modal(modal)[source]
Parameters:

modal (bool) – the new value

Sets whether the file chooser dialog blocks interaction with the parent window while it is presented.

New in version 4.10.

set_title(title)[source]
Parameters:

title (str) – the new title

Sets the title that will be shown on the file chooser dialog.

New in version 4.10.

Property Details

Gtk.FileDialog.props.accept_label
Name:

accept-label

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Label for the file chooser’s accept button.

New in version 4.10.

Gtk.FileDialog.props.default_filter
Name:

default-filter

Type:

Gtk.FileFilter

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

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 of [property`Gtk`.FileDialog:filters] is used as the default filter. If that property contains no filter, the dialog will be unfiltered.

If [property`Gtk`.FileDialog:filters] is not None, the default filter should be part of the list. If it is not, the dialog may choose to not make it available.

New in version 4.10.

Gtk.FileDialog.props.filters
Name:

filters

Type:

Gio.ListModel

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The list of filters.

See [property`Gtk`.FileDialog:default-filter] about how those two properties interact.

New in version 4.10.

Gtk.FileDialog.props.initial_file
Name:

initial-file

Type:

Gio.File

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The initial file, that is, the file that is initially selected in the file chooser dialog

This is a utility property that sets both [property`Gtk`.FileDialog:initial-folder] and [property`Gtk`.FileDialog:initial-name].

New in version 4.10.

Gtk.FileDialog.props.initial_folder
Name:

initial-folder

Type:

Gio.File

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The initial folder, that is, the directory that is initially opened in the file chooser dialog

New in version 4.10.

Gtk.FileDialog.props.initial_name
Name:

initial-name

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The initial name, that is, the filename that is initially selected in the file chooser dialog.

New in version 4.10.

Gtk.FileDialog.props.modal
Name:

modal

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether the file chooser dialog is modal.

New in version 4.10.

Gtk.FileDialog.props.title
Name:

title

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

A title that may be shown on the file chooser dialog.

New in version 4.10.