Skip to content

Gtk.StringFilter

class — extends Filter

Determines whether to include items by comparing strings to a fixed search term.

The strings are obtained from the items by evaluating an expression set with StringFilter.set_expression, and they are compared against a search term set with StringFilter.set_search.

GtkStringFilter has several different modes of comparison - it can match the whole string, just a prefix, or any substring. Use StringFilter.set_match_mode choose a mode.

It is also possible to make case-insensitive comparisons, with StringFilter.set_ignore_case.

Constructors

new

@classmethod
def new(cls, expression: Expression | None = ...) -> StringFilter

Creates a new string filter.

You will want to set up the filter by providing a string to search for and by providing a property to look up on the item.

Parameters:

  • expression — the expression to evaluate

Methods

get_expression

def get_expression(self) -> Expression | None

Gets the expression that the string filter uses to obtain strings from items.

get_ignore_case

def get_ignore_case(self) -> bool

Returns whether the filter ignores case differences.

get_match_mode

def get_match_mode(self) -> StringFilterMatchMode

Returns the match mode that the filter is using.

def get_search(self) -> str | None

Gets the search term.

set_expression

def set_expression(self, expression: Expression | None = ...) -> None

Sets the expression that the string filter uses to obtain strings from items.

The expression must have a value type of G_TYPE_STRING.

Parameters:

  • expression — the expression

set_ignore_case

def set_ignore_case(self, ignore_case: bool) -> None

Sets whether the filter ignores case differences.

Parameters:

  • ignore_case — true to ignore case

set_match_mode

def set_match_mode(self, mode: StringFilterMatchMode | int) -> None

Sets the match mode for the filter.

Parameters:

  • mode — the new match mode
def set_search(self, search: str | None = ...) -> None

Sets the string to search for.

Parameters:

  • search — the string to search for

Properties

expression

expression: Expression  # read/write

The expression to evaluate on each item to get a string to compare with.

ignore_case

ignore_case: bool  # read/write

If matching is case sensitive.

match_mode

match_mode: StringFilterMatchMode | int  # read/write

If exact matches are necessary or if substrings are allowed.

search: str  # read/write

The search term.