FileFilter

class FileFilter(**properties: Any)

Superclasses: Filter, Object

Implemented Interfaces: Buildable

Constructors:

FileFilter(**properties)
new() -> Gtk.FileFilter
new_from_gvariant(variant:GLib.Variant) -> Gtk.FileFilter

Constructors

class FileFilter
classmethod new() 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 add_mime_type, add_pattern, add_suffix or add_pixbuf_formats.

To create a filter that accepts any file, use:

GtkFileFilter *filter = gtk_file_filter_new ();
gtk_file_filter_add_pattern (filter, "*");
classmethod new_from_gvariant(variant: Variant) FileFilter

Deserialize a file filter from a GVariant.

The variant must be in the format produced by to_gvariant.

Parameters:

variant – an a{sv} GVariant

Methods

class FileFilter
add_mime_type(mime_type: str) None

Adds a rule allowing a given mime type to filter.

Parameters:

mime_type – name of a MIME type

add_pattern(pattern: str) None

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.

Parameters:

pattern – a shell style glob

add_pixbuf_formats() None

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

This is equivalent to calling add_mime_type for all the supported mime types.

add_suffix(suffix: str) None

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.

Added in version 4.4.

Parameters:

suffix – filename suffix to match

get_attributes() list[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() str | None

Gets the human-readable name for the filter.

See set_name.

set_name(name: str | None = None) None

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.

Parameters:

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

to_gvariant() Variant

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

Properties

class FileFilter
props.mime_types: Sequence[str]

The MIME types that this filter matches.

Added in version 4.10.

props.name: str

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.

props.patterns: Sequence[str]

The patterns that this filter matches.

Added in version 4.10.

props.suffixes: Sequence[str]

The suffixes that this filter matches.

Added in version 4.10.