gtk.file_chooser

Module for [FileChooser] interface

Types 2

interfaceFileChooser

[gtk.file_chooser.FileChooser] is an interface that can be implemented by file selection widgets.

In GTK, the main objects that implement this interface are [gtk.file_chooser_widget.FileChooserWidget] and [gtk.file_chooser_dialog.FileChooserDialog].

You do not need to write an object that implements the [gtk.file_chooser.FileChooser] interface unless you are trying to adapt an existing file selector to expose a standard programming interface.

[gtk.file_chooser.FileChooser] allows for shortcuts to various places in the filesystem. In the default implementation these are displayed in the left pane. It may be a bit confusing at first that these shortcuts come from various sources and in various flavours, so lets explain the terminology here:

  • Bookmarks: are created by the user, by dragging folders from the

right pane to the left pane, or by using the “Add”. Bookmarks can be renamed and deleted by the user.

  • Shortcuts: can be provided by the application. For example, a Paint

program may want to add a shortcut for a Clipart folder. Shortcuts cannot be modified by the user.

  • Volumes: are provided by the underlying filesystem abstraction. They are

the “roots” of the filesystem.

File Names and Encodings

When the user is finished selecting files in a [gtk.file_chooser.FileChooser], your program can get the selected filenames as [gio.file.File]s.

Adding options

You can add extra widgets to a file chooser to provide options that are not present in the default design, by using [gtk.file_chooser.FileChooser.addChoice]. Each choice has an identifier and a user visible label; additionally, each choice can have multiple options. If a choice has no option, it will be rendered as a check button with the given label; if a choice has options, it will be rendered as a combo box.

Deprecated

Use [gtk.file_dialog.FileDialog] instead
Methods
gtk.types.FileChooserAction action() @propertyGet `action` property. Returns: The type of operation that the file chooser is performing.
void action(gtk.types.FileChooserAction propval) @propertySet `action` property. Params: propval = The type of operation that the file chooser is performing.
bool createFolders() @propertyGet `createFolders` property. Returns: Whether a file chooser not in [gtk.types.FileChooserAction.Open] mode will offer the user to create new folders.
void createFolders(bool propval) @propertySet `createFolders` property. Params: propval = Whether a file chooser not in [gtk.types.FileChooserAction.Open] mode will offer the user to create new folders.
gtk.file_filter.FileFilter filter() @propertyGet `filter` property. Returns: The current filter for selecting files that are displayed.
void filter(gtk.file_filter.FileFilter propval) @propertySet `filter` property. Params: propval = The current filter for selecting files that are displayed.
gio.list_model.ListModel filters() @propertyGet `filters` property. Returns: A [gio.listmodel.ListModel] containing the filters that have been added with [gtk.filechooser.FileChooser.addFilter].
bool selectMultiple() @propertyGet `selectMultiple` property. Returns: Whether to allow multiple files to be selected.
void selectMultiple(bool propval) @propertySet `selectMultiple` property. Params: propval = Whether to allow multiple files to be selected.
gio.list_model.ListModel shortcutFolders() @propertyGet `shortcutFolders` property. Returns: A [gio.listmodel.ListModel] containing the shortcut folders that have been added with [gtk.filechooser.FileChooser.addShortcutFolder].
void addChoice(string id, string label, string[] options = null, string[] optionLabels = null)Adds a 'choice' to the file chooser.
void addFilter(gtk.file_filter.FileFilter filter)Adds filter to the list of filters that the user can select between.
bool addShortcutFolder(gio.file.File folder)Adds a folder to be displayed with the shortcut folders in a file chooser.
gtk.types.FileChooserAction getAction()Gets the type of operation that the file chooser is performing. Returns: the action that the file selector is performing
string getChoice(string id)Gets the currently selected option in the 'choice' with the given ID.
bool getCreateFolders()Gets whether file chooser will offer to create new folders. Returns: true if the Create Folder button should be displayed.
gio.file.File getCurrentFolder()Gets the current folder of chooser as [gio.file.File]. Returns: the [gio.file.File] for the current folder.
string getCurrentName()Gets the current name in the file selector, as entered by the user.
gio.file.File getFile()Gets the [gio.file.File] for the currently selected file in the file selector.
gio.list_model.ListModel getFiles()Lists all the selected files and subfolders in the current folder of chooser as [gio.file.File]. Returns: a list model containing a [gio.file.File] for each selected file and subfolder in the curre...
gtk.file_filter.FileFilter getFilter()Gets the current filter. Returns: the current filter
gio.list_model.ListModel getFilters()Gets the current set of user-selectable filters, as a list model.
bool getSelectMultiple()Gets whether multiple files can be selected in the file chooser. Returns: true if multiple files can be selected.
gio.list_model.ListModel getShortcutFolders()Queries the list of shortcut folders in the file chooser.
void removeChoice(string id)Removes a 'choice' that has been added with [gtk.file_chooser.FileChooser.addChoice].
void removeFilter(gtk.file_filter.FileFilter filter)Removes filter from the list of filters that the user can select between.
bool removeShortcutFolder(gio.file.File folder)Removes a folder from the shortcut folders in a file chooser.
void setAction(gtk.types.FileChooserAction action)Sets the type of operation that the chooser is performing.
void setChoice(string id, string option)Selects an option in a 'choice' that has been added with [gtk.file_chooser.FileChooser.addChoice].
void setCreateFolders(bool createFolders)Sets whether file chooser will offer to create new folders.
bool setCurrentFolder(gio.file.File file = null)Sets the current folder for chooser from a [gio.file.File].
void setCurrentName(string name)Sets the current name in the file selector, as if entered by the user.
bool setFile(gio.file.File file)Sets file as the current filename for the file chooser.
void setFilter(gtk.file_filter.FileFilter filter)Sets the current filter.
void setSelectMultiple(bool selectMultiple)Sets whether multiple files can be selected in the file chooser.
Methods
T action(gtk.types.FileChooserAction propval)Set `action` property. Params: propval = The type of operation that the file chooser is performing. Returns: Builder instance for fluent chaining
T createFolders(bool propval)Set `createFolders` property. Params: propval = Whether a file chooser not in [gtk.types.FileChooserAction.Open] mode will offer the user to create new folders. Returns: Builder instance for fluent...
T filter(gtk.file_filter.FileFilter propval)Set `filter` property. Params: propval = The current filter for selecting files that are displayed. Returns: Builder instance for fluent chaining
T selectMultiple(bool propval)Set `selectMultiple` property. Params: propval = Whether to allow multiple files to be selected. Returns: Builder instance for fluent chaining