Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
P is for Practical
 
PerlMonks  

pTk Text Selection: Win32 Issue?

by cmv (Chaplain)
on Dec 04, 2012 at 15:26 UTC ( #1007107=perlquestion: print w/ replies, xml ) Need Help??
cmv has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks-

I have an issue that seems to work correctly under unix, but not under windows.

Specifically, it has to do with keeping selected text highlighted in a pTk Text window, even after the user clicks into an entry widget.

If you run the attached code, do the following:

  • Select some text (it should turn light green)
  • Click in the entry widget on top (does the light-green highlighting disappear? If so, this is my issue)
  • Click the bottom button (selected text should print on STDERR)

    When I do this under unix, the light-green highlighting remains, even when typing in the entry widget

    When I do this under windows, the light-green highlighting disappears as soon as I click in the entry widget. However, the text still shows up on STDERR when clicking the button.

    Why does the light-green highlighting disappear if the text is still selected? How can I fix this?

    Thanks

    -Craig

    Update: thundergnat++ for your solution.

    #!/opt/exp/bin/perl5.8 use strict; use warnings; use Tk; my $mw = new MainWindow; my $lines = "Distribution ILYAZ/os2/tk/Tk-OS2src-1.04.zip Distribution INGY/Kwiki-Zipcode-0.12.tar.gz Distribution ISHIGAKI/Archive-Any-Plugin-Bzip2-0.01.tar.gz Distribution JAE/perlipse/Perlipse-0.02.zip Distribution JALYCAI/article_fetcher.zip Distribution JAME/ftndb-0.35.zip Distribution JBNIVOIT/Win32-ShellExt-0.1.zip Distribution JBRYAN/AI-NeuralNet-BackProp-0.77.zip Distribution JBRYAN/AI-NeuralNet-BackProp-0.89.zip Distribution JBRYAN/AI-NeuralNet-Mesh-0.44.zip Distribution KRYDE/Filter-gunzip-4.tar.gz"; my $entry = $mw->Entry->pack; my $txt = $mw->Text(-selectbackground=>'lightgreen')->pack; my $but = $mw->Button(-text=>'List Selected to STDOUT', -command=>sub{ print STDERR $txt->getSelected,"\n"; print STDERR "HI THERE\n"; })->pack; $txt->insert('end', $lines); MainLoop;
  • Comment on pTk Text Selection: Win32 Issue?
    Download Code
    Re: pTk Text Selection: Win32 Issue?
    by thundergnat (Deacon) on Dec 04, 2012 at 17:27 UTC

      I believe, (though am not able to prove), that you are running into an issue with the way Windows handles selections. I haven't figured out a way to prevent that, though you can kind of half-assed work around it by doing something like this:

      use strict; use warnings; use Tk; my $mw = new MainWindow; my $lines = "Distribution ILYAZ/os2/tk/Tk-OS2src-1.04.zip Distribution INGY/Kwiki-Zipcode-0.12.tar.gz Distribution ISHIGAKI/Archive-Any-Plugin-Bzip2-0.01.tar.gz Distribution JAE/perlipse/Perlipse-0.02.zip Distribution JALYCAI/article_fetcher.zip Distribution JAME/ftndb-0.35.zip Distribution JBNIVOIT/Win32-ShellExt-0.1.zip Distribution JBRYAN/AI-NeuralNet-BackProp-0.77.zip Distribution JBRYAN/AI-NeuralNet-BackProp-0.89.zip Distribution JBRYAN/AI-NeuralNet-Mesh-0.44.zip Distribution KRYDE/Filter-gunzip-4.tar.gz"; my $entry = $mw->Entry->pack; my $txt = $mw->Text(-selectbackground=>'lightgreen')->pack; my $but = $mw->Button(-text=>'List Selected to STDOUT', -command=>sub{ print STDERR $txt->getSelected,"\n"; print STDERR "HI THERE\n"; })->pack; $txt->insert('end', $lines); $txt->tagConfigure('winsel', -background => $txt->tagCget('sel','-back +ground')); $txt->bind('<<Selection>>', sub { $txt->tagRemove('winsel','1.0', 'end'); return if !defined $txt->tagRanges('sel'); $txt->tagAdd('winsel', $txt->tagRanges('sel')) } ); MainLoop;

      Create your own tag with the same coloring then shadow the selection tag. Works on windows and shouldn't cause problems elsewhere.

    Re: pTk Text Selection: Win32 Issue?
    by Anonymous Monk on Dec 05, 2012 at 07:48 UTC

    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Node Status?
    node history
    Node Type: perlquestion [id://1007107]
    Approved by cjb
    help
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (5)
    As of 2014-04-20 11:50 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (485 votes), past polls