Subject: | bug Tcl-pTk-0.92 |
Date: | Sat, 2 Jun 2018 14:51:47 +0200 |
To: | bug-Tcl-pTk [...] rt.cpan.org |
From: | "Claudio Fantinuoli" <fantinuoli [...] gmx.de> |
OS: macOS HighSierra
Module: Tcl-pTk-0.92
Perl: 5.24.4
I discovered a strange behavior of "bind". In many cases, if a selection has been done in a Widget and a subrutine is invoked through binding a key, a copy of the selection is inserted into the Widget.
#!/usr/bin/perl
use strict;
use warnings;
use Tcl::pTk;
use Tk::Text;
my $mw = MainWindow->new();
my $text = $mw->Text()->pack();
$text->bind('<Key-F2>', [sub {print "something"}, Ev('X'), Ev('Y'), ]); #if F2 is pressed while a string is selected, an error message is displayed: Tcl::pTk::Error: Can't call method "_retListContext" without a package or object reference at perl-5.24.4/lib/site_perl/5.24.4/Tcl/pTk/Widget.pm line 2842.
PupupTextWidget($mw, $text);#In this case, if the popup is called while a string is selected, the same string is copied in the Widget after the popup has been distroyed
MainLoop;
sub PupupTextWidget{
my ($mw, $obj) = @_;
my $menu = $mw->Menu(-tearoff=>0, -menuitems=>[
[command=>'My command', -command=>[sub {print "something"}, $obj,]],
]);
$obj->bind('<2>', ['PostPopupMenu', Ev('X'), Ev('Y'), ]);
return $obj;
}