NodeData Reference Manual

Name

NodeData - (abstract) class to represent tree nodes for TreeWidget

Description

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.

Attributes

_widget
a reference to the TreeWidget instance, the node is displayed in.
_treenode
a reference to the TreeNode instance, this node belongs to. This reference may be used to update node's subtree after modifications to node.
_tree
a reference to the 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.
_start, _end
unique text marks with left and right gravity, respectively. The default _update expects the node's presentation to be contained between these two marks.
_tag
a text tag, associated by the default _show with the node's textual representation. A behaviour can be bound to this tag via calls to bindTag.
_children
the sequence of children. This attribute is only used by the methods 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.

Methods

id()
is used to recognize this node among its siblings. It, therefore, must return a value that identifies the node among its siblings. The default is the builtin id function. It is adequate for static trees and potentially for internal Python trees. Classes managing external trees will override this function.
info()
used in the default _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.
map(pos,id,treenode,widget)
called to display the node in the tree. It defines most of the attributes described above. Do not tamper with it, unless you know what you are doing.
unmap()
called to remove the node from the display. Do not tamper with it, unless you know what you are doing.
update()
update the node's presentation. The default implementation deletes the content between the marks _start and _end and then calls _show.
_show()
places the node's representation between the text marks _start and _end. The default calls info to get a purely textual representation and associates it with the text mark _tag.
_bind()
associates behaviour to the node's representation. The default does nothing.
_unbind()
the inverse of _bind. Defining _unbind may be necessary to ensure early release of resources.
bindTag(event,func,tag=None,add=0)
binds func to event for tag (_tag, if None). The commands created for bindTag are automatically released during unmap. This ensures early resource release.
hasChildren(), getChildren()
to be overridden for dynamic trees. The default use the attribute _children which the class does not define by itself. Deriving classes must either provide a _children attribute or redefine the methods.
The order in which 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.

Dieter Maurer
Last modified: Sun Nov 14 16:28:45 CET 1999