Gtk.FileFilter¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
None
Signals¶
- Inherited:
Fields¶
- Inherited:
Class Details¶
- class Gtk.FileFilter(**kwargs)¶
- Bases:
- Abstract:
No
A
Gtk.FileFilter
can be used to restrict the files being shown in aGtk.FileChooser
. Files can be filtered based on their name (withGtk.FileFilter.add_pattern
()), on their mime type (withGtk.FileFilter.add_mime_type
()), or by a custom filter function (withGtk.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
, seeGtk.FileChooser.add_filter
(), but it is also possible to manually use a filter on a file withGtk.FileFilter.filter
().The
Gtk.FileFilter
implementation of theGtk.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 callingGtk.FileFilter.add_mime_type
() orGtk.FileFilter.add_pattern
().An example of a UI definition fragment specifying
Gtk.FileFilter
rules:<object class="GtkFileFilter"> <mime-types> <mime-type>text/plain</mime-type> <mime-type>image/ *</mime-type> </mime-types> <patterns> <pattern>*.txt</pattern> <pattern>*.png</pattern> </patterns> </object>
- classmethod new()[source]¶
- Returns:
a new
Gtk.FileFilter
- Return type:
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 withGtk.FileFilter.add_mime_type
(),Gtk.FileFilter.add_pattern
(), orGtk.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:
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]¶
- Parameters:
needed (
Gtk.FileFilterFlags
) – bitfield of flags indicating the information that the custom filter function needs.func (
Gtk.FileFilterFunc
) – callback function; if the function returnsTrue
, then the file will be displayed.
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.
- 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.
New in version 2.4.
- add_pattern(pattern)[source]¶
- Parameters:
pattern (
str
) – a shell style glob
Adds a rule allowing a shell style glob to a filter.
New in version 2.4.
- add_pixbuf_formats()[source]¶
Adds a rule allowing image files in the formats supported by
GdkPixbuf.Pixbuf
.New in version 2.6.
- filter(filter_info)[source]¶
- Parameters:
filter_info (
Gtk.FileFilterInfo
) – aGtk.FileFilterInfo
containing information about a file.- Returns:
True
if the file should be displayed- Return type:
Tests whether a file should be displayed according to self. The
Gtk.FileFilterInfo
filter_info should include the fields returned fromGtk.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.
- get_name()[source]¶
- 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:
Gets the human-readable name for the filter. See
Gtk.FileFilter.set_name
().New in version 2.4.
- get_needed()[source]¶
- Returns:
bitfield of flags indicating needed fields when calling
Gtk.FileFilter.filter
()- Return type:
Gets the fields that need to be filled in for the
Gtk.FileFilterInfo
passed toGtk.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.
- set_name(name)[source]¶
- Parameters:
name (
str
orNone
) – the human-readable-name for the filter, orNone
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.
- to_gvariant()[source]¶
- Returns:
a new, floating,
GLib.Variant
- Return type:
Serialize a file filter to an a{sv} variant.
New in version 3.22.