Skip to content

Gtk.TreeStore

class — extends GObject.Object, Buildable, TreeDragDest, TreeDragSource, TreeModel, TreeSortable

:::warning Deprecated since 4.10 This API is deprecated. :::

A tree-like data structure that can be used with the TreeView.

The GtkTreeStore object is a list model for use with a GtkTreeView widget. It implements the TreeModel interface, and consequently, can use all of the methods available there. It also implements the TreeSortable interface so it can be sorted by the view. Finally, it also implements the tree [drag]TreeDragSource and [drop]TreeDragDest interfaces.

GtkTreeStore is deprecated since GTK 4.10, and should not be used in newly written code. You should use TreeListModel for a tree-like model object.

GtkTreeStore as GtkBuildable

The GtkTreeStore implementation of the GtkBuildable interface allows to specify the model columns with a <columns> element that may contain multiple <column> elements, each specifying one model column. The “type” attribute specifies the data type for the column.

An example of a UI Definition fragment for a tree store:

<object class="GtkTreeStore">
  <columns>
    <column type="gchararray"/>
    <column type="gchararray"/>
    <column type="gint"/>
  </columns>
</object>

Constructors

newv

@classmethod
def newv(cls, types: list[type | GObject.Type]) -> TreeStore

:::warning Deprecated since 4.10 This API is deprecated. :::

Creates a new tree store.

This constructor is meant for language bindings.

Parameters:

  • types — an array of GType types for the columns, from first to last

Methods

append

def append(self, parent: TreeIter | None = ...) -> TreeIter

:::warning Deprecated since 4.10 This API is deprecated. :::

Appends a new row to tree_store.

If parent is non-None, then it will append the new row after the last child of parent, otherwise it will append a row to the top level.

The iter parameter will be changed to point to this new row. The row will be empty after this function is called. To fill in values, you need to call gtk_tree_store_set() or TreeStore.set_value.

Parameters:

  • parent — A valid GtkTreeIter

clear

def clear(self) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Removes all rows from tree_store

insert

def insert(self, parent: TreeIter | None, position: int) -> TreeIter

:::warning Deprecated since 4.10 This API is deprecated. :::

Creates a new row at position.

If parent is non-None, then the row will be made a child of parent. Otherwise, the row will be created at the toplevel.

If position is -1 or is larger than the number of rows at that level, then the new row will be inserted to the end of the list.

The iter parameter will be changed to point to this new row. The row will be empty after this function is called. To fill in values, you need to call gtk_tree_store_set() or TreeStore.set_value.

Parameters:

  • parent — A valid GtkTreeIter
  • position — position to insert the new row, or -1 for last

insert_after

def insert_after(self, parent: TreeIter | None = ..., sibling: TreeIter | None = ...) -> TreeIter

:::warning Deprecated since 4.10 This API is deprecated. :::

Inserts a new row after sibling.

If sibling is None, then the row will be prepended to parent’s children.

If parent and sibling are None, then the row will be prepended to the toplevel.

If both sibling and parent are set, then parent must be the parent of sibling. When sibling is set, parent is optional.

The iter parameter will be changed to point to this new row. The row will be empty after this function is called. To fill in values, you need to call gtk_tree_store_set() or TreeStore.set_value.

Parameters:

  • parent — A valid GtkTreeIter
  • sibling — A valid GtkTreeIter

insert_before

def insert_before(self, parent: TreeIter | None = ..., sibling: TreeIter | None = ...) -> TreeIter

:::warning Deprecated since 4.10 This API is deprecated. :::

Inserts a new row before sibling.

If sibling is None, then the row will be appended to parent’s children.

If parent and sibling are None, then the row will be appended to the toplevel.

If both sibling and parent are set, then parent must be the parent of sibling. When sibling is set, parent is optional.

The iter parameter will be changed to point to this new row. The row will be empty after this function is called. To fill in values, you need to call gtk_tree_store_set() or TreeStore.set_value.

Parameters:

  • parent — A valid GtkTreeIter
  • sibling — A valid GtkTreeIter

insert_with_values

def insert_with_values(self, parent: TreeIter | None, position: int, columns: list[int], values: list[GObject.Value]) -> TreeIter

