in reply to Waking up text select

Postscript from humble supplicant: I examined Text.pm (see Re: re: for Reply #1) and noted that for manual selections it uses (e.g. for 'select all'):
$t->tagAdd('sel', '1.0', 'end');
So I tried it. It didn't work. Now how could Text.pm get by with this and not my program?

To make a long story short, it turns out not to be manual selection that wakes up the select mechanism, but any manual activity (including a single mouse click) in the text area. And when manual activity takes place, the widget has the focus. So I tried forcing the issue with the focus method:

$t = $mw->ROText(-foo => 'bar' etc.)->pack; $t->focus;
It worked! I use it once at the beginning of the program, before calling MainLoop. It appears sufficient to activate the selection mechanism for the duration of the program.

Replies are listed 'Best First'.
RE: RE: Waking up text select
by Anonymous Monk on Oct 11, 2000 at 01:58 UTC

    Post-postscript:

    Well not quite! It's actually not sufficient to invoke the focus method only once. The Text or ROText widget must have the focus when the selecting is being done. If there are other widgets capable of acquiring focus, you must return the focus to the text widget using $t->focus; before any operations involving 'sel' are performed.

    Now I'm curious if the code given in the first reply would work, even under Linux, if there were other widgets competing for the focus. Perhaps the only relevant difference between Linux and Windows is that Linux always assigns the focus to something when the program starts, and Windows doesn't.

      Hrm. I did the test you mention, and it still worked under Linux. I added and focused on a new ROText at every opportunity, and it still insisted on working. Here's the code I used:
      #!/usr/local/bin/perl use Tk; use Tk::ROText; my $mw = MainWindow->new(); $a=$mw->ROText(height=>2)->pack; $a->insert('end','foo'); $a->focus; $rot = $mw->ROText(height=>2)->pack; $a=$mw->ROText(height=>2)->pack; $a->insert('end','foo'); $a->focus; $rot->insert('end', 'foo '); $a=$mw->ROText(height=>2)->pack; $a->insert('end','foo'); $a->focus; $rot->insert('end', 'the bar', ['mytag','sel']); $a=$mw->ROText(height=>2)->pack; $a->insert('end','foo'); $a->focus; $rot->insert('end', ' is baz'); $a=$mw->ROText(height=>2)->pack; $a->insert('end','foo'); $a->focus; MainLoop;
      So it looks like Linux doesn't care about where the focus is, when it's selecting text. Having to push the focus around to do selections strikes me as more than a little odd. Apparently Linux has the same opinion.. Anyways, glad you were able to puzzle this one out -- it looks like it's one of the long list of "problems that aren't documented anywhere, but should be!"


      Addendum: It looks like this is tied to Windows' treatment of selections. For instance, the following code leaves all three boxes with selections under Linux, but only the last one selected under Windows:
      #!/usr/local/bin/perl use Tk; use Tk::ROText; my $mw = MainWindow->new(); for (1..3) { $a = $mw->ROText(height=>2)->pack; $a->focus; $a->insert('end','foo',['sel']); $a->focus; } MainLoop;
      ..which means that the Windows port will always be slightly broken -- the ->focus() stuff is just an indication of this. Anyways, hope this helps.
        Many thanks for your time and effort! Yet another Windows anomaly, it seems. I yearn for the day when Mr. Bill doesn't live in my computer anymore. It's not here yet, but it's drawing nigh.