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.
- Name: browseCmd
- Class: BrowseCmd
- Switch: -browsecmd
-
Specifies a callback to call whenever the user browses on an entry
(usually by single-clicking on the entry). The callback is called with
one argument, the pathname of the entry.
- Name: closeCmd
- Class: CloseCmd
- Switch: -closecmd
-
Specifies a callback to call whenever an entry needs to be closed (See
BINDINGS below). This method is called with one argument,
the pathname of the entry. This method should perform appropriate
actions to close the specified entry. If the -closecmd option
is not specified, the default closing action is to hide all child
entries of the specified entry.
- Name: command
- Class: Command
- Switch: -command
-
Specifies a callback to call whenever the user activates an entry
(usually by double-clicking on the entry). The callback
is called with one argument, the pathname of the entry.
- Name: ignoreInvoke
- Class: IgnoreInvoke
- Switch: -ignoreinvoke
-
A Boolean value that specifies when a branch should be opened or
closed. A branch will always be opened or closed when the user presses
the (+) and (-) indicators. However, when the user invokes a branch
(by doublc-clicking or pressing <Return>), the branch will be opened
or closed only if -ignoreinvoke is set to false (the default
setting).
- Name: openCmd
- Class: OpenCmd
- Switch: -opencmd
-
Specifies a callback to call whenever an entry needs to be opened (See
BINDINGS below). This method is called with one argument,
the pathname of the entry. This method should perform appropriate
actions to open the specified entry. If the -opencmd option
is not specified, the default opening action is to show all the child
entries of the specified entry.
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:
- $tree->autosetmode
-
This method calls the setmode method for all the entries in
this Tree widget: if an entry has no child entries, its mode is set to
none. Otherwise, if the entry has any hidden child entries, its
mode is set to open; otherwise its mode is set to close.
- $tree->close(entryPath)
-
Close the entry given by entryPath if its mode is close.
- $tree->getmode(entryPath)
-
Returns the current mode of the entry given by entryPath.
- $tree->open(entryPath)
-
Open the entry given by entryPath if its mode is open.
- $tree->setmode(entryPath, mode)
-
This method is used to indicate whether the entry given by
entryPath has children entries and whether the children are
visible. mode must be one of open,
close or none. If mode is set to open, a (+)
indicator is drawn next the the entry. If mode is set to
close, a (-) indicator is drawn next the the entry. If
mode is set to none, no indicators will be drawn for this
entry. The default mode is none. The open mode indicates
the entry has hidden children and this entry can be opened by the
user. The close mode indicates that all the children of the entry
are now visible and the entry can be closed by the user.
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:
- [1]
-
If the mode of the entry is open, it can be opened by clicking
on its (+) indicator.
- [2]
-
If the mode of the entry is close, it can be closed by clicking
on its (-) indicator.
Tk::HList
Perl/TK version by Chris Dean <ctdean@cogit.com>. Original Tcl/Tix
version by Ioi Kim Lam.
Thanks to Achim Bohnet <ach@mpe.mpg.de> for all his help.
Tk::Tree - Create and manipulate Tree widgets
|