Skip to content

Gtk.TreeSelection

class — extends GObject.Object

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

The selection object for GtkTreeView

The GtkTreeSelection object is a helper object to manage the selection for a GtkTreeView widget. The GtkTreeSelection object is automatically created when a new GtkTreeView widget is created, and cannot exist independently of this widget. The primary reason the GtkTreeSelection objects exists is for cleanliness of code and API. That is, there is no conceptual reason all these functions could not be methods on the GtkTreeView widget instead of a separate function.

The GtkTreeSelection object is gotten from a GtkTreeView by calling TreeView.get_selection. It can be manipulated to check the selection status of the tree, as well as select and deselect individual rows. Selection is done completely view side. As a result, multiple views of the same model can have completely different selections. Additionally, you cannot change the selection of a row on the model that is not currently displayed by the view without expanding its parents first.

One of the important things to remember when monitoring the selection of a view is that the GtkTreeSelection::changed signal is mostly a hint. That is, it may only emit one signal when a range of rows is selected. Additionally, it may on occasion emit a GtkTreeSelection::changed signal when nothing has happened (mostly as a result of programmers calling select_row on an already selected row).

Methods

count_selected_rows

def count_selected_rows(self) -> int

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

Returns the number of rows that have been selected in tree.

get_mode

def get_mode(self) -> SelectionMode

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

Gets the selection mode for selection. See TreeSelection.set_mode.

get_selected

def get_selected(self) -> tuple[bool, TreeModel, TreeIter]

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

Sets iter to the currently selected node if selection is set to SelectionMode.SINGLE or SelectionMode.BROWSE. iter may be NULL if you just want to test if selection has any selected nodes. model is filled with the current model as a convenience. This function will not work if you use selection is SelectionMode.MULTIPLE.

get_selected_rows

def get_selected_rows(self) -> tuple[list[TreePath], TreeModel]

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

Creates a list of path of all selected rows. Additionally, if you are planning on modifying the model after calling this function, you may want to convert the returned list into a list of GtkTreeRowReferences. To do this, you can use TreeRowReference.new.

To free the return value, use:

g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);

get_tree_view

def get_tree_view(self) -> TreeView

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

Returns the tree view associated with selection.

iter_is_selected

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

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

Returns True if the row at iter is currently selected.

Parameters:

  • iter — A valid GtkTreeIter

path_is_selected

def path_is_selected(self, path: TreePath) -> bool

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

Returns True if the row pointed to by path is currently selected. If path does not point to a valid location, False is returned

Parameters:

  • path — A GtkTreePath to check selection on.

select_all

def select_all(self) -> None

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

Selects all the nodes. selection must be set to SelectionMode.MULTIPLE mode.

select_iter

def select_iter(self, iter: TreeIter) -> None

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

Selects the specified iterator.

Parameters:

  • iter — The GtkTreeIter to be selected.

select_path

def select_path(self, path: TreePath) -> None

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

Select the row at path.

Parameters:

  • path — The GtkTreePath to be selected.

select_range

def select_range(self, start_path: TreePath, end_path: TreePath) -> None

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

Selects a range of nodes, determined by start_path and end_path inclusive. selection must be set to SelectionMode.MULTIPLE mode.

Parameters:

  • start_path — The initial node of the range.
  • end_path — The final node of the range.

selected_foreach

def selected_foreach(self, func: TreeSelectionForeachFunc) -> None

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

Calls a function for each selected node. Note that you cannot modify the tree or selection from within this function. As a result, TreeSelection.get_selected_rows might be more useful.

Parameters:

  • func — The function to call for each selected node.

set_mode

def set_mode(self, type: SelectionMode | int) -> None

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

Sets the selection mode of the selection. If the previous type was SelectionMode.MULTIPLE, then the anchor is kept selected, if it was previously selected.

Parameters:

  • type — The selection mode

set_select_function

def set_select_function(self, func: TreeSelectionFunc | None = ...) -> None

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

Sets the selection function.

If set, this function is called before any node is selected or unselected, giving some control over which nodes are selected. The select function should return True if the state of the node may be toggled, and False if the state of the node should be left unchanged.

Parameters:

  • func — The selection function. May be None

unselect_all

def unselect_all(self) -> None

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

Unselects all the nodes.

unselect_iter

def unselect_iter(self, iter: TreeIter) -> None

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

Unselects the specified iterator.

Parameters:

  • iter — The GtkTreeIter to be unselected.

unselect_path

def unselect_path(self, path: TreePath) -> None

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

Unselects the row at path.

Parameters:

  • path — The GtkTreePath to be unselected.

unselect_range

def unselect_range(self, start_path: TreePath, end_path: TreePath) -> None

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

Unselects a range of nodes, determined by start_path and end_path inclusive.

Parameters:

  • start_path — The initial node of the range.
  • end_path — The initial node of the range.

Properties

mode

mode: SelectionMode | int  # read/write

Selection mode. See TreeSelection.set_mode for more information on this property.

Signals

changed

def on_changed(self) -> None: ...

Emitted whenever the selection has (possibly) changed. Please note that this signal is mostly a hint. It may only be emitted once when a range of rows are selected, and it may occasionally be emitted when nothing has happened.