in reply to RE: Waking up text select
in thread Waking up text select

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.

Replies are listed 'Best First'.
RE: RE: RE: Waking up text select
by Chmrr (Vicar) on Oct 12, 2000 at 10:30 UTC
    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.