NodeData - (abstract) class to represent tree nodes for TreeWidget
NodeData
instances represent nodes in trees
displayed by a TreeWidget.
Such an instance completely determines how the corresponding
node itself is presented and what node interactions are possible.
The presentation can contain, for example, text,
icons, tags bound to commands etc.
The class is abstract. Real tree node classes will derive from this class and define essential information, e.g. how to determine the node's children, and override some default behaviour, e.g. how to represent the node.
By default, the class allocates a single display segment
between the marks _start
and _end
for the node's representation. The default representation
is purely textual. The string returned by a call
to info
is placed at _start
and associated with the tag _tag
.
By redefining _show
the presentation
can be modified. Defining the hook function _bind
(and maybe _unbind
) allows to add behaviour for
the node.
To allow to recognize tree nodes during update
,
the method id
is used. It should return
a value identifying this node among its siblings.
The default is Python's id
function
applied to the node.
TreeWidget
instance, the node
is displayed in.
TreeNode
instance, this node
belongs to. This reference may be used to update node's
subtree after modifications to node.
text
widget used to display
the tree. This reference is used to add text, images, marks,
tags, bindings etc. necessary to represent the node
or associate actions for it.
_update
expects the
node's presentation to be contained between these two marks.
_show
with the node's textual representation.
A behaviour can be bound to this tag via calls to
bindTag
.
hasChildren
and getChildren
.
Deriving classes must either define _children
or redefine both hasChildren
and getChildren
.
For static trees, usually the first case will be chosen
while the second case is preferable for dynamic trees.
id
function.
It is adequate for static trees and potentially for internal
Python trees. Classes managing external trees will
override this function.
_show
function to
provide the node's textual representation.
The default is the builtin str
function.
This method is very likely to be redefined by deriving
classes.
_start
and
_end
and then calls _show
.
_start
and _end
.
The default calls info
to get a purely
textual representation and associates it with the
text mark _tag
.
_bind
. Defining _unbind
may be necessary to ensure early release of resources.
_tag
,
if None
). The commands created for bindTag
are automatically released during unmap
. This
ensures early resource release.
_children
which the class does
not define by itself. Deriving classes must either
provide a _children
attribute or
redefine the methods.getChildren
returns
a node's children should remain constant with respect
to the id
method. This
is ensured, for example, by sorting the children
of a node according to their id
with a fixed order. If this condition is not met,
expanded tree nodes may be collapsed during updates.