Gtk.TreeStore

g GObject.GInterface GObject.GInterface Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.TreeDragDest Gtk.TreeDragDest GObject.GInterface->Gtk.TreeDragDest Gtk.TreeDragSource Gtk.TreeDragSource GObject.GInterface->Gtk.TreeDragSource Gtk.TreeModel Gtk.TreeModel GObject.GInterface->Gtk.TreeModel Gtk.TreeSortable Gtk.TreeSortable GObject.GInterface->Gtk.TreeSortable GObject.Object GObject.Object Gtk.TreeStore Gtk.TreeStore GObject.Object->Gtk.TreeStore Gtk.Buildable->Gtk.TreeStore Gtk.TreeDragDest->Gtk.TreeStore Gtk.TreeDragSource->Gtk.TreeStore Gtk.TreeModel->Gtk.TreeStore Gtk.TreeSortable->Gtk.TreeStore

Subclasses:

None

Methods

Inherited:

GObject.Object (37), Gtk.Buildable (1), Gtk.TreeDragDest (2), Gtk.TreeDragSource (3), Gtk.TreeModel (28), Gtk.TreeSortable (6)

Structs:

GObject.ObjectClass (5)

class

new (types)

append (parent, row=None)

clear ()

insert (parent, position, row=None)

insert_after (parent, sibling)

insert_before (parent, sibling, row=None)

insert_with_values (parent, position, columns, values)

is_ancestor (iter, descendant)

iter_depth (iter)

iter_is_valid (iter)

move_after (iter, position)

move_before (iter, position)

prepend (parent, row=None)

remove (iter)

set (iter, columns, values)

set_column_types (types)

set_value (iter, column, value)

swap (a, b)

Virtual Methods

Inherited:

GObject.Object (7), Gtk.Buildable (9), Gtk.TreeDragDest (2), Gtk.TreeDragSource (3), Gtk.TreeModel (19), Gtk.TreeSortable (6)

Properties

None

Signals

Inherited:

GObject.Object (1), Gtk.TreeModel (5), Gtk.TreeSortable (1)

Fields

Inherited:

GObject.Object (1), Gtk.TreeModel (5), Gtk.TreeSortable (1)

Name

Type

Access

Description

parent

GObject.Object

r

Class Details

class Gtk.TreeStore(*column_types)
Bases:

GObject.Object, Gtk.Buildable, Gtk.TreeDragDest, Gtk.TreeDragSource, Gtk.TreeModel, Gtk.TreeSortable

Abstract:

No

Structure:

Gtk.TreeStoreClass

A tree-like data structure that can be used with the [class`Gtk`.TreeView].

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

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

Gtk.TreeStore as Gtk.Buildable

The Gtk.TreeStore 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:

``xml <object class=”GtkTreeStore”>

<columns>

<column type=”gchararray”/> <column type=”gchararray”/> <column type=”gint”/>

</columns>

</object> ``

Deprecated since version 4.10: Use [class`Gtk`.TreeListModel] instead

classmethod new(types)[source]
Parameters:

types ([GObject.GType]) – an array of GType types for the columns, from first to last

Returns:

a new GtkTreeStore

Return type:

Gtk.TreeStore

Creates a new tree store.

This constructor is meant for language bindings.

Deprecated since version 4.10: Use [class`Gtk`.TreeListModel] instead

append(parent, row=None)[source]
Parameters:
Returns:

obj:Gtk.TreeIter pointing to the inserted row

Return type:

Gtk.TreeIter

Appends a new row to self. If parent is not 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 returned iterator will point to the new row. The row will be empty after this function is called if row is None. To fill in values, you need to call Gtk.TreeStore.set() or Gtk.TreeStore.set_value().

If row isn’t None it has to be a list of values which will be used to fill the row.

Deprecated since version 4.10: Use [class`Gtk`.TreeListModel] instead

clear()[source]

Removes all rows from self

Deprecated since version 4.10: Use [class`Gtk`.TreeListModel] instead

insert(parent, position, row=None)[source]
Parameters:
Returns:

a Gtk.TreeIter pointing to the new row

Return type:

Gtk.TreeIter

Creates a new row at position. If parent is not 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 returned iterator will point to the newly inserted row. The row will be empty after this function is called if row is None. To fill in values, you need to call Gtk.TreeStore.set() or Gtk.TreeStore.set_value().

If row isn’t None it has to be a list of values which will be used to fill the row.

Deprecated since version 4.10: Use [class`Gtk`.TreeListModel] instead

insert_after(parent, sibling)[source]
Parameters:
Returns:

