g GObject.GInterface GObject.GInterface Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable GObject.InitiallyUnowned GObject.InitiallyUnowned Gtk.FileFilter Gtk.FileFilter GObject.InitiallyUnowned->Gtk.FileFilter GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Buildable->Gtk.FileFilter



Inherited:GObject.Object (37), Gtk.Buildable (10)
Structs:GObject.ObjectClass (5)
class new ()
class new_from_gvariant (variant)
  add_custom (needed, func, *data)
  add_mime_type (mime_type)
  add_pattern (pattern)
  add_pixbuf_formats ()
  filter (filter_info)
  get_name ()
  get_needed ()
  set_name (name)
  to_gvariant ()

Virtual Methods

Inherited:GObject.Object (7), Gtk.Buildable (10)




Inherited:GObject.Object (1)


Inherited:GObject.Object (1)

Class Details

class Gtk.FileFilter(**kwargs)
Bases:GObject.InitiallyUnowned, Gtk.Buildable

A Gtk.FileFilter can be used to restrict the files being shown in a Gtk.FileChooser. Files can be filtered based on their name (with Gtk.FileFilter.add_pattern()), on their mime type (with Gtk.FileFilter.add_mime_type()), or by a custom filter function (with Gtk.FileFilter.add_custom()).

Filtering by mime types handles aliasing and subclassing of mime types; e.g. a filter for text/plain also matches a file with mime type application/rtf, since application/rtf is a subclass of text/plain. Note that Gtk.FileFilter allows wildcards for the subtype of a mime type, so you can e.g. filter for image/\*.

Normally, filters are used by adding them to a Gtk.FileChooser, see Gtk.FileChooser.add_filter(), but it is also possible to manually use a filter on a file with Gtk.FileFilter.filter().

Gtk.FileFilter as Gtk.Buildable

The Gtk.FileFilter implementation of the Gtk.Buildable interface supports adding rules using the <mime-types>, <patterns> and <applications> elements and listing the rules within. Specifying a <mime-type> or <pattern> has the same effect as as calling Gtk.FileFilter.add_mime_type() or Gtk.FileFilter.add_pattern().

An example of a UI definition fragment specifying Gtk.FileFilter rules:

<object class="GtkFileFilter">
    <mime-type>image/ *</mime-type>
classmethod new()[source]
Returns:a new Gtk.FileFilter
Return type:Gtk.FileFilter

Creates a new Gtk.FileFilter with no rules added to it. Such a filter doesn’t accept any files, so is not particularly useful until you add rules with Gtk.FileFilter.add_mime_type(), Gtk.FileFilter.add_pattern(), or Gtk.FileFilter.add_custom(). To create a filter that accepts any file, use:

GtkFileFilter *filter = gtk_file_filter_new ();
gtk_file_filter_add_pattern (filter, "*");

New in version 2.4.

classmethod new_from_gvariant(variant)[source]
Parameters:variant (GLib.Variant) – an a{sv} GLib.Variant
Returns:a new Gtk.FileFilter object
Return type:Gtk.FileFilter

Deserialize a file filter from an a{sv} variant in the format produced by Gtk.FileFilter.to_gvariant().

New in version 3.22.

add_custom(needed, func, *data)[source]
  • needed (Gtk.FileFilterFlags) – bitfield of flags indicating the information that the custom filter function needs.
  • func (Gtk.FileFilterFunc) – callback function; if the function returns True, then the file will be displayed.
  • data (object or None) – data to pass to func

Adds rule to a filter that allows files based on a custom callback function. The bitfield needed which is passed in provides information about what sorts of information that the filter function needs; this allows GTK+ to avoid retrieving expensive information when it isn’t needed by the filter.

New in version 2.4.

Parameters:mime_type (str) – name of a MIME type

Adds a rule allowing a given mime type to self.

New in version 2.4.

Parameters:pattern (str) – a shell style glob

Adds a rule allowing a shell style glob to a filter.

New in version 2.4.


Adds a rule allowing image files in the formats supported by GdkPixbuf.Pixbuf.

New in version 2.6.

Parameters:filter_info (Gtk.FileFilterInfo) – a Gtk.FileFilterInfo containing information about a file.
Returns:True if the file should be displayed
Return type:bool

Tests whether a file should be displayed according to self. The Gtk.FileFilterInfo filter_info should include the fields returned from Gtk.FileFilter.get_needed().

This function will not typically be used by applications; it is intended principally for use in the implementation of Gtk.FileChooser.

New in version 2.4.

Returns:The human-readable name of the filter, or None. This value is owned by GTK+ and must not be modified or freed.
Return type:str or None

Gets the human-readable name for the filter. See Gtk.FileFilter.set_name().

New in version 2.4.

Returns:bitfield of flags indicating needed fields when calling Gtk.FileFilter.filter()
Return type:Gtk.FileFilterFlags

Gets the fields that need to be filled in for the Gtk.FileFilterInfo passed to Gtk.FileFilter.filter()

This function will not typically be used by applications; it is intended principally for use in the implementation of Gtk.FileChooser.

New in version 2.4.

Parameters:name (str or None) – the human-readable-name for the filter, or None to remove any existing name.

Sets the human-readable name of the filter; this is the string that will be displayed in the file selector user interface if there is a selectable list of filters.

New in version 2.4.

Returns:a new, floating, GLib.Variant
Return type:GLib.Variant

Serialize a file filter to an a{sv} variant.

New in version 3.22.