ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-win32-users
perl-win32-users
RE: TK question
by Jack other posts by this author
Sep 20 2009 8:20PM messages near this date
view in the new Beta List Site
TK question | Re: TK question
Sorry for the top post..
 
Your problem is well-known but I don't recall any workarounds being found -
until now that is ;)
 
The problem stems from the fact that the windows getopenfile dialog is
closed on a Double-Button*Press* (that is a windows problem AFAIC) however
most other Tk widgets respond on a Button*Release* event. So - If you double
click - then hold the button down on the second click. You won't see any
event until you release the mouse. I guess you could tell your users to hold
the mouse button down, move it off the main window and then release - right?
 
Just kidding.
 
There are only two workarounds I can think of. Make main window "not" be
there by withdrawing it before you launch the getOpenFile and then
deiconify/raise it again upon the file being chosen - or - a neat trick -
could be to cover up the window with a fake transparent widget to ensure
that it is the one that consumes the event.
 
#!/usr/bin/perl -w
 
use Tk;
use strict;
my $var = undef;
my $file;
## Ensure the canvas lies beneath the "double-click"
## event of your getOpenFile dialog to see the event
## as a printed warning.
 
my $mw = tkinit;
my $canvas = $mw-> Canvas(-background=>'red')->pack(-expand=>1,
-fill=> 'both');
 
$canvas-> Tk::bind('<ButtonRelease-1>'=>sub{warn "Buttonrelease invoked";});
$mw-> Button(-text=>'Launch',-command=>\&getfile)->pack;
$mw-> Radiobutton(-text=>'Withdraw/Restore',-variable=>\$var,-value=>'withdra
w')-> pack;
$mw-> Radiobutton(-text=>'Transparent
Frame',-variable=> \$var,-value=>'frame')->pack;
$mw-> Radiobutton(-text=>'Normal',-variable=>\$var,-value=>'normal')->pack;
MainLoop;
 
sub getfile {
 
  if ($var eq 'withdraw') {
    $mw-> after(100,sub{$mw->withdraw});
    $file = $mw-> getOpenFile();
 $mw-> deiconify;
 $mw-> raise;
 print "File is: $file\n";
  }
  elsif ($var eq 'frame') {
      my $frame = $mw-> Frame(-bg=>undef);
   $frame-> place(-in=>$mw,-x=>0, -y=>0, -relwidth=>1.0, -relheight=>1.0);
   $frame-> update;# Ensure frame is placed before calling getOpenFile..
   $file = $mw-> getOpenFile();
   $frame-> update;# Flush all events so the buttonrelease is consumed.
      $frame-> placeForget;
   print "File is: $file\n";
  }
  else {
 $file = $mw-> getOpenFile();
   print "File is: $file\n";
  }
 
}
__END__
 
I'm not necessarily sure you would want to do this in production - but it
seems to work.
 
Jack D.

________________________________

From: perl-win32-users-bounces@[...].com
[mailto:perl-win32-users-bounces@[...].com] On Behalf Of
Spencer Chase
Sent: September-18-09 5:05 PM
To: Perl-Win32-Users
Subject: TK question


Greetings Perl-Win32-Users,

I have been trying everything I can think of and nothing works. I have a TK
application that uses getopenfile. The problem is that you can select a file
in the browser window by either clicking the file and then clicking "open"
or you can double click the file and not have to click "open." This is fine
but if the browser window happens to be over another widget, the second
click seems to select something in that widget. In my case, that widget is s
scrolled listbox. I do not want to change the selection accidentally. I have
tried everything I can think of to lock the listbox but nothing works. A
button to lock the listbox would be fine but I can't figure out how to do
it. Disabling a double click in the getopenfile browser would also be fine
but can't find a way to do that either. Open to any and all suggestions.

--
Best regards,
Spencer Chase        mailto:spencer@[...].com
67550 Bell Springs Rd.
Garberville, CA 95542  Postal service only.
Laytonville, CA 95454  UPS only.
Spencer@[...].com
http://www.spencerserolls.com
http://www.spencerserolls.com/MidiValve.htm
(707) 984-8356

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Spencer Chase
Jack
Justin Allegakoen

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved