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¶
:::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 ofGTypetypes for the columns, from first to last
Methods¶
append¶
:::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 validGtkTreeIter
clear¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Removes all rows from tree_store
insert¶
:::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 validGtkTreeIterposition— position to insert the new row, or -1 for last
insert_after¶
:::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 validGtkTreeItersibling— A validGtkTreeIter
insert_before¶
:::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 validGtkTreeItersibling— A validGtkTreeIter
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 validGtkTreeIterposition— position to insert the new row, or -1 for lastcolumns— an array of column numbersvalues— an array of GValues
is_ancestor¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Checks if iter is an ancestor of descendant.
Parameters:
iter— A validGtkTreeIterdescendant— A validGtkTreeIter
iter_depth¶
:::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 validGtkTreeIter
iter_is_valid¶
:::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¶
:::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— AGtkTreeIter.position— AGtkTreeIter.
move_before¶
:::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— AGtkTreeIterposition— AGtkTreeIter
prepend¶
:::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 validGtkTreeIter
remove¶
:::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 validGtkTreeIter
set_column_types¶
:::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 ofGTypetypes, one for each column
set_value¶
:::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 validGtkTreeIterfor the row being modifiedcolumn— column number to modifyvalue— new value for the cell
set¶
:::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 validGtkTreeIterfor the row being modifiedcolumns— an array of column numbersvalues— an array of GValues
swap¶
:::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— AGtkTreeIter.b— AnotherGtkTreeIter.