a Gtk.TreeIter pointing to the new row

Return type:

Gtk.TreeIter

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 returned iterator will point to this new row. The row will be empty after this function is called if row is None. To fill in values, you need to call Gtk.TreeStore.set() or Gtk.TreeStore.set_value().

If row isn’t None it has to be a list of values which will be used to fill the row.

Deprecated since version 4.10: Use [class`Gtk`.TreeListModel] instead

insert_before(parent, sibling, row=None)[source]
Parameters:
Returns:

a Gtk.TreeIter pointing to the new row

Return type:

Gtk.TreeIter

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 returned iterator will point to this new row. The row will be empty after this function is called if row is None. To fill in values, you need to call Gtk.TreeStore.set() or Gtk.TreeStore.set_value().

If row isn’t None it has to be a list of values which will be used to fill the row.

Deprecated since version 4.10: Use [class`Gtk`.TreeListModel] instead

insert_with_values(parent, position, columns, values)[source]
Parameters:
  • parent (Gtk.TreeIter or None) – A valid GtkTreeIter

  • position (int) – position to insert the new row, or -1 for last

  • columns ([int]) – an array of column numbers

  • values ([GObject.Value]) – an array of GValues

Returns:

An unset GtkTreeIter to set the new row

Return type:

iter: Gtk.TreeIter

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

This function is mainly intended for language bindings.

Deprecated since version 4.10: Use [class`Gtk`.TreeListModel] instead

is_ancestor(iter, descendant)[source]
Parameters:
Returns:

true if iter is an ancestor of descendant, and false otherwise

Return type:

bool

Checks if iter is an ancestor of descendant.

Deprecated since version 4.10: Use [class`Gtk`.TreeListModel] instead

iter_depth(iter)[source]
Parameters:

iter (Gtk.TreeIter) – A valid GtkTreeIter

Returns:

The depth of the position pointed by the iterator

Return type:

int

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.

Deprecated since version 4.10: Use [class`Gtk`.TreeListModel] instead

iter_is_valid(iter)[source]
Parameters:

iter (Gtk.TreeIter) – the iterator to check

Returns:

true if the iter is valid, and false otherwise

Return type:

bool

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.

Deprecated since version 4.10: Use [class`Gtk`.TreeListModel] instead

move_after(iter, position)[source]
Parameters:

Moves iter in self 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.

Deprecated since version 4.10: Use [class`Gtk`.TreeListModel] instead

move_before(iter, position)[source]
Parameters:

Moves iter in self 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.

Deprecated since version 4.10: Use [class`Gtk`.TreeListModel] instead

prepend(parent, row=None)[source]
Parameters:
Returns:

obj:Gtk.TreeIter pointing to the inserted row

Return type:

Gtk.TreeIter

Prepends a new row to self. If parent is not 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 returned iterator will point to the new row. The row will be empty after this function is called if row is None. To fill in values, you need to call Gtk.TreeStore.set() or Gtk.TreeStore.set_value().

If row isn’t None it has to be a list of values which will be used to fill the row.

Deprecated since version 4.10: Use [class`Gtk`.TreeListModel] instead

remove(iter)[source]
Parameters:

iter (Gtk.TreeIter) – A valid GtkTreeIter

Returns:

true if iter is still valid, and false otherwise

Return type:

bool

Removes iter from self.

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

Deprecated since version 4.10: Use [class`Gtk`.TreeListModel] instead

set(iter, columns, values)[source]
Parameters:
  • iter (Gtk.TreeIter) – A valid GtkTreeIter for the row being modified

  • columns ([int]) – an array of column numbers

  • values ([GObject.Value]) – an array of GValues

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.

Deprecated since version 4.10: Use [class`Gtk`.TreeListModel] instead

set_column_types(types)[source]
Parameters:

types ([GObject.GType]) – An array of GType types, one for each column

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.

Deprecated since version 4.10: Use [class`Gtk`.TreeListModel] instead

set_value(iter, column, value)[source]
Parameters:
  • iter (Gtk.TreeIter) – A valid GtkTreeIter for the row being modified

  • column (int) – column number to modify

  • value (GObject.Value) – new value for the cell

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

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

value can also be a Python value and will be converted to a GObject.Value using the corresponding column type (See Gtk.ListStore.set_column_types()).

Deprecated since version 4.10: Use [class`Gtk`.TreeListModel] instead

swap(a, b)[source]
Parameters:

Swaps a and b in the same level of self.

Note that this function only works with unsorted stores.

Deprecated since version 4.10: Use [class`Gtk`.TreeListModel] instead