Ancestry

gtk.TreeSelection Signal Prototypes

Description

The gtk.TreeSelection
object is a helper object to manage the selection for a gtk.TreeView
widget. The gtk.TreeSelection
object is automatically created when a new gtk.TreeView
widget is created, and cannot exist independent of this widget. The primary
reason the gtk.TreeSelection
object 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 retrieved from a gtk.TreeView by
calling the gtk.TreeView.get_selection()
method. It can be manipulated to check the selection status of the tree, as
well as select and deselect individual rows. Selection is done completely on
the 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 "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 "changed" signal when nothing has happened (mostly
as a result of programmers calling the select_path()
or select_iter()
methods on an already selected row).

Methods

gtk.TreeSelection.set_mode

def set_mode(type)

type :

the selection mode

The set_mode() method sets the
selection mode of the treeselection to the mode specified by
type. The value of type must
be one of: gtk.SELECTION_NONE,
gtk.SELECTION_SINGLE,
gtk.SELECTION_BROWSE or
gtk.SELECTION_MULTIPLE. See the GTK Selection Mode Constants description for more
detail.

If the previous type was
gtk.SELECTION_MULTIPLE, then the anchor is kept selected,
if it was previously selected.

gtk.TreeSelection.get_mode

def get_mode()

Returns :

the current selection mode

The get_mode() method returns the
selection mode for treeselection. See the set_mode()
method for more information.

gtk.TreeSelection.set_select_function

def set_select_function(func, data=None, full=False)

func :

the selection function.

data :

the selection function's
data.

full :

if Truefunc will be passed a full set of
args

The set_selection_function() method
sets the selection function to func (a function or
method). If the selection function is set, it is called before any node is
selected or unselected, giving some control over which nodes are selected.
The selection 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. The signature of the selection function
callback is:

def selectfunction(info) def selectmethod(self, info)

where info is a tuple containing a path or a
path and data if data was
passed to the set_select_function()
method.

In PyGTK 2.10 and above if the additional optional parameter
full is True the signature of
func should be:

where selection is the gtk.TreeSelection,
model is the gtk.TreeModel
used by the gtk.TreeView
associated with selection, path is the path of
the selected row, is_selected is
True if the row is currently selected and
user_data is data if any
(may not be present if data was
None). If func is a method
then self is the object that the method is
called upon.

gtk.TreeSelection.get_selected

The get_selected() method returns a
2-tuple containing the treemodel and a treeiter pointing to the selected node
in the treemodel if the treeselection is set to
gtk.SELECTION_SINGLE or
gtk.SELECTION_BROWSE. The returned gtk.TreeIter will
be None if there is no row selected. This method will not
work if you use selection is
gtk.SELECTION_MULTIPLE.

gtk.TreeSelection.get_selected_rows

def get_selected_rows()

Returns :

a 2-tuple containing the tree model and a list
of the tree paths of all selected rows.

Note

This method is available in PyGTK 2.2 and above.

The get_selected_rows() method returns
a 2-tuple containing a gtk.TreeModel and
a list of the tree paths of all selected rows. Additionally, if you are
planning on modifying the tree model after calling this method, you may want
to convert the returned list into a list of gtk.TreeRowReference
objects. To do this, you can use the gtk.TreeRowReference()
constructor.

gtk.TreeSelection.count_selected_rows

def count_selected_rows()

Returns :

The number of rows selected.

Note

This method is available in PyGTK 2.2 and above.

The count_selected_rows() method
returns the number of rows that have been selected.

gtk.TreeSelection.selected_foreach

def selected_foreach(func, data=None)

func :

the function or method to call for each
selected node.

data :

the user data to pass to
func.

The selected_foreach() method calls the
function or method specified by func for each
selected node passing the user data specified by
data. The signature of func
is:

where treemodel is the gtk.TreeModel
being viewed, path is the path of the selected row,
iter is a gtk.TreeIter
pointing to the selected row and ... is the user data
if any (may not be present if data was
None). If func is a method then
self is the object that the method is called
upon.