FileFilter#
Implemented Interfaces: Buildable
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
add_pattern or add_suffix)
or on their mime type (with 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 add_filter), but it is also possible to
manually use a file filter on any FilterListModel containing
GFileInfo objects.
GtkFileFilter as GtkBuildable#
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
add_mime_type or
add_pattern or
add_suffix.
An example of a UI definition fragment specifying GtkFileFilter
rules:
<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>
Constructors#
- class FileFilter
- classmethod new() FileFilter#
Creates a new
GtkFileFilterwith 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_suffixoradd_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_typefor 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
GFileInfopassed to this filter.This function will not typically be used by applications; it is intended principally for use in the implementation of
GtkFileChooser.
Properties#
- class FileFilter