Skip Menu |
 

This queue is for tickets about the Tcl-pTk CPAN distribution.

Report information
The Basics
Id: 125460
Status: resolved
Priority: 0/
Queue: Tcl-pTk

People
Owner: CAC [...] cpan.org
Requestors: fantinuoli [...] gmx.de
Cc: CAC [...] cpan.org
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.93



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; }
 
Download (untitled) / with headers
text/plain 2.3k
Thanks for reporting this. I have observed some peculiarities with bind() as well, in that certain syntax that works under Perl/Tk doesn't work under Tcl::pTk, but your syntax looks OK. In your test program, note that your menu (the one with a "My command" entry) won't appear since nothing was configured to use it. A little background: Some of the issues you observe and workarounds in your test program are due to the right and middle mouse buttons (buttons 2 and 3) being swapped on macOS aqua to be opposite of other windowingsystems (X11 and Windows). Please have a look at my earlier ticket, https://rt.cpan.org/Ticket/Display.html?id=125050 as well as the Perl/Tk issue: https://github.com/eserte/perl-tk/issues/31. Because Tk chooses to preserve the OS/windowingsystem's mapping of mouse buttons rather than make it consistent across windowingsystems, any widgets or programs using buttons 2 and 3 are supposed to check which windowingsystem is present. But neither Perl/Tk nor Tcl::pTk have yet to update all the widgets to do this. If your mouse happens to have a middle/third mouse button (and which isn't bound to Exposé or Mission Control in System Preferences), or you use a program like Karabiner-Elements to map a spare keyboard key to the middle mouse button, you can observe this "backwards" behavior. If and when this issue gets addressed, you won't have to bind the mouse to PostPopupMenu as you've done in your program. The Text widget already binds PostPopupMenu to a mouse button--it's just bound to the wrong one currently. Likewise, the cause of the text getting copied is that the middle button causes any selected text to be inserted where the mouse cursor is. This is "intended" behavior as far as I can tell, and can be reproduced from e.g. the "Basic editable text" widget demo on both Tcl::pTk and Perl/Tk (in X11). But currently on macOS aqua this event is bound to the right mouse button, so it would happen along with the other event you manually bound to it (PostPopupMenu). Regarding the error when pressing F2: The Text widget already binds F2 to clipboardColumnCut, which is supposed to cut any selected text. However this appears to be broken in Tcl::pTk. Also, F1 is bound to clipboardColumnCopy, and F3 is bound to clipboardColumnPaste. If you pick a different unused F-key you might get something closer to the desired behavior. Hope this helps
I've found why there's an error when pressing F2 (or F1) for cut/copy respectively in a Text widget. Both bind event callbacks rely on a subroutine in Text.pm called Column_Copy_or_Cut, and in it there are uses of expand() from Text::Tabs. But use Text::Tabs; is missing from Text.pm (Perl/Tk has it at the top of its Text.pm), even though we don't see a "Undefined subroutine expand called" error.

My understanding is that this is because Tcl::pTk relies heavily on AUTOLOAD, where if some function isn't defined in Perl it's assumed to be a function provided by Tcl, so it attempts translate it to a Tcl call. This fails for expand(), hence the unusual errors "Tcl::pTk::Error: Can't call method "_retListContext" without a package or object reference" or "via package [selected text]".
Related: there's a couple of tests (bgerror2.t and tkHijack_bgerror2.t) which attempt to make the "Undefined subroutine" error message appear on purpose. Another user reported that those two tests were failing (see https://rt.cpan.org/Ticket/Display.html?id=119754); I think it may be due to the same reason I discussed here (Tcl::pTk's use of AUTOLOAD preventing that specific error from appearing). See 
I've released Tcl::pTk 0.93, which fixes the Can't call method "_retListContext" without a package or object reference error, and binds the middle and right mouse buttons appropriately. It should no longer be necessary to manually bind PostPopupMenu to <2> (the right mouse button on aqua).

Another odd behavior I observed in your test program is that pressing function keys other than F1, F2, F3, or F4 caused strange characters to be inserted. Specifically, the code point (0xF708 + [the number of the function key]) is what gets inserted, e.g. \N{U+F708} for F5 and \N{U+F716} for F19. These are "private use area" characters, so they only appear as boxes (either empty or with a '?' inside). I'm inclined to open a separate ticket for this.

Please reopen this if you find there's still an issue.

PS: I recently added a p5-tcl-ptk port for MacPorts, in case you'd like to try that. However the existing ports for Tk extensions (e.g. Tix and Tktable) only support X11 currently, so there is some functionality not yet available to p5-tcl-ptk when used from macOS aqua.

I've opened a new ticket regarding the issue of function keys inserting unusual characters: https://rt.cpan.org/Ticket/Display.html?id=125844

I think it is an upstream Tcl/Tk bug because the issue can be reproduced from the pure Tcl/Tk widget demo.
On Fri Jul 13 16:39:37 2018, CAC wrote:
Show quoted text
> I've released Tcl::pTk 0.93, which fixes the Can't call method
> "_retListContext" without a package or object reference error, and
> binds the
> middle and right mouse buttons appropriately. It should no longer be
> necessary
> to manually bind PostPopupMenu to <2> (the right mouse button on
> aqua).
>
> Another odd behavior I observed in your test program is that pressing
> function
> keys other than F1, F2, F3, or F4 caused strange characters to be
> inserted.
> Specifically, the code point (0xF708 + [the number of the function
> key]) is
> what gets inserted, e.g. \N{U+F708} for F5 and \N{U+F716} for F19.
> These are
> "private use area" characters, so they only appear as boxes (either
> empty or
> with a '?' inside). I'm inclined to open a separate ticket for this.
>
> Please reopen this if you find there's still an issue.
>
> PS: I recently added a p5-tcl-ptk port for MacPorts, in case you'd
> like to try
> that. However the existing ports for Tk extensions (e.g. Tix and
> Tktable) only
> support X11 currently, so there is some functionality not yet
> available to
> p5-tcl-ptk when used from macOS aqua.

For reference, this was also reported on PerlMonks: https://www.perlmonks.org/?node_id=1215728


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.