Skip to content

Gtk.Filter

class — extends GObject.Object

Describes the filtering to be performed by a FilterListModel.

The model will use the filter to determine if it should include items or not by calling Filter.match for each item and only keeping the ones that the function returns true for.

Filters may change what items they match through their lifetime. In that case, they will emit the Filter.changed signal to notify that previous filter results are no longer valid and that items should be checked again via Filter.match.

GTK provides various pre-made filter implementations for common filtering operations. These filters often include properties that can be linked to various widgets to easily allow searches.

However, in particular for large lists or complex search methods, it is also possible to subclass GtkFilter and provide one's own filter.

Methods

changed

def changed(self, change: FilterChange | int) -> None

Notifies all users of the filter that it has changed.

This emits the Filter.changed signal. Users of the filter should then check items again via Filter.match.

Depending on the change parameter, not all items need to be changed, but only some. Refer to the FilterChange documentation for details.

This function is intended for implementers of GtkFilter subclasses and should not be called from other functions.

Parameters:

  • change — how the filter changed

get_strictness

def get_strictness(self) -> FilterMatch

Gets the known strictness of a filter.

If the strictness is not known, FilterMatch.some is returned.

This value may change after emission of the Filter.changed signal.

This function is meant purely for optimization purposes. Filters can choose to omit implementing it, but GtkFilterListModel uses it.

match_

def match_(self, item: GObject.Object) -> bool

Checks if the given item is matched by the filter or not.

Parameters:

  • item — The item to check

Virtual methods

do_get_strictness

def do_get_strictness(self) -> FilterMatch

Gets the known strictness of a filter.

If the strictness is not known, FilterMatch.some is returned.

This value may change after emission of the Filter.changed signal.

This function is meant purely for optimization purposes. Filters can choose to omit implementing it, but GtkFilterListModel uses it.

do_match_

def do_match_(self, item: GObject.Object | None = ...) -> bool

Checks if the given item is matched by the filter or not.

Parameters:

  • item — The item to check

Signals

changed

def on_changed(self, change: FilterChange) -> None: ...

Emitted whenever the filter changed.

Users of the filter should then check items again via Filter.match.

GtkFilterListModel handles this signal automatically.

Depending on the change parameter, not all items need to be checked, but only some. Refer to the FilterChange documentation for details.