SortListModel

class SortListModel(**properties: Any)

Superclasses: Object

Implemented Interfaces: ListModel, SectionModel

Constructors:

SortListModel(**properties)
new(model:Gio.ListModel=None, sorter:Gtk.Sorter=None) -> Gtk.SortListModel

Constructors

class SortListModel
classmethod new(model: ListModel | None = None, sorter: Sorter | None = None) SortListModel

Creates a new sort list model that uses the sorter to sort model.

Parameters:
  • model – the model to sort

  • sorter – the GtkSorter to sort model with,

Methods

class SortListModel
get_incremental() bool

Returns whether incremental sorting is enabled.

See set_incremental.

get_model() ListModel | None

Gets the model currently sorted or None if none.

get_pending() int

Estimates progress of an ongoing sorting operation.

The estimate is the number of items that would still need to be sorted to finish the sorting operation if this was a linear algorithm. So this number is not related to how many items are already correctly sorted.

If you want to estimate the progress, you can use code like this:

pending = gtk_sort_list_model_get_pending (self);
model = gtk_sort_list_model_get_model (self);
progress = 1.0 - pending / (double) MAX (1, g_list_model_get_n_items (model));

If no sort operation is ongoing - in particular when incremental is False - this function returns 0.

get_section_sorter() Sorter | None

Gets the section sorter that is used to sort items of self into sections.

Added in version 4.12.

get_sorter() Sorter | None

Gets the sorter that is used to sort self.

set_incremental(incremental: bool) None

Sets the sort model to do an incremental sort.

When incremental sorting is enabled, the GtkSortListModel will not do a complete sort immediately, but will instead queue an idle handler that incrementally sorts the items towards their correct position. This of course means that items do not instantly appear in the right place. It also means that the total sorting time is a lot slower.

When your filter blocks the UI while sorting, you might consider turning this on. Depending on your model and sorters, this may become interesting around 10,000 to 100,000 items.

By default, incremental sorting is disabled.

See get_pending for progress information about an ongoing incremental sorting operation.

Parameters:

incrementalTrue to sort incrementally

set_model(model: ListModel | None = None) None

Sets the model to be sorted.

The model’s item type must conform to the item type of self.

Parameters:

model – The model to be sorted

set_section_sorter(sorter: Sorter | None = None) None

Sets a new section sorter on self.

Added in version 4.12.

Parameters:

sorter – the GtkSorter to sort model with

set_sorter(sorter: Sorter | None = None) None

Sets a new sorter on self.

Parameters:

sorter – the GtkSorter to sort model with

Properties

class SortListModel
props.incremental: bool

If the model should sort items incrementally.

props.item_type: type

The type of items. See get_item_type.

Added in version 4.8.

props.model: ListModel

The model being sorted.

props.n_items: int

The number of items. See get_n_items.

Added in version 4.8.

props.pending: int

Estimate of unsorted items remaining.

props.section_sorter: Sorter

The section sorter for this model, if one is set.

Added in version 4.12.

props.sorter: Sorter

The sorter for this model.