Gtk.FileFilter

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

Subclasses:

None

Methods

Inherited:

Gtk.Filter (3), GObject.Object (37), Gtk.Buildable (1)

Structs:

GObject.ObjectClass (5)

class

new ()

class

new_from_gvariant (variant)

add_mime_type (mime_type)

add_pattern (pattern)

add_pixbuf_formats ()

add_suffix (suffix)

get_attributes ()

get_name ()

set_name (name)

to_gvariant ()

Virtual Methods

Inherited:

Gtk.Filter (2), GObject.Object (7), Gtk.Buildable (9)

Properties

Name

Type

Flags

Short Description

mime-types

[str]

w/co

name

str

r/w/en

patterns

[str]

w/co

suffixes

[str]

w/co

Signals

Inherited:

Gtk.Filter (1), GObject.Object (1)

Fields

Inherited:

Gtk.Filter (1), GObject.Object (1)

Class Details

class Gtk.FileFilter(**kwargs)
Bases:

Gtk.Filter, Gtk.Buildable

Abstract:

No

GtkFileFilter filters files by name or mime type.

GtkFileFilter can be used to restrict the files being shown in a GtkFileChooser. Files can be filtered based on their name (with [method`Gtk`.FileFilter.add_pattern] or [method`Gtk`.FileFilter.add_suffix]) or on their mime type (with [method`Gtk`.FileFilter.add_mime_type]).

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 GtkFileFilter allows wildcards for the subtype of a mime type, so you can e.g. filter for image/\*.

Normally, file filters are used by adding them to a GtkFileChooser (see [method`Gtk`.FileChooser.add_filter]), but it is also possible to manually use a file filter on any [class`Gtk`.FilterListModel] containing GFileInfo objects.

Gtk.FileFilter as Gtk.Buildable

The GtkFileFilter implementation of the GtkBuildable interface supports adding rules using the <mime-types> and <patterns> and <suffixes> elements and listing the rules within. Specifying a <mime-type> or <pattern> or <suffix> has the same effect as as calling [method`Gtk`.FileFilter.add_mime_type] or [method`Gtk`.FileFilter.add_pattern] or [method`Gtk`.FileFilter.add_suffix].

An example of a UI definition fragment specifying GtkFileFilter rules: ``xml <object class=”GtkFileFilter”>

<property name=”name” translatable=”yes”>Text and Images</property> <mime-types>

<mime-type>text/plain</mime-type> <mime-type>image/ *</mime-type>

</mime-types> <patterns>

<pattern>*.txt</pattern>

</patterns> <suffixes>

<suffix>png</suffix>

</suffixes>

</object> ``

classmethod new()[source]
Returns:

a new GtkFileFilter

Return type:

Gtk.FileFilter

Creates a new GtkFileFilter with no rules added to it.

Such a filter doesn’t accept any files, so is not particularly useful until you add rules with [method`Gtk`.FileFilter.add_mime_type], [method`Gtk`.FileFilter.add_pattern], [method`Gtk`.FileFilter.add_suffix] or [method`Gtk`.FileFilter.add_pixbuf_formats].

To create a filter that accepts any file, use: ``c GtkFileFilter filter = gtk_file_filter_new (); gtk_file_filter_add_pattern (filter, “”); ``

classmethod new_from_gvariant(variant)[source]
Parameters:

variant (GLib.Variant) – an a{sv} GVariant

Returns:

a new GtkFileFilter object

Return type:

Gtk.FileFilter

Deserialize a file filter from a GVariant.

The variant must be in the format produced by [method`Gtk`.FileFilter.to_gvariant].

add_mime_type(mime_type)[source]
Parameters:

mime_type (str) – name of a MIME type

Adds a rule allowing a given mime type to self.

add_pattern(pattern)[source]
Parameters:

pattern (str) – a shell style glob

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

Note that it depends on the platform whether pattern matching ignores case or not. On Windows, it does, on other platforms, it doesn’t.

add_pixbuf_formats()[source]

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

This is equivalent to calling [method`Gtk`.FileFilter.add_mime_type] for all the supported mime types.

add_suffix(suffix)[source]
Parameters:

suffix (str) – filename suffix to match

Adds a suffix match rule to a filter.

This is similar to adding a match for the pattern “*.`suffix`".

In contrast to pattern matches, suffix matches are *always* case-insensitive.

New in version 4.4.

get_attributes()[source]
Returns:

the attributes

Return type:

[str]

Gets the attributes that need to be filled in for the GFileInfo passed to this filter.

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

get_name()[source]
Returns:

The human-readable name of the filter

Return type:

str or None

Gets the human-readable name for the filter.

See [method`Gtk`.FileFilter.set_name].

set_name(name)[source]
Parameters:

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

Sets a human-readable name of the filter.

This is the string that will be displayed in the file chooser if there is a selectable list of filters.

to_gvariant()[source]
Returns:

a new, floating, GVariant

Return type:

GLib.Variant

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

Property Details

Gtk.FileFilter.props.mime_types
Name:

mime-types

Type:

[str]

Default Value:

[]

Flags:

WRITABLE, CONSTRUCT_ONLY

The MIME types that this filter matches.

New in version 4.10.

Gtk.FileFilter.props.name
Name:

name

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The human-readable name of the filter.

This is the string that will be displayed in the file chooser user interface if there is a selectable list of filters.

Gtk.FileFilter.props.patterns
Name:

patterns

Type:

[str]

Default Value:

[]

Flags:

WRITABLE, CONSTRUCT_ONLY

The patterns that this filter matches.

New in version 4.10.

Gtk.FileFilter.props.suffixes
Name:

suffixes

Type:

[str]

Default Value:

[]

Flags:

WRITABLE, CONSTRUCT_ONLY

The suffixes that this filter matches.

New in version 4.10.