|
NAMETk::HistEntry - Entry widget with history capabilitySYNOPSISuse Tk::HistEntry; $hist1 = $top->HistEntry(-textvariable => \$var1); $hist2 = $top->SimpleHistEntry(-textvariable => \$var2); DESCRIPTION"Tk::HistEntry" defines entry widgets with history capabilities. The widgets come in two flavours:
The user may browse with the Up and Down keys through the history list. New history entries may be added either manually by binding the Return key to historyAdd() or automatically by setting the -command option. OPTIONSHistEntry is an descendant of BrowseEntry and thus supports all of its standard options.SimpleHistEntry is an descendant of Entry and supports all of the Entry options. In addition, the widgets support following specific options:
METHODS
KEY BINDINGS
EXAMPLEThis is an simple example for Tk::HistEntry. More examples can be found in the t and examples directories of the source distribution.use Tk; use Tk::HistEntry; $top = new MainWindow; $he = $top->HistEntry(-textvariable => \$foo, -command => sub { # automatically adds $foo to history print STDERR "Do something with $foo\n"; })->pack; $b = $top->Button(-text => 'Do it', -command => sub { $he->invoke })->pack; MainLoop; If you like to not depend on the installation of Tk::HistEntry, you can write something like this: $Entry = "Entry"; # default Entry widget eval { # try loading the module, otherwise $Entry is left to the value "Entry" require Tk::HistEntry; $Entry = "SimpleHistEntry"; }; $entry = $mw->$Entry(-textvariable => \$res)->pack; $entry->bind("<Return>" => sub { # check whether the historyAdd method is # known to the widget if ($entry->can('historyAdd')) { $entry->historyAdd; } }); In this approach the history lives in an array variable. Here the entry widget does not need to be permanent, that is, it is possible to destroy the containing window and restore the history again: $Entry = "Entry"; eval { require Tk::HistEntry; $Entry = "HistEntry"; }; $entry = $mw->$Entry(-textvariable => \$res)->pack; if ($entry->can('history') && @history) { $entry->history(\@history); } # Later, after clicking on a hypothetical "Ok" button: if ($res ne "" && $entry->can('historyAdd')) { $entry->historyAdd($res); @history = $entry->history; } BUGS/TODO- C-s/C-r do not work as nice as in gnu readline - use -browsecmd from Tk::BrowseEntry - use Tie::Array if present AUTHORSlaven Rezic <slaven@rezic.de>CREDITSThanks for Jason Smith <smithj4@rpi.edu> and Benny Khoo <kkhoo1@penang.intel.com> for their suggestions. The auto-completion code is stolen from Tk::IntEntry by Dave Collins <Dave.Collins@tiuk.ti.com>.COPYRIGHTCopyright (c) 1997, 2000, 2001, 2003, 2008, 2016, 2017 Slaven Rezic. All rights reserved. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |