Skip to content

Gtk.TreeListModel

class — extends GObject.Object, Gio.ListModel

A list model that can create child models on demand.

Constructors

new

@classmethod
def new(cls, root: Gio.ListModel, passthrough: bool, autoexpand: bool, create_func: TreeListModelCreateModelFunc) -> TreeListModel

Creates a new empty GtkTreeListModel displaying root with all rows collapsed.

Parameters:

  • root — The GListModel to use as root
  • passthroughTrue to pass through items from the models
  • autoexpandTrue to set the autoexpand property and expand the root model
  • create_func — function to call to create the GListModel for the children of an item

Methods

get_autoexpand

def get_autoexpand(self) -> bool

Gets whether the model is set to automatically expand new rows that get added.

This can be either rows added by changes to the underlying models or via TreeListRow.set_expanded.

get_child_row

def get_child_row(self, position: int) -> TreeListRow | None

Gets the row item corresponding to the child at index position for self's root model.

If position is greater than the number of children in the root model, None is returned.

Do not confuse this function with TreeListModel.get_row.

Parameters:

  • position — position of the child to get

get_model

def get_model(self) -> Gio.ListModel

Gets the root model that self was created with.

get_passthrough

def get_passthrough(self) -> bool

Gets whether the model is passing through original row items.

If this function returns False, the GListModel functions for self return custom GtkTreeListRow objects. You need to call TreeListRow.get_item on these objects to get the original item.

If True, the values of the child models are passed through in their original state. You then need to call TreeListModel.get_row to get the custom GtkTreeListRows.

get_row

def get_row(self, position: int) -> TreeListRow | None

Gets the row object for the given row.

If position is greater than the number of items in self, None is returned.

The row object can be used to expand and collapse rows as well as to inspect its position in the tree. See its documentation for details.

This row object is persistent and will refer to the current item as long as the row is present in self, independent of other rows being added or removed.

If self is set to not be passthrough, this function is equivalent to calling g_list_model_get_item().

Do not confuse this function with TreeListModel.get_child_row.

Parameters:

  • position — the position of the row to fetch

set_autoexpand

def set_autoexpand(self, autoexpand: bool) -> None

Sets whether the model should autoexpand.

If set to True, the model will recursively expand all rows that get added to the model. This can be either rows added by changes to the underlying models or via TreeListRow.set_expanded.

Parameters:

  • autoexpandTrue to make the model autoexpand its rows

Properties

autoexpand

autoexpand: bool  # read/write

If all rows should be expanded by default.

item_type

item_type: type | GObject.Type  # read-only

The type of items. See Gio.ListModel.get_item_type.

model

model: Gio.ListModel  # read-only

The root model displayed.

n_items

n_items: int  # read-only

The number of items. See Gio.ListModel.get_n_items.

passthrough

passthrough: bool  # read/write

Gets whether the model is in passthrough mode.

If False, the GListModel functions for this object return custom TreeListRow objects. If True, the values of the child models are pass through unmodified.