Lamprecht Christoph > Tk-EntrySet > Tk::MatchingBE

Download:
Tk-EntrySet-0.11.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.11   Source  

NAME ^

Tk::MatchingBE - A single-selection BrowseEntry with 'matching' Entry widget

SYNOPSIS ^

  require Tk::MatchingBE;

  $mw->MatchingBE(-choices => [qw/foo bar baz/])->pack;

DESCRIPTION ^

Tk::MatchingBE is a Tk::BrowseEntry which allows for a single selection from a given list of choices/options. In order to find the right item in the choices list, the Entry widgets content is matched against the lists elements as the user types. The first matching item gets selected and the list is popped up if a match occurs. Key-press events causing non-matching content of the Entry are ignored. The only exception here are 'Delete' events. Matching is case insensitive and metacharacters are disabled (\Q). '<Return>' will select the active entry, popdown the list and trigger -selectcmd. Possible states of the widget are undef or a single selection - accessible per value or index. Tk::MatchingBE is a Tk::BrowseEntry derived widget.

METHODS ^

Tk::MatchingBE supports the following methods:

choices([qw/a list of possible choices/])

Get/Set the choices list (arrayref).

labels_and_values([{label=>'aLabel',value=>'aValue'},{},{}])

Get/Set the choices list with value/label associations. Labels are displayed in the Listbox. Selected value can be accessed with get_selected_value

get_selected_index

Get the selected index.

set_selected_index(anInteger)

Set the selected index.

get_selected_value

Get the selected value. Returns the selected 'value' in case -labels_and_values has been set. Returns the selected 'label' (Listbox entry) if -choices has been set.

set_selected_value

Sets the selected 'value' in case -labels_and_values has been set. Croaks otherwise.

OPTIONS ^

Tk::MatchingBE supports the following options:

-choices

Get/set the list of possible choices.

-labels_and_values

Get/set the choices list with value/label associations (see above).

-value_variable

Ties a variable to the widget using 'get/set_selected_value' methods.

-selectcmd

A callback to be called when the user selects an entry.

EXAMPLE ^

  use Tk;
  use Tk::MatchingBE;

  my $mw = tkinit;
  my $be = $mw->MatchingBE(-choices=>[qw/aaa bbb ccc ddd asd/])->pack;
  $be->set_selected_index(0);
  $mw->Button(-text => 'selected',
              -command => sub{
                  for (qw/get_selected_index
                          get_selected_value/){
                      print $be->$_, "\n";
                  }
              },
          )->pack;

  $mw->Button(-text => 'next_item',
              -command => sub{
                  my $i = $be->get_selected_index;
                  $i = ($i+1) % 5 ;
                  $be->set_selected_index($i);
              },
          )->pack;
  MainLoop;

SEE ALSO ^

This module was written for Tk::ChoicesSet. There are others that offer more flexibility like:

JBrowseEntry
JComboBox
MatchEntry

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.

syntax highlighting: