CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Perl/Tk: waitVariable doesn't work when multiple Toplevel opened

 



kaza_perl
New User

Nov 8, 2011, 5:51 AM

Post #1 of 1 (932 views)
Perl/Tk: waitVariable doesn't work when multiple Toplevel opened Can't Post

Hello,

I'm writing a Perl/Tk script (my first GUI ever) and I have
a problem that looks to me like a very basic misunderstanding
of how things should work in GUI.

The program sometimes opens a warning popup which I
implemented as a "Dialog" widget. It worked as it
should at first - clicking the "OK" button closed the
dialog and the main program continued doing what it warned
me about. But when I added an additional "Toplevel" to the
main window the troubles began: if the warning popup
appeared while the additional "Toplevel" is opened, clicking on
the "OK" button doesn't cause the popup window to close and
in fact, the whole program stops responding to buttons clicks,
scroll sliders and the only thing that works is clicking on
main window/additional "Toplevel"/warning popup brings it
to front.

After googling on multiple "Toplevel"-s and "Dialog" and finding
nothing that helped, I dove into the code of the packages
(Dialog.pm, DialogBox.pm) and found in DialogBox.pm
the function:


Code
sub Wait 
{
my $cw = shift;
$cw->Callback(-showcommand => $cw);
$cw->waitVariable(\$cw->{'selected_button'});
$cw->grabRelease if Tk::Exists($cw);
$cw->withdraw if Tk::Exists($cw);
$cw->Callback(-command => $cw->{'selected_button'});
}


I placed some debug prints (sorry for ugly way of debugging)
in various places and found that the code get stuck on:


Code
 $cw->waitVariable(\$cw->{'selected_button'});


I also placed debug prints on the value of

Code
$cw->{'selected_button'}


itself and saw it changes from "" to "OK" when I click
the "OK" button. It seems I don't understand how the
"waitVariable" works: it looks to me the monitored variable
changes regardless of weather the additional "Toplevel"
is opened or not but the "Dialog" code seems to "miss"
the click if additional "Toplevel" is opened or to respond
to click if no additional "Toplevel"is opened.Here's the
"Dialog" creation code (parts that look relevant to me):


Code
my $gui_mw_wrapper = new MainWindow; 
my $gui_warn_text;
.
.
.
sub gui_warn {
.
.
.
$gui_warn_text = $gui_mw_wrapper -> Dialog( -title=>$title,
-text=>$message,
-width=>$text_width,
-font=>"Times 12 normal",
-buttons=>["OK"],
-wraplength=>$text_width_pixels);

$dbg_answer = $gui_warn_text -> Show();

}


and the code creating the additional "Toplevel":


Code
my $gui_src_wrapper_frm_wr; 
.
.
.
sub gui_open_tree {
.
.
.
$gui_src_wrapper_frm_wr = $gui_mw_wrapper -> Toplevel( -title=>"Tree",
-borderwidth=>1);
}


At some point I added the argument "global" to the "Show"
call:


Code
      $dbg_answer = $gui_warn_text -> Show("global");


At first I thought it solved the problem - clicking "OK"
caused the "Dialog" to close even while additional "Toplevel"
was opened. But since this caused the "grab" to be
"system global", when a little later this dialog popped together
with some other popup and refused to close, I discovered
(fully according to docs of "global grab") that my entire
desktop is stuck thus I had to open a command line session
in order to kill the script so I prefare not to use "global grab"
anymore.


What am I missing here? I attempted to google things like
"waitVariable multiple Toplevel" or "waitVariable implementation" or "grab global" or similar things but found
nothing that helped me. The script runs with "-w"
and with "use strict;"


TIA for any help!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives