NAME

Tk::EntrySet - display/edit a list of values in a Set of Widgets.

SYNOPSIS

require Tk::EntrySet;

my $valuelist = [];
my $instance = $main_window->EntrySet()->pack;
$instance->configure(-valuelist_variable => \$valuelist);
$instance->valuelist([qw/foo bar baz/]);

DESCRIPTION

Tk::EntrySet creates a Set of widgets to display/edit a list of values. The widget class is configurable. Tk::EntrySet adds/removes widgets to match the size of the valuelist. If a user deletes an entrywidgets content, the value is deleted from the valuelist and the entry is removed from the set on view update. View updates are by default bound to <Return> events. This is configurable through the -callback_installer option. The last widget in the Set is always empty to allow users to append values to the list. Tk::EntrySet is a Tk::Frame derived widget.

METHODS

Tk::EntrySet supports the following methods:

valuelist([qw/a list of values/])

Get/Set the valuelist (arrayref)

OPTIONS

Tk::EntrySet supports the following options:

-entryclass

A Tk widget class to be used for the entrywidgets. Defaults to 'Entry'.

-entryoptions

Options to be passed to each entry on creation (arrayref).

-getter

A coderef which is used by Tk::EntrySet to read the Entrywidgets content. It gets passed the Entrywidget instance and is expected to return its content. Defaults to sub{ $_[0]->get }, which is suitable for Tk::Entry.

-setter

A coderef which is used by Tk::EntrySet to write the Entrywidgets content. It gets passed the Entrywidget instance and the new value. Defaults to sub{ $_[0]->delete(0,'end'); $_[0]->insert('end',$_[1]) }, which is suitable for Tk::Entry.

-callback_installer

A coderef which is called after each Entrywidgets instantiation. The callback_installer gets passed the Entrywidget and a coderef that will update the Tk::EntrySet view when called. Defaults to sub{$_[0]->bind('<Key-Return>',$_[1])}.

-empty_is_undef

If set to true (default) empty strings will be treated like undef. Undef elements will be removed from the list and from the EntrySet on view updates.

-unique_values

If set to true (default) duplicate elements will be removed on view updates.

-valuelist

Get/Set the list of values (arrayref).

-valuelist_variable

Ties a variable (scalarref) to the -valuelist atribute. This is a Scalar Tie only.

-changed_command

A Callback that is called after the valuelist is updated on user interaction. By default -changed_command is triggered if the user hits <Return> in any of the Entries. (See -callback_installer above if you want to change that.)

Examples

require Tk::EntrySet;

my $valuelist = [];
my $instance = $main_window->EntrySet()->pack;
$instance->configure(-valuelist_variable => \$valuelist);
$instance->valuelist([qw/foo bar baz/]);
print Dumper $valuelist;

# use another entryclass:

my $num_set = $main_window->EntrySet(-entryclass => 'NumEntry')->pack;
$num_set->valuelist([3,15,42]);


# use a BrowseEntry  with custom get/set/callback_installer:

my $getter = sub{ $_[0]->Subwidget('entry')->get};
my $setter = sub{my $e = $_[0]->Subwidget('entry');
                 $e->delete(0,'end');
                 $e->insert('end', $_[1]);
            };
my $inst = sub{$_[0]->bind('<Key-Return>' ,$_[1]);
               $_[0]->configure(-browsecmd => $_[1]);
         };
my $mbe = $mw->EntrySet(-entryclass   => 'BrowseEntry',
                        -entryoptions => [-choices => [qw/ a b c d /]],
                        -getter       => $getter,
                        -setter       => $setter,
                        -callback_installer => $inst,
                      )->pack(-fill => 'both',
                                    -expand => 1);
$mbe->valuelist([qw/a c/]);

AUTHOR

Christoph Lamprecht, ch.l.ngre@online.de

COPYRIGHT AND LICENSE

Copyright (C) 2008 by Christoph Lamprecht

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available.