Gtk.RecentFilter

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

Subclasses:None

Methods

Inherited:GObject.Object (37), Gtk.Buildable (10)
Structs:GObject.ObjectClass (5)
class new ()
  add_age (days)
  add_application (application)
  add_custom (needed, func, *data)
  add_group (group)
  add_mime_type (mime_type)
  add_pattern (pattern)
  add_pixbuf_formats ()
  filter (filter_info)
  get_name ()
  get_needed ()
  set_name (name)

Virtual Methods

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

Properties

None

Signals

Inherited:GObject.Object (1)

Fields

Inherited:GObject.Object (1)

Class Details

class Gtk.RecentFilter(**kwargs)
Bases:GObject.InitiallyUnowned, Gtk.Buildable
Abstract:No

A Gtk.RecentFilter can be used to restrict the files being shown in a Gtk.RecentChooser. Files can be filtered based on their name (with Gtk.RecentFilter.add_pattern()), on their mime type (with Gtk.FileFilter.add_mime_type()), on the application that has registered them (with Gtk.RecentFilter.add_application()), or by a custom filter function (with Gtk.RecentFilter.add_custom()).

Filtering by mime type 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.RecentFilter 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.RecentChooser, see Gtk.RecentChooser.add_filter(), but it is also possible to manually use a filter on a file with Gtk.RecentFilter.filter().

Recently used files are supported since GTK+ 2.10.

Gtk.RecentFilter as Gtk.Buildable

The Gtk.RecentFilter 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>, <pattern> or <application> has the same effect as calling Gtk.RecentFilter.add_mime_type(), Gtk.RecentFilter.add_pattern() or Gtk.RecentFilter.add_application().

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

<object class="GtkRecentFilter">
  <mime-types>
    <mime-type>text/plain</mime-type>
    <mime-type>image/png</mime-type>
  </mime-types>
  <patterns>
    <pattern>*.txt</pattern>
    <pattern>*.png</pattern>
  </patterns>
  <applications>
    <application>gimp</application>
    <application>gedit</application>
    <application>glade</application>
  </applications>
</object>
classmethod new()[source]
Returns:a new Gtk.RecentFilter
Return type:Gtk.RecentFilter

Creates a new Gtk.RecentFilter with no rules added to it. Such filter does not accept any recently used resources, so is not particularly useful until you add rules with Gtk.RecentFilter.add_pattern(), Gtk.RecentFilter.add_mime_type(), Gtk.RecentFilter.add_application(), Gtk.RecentFilter.add_age(). To create a filter that accepts any recently used resource, use:

GtkRecentFilter *filter = gtk_recent_filter_new ();
gtk_recent_filter_add_pattern (filter, "*");

New in version 2.10.

add_age(days)[source]
Parameters:days (int) – number of days

Adds a rule that allows resources based on their age - that is, the number of days elapsed since they were last modified.

New in version 2.10.

add_application(application)[source]
Parameters:application (str) – an application name

Adds a rule that allows resources based on the name of the application that has registered them.

New in version 2.10.

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

Adds a rule to a filter that allows resources 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.10.

add_group(group)[source]
Parameters:group (str) – a group name

Adds a rule that allows resources based on the name of the group to which they belong

New in version 2.10.

add_mime_type(mime_type)[source]
Parameters:mime_type (str) – a MIME type

Adds a rule that allows resources based on their registered MIME type.

New in version 2.10.

add_pattern(pattern)[source]
Parameters:pattern (str) – a file pattern

Adds a rule that allows resources based on a pattern matching their display name.

New in version 2.10.

add_pixbuf_formats()[source]

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

New in version 2.10.

filter(filter_info)[source]
Parameters:filter_info (Gtk.RecentFilterInfo) – a Gtk.RecentFilterInfo containing information about a recently used resource
Returns:True if the file should be displayed
Return type:bool

Tests whether a file should be displayed according to self. The Gtk.RecentFilterInfo filter_info should include the fields returned from Gtk.RecentFilter.get_needed(), and must set the Gtk.RecentFilterInfo.contains field of filter_info to indicate which fields have been set.

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

New in version 2.10.

get_name()[source]
Returns:the name of the filter, or None. The returned string is owned by the filter object and should not be freed.
Return type:str or None

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

New in version 2.10.

get_needed()[source]
Returns:bitfield of flags indicating needed fields when calling Gtk.RecentFilter.filter()
Return type:Gtk.RecentFilterFlags

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

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

New in version 2.10.

set_name(name)[source]
Parameters:name (str) – then human readable name of self

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

New in version 2.10.