[ANNOUNCE] Tk-JComboBox 1.10
Rob Seegel <[email protected]>
| Newsgroups | gmane.comp.lang.perl.tk |
|---|---|
| Message-ID | <[email protected]> |
I've released the latest version of Tk-JComboBox to CPAN today. The new
release contains a new implementation for supporting the -textvariable
option, and I've also done a little more proofreading/spell-checking of
the JComboBox.pod. The new release *may* introduce issues with code
that uses Tk-JComboBox, and used the -textvariable option depending on
how the option was being used. The changes to the widget are listed in
the Changes and README files, in addition to the JComboBox.pod doc. I
will also briefly cover them here.
The Problem
I used a naive approach to handling the -textvariable option before by
delegating its implementation to the Entry subwidget. So changes to the
variable looked as though they resulted in state changes to JComboBox,
however all they really resulted in were changes to the Entry subwidget.
Changes that were detected and accounted for by some, but not all method
calls. (refer to the recent Tk::JComboBox Question in c.l.p.tk posting).
The Solution
I could have added more code to the naive approach, and worked around
the problem further. Instead I decided to reimplement the -textvariable
support using Steve Lidie's Tie::Watch module,
and tie access to the variable to various JComboBox options. With this
change, there are two potential issues you may find in code that uses
JComboBox.:
1. In *readonly* mode, you can no longer use -textvariable to set an
entry that does not appear within the list of choices.
Readonly mode was intended to support selection of an exclusive item
from a list of choices. In the older versions, textvariable could be
used to create an Entry that did not occur within the Listbox. In the
new code, such values will be ignored. These values are still allowed in
editable mode. Note: there are still ways (by accessing the subwidget
directly) of setting the Entry in readonly mode, however the fact that
it was "supported" before was a bug rather than a feature.
2. Textvariable provides access to the selected value and *not* the name.
This is an important distinction, because each JComboBox choice can
represent two related but different pieces of information. The first is
the "name" which serves as a visual label for a choice. This is what a
user sees when browsing through choices. The second is a "value" that is
associated with the label. The name is mean to be human friendly, where
the value is usually intended for processing. In some simple cases, the
"name" and "value" may be identical. The following example may help:
use Tk;
use Tk::JComboBox;
my $value;
my $mw = MainWindow->new;
my $jcb = $mw->JComboBox(
-textvariable => \$value,
-choices => [
{ -name => "one", -value => 1 },
{ -name => "two", -value => 2 },
"three"
],
)->pack;
This JComboBox instance has three options: one, two, and three. Their
values, respectively are 1, 2, and three. With that in mind, look at the
next few lines of code and their expected output:
$jcb->setSelectedIndex(0);
print $value . "\n"; ## prints "1"
$jcb->setSelectedIndex(2);
print $value . "\n"; ## prints "three"
$value = 2; ## The selection should now reflect "two"
being selected.
$value ="three"; ## The selection shold not reflect "three" being
selected.
$value = ""; ## Will clear the selection.
If your code used a simple list of choices, such as [qw/one two three
four five/] where a separate value wasn't explicity defined, then the
new version should not break anything.
This should provide enough information to help cope with the changes. As
always, feel free to post questions and comments to any of the following
areas:
*this mailing list,
*c.l.p.tk,
*http://rt.cpan.org/NoAuth/Bugs.html?Dist=Tk-JComboBox
*my email address
I also browse Perlmonks.org periodically, but really prefer to
receive bug reports and feedback on one of the listed ways. Also, if you
send via email, please tell me if you do not wish me to post replys to
the mailing list, and if you would like me to withhold your name/email
address from the Changes file. Thanks!
Rob Seegel
Tk-JComboBox-1.10.tar.gz
(application/x-gzip, 58.2 KB) - not displayed