Skip to content

Gtk.StringSorter

class — extends Sorter

Sorts items by comparing strings.

To obtain the strings to compare, this sorter evaluates a Expression.

It does the comparison in a linguistically correct way using the current locale by normalizing Unicode strings and possibly case-folding them before performing the comparison.

Constructors

new

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

Creates a new string sorter that compares items using the given expression.

Unless an expression is set on it, this sorter will always compare items as invalid.

Parameters:

  • expression — The expression to evaluate

Methods

get_collation

def get_collation(self) -> Collation

Gets which collation method the sorter uses.

get_expression

def get_expression(self) -> Expression | None

Gets the expression that is evaluated to obtain strings from items.

get_ignore_case

def get_ignore_case(self) -> bool

Gets whether the sorter ignores case differences.

set_collation

def set_collation(self, collation: Collation | int) -> None

Sets the collation method to use for sorting.

Parameters:

  • collation — the collation method

set_expression

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

Sets the expression that is evaluated to obtain strings from items.

The expression must have the type G_TYPE_STRING.

Parameters:

  • expression — a GtkExpression

set_ignore_case

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

Sets whether the sorter will ignore case differences.

Parameters:

  • ignore_caseTrue to ignore case differences

Properties

collation

collation: Collation | int  # read/write

The collation method to use for sorting.

The GTK_COLLATION_NONE value is useful when the expression already returns collation keys, or strings that need to be compared byte-by-byte.

The default value, GTK_COLLATION_UNICODE, compares strings according to the Unicode collation algorithm.

expression

expression: Expression  # read/write

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

ignore_case

ignore_case: bool  # read/write

If sorting is case sensitive.