Tk::Tree - Create and manipulate Tree widgets |
Tk::Tree - Create and manipulate Tree widgets
use Tk::Tree;
$tree = $parent->Tree(?options?);
The Tree class is derived from the HList class and inherits all the methods, options and subwidgets of its super-class. A Tree widget is not scrolled by default.
Tree supports all the standard options of an HList widget. See the Tk::options manpage for details on the standard options.
The Tree method creates a new window and makes it into a Tree widget and return a reference to it. Additional options, described above, may be specified on the command line or in the option database to configure aspects of the Tree widget such as its cursor and relief.
The Tree widget can be used to display hierarchical data in a tree form. The user can adjust the view of the tree by opening or closing parts of the tree.
To display a static tree structure, you can add the entries into the Tree widget and hide any entries as desired. Then you can call the autosetmode method. This will set up the Tree widget so that it handles all the open and close events automatically. the demonstration program Tixish/examples/perl-tix-tree).
The above method is not applicable if you want to maintain a dynamic tree structure, i.e, you do not know all the entries in the tree and you need to add or delete entries subsequently. To do this, you should first create the entries in the Tree widget. Then, use the setmode method to indicate the entries that can be opened or closed, and use the -opencmd and -closecmd options to handle the opening and closing events. (Please see the demonstration program Tixish/examples/perl-tix-dyntree).
Use either
$parent->Scrolled('Tree', ... );
or
$parent->ScrlTree( ... );
to create a scrolled Tree. See the Tk::Scrolled manpage for details.
The Tree method creates a widget object. This object supports the configure and cget methods described in the Tk::options manpage which can be used to enquire and modify the options described above. The widget also inherits all the methods provided by the generic Tk::Widget class.
The following additional methods are available for Tree widgets:
treeRegExp
same as in Perl regular
expressions
TreeRegExp
, the same as in Perl regular
expressions
Examples:
$tree->add_pathimage('^root','openfolder','folder');
matches root
, root.foo
, root.bar
, but not foo.root
$tree->add_pathimage('root.*.class','openfolder','folder');
matches all paths containing root.<anything>.class
, but not
root.<anything>.<anything>.class
*
is one part of the path. If
you want to use a wildcard for two steps, you have to use *.*
.
$tree->add_pathimage('class$','openfolder','folder');
This matches all path with class
at the end.
Example: root | foo | bar | | bar1 | | bar2
my @childentries = $tree->child_entries('root.bar'); # returns (root.bar.bar1, root.bar.bar2)
my $nr_of_subentries = $tree->child_entries('root',2); # returns 4
If $path
is omitted, all it is assumed, that the entry above
'root' is meant. $depth
defines the numbers of levels.
The basic mouse and keyboard bindings of the Tree widget are the same as the bindings of the HList widget. In addition, the entries can be opened or closed under the following conditions:
Perl/TK version by Chris Dean <ctdean@cogit.com>. Original Tcl/Tix version by Ioi Kim Lam.
Additions by Renee Baecker <module@renee-baecker.de>
Thanks to Achim Bohnet <ach@mpe.mpg.de> for all his help.
Tk::Tree - Create and manipulate Tree widgets |