:::warning Deprecated since 4.10 This API is deprecated. :::

A variant of gtk_tree_store_insert_with_values() which takes the columns and values as two arrays, instead of varargs.

This function is mainly intended for language bindings.

Parameters:

  • parent — A valid GtkTreeIter
  • position — position to insert the new row, or -1 for last
  • columns — an array of column numbers
  • values — an array of GValues

is_ancestor

def is_ancestor(self, iter: TreeIter, descendant: TreeIter) -> bool

:::warning Deprecated since 4.10 This API is deprecated. :::

Checks if iter is an ancestor of descendant.

Parameters:

  • iter — A valid GtkTreeIter
  • descendant — A valid GtkTreeIter

iter_depth

def iter_depth(self, iter: TreeIter) -> int

:::warning Deprecated since 4.10 This API is deprecated. :::

Returns the depth of the position pointed by the iterator

The depth will be 0 for anything on the root level, 1 for anything down a level, etc.

Parameters:

  • iter — A valid GtkTreeIter

iter_is_valid

def iter_is_valid(self, iter: TreeIter) -> bool

:::warning Deprecated since 4.10 This API is deprecated. :::

Checks if the given iter is a valid iter for this GtkTreeStore.

This function is slow. Only use it for debugging and/or testing purposes.

Parameters:

  • iter — the iterator to check

move_after

def move_after(self, iter: TreeIter, position: TreeIter | None = ...) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Moves iter in tree_store to the position after position.

iter and position should be in the same level.

Note that this function only works with unsorted stores.

If position is None, iter will be moved to the start of the level.

Parameters:

  • iter — A GtkTreeIter.
  • position — A GtkTreeIter.

move_before

def move_before(self, iter: TreeIter, position: TreeIter | None = ...) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Moves iter in tree_store to the position before position.

iter and position should be in the same level.

Note that this function only works with unsorted stores.

If position is None, iter will be moved to the end of the level.

Parameters:

  • iter — A GtkTreeIter
  • position — A GtkTreeIter

prepend

def prepend(self, parent: TreeIter | None = ...) -> TreeIter

:::warning Deprecated since 4.10 This API is deprecated. :::

Prepends a new row to tree_store.

If parent is non-None, then it will prepend the new row before the first child of parent, otherwise it will prepend a row to the top level. The iter parameter will be changed to point to this new row. The row will be empty after this function is called. To fill in values, you need to call gtk_tree_store_set() or TreeStore.set_value.

Parameters:

  • parent — A valid GtkTreeIter

remove

def remove(self, iter: TreeIter) -> bool

:::warning Deprecated since 4.10 This API is deprecated. :::

Removes iter from tree_store.

After being removed, iter is set to the next valid row at that level, or invalidated if it previously pointed to the last one.

Parameters:

  • iter — A valid GtkTreeIter

set_column_types

def set_column_types(self, types: list[type | GObject.Type]) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Sets the type of the columns in a tree store.

This function is meant primarily for types that inherit from GtkTreeStore, and should only be used when constructing a new GtkTreeStore.

This functions cannot be called after a row has been added, or a method on the GtkTreeModel interface is called on the tree store.

Parameters:

  • types — An array of GType types, one for each column

set_value

def set_value(self, iter: TreeIter, column: int, value: GObject.Value) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Sets the data in the cell specified by iter and column.

The type of value must be convertible to the type of the column.

Parameters:

  • iter — A valid GtkTreeIter for the row being modified
  • column — column number to modify
  • value — new value for the cell

set

def set(self, iter: TreeIter, columns: list[int], values: list[GObject.Value]) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

A variant of gtk_tree_store_set_valist() which takes the columns and values as two arrays, instead of using variadic arguments.

This function is mainly intended for language bindings or in case the number of columns to change is not known until run-time.

Parameters:

  • iter — A valid GtkTreeIter for the row being modified
  • columns — an array of column numbers
  • values — an array of GValues

swap

def swap(self, a: TreeIter, b: TreeIter) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Swaps a and b in the same level of tree_store.

Note that this function only works with unsorted stores.

Parameters:

  • a — A GtkTreeIter.
  • b — Another GtkTreeIter.