Tk::DTree - A Tree widget with a visible/hidden data column |
Tk::DTree - A Tree widget with a visible/hidden data column
use Tk; use Tk::DTree
my $mw = MainWindow->new();
#my $tree = $mw->DTree( my $tree = $mw->Scrolled('DTree', -scrollbars => 'e', -cursor => 'right_ptr', -relief => 'sunken', -borderwidth => '2', -width => '10', # columns -height => '15', # lines -background => 'orange', -selectmode => 'single', -sizecmd => \&size_cb, #new options -viewtype => 'withdata', -datastyle => $datastyle; -databackground => 'skyblue', -numeric_primary_sort => '0', -numeric_secondary_sort => '1', )->pack;
$tree->autosetmode(); Tk::MainLoop; sub add_data { # 1) insert a complete array with texts and data, keys become 'visible' entry, # values are stored as data and are shown in transient column. $tree->add($key, -data => 'i02', -itemtype => 'imagetext', -text => 'Dummy', -image => $xpms{dummy}, #-datastyle => $datastyle, ); } sub size_cb { print "we have resized\n"; }
A Tree derived widget that offers several add-on functions like in-place-editing, sorting, reordering and inserting/retrieving of item text & data, suitable for perl Tk800.x (developed with Tk800.024).
You can insert item-texts or item-text/-value pair/s into the DTree widget with the standard-like add() method . The delete removes visible list-items as well as the associated data.
get_item(), get_item_text(), get_item_value() retrieve either a scalar or lists, depending on the context it was invoked. In scalar mode they return the first item only (/first item-text/-text/-value/). In list context they return the text AND the belonging data.
getcurselection(), getcurselection_text(), getcurselection_value(), and getcurselection_index() also retrieve either a scalar or a list, depending on the context but for the currently selected listitem. For scalar mode same rule applies as for get_item.
reverse() reverses the whole list and all item values.
sort() sorts the whole list alphanumerical and reorders and all items and belonging
Configure() understands the new editing-related options -editactivationEvent, -editfinishonLeave, -posteditcommand and -validate. The first one allows to specify an event descriptor for the activation of the Editing features, the second enables the automatic finish-edit feature if the mouse leaves the edit-area, The others may be used to specify callbacks: One for postprocessing after editing is finished and the other one, which can be used to perform validation operations during editing.
viewtype() might be invoked directly or via configure to switch between 'withdata' or 'normal' listbox view.
If the Listbox has the input focus the key 'Control-Key-[' makes the data-list visible and 'Control-Key-]' hides it.
sort()
function (numeric on primary keys / first column).
sort()
function (numeric on secondary keys / second column).
Michael Krause, KrauseM_AT_gmx_DOT_net
This code may be distributed under the same conditions as Perl.
V1.01 (C) January 2004
Tk::DTree - A Tree widget with a visible/hidden data column |