Gtk.RecentFilter


Gtk.RecentFilter — A filter for selecting a subset of recently used files

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.RecentFilter

Functions:

Description:

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 GtkBuildable

The Gtk.RecentFilter implementation of the GtkBuildable interface supports adding rules using the \, \ and \ elements and listing the rules within. Specifying a \, \ or \ 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>

Function Details:

new()

new () -> Gtk.RecentFilter

Creates a new Gtk.RecentFilter with no rules added to it.Such filter does not accept any recently used resources, so is notparticularly useful until you add rules withGtk.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: Gtk.RecentFilter filter = Gtk.RecentFilter:new ();Gtk.RecentFilter:add_pattern (filter, "");

  • Returns: a new Gtk.RecentFilter

  • Since: 2.10


get_name()

get_name (self) -> str

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

  • Returns: the name of the filter, or None. The returned stringis owned by the filter object and should not be freed.

  • Since: 2.10


set_name()

set_name (self, name:str)

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

  • Since: 2.10

add_mime_type()

add_mime_type (self, mime_type:str)

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

  • Since: 2.10

add_pattern()

add_pattern (self, pattern:str)

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

  • Since: 2.10

add_pixbuf_formats()

add_pixbuf_formats (self)

Adds a rule allowing image files in the formats supportedby GdkPixbuf.

  • Since: 2.10

add_application()

add_application (self, application:str)

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

  • Since: 2.10

add_group()

add_group (self, group:str)

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

  • Since: 2.10

add_age()

add_age (self, days:int)

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

  • Since: 2.10

add_custom()

add_custom (self, needed:Gtk.RecentFilterFlags, func:Gtk.RecentFilterFunc, data=None)

Adds a rule to a filter that allows resources based on a custom callbackfunction. The bitfield needed which is passed in provides informationabout what sorts of information that the filter function needs;this allows GTK+ to avoid retrieving expensive information whenit isn’t needed by the filter.

  • Since: 2.10

get_needed()

get_needed (self) -> Gtk.RecentFilterFlags

Gets the fields that need to be filled in for the Gtk.RecentFilterInfopassed to Gtk.RecentFilter:filter() This function will not typically be used by applications; itis intended principally for use in the implementation ofGtk.RecentChooser.

  • Returns: bitfield of flags indicating needed fields whencalling Gtk.RecentFilter:filter()

  • Since: 2.10


filter()

filter (self, filter_info:Gtk.RecentFilterInfo) -> bool

Tests whether a file should be displayed according to filter.The Gtk.RecentFilterInfo filter_info should includethe fields returned from Gtk.RecentFilter:get_needed(), andmust set the Gtk.RecentFilterInfo.contains field of filter_infoto indicate which fields have been set. This function will not typically be used by applications; itis intended principally for use in the implementation ofGtk.RecentChooser.

  • Returns: True if the file should be displayed

  • Since: 2.10


Example:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class RecentFilter(Gtk.RecentChooserDialog):
    def __init__(self):
        Gtk.RecentChooserDialog.__init__(self)
        self.set_title('RecentFilter')
        self.set_default_size(300, 200)

        recentfilter = Gtk.RecentFilter()
        recentfilter.set_name('All Items')
        recentfilter.add_pattern('*')
        self.add_filter(recentfilter)

        recentfilter = Gtk.RecentFilter()
        recentfilter.set_name('Within last 3 days')
        recentfilter.add_age(3)
        self.add_filter(recentfilter)

        recentfilter = Gtk.RecentFilter()
        recentfilter.set_name('Image Files')
        recentfilter.add_pattern('*.png')
        recentfilter.add_pattern('*.jpg')
        recentfilter.add_pattern('*.svg')
        self.add_filter(recentfilter)

dialog = RecentFilter()
dialog.run()
dialog.destroy()

results matching ""

    No results matching ""