Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing state of cancle button in WaitBox

Status
Not open for further replies.

Holly3g

Technical User
Jul 3, 2007
5
0
0
US
Hi There!

I'm writing a GUI that uses the WaitBox ( and am wondering if it is possible to modify the state of the cancel button. Basically, I want the button to be initially disabled, until 2 seconds have passed. I know how to set up the timer appropriately, but am not sure how to configure the state of the cancel button in this particular widget.

Any help is very much appreciated!

Thanks!!

~Holly
 
Looking at the source code...

Code:
	$wd->{CanFrame} = $canFrame;
	$canFrame->pack(-side => 'top', @wd_packtop, -fill => 'both');
	$canFrame->configure(-cursor => 'top_left_arrow');
	$canFrame->Button(-text => $wd->{Configure}{-canceltext},
			  -command => $wd->{Configure}{-cancelroutine})
		->pack(-padx => 5, -pady => 5,
		       -ipadx => 5, -ipady => 5);

$canFrame->Button is called in void context; the Button object isn't kept anywhere, neither internally somewhere within your WaitBox object or otherwise.

So you can't get to the button to change it.

You can try editing the module to add this functionality and shipping your custom version with your code, sending a patch to the module's maintainer so they can include this in a future release, or... you can just implement something like this yourself, without using a module for it.

The basics:

Code:
# $mw = your MainWindow...

# create a popup window
my $win = $mw->Toplevel (
  -title => 'Whatever You Want',
);

# make it a transient window (it has to be closed before
# the user can interact with $mw again)
$win->transient($win->Parent->toplevel);

# now just put whatever you want in your new window,
# including your cancel button
my $cancel = $win->Button (
   -text => 'Cancel',
   -state => 'disabled',
   -command => sub {
      $win->destroy();
   },
);

#...
$cancel->configure(-state => 'normal');
#...

Kirsle.net | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Actually I forgot one thing,

Code:
$win->grab;

You'd put this after transient()...

transient just means that the popup window is a "slave" to its parent, and always stays on top of its parent (clicking back in the parent window doesn't make it rise to cover up the dialog box, but the dialog box otherwise isn't "special", i.e. your other apps that aren't related to it can still cover it up)...

grab() will make it actually grab the focus from the other windows in your app, so it's the only window where buttons can be clicked or anything like that, until the window is destroyed or releases the grab.

Kirsle.net | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top