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 (10), 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 (10), 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

The Gtk.TreeStore object is a list model for use with a Gtk.TreeView widget. It implements the Gtk.TreeModel interface, and consequentially, can use all of the methods available there. It also implements the Gtk.TreeSortable interface so it can be sorted by the view. Finally, it also implements the tree drag and drop interfaces.

Gtk.TreeStore as Gtk.Buildable

The Gtk.TreeStore implementation of the Gtk.Buildable 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>
classmethod new(types)[source]
Parameters:

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

Returns:

a new Gtk.TreeStore

Return type:

Gtk.TreeStore

Non vararg creation function. Used primarily by language bindings.

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.

clear()[source]

Removes all rows from self

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.

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.

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.

insert_with_values(parent, position, columns, values)[source]
Parameters:
Returns:

An unset Gtk.TreeIter to set the new row, or None.

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.

New in version 2.10.

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

True, if iter is an ancestor of descendant

Return type:

bool

Returns True if iter is an ancestor of descendant. That is, iter is the parent (or grandparent or great-grandparent) of descendant.

iter_depth(iter)[source]
Parameters:

iter (Gtk.TreeIter) – A valid Gtk.TreeIter

Returns:

The depth of iter

Return type:

int

Returns the depth of iter. This will be 0 for anything on the root level, 1 for anything down a level, etc.

iter_is_valid(iter)[source]
Parameters:

iter (Gtk.TreeIter) – A Gtk.TreeIter.

Returns:

True if the iter is valid, False if the iter is invalid.

Return type:

bool

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

Checks if the given iter is a valid iter for this Gtk.TreeStore.

New in version 2.2.

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.

New in version 2.2.

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.

New in version 2.2.

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.

remove(iter)[source]
Parameters:

iter (Gtk.TreeIter) – A valid Gtk.TreeIter

Returns:

True if iter is still valid, False if not.

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.

set(iter, columns, values)[source]
Parameters:

A variant of gtk_tree_store_set_valist() which takes the columns and values as two arrays, instead of varargs. This function is mainly intended for language bindings or in case the number of columns to change is not known until run-time.

New in version 2.12.

set_column_types(types)[source]
Parameters:

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

This function is meant primarily for GObject.Objects that inherit from Gtk.TreeStore, and should only be used when constructing a new Gtk.TreeStore. It will not function after a row has been added, or a method on the Gtk.TreeModel interface is called.

set_value(iter, column, value)[source]
Parameters:

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

swap(a, b)[source]
Parameters:

Swaps a and b in the same level of self. Note that this function only works with unsorted stores.

New in version 2.2.