TreeListModel#

class TreeListModel(**properties: Any)#

Superclasses: Object

Implemented Interfaces: ListModel

GtkTreeListModel is a list model that can create child models on demand.

Constructors#

class TreeListModel
classmethod new(root: ListModel, passthrough: bool, autoexpand: bool, create_func: Callable[[...], ListModel | None], *user_data: Any) 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

  • user_data – Data to pass to create_func

Methods#

class TreeListModel
get_autoexpand() 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 set_expanded.

get_child_row(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 get_row.

Parameters:

position – position of the child to get

get_model() ListModel#

Gets the root model that self was created with.

get_passthrough() 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 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 get_row to get the custom GtkTreeListRow’s.

get_row(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 get_item().

Do not confuse this function with get_child_row.

Parameters:

position – the position of the row to fetch

set_autoexpand(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 set_expanded.

Parameters:

autoexpandTrue to make the model autoexpand its rows

Properties#

class TreeListModel
props.autoexpand: bool#

The type of the None singleton.

props.item_type: type#

The type of the None singleton.

Added in version 4.8.

props.model: ListModel#

The type of the None singleton.

props.n_items: int#

The type of the None singleton.

Added in version 4.8.

props.passthrough: bool#

The type of the None singleton.