Gtk.TreeSelection
Gtk.TreeSelection — The selection object for Gtk.TreeView
Object Hierarchy:
GObject
╰── Gtk.TreeSelection
See also:
Gtk.TreeView, Gtk.TreeViewColumn, Gtk.TreeModel, Gtk.TreeSortable, Gtk.TreeModelSort, Gtk.ListStore, Gtk.TreeStore, Gtk.CellRenderer, Gtk.CellEditable, Gtk.CellRendererPixbuf, Gtk.CellRendererText, Gtk.CellRendererToggle, [Gtk.TreeView drag-and-drop][gtk3-Gtk.TreeView-drag-and-drop]
Functions:
- set_mode
(self, type:Gtk.SelectionMode)
- get_mode
(self) -> Gtk.SelectionMode
- set_select_function
(self, func:Gtk.TreeSelectionFunc, data=None)
- get_tree_view
(self) -> Gtk.TreeView
- get_selected
(self) -> bool, model:Gtk.TreeModel, iter:Gtk.TreeIter
- selected_foreach
(self, func:Gtk.TreeSelectionForeachFunc, data=None)
- get_selected_rows
(self) -> list, model:Gtk.TreeModel
- count_selected_rows
(self) -> int
- select_path
(self, path:Gtk.TreePath)
- unselect_path
(self, path:Gtk.TreePath)
- path_is_selected
(self, path:Gtk.TreePath) -> bool
- select_iter
(self, iter:Gtk.TreeIter)
- unselect_iter
(self, iter:Gtk.TreeIter)
- iter_is_selected
(self, iter:Gtk.TreeIter) -> bool
- select_all
(self)
- unselect_all
(self)
- select_range
(self, start_path:Gtk.TreePath, end_path:Gtk.TreePath)
- unselect_range
(self, start_path:Gtk.TreePath, end_path:Gtk.TreePath)
Description:
The Gtk.TreeSelection
object is a helper object to manage the selection for a GtkTreeView widget. The Gtk.TreeSelection
object is automatically created when a new Gtk.TreeView widget is created, and cannot exist independently of this widget. The primary reason the Gtk.TreeSelection
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 Gtk.TreeView widget instead of a separate function.
The Gtk.TreeSelection
object is gotten from a GtkTreeView by calling Gtk.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 Gtk.TreeSelection::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 Gtk.TreeSelection::changed
signal when nothing has happened (mostly as a result of programmers calling select_row on an already selected row).
Code snap:
...
treeview.connect('cursor-changed', self.on_select)
def on_select(self, tree):
# Get the current selected row and the model.
model, iter = tree.get_selection().get_selected()
# Look up the current value on the selected row and get
# a new value to change it to.
data = model.get_value(iter, 0)
Function Details:
set_mode()
set_mode (self, type:Gtk.SelectionMode)
Sets the selection mode of the selection
. If the previous type wasGTK_SELECTION_MULTIPLE, then the anchor is kept selected, if it waspreviously selected.
get_mode()
get_mode (self) -> Gtk.SelectionMode
Gets the selection mode for selection
. SeeGtk.TreeSelection:set_mode()
.
- Returns: the current selection mode
set_select_function()
set_select_function (self, func:Gtk.TreeSelectionFunc, data=None)
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 functionshould return True
if the state of the node may be toggled, and FALSE
if the state of the node should be left unchanged.
get_tree_view()
get_tree_view (self) -> Gtk.TreeView
Returns the tree view associated with selection
.
- Returns:
A
Gtk.TreeView
.
get_selected()
get_selected (self) -> bool, model:Gtk.TreeModel, iter:Gtk.TreeIter
Sets iter
to the currently selected node if selection
is set toGTK_SELECTION_SINGLE or GTK_SELECTION_BROWSE. iter
may be None if youjust want to test if selection
has any selected nodes. model
is filledwith the current model as a convenience. This function will not work if youuse selection
is GTK_SELECTION_MULTIPLE.
- Returns: True, if there is a selected node.
selected_foreach()
selected_foreach (self, func:Gtk.TreeSelectionForeachFunc, data=None)
Calls a function for each selected node. Note that you cannot modifythe tree or selection from within this function. As a result,Gtk.TreeSelection:get_selected_rows()
might be more useful.
get_selected_rows()
get_selected_rows (self) -> list, model:Gtk.TreeModel
Creates a list of path of all selected rows. Additionally, if you areplanning on modifying the model after calling this function, you maywant to convert the returned list into a list of Gtk.TreeRowReferences
.To do this, you can use `Gtk.TreeRowReference:new
().
To free the return value, use:
g_list_free_full (list, (GDestroyNotify)
Gtk.TreePath:free);`
Returns: A GList containing a
Gtk.TreePath
for each selected row.Since: 2.2
count_selected_rows()
count_selected_rows (self) -> int
Returns the number of rows that have been selected in tree
.
Returns: The number of rows selected.
Since: 2.2
select_path()
select_path (self, path:Gtk.TreePath)
Select the row at path
.
unselect_path()
unselect_path (self, path:Gtk.TreePath)
Unselects the row at path
.
path_is_selected()
path_is_selected (self, path:Gtk.TreePath) -> bool
Returns True
if the row pointed to by path
is currently selected. If path
does not point to a valid location, FALSE
is returned
- Returns:
True
ifpath
is selected.
select_iter()
select_iter (self, iter:Gtk.TreeIter)
Selects the specified iterator.
unselect_iter()
unselect_iter (self, iter:Gtk.TreeIter)
Unselects the specified iterator.
iter_is_selected()
iter_is_selected (self, iter:Gtk.TreeIter) -> bool
Returns True
if the row at iter
is currently selected.
- Returns:
True
, ifiter
is selected
select_all()
select_all (self)
Selects all the nodes. selection
must be set to GTK_SELECTION_MULTIPLEmode.
unselect_all()
unselect_all (self)
Unselects all the nodes.
select_range()
select_range (self, start_path:Gtk.TreePath, end_path:Gtk.TreePath)
Selects a range of nodes, determined by start_path
and end_path
inclusive.selection
must be set to GTK_SELECTION_MULTIPLE mode.
unselect_range()
unselect_range (self, start_path:Gtk.TreePath, end_path:Gtk.TreePath)
Unselects a range of nodes, determined by start_path
and end_path
inclusive.
- Since: 2.2