in reply to Tcl::pTk right-click macOS

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

Replies are listed 'Best First'.
Re^2: Tcl::pTk right-click macOS
by IB2017 (Pilgrim) on Jun 02, 2018 at 10:40 UTC

    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)

        This particular error is a bug. It was reported in RT #125460 and was fixed in Tcl::pTk 0.93. It was because of a missing use Text::Tabs; statement in one of its modules, but the error it gave was unusual because rather than an "Undefined subroutine" error, the reliance on AUTOLOAD by Tcl::pTk means it was mistaken for Tcl/Tk functionality, so some other error appears instead.

      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.