Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Tcl::pTk right-click macOS

by Anonymous Monk
on May 29, 2018 at 09:08 UTC ( [id://1215349]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi there

My Perl application for macOS uses Tcl::pTk (Tcl 8.6). The GUI doesn't accept the right click of the mouse/trackpad or the Control+Click combination to show the standard pop-ups which are bound to the widget. After some experimenting I discovered that the binding for right click on a macOS is '2' and not '3' as (I think) it should be. So I can manually override the binding. Note that on any other application the right click works normally. Am I correct that I have to override the binding or am I missing something? Here is my code example:

#!/usr/bin/perl use strict; use warnings; use Tcl::pTk; use Tk::Text; my $mw = MainWindow->new(); my $text = $mw->Text()->pack(); PupupTextWidget($mw, $text);#If I comment out this, no popup (the orig +inal one) shows MainLoop; sub PupupTextWidget{ my ($mw, $obj) = @_; my $menu = $mw->Menu(-tearoff=>0, -menuitems=>[ [command=>'My command', -command=>[sub {print "something"}, $obj,] +], ]); $obj->menu($menu); $obj->bind('<2>', ['PostPopupMenu', Ev('X'), Ev('Y'), ]); return $obj; }

On Windows the bind is '3'. Any idea?

Replies are listed 'Best First'.
Re: Tcl::pTk right-click macOS
by kcott (Archbishop) on May 29, 2018 at 11:57 UTC

    I found a virtual event to handle this a year or two ago. Unfortunately, all details are on my macOS machine which is 300 miles away, so this is all based on memory (which could be a bit shakey on something from that long ago).

    The virtual event was triggered by whatever event normally resulted in a context menu; it was platform independent. I think it was <<ContextMenu>>.

    I recall finding it purely by accident; I think somewhere in https://wiki.tcl.tk/. I also recall not being able to find any official documentation. I had a quick look around for it before posting this: I found it mentioned (by name only) in https://sourceforge.net/p/tcl/mailman/tcl-bugs/?viewmonth=201303&page=1; I also found <<Contextual>> in https://wiki.tcl.tk/15406 (although, for some reason, that doesn't sound right).

    Anyway, it did work well, and meant I didn't have to write any platform-specific code (at least for that part).

    Sorry for the vagueness. Perhaps it might jog another monk's memory who can give a better answer.

    — Ken

      Having the same issue. Unfortunately neither <<ContextMenu>> nor <<Contextual>> produce any action in my script. Even worse: using <2> it produces a strange, undesired effect. The popup appears correctly, but if a word has been selected in the widget before calling the popup, the same word is copied and pasted (with an undefined time lag, from a few ms to a few s)This can be reproduced simply by the following:

      #!/usr/bin/perl use strict; use warnings; use Tcl::pTk; use Tk::Text; my $mw = MainWindow->new(); my $text = $mw->Text()->pack(); $text->bind('<2>', [sub {print "something"}, Ev('X'), Ev('Y'), ]); MainLoop;

      I am on macOS Highsierra and using Tcl/Tk 8.5

        I think my macOS is the same version; fairly sure Tcl/Tk was 8.6.

        My current work has taken me away from home for some time; and, I wasn't going to lug a Mac Pro around with me. I'll be back in about two months. I can check code, versions, etc. then: sorry, but that's the best I can do at the moment.

        — Ken

        I start to thing it is a bug. If I use <Key-F2> as event, just an example, it works if no text has been previously selected. Otherwise the following error is prompted :

        Tcl::pTk::Error: Can't call method "_retListContext" without a package + or object reference at /Users/xxx/perl5/perlbrew/perls/perl-5.24.4/l +ib/site_perl/5.24.4/Tcl/pTk/Widget.pm line 2842. while executing "if {$catchVal != 0} { if { $retVal != "_TK_BREAK_\n" } { # BREAK ret +urns are not errors return..." (command bound to event)

        IB2017’s issue has since been reported as RT #127120. The cause is that the global <<PasteSelection>> (using middle-click to paste currently selected text) event in older versions of Tcl/Tk (prior to 8.5.16 and 8.6.1) is incorrectly bound to the right mouse button. While the responsible code is in Tcl/Tk itself (not Tcl::pTk), it can effectively be patched at runtime, so a future Tcl::pTk version will likely do this automatically if an affected Tk version is detected.

        Update: Tcl::pTk 0.95 includes the runtime patch for older Tcl/Tk.

Re: Tcl::pTk right-click macOS (dynamousewheelbind)
by Anonymous Monk on May 29, 2018 at 10:54 UTC

      I haven't used Dynamousewheelbind, but if I understand what it is correctly, it's for binding to mousewheel events rather than middle and right mouse buttons as the OP asked about.

      Also, mousewheel events are slightly different on macOS aqua; they don't use buttons 4 or 5 as X11 does, and they are scaled differently. (Both are things I addressed in Tcl::pTk 0.93.)

Re: Tcl::pTk right-click macOS
by chrstphrchvz (Scribe) on Jul 20, 2018 at 02:31 UTC

    Howdy, this is indeed inherited from Tcl/Tk as the OP discovered. I wish I found this earlier, since this was a known issue I reported a few months ago (cf. RT #125050).

    I was recently added as a co-maintainer to Tcl::pTk, and have released Tcl::pTk 0.93; one of the things it includes is if it detects macOS aqua, any widget events normally binding to buttons 2 or 3 will bind with the opposite one instead. Note that if your program has its own bind events (i.e. not already provided by a widget) it will still need its own workaround; I will try mentioning this in the Tcl::pTk documentation. The following expression for right-click will evaluate to '<3>' on X11 and Windows, and '<2>' on macOS aqua:

    $widget->windowingsystem ne 'aqua' ? '<3>' : '<2>'
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1215349]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-24 16:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found