Re: Startup Button
- From: "Jack D" <goodcall1@xxxxxxxxxxxxxxx>
- Date: Thu, 30 Jun 2005 11:46:22 GMT
"kw" <shockers_sgp@xxxxxxxxx> wrote in message
news:d9v90t$lh4$1@xxxxxxxxxxxxxxxxxx
> zentara,
>
> This is basic stuff I'm sure, but I'm still in a haze.
>
> I took your example here and I'm trying to figure out some of my problems
> in my separate question. In your example, I replaced the button/key
> binding with a Dialog.
>
> Then display window/contents differently depending on the button selected.
>
> My first problem:
>
> I want a 5 second timeout if a button is not pressed. With what I have,
> I get the following upon timeout (ActivePerl on Win32) and the window
> hangs:
>
> exit value = -1
> Tk::Errpr:
> ("after" script)
>
> Obviously, I missed something here but not sure what. Do I need to
> remove the dialog before exiting the script?
Yes. That is - if you want to avoid the Win32 error message.
>
> If they do click on a button within 5 seconds, then I want a 15 second
> timeout on the MainWindow. This is working okay and exits with the
> correct exit value of -2.
>
You never really described "why" you want to exit the brogram. I would
assume that you are using these return codes in another program to "do
something" - yes? Otherwise - why would you want to kill your mainwindow?
The only program that I have coded in a destroy after a certain time has
been an alert window. If the user isn't around to see it - then it kills
itself after a command-line timeout.
> Finally, the other thing I'm wanting to accomplish is changing the
> text in a MainWindow WITHOUT having scrolled Text (because in my
> other question I have Labels and Radiobuttons I'm wanting dependent
> on their response).
See my code and have a look at the documenation for the 'destroy' method
under Tk::Widget.
Other interesting docs:
To kill and redo widgets learn about 'destroy' and 'pack'.
To just change existing widgets within a window - learn about
'configure', 'packForget', 'pack'.
[snipped Tk::Text stuff that you said you don't want or need]
The method I have chosen to "redo" your window is to put everything
changeable into a separate frame - and then destroy the frame when the user
selects something "new";
A smart thing to do would be to use a lexical variable in your create_group
subroutine to check if the group chosen is the current group and return if
it is. i.e. No use destroying and recreating the same group !
Let use know if you have any further questions. But keep your posts to
something like:
1) **Here is what I want to do**
This is extremely important to know as there might be a more
reliable/efficient method than what you may post in number 2. This means
that completely new code might be offered instead of rehashing-editing your
posted code. (Like Zentara kinda did)
2) Here is what I'm doing (show code)
3) Here is what is wrong or not working.
Now - going back to your *originally posted code*......highly edited !!
##############################################################
use warnings;
use strict;
use Tk;
use Tk::Dialog;
### JD ### my ($group,$t1,$t2,$noMW,$clrMW,$TB_on,$subgroup) =
(0,0,5,0,0,1,0);
my ($group,$t2,$TB_on,$subgroup) = (0,5,1,0);
foreach (@ARGV) {
$group = $1 if /^-g=(.*)$/i; # phrases group number
### JD ### $t1 = $1 if /^-t1=(.*)$/i; # MW timeout value (secs)
### Jack wants to know why you would delete your MW??
$t2 = $1 if /^-t2=(.*)$/i; # Dialog timeout value (secs)
### JD ### $noMW = 1 if /^-noMW$/i; # MW 0x0 on start
### JD ### $clrMW = 1 if /^-clrMW$/i; # new MW each &create_gui
$TB_on = 1 if /^-titlebar/i; # no overridedirect()
}
my $MW;
my $groupFrame;
$MW = new MainWindow;
$MW -> geometry('800x600+200+200');
$MW -> overrideredirect(1) if ! $TB_on;
### JD ??? ### $MW -> after($t1*1000, sub { $group=1; $MW->destroy; }) if
$t1;
$MW->withdraw;
&define_menu;
my $bottomFrame = $MW->Frame->pack(-side=>'bottom');
$bottomFrame->Button(-text=>"QUIT", -command=>sub{$MW->destroy})->pack;
if (! $group) {
$MW->after(100,\&showDialog);
}
else {
create_groups();
}
MainLoop;
print "Destroyed on current group: $group\n";
sub showDialog
{
my $dialog = $MW->Dialog ( -text => 'Which group of phrases?',
-buttons => [ 0, 1, 2, 3 ] );
$dialog->transient('');
my $id = $dialog->after ($t2*1000, sub {
print "You took too long to choose\nDefaulting to Group 2 !!\n";
$group=2;
$dialog->destroy;
create_groups();
$MW->deiconify;
$MW->raise;
}) if $t2;
$group = $dialog->Show();
$id->cancel;
create_groups();
$MW->deiconify;
$MW->raise;
}
sub create_groups
{
$groupFrame->destroy if ( Exists($groupFrame) );
$groupFrame = $MW->Frame->pack(-side=>'top',-fill=>'both',-expand=>1);
if ( $group == 1 ) {
$groupFrame->Label (-text=>"\nTyping Exercises", -font=>'arial 14
bold')->pack;
$groupFrame->Label (-text=>'Now is the time for all good men
....')->pack;
$groupFrame->Label (-text=>'The quick brown fox ...')->pack;
}
if ( $group == 2 ) {
$groupFrame->Label (-text=>"\nTongue Twisters", -font=>'arial 14
bold')->pack;
$groupFrame->Label (-text=>'She sells seashells by the
seashore.')->pack;
$groupFrame->Label (-text=>'Peter Piper picked a peck of ...')->pack;
}
if ( $group == 3 ) {
$groupFrame->Label (-text=>"\nMovie Lines", -font=>'arial 14
bold')->pack;
$groupFrame->Label (-text=>'What in the wide, wide world of sports
....')->pack;
$groupFrame->Label (-text=>'Does your dog bite?')->pack;
$groupFrame->Label (-text=>"Roads? Where we're going, ...")->pack;
}
}
sub define_menu
{
$MW->configure( -menu => my $menubar = $MW->Menu);
my $phrases = $menubar->cascade( -label=>"PHRASES" );
$phrases->radiobutton(-label=>0, -variable=>\$group, -command=>\&create_grou
ps);
$phrases->radiobutton(-label=>1, -variable=>\$group, -command=>\&create_grou
ps);
$phrases->radiobutton(-label=>2, -variable=>\$group, -command=>\&create_grou
ps);
$phrases->radiobutton(-label=>3, -variable=>\$group, -command=>\&create_grou
ps);
my $dynamic = $menubar->cascade( -label=>"GROUP$group-stuff" );
$dynamic->radiobutton(-label=>"$group-A", -variable=>\$subgroup );
$dynamic->radiobutton(-label=>"$group-B", -variable=>\$subgroup );
$dynamic->radiobutton(-label=>"$group-C", -variable=>\$subgroup );
}
###################### end code ##########################
.
- Follow-Ups:
- Re: Startup Button
- From: kw
- Re: Startup Button
- References:
- Re: Startup Button
- From: kw
- Re: Startup Button
- Prev by Date: Windows-Icon / Tk-Builder
- Next by Date: Re: Windows-Icon / Tk-Builder
- Previous by thread: Re: Startup Button
- Next by thread: Re: Startup Button
- Index(es):