Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am creating a WaitBox widget but I am unable to do a local grab on it. What I need is –

After creating a mainwindow, if user presses some button (say diff of two large directories), I will open a WaitBox. Now only this wait-box should have focus and no Mouse Events should pass on to mainwindow. But I am even able to close MainWindow if I click on close button, so in short I am not grabbing WaitBox window correctly. If I do grabGlobal it works, but it locks my WindowManager. Please let me know if you have some way for keeping WaitBox widget on top of MainWindow and disabling mainwindow for taking any mouse events.

Thanks
Ankur Chaplot

Edited by Arunbear: Changed title from 'waitbox', as per Monastery guidelines

  • Comment on Tk: WaitBox widget not grabbing correctly

Replies are listed 'Best First'.
Re: Tk: WaitBox widget not grabbing correctly
by anonymized user 468275 (Curate) on Jun 28, 2005 at 08:56 UTC
    I rather think we'd need some code that reproduces the symptoms before we can comment further.

    -S

    One world, one people

      use strict; use Tk; use Tk::WaitBox; use Tk::ProgressBar; my($root) = MainWindow->new; my($utxt) = "Initializing..."; my($percent); my($wd); $wd = $root->WaitBox( -bitmap =>'questhead', # Default would be 'hourglass' -txt2 => 'tick-tick-tick', #default would be 'Please Wait' -title => 'Takes forever to get service around here', -cancelroutine => sub { print "\nI'm cancelling....\n"; $wd->unShow; $utxt = undef; } ); ### Do something quite boring with the user frame my($u) = $wd->{SubWidget}{uframe}; $u->configure (-relief => 'groove', -borderwidth => 5); $u->pack(-expand => 1, -fill => 'both'); $u->Label(-textvariable => \$utxt)->pack(-expand => 1, -fill => 'both' +); ## It would definitely be better to do this with a canvas... this is d +umb my($bar) = $u->ProgressBar( -variable => \$percent, -blocks => 0, -width => 20, -relief => 'sunken', ) ->pack(-expand =>1, -fill =>'both'); $wd->configure(-canceltext => 'Halt, Cease, Desist'); # default is 'Ca +ncel' $wd->Show; my($diff) = 20; for (1..$diff) { sleep(1); $percent = int($_/$diff*100); $utxt = sprintf("%5.2f%% Complete",$percent); $root->update; last if !defined($utxt); } $wd->unShow; MainLoop;  

      ### This code will open one MainWindow and other Wait box, But WaitBox is not really on Top of MainWindow. I am trying to get a way by which this Widget can be placed on top of MainWindow and MainWindow should not get any user actions. This is usually seen in Windows Widgets, where parent window will not accept focus unless the Child window is closed.
      Let me know if you have thoughts

Re: Tk: WaitBox widget not grabbing correctly
by zentara (Cardinal) on Jun 28, 2005 at 13:03 UTC
    I think the WaitBox module is buggy. I kept getting errors with the latest version of Tk. It's no wonder I hardly ever see WaitBox in use.
    can't make ".waitbox" its own master at /usr/lib/perl5/5.8.6/i686-linu +x-thread-multi/Tk/Submethods.pm line 37. at /usr/lib/perl5/site_perl/5.8.6/Tk/WaitBox.pm line 58

    If you are just looking for a dialog which grabs control, and prevents $mw from responding, try something like the following. There is also DialogBox which will allow you to place your Progressbar into it( I've not tested that combo , but it should work).

    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Dialog; my $mw = MainWindow->new(); $mw->geometry("+100+100"); $mw->title("Main Window"); $mw->geometry("250x250"); $mw->bind("<Return>", \&do_dialog); my $result = "Dialog Result Here"; $mw->Label( -textvariable => \$result, -relief => "sunken", -borderwidth => 1 )->pack( -side => "bottom", -fill => "both", -padx => 5, -pady => 5, -ipadx => 3, -ipady => 3 ); $mw->Button( -text => "Exit", -command => sub{ exit(0) }, )->pack( -fill => "x", -padx => 5, -pady => 5, ); $mw->Button( -text => "Test Dialog", -command => \&do_dialog, )->pack( -expand => 1, -fill => "both", -padx => 5, -pady => 5, ); MainLoop; exit(0); sub do_dialog { my $dlg = $mw->Dialog( -title=>"Here is a question for you.", -buttons => ["Cancel", "No", "Yes"], -default_button => "No", -text => "Let's see what the result is..", -font => "Helvetica" ); $result = "Result: " . $dlg->Show(); print("got: $result\n"); }

    I'm not really a human, but I play one on earth. flash japh
      Hi,

      I think I am still unable to get main window out of focus. If I use the above code - it opens a dialog box which has initial focus, but I can easily move mouse to MainWindow and do all operations like - Minimize, Maximize, Move and even CLOSE, which I dont want

      You might try grabGlobal and see the effect, I want the same affect but locking only the MainWindow and not whole WindowManager.

        The operations you are talking about, are "Window Manager" controls, which are not controlled by Tk. However Tk has a way to disable/enable them. Use overrideredirect(). In the code I posted above do this:
        my $mw = MainWindow->new(); $mw->geometry("+100+100"); $mw->title("Main Window"); $mw->overrideredirect(1); $mw->bind("<Return>", \&do_dialog);
        then if you desire to return full WindowManager controls back to the mainwindow, put:
        $mw->overrideredirect(0);
        somewhere in your code where it's convenient, like only if you get a "yes" response.

        You could also set it up to have your popup dialog use overrideredirect too.


        I'm not really a human, but I play one on earth. flash japh