gtk.TreeModelSort
Prev | The gtk Class Reference | Next

## gtk.TreeModelSort

gtk.TreeModelSort — a tree model that is a sorted version of a child `gtk.TreeModel`

## Synopsis

    class gtk.TreeModelSort(gobject.GObject, gtk.TreeModel, gtk.TreeSortable):
        gtk.TreeModelSort(child_model)
        def get_model()
        def convert_child_path_to_path(child_path)
        def convert_child_iter_to_iter(sort_iter, child_iter)
        def convert_path_to_child_path(sorted_path)
        def convert_iter_to_child_iter(child_iter, sorted_iter)
        def reset_default_sort_func()
        def clear_cache()
        def iter_is_valid(iter)

## Ancestry

    +-- gobject.GObject
      +-- gtk.TreeModelSort (implements gtk.TreeModel, gtk.TreeSortable)

## gtk.TreeModelSort Properties

"model" | Read-Write-Construct | The child model for the `gtk.TreeModelSort` to sort.

## gtk.TreeModelSort Signal Prototypes

gobject.GObject Signal Prototypes

gtk.TreeSortable Signal Prototypes

gtk.TreeModel Signal Prototypes

## Description

A `gtk.TreeModelSort` is a sorted model of its child model. A `gtk.TreeModelSort` implements the `gtk.TreeModel` interface and the `gtk.TreeSortable` interface to manage the sort functions.

The `gtk.TreeModelSort` objects support the Python mapping and iterator protocols. See the `gtk.TreeModel` Description and the PyGTK tutorial for more information.

## Constructor

        gtk.TreeModelSort(child_model)

`child_model` : | a child `gtk.TreeModel`
Returns : | A new `gtk.TreeModel`.

Creates a new `gtk.TreeModel`, with `child_model` as the child model.

## Methods

### gtk.TreeModelSort.get_model

        def get_model()

Returns : | the "child model" being sorted

The `get_model`() method returns the model that the `gtk.TreeModelSort` is sorting.

### gtk.TreeModelSort.convert_child_path_to_path

        def convert_child_path_to_path(child_path)

`child_path` : | A child tree path to convert
Returns : | A new tree path in the treemodelsort, or `None`

The `convert_child_path_to_path`() method converts the path in the child model specified by `child_path` to a path relative to the treemodelsort. That is, `child_path` points to a path in the child model. The returned path will point to the same row in the sorted model. If `child_path` isn't a valid path on the child model, then `None` is returned.

### gtk.TreeModelSort.convert_child_iter_to_iter

        def convert_child_iter_to_iter(sort_iter, child_iter)

`sort_iter` : | `None` or a `gtk.TreeIter` for backward compatibility.
`child_iter` : | A valid `gtk.TreeIter` pointing to a row on the child model
Returns : | A `gtk.TreeIter` pointing to the same path in the sorted model.

The `convert_child_iter_to_iter`() method returns a `gtk.TreeIter` that points to the row in the treemodelsort that corresponds to the row pointed to by `child_iter`. `sort_iter` parameter should be `None` but can specify a `gtk.TreeIter` for backward compatibility.

### gtk.TreeModelSort.convert_path_to_child_path

        def convert_path_to_child_path(sorted_path)

`sorted_path` : | a path in the sorted model
Returns : | a new path in the child model, or `None`

The `convert_path_to_child_path`() method returns a path in the child model that refers to the same row as the path in the sorted model specified by `sorted_path`. That is, `sorted_path` points to a location in treemodelsort and the returned path will point to the same location in the child model. If `sorted_path` does not point to a location in the child model, `None` is returned.

### gtk.TreeModelSort.convert_iter_to_child_iter

        def convert_iter_to_child_iter(child_iter, sorted_iter)

`child_iter` : | `None` or a `gtk.TreeIter` for backward compatibility.
`sorted_iter` : | A valid `gtk.TreeIter` pointing to a row on `tree_model_sort`.
Returns : | A `gtk.TreeIter` that points to a row in the child model

The `convert_iter_to_child_iter`() method returns a `gtk.TreeIter` that points to the row in the child model that is the same row pointed to by `sorted_iter` in the treemodelsort. `child_iter` should be `None` but can specify a `gtk.TreeIter` for backward compatibility.

### gtk.TreeModelSort.reset_default_sort_func

        def reset_default_sort_func()

The `reset_default_sort_func`() method resets the default sort function to be in the 'unsorted' state. That is, it is in the same order as the child model. It will re-sort the model to be in the same order as the child model only if the `gtk.TreeModelSort` is in 'unsorted' state.

### gtk.TreeModelSort.clear_cache

        def clear_cache()

The `clear_cache`() method clears the treemodelsort of any cached iterators that haven't been reffed with the `ref_node`() method. This might be useful if the child model being sorted is static (and doesn't change often) and there has been a lot of unreffed access to nodes. As a side effect of this function, all unreffed `gtk.TreeIter` objects will be invalid.

### gtk.TreeModelSort.iter_is_valid

        def iter_is_valid(iter)

`iter` : | A `gtk.TreeIter`.
Returns : | `TRUE` if `iter` is valid

### Note

This method is available in PyGTK 2.2 and above.

The `iter_is_valid`() method checks if the `gtk.TreeIter` specified by `iter` is valid for the treemodel sort.

### Warning

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

Prev | Up | Next
gtk.TreeModelFilter | Home | gtk.TreeModelRow