For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > September 2004 > Trying to figure out waitVariable command









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Trying to figure out waitVariable command
Golgi !

2004-09-19, 3:56 am

Can't seem to figure out waitVariable command. This test simply hangs at
the command, although the referenced variable was changed right before it.

#!/usr/local/bin/perl -w
use Tk;
use strict;

my $mw = MainWindow->new;
my $button = $mw -> Button(-text => 'Test waitVariable',
-command => sub {
my $status = &subroutine('First Value');
print "Status: $status\n";
}) -> pack();
MainLoop;

sub subroutine
{
my $var = shift;
print "Value = $var\n";

$var = 'Second Value';
print "Value = $var\n";

$mw->waitVariable(\$var); # <- Hangs here. Is $mw ok?
return $var;
}

________________________________________
_________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE!
hthttp://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server. If you wish to unsubscribe from this mailing list, send the
message body of "unsubscribe ptk" to majordomo@lists.stanford.edu
Wolfgang Hommel

2004-09-19, 9:00 am

Hello Golgi,

> Can't seem to figure out waitVariable command. This test simply hangs at
> the command, although the referenced variable was changed right before it.


It doesn't "hang", it simply waits for the variable being changed.

Your example is lacking any way to change the variable content, e.g.
through a widget, a Tk or file event, a background process, ... so
waitVariable never returns, because the variable never changes after
waitVariable gets invoked.


Regards,
Wolfgang
Hans Jeuken

2004-09-19, 3:57 pm

On Sunday 19 September 2004 03:27, Golgi ! wrote:
> Can't seem to figure out waitVariable command. This test simply hangs at
> the command, although the referenced variable was changed right before it.
>


Try this instead:

#!/usr/local/bin/perl -w
use Tk;
use strict;

my $mw = MainWindow->new;
my $var;

$mw -> Button(
-text => 'Initialize',
-command => sub {
$var = 'initial value';
print "variable initialized\n";
$mw->waitVariable(\$var);
print "variable has changed to: $var,\ncontinuing MainLoop\n";
}
)->pack(-fill => 'x');

$mw->Button(
-text=> "Change value",
-command => sub {
print "Changing variable\n";
$var = "another value"
}
)->pack(-fill => 'x');

MainLoop;
-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server. If you wish to unsubscribe from this mailing list, send the
message body of "unsubscribe ptk" to majordomo@lists.stanford.edu
Golgi !

2004-09-19, 3:57 pm

Nice. Thanks for the test code. It works and I'll study it a bit further
to better understand it.

________________________________________
_________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE!
http://messenger.msn.click-url.com/...1ave/direct/01/

-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server. If you wish to unsubscribe from this mailing list, send the
message body of "unsubscribe ptk" to majordomo@lists.stanford.edu
Lidie Steve

2004-09-19, 8:58 pm


On Sep 19, 2004, at 2:02 PM, Golgi ! wrote:

> Nice. Thanks for the test code. It works and I'll study it a bit
> further to better understand it.


In your original code you first changed the variable and then tried a
waitVariable(). But you need to invoke waitVariable() *before*
changing the variable: that's how the method is defined. No tachyon
messages in Perl/Tk programming ;)

-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server. If you wish to unsubscribe from this mailing list, send the
message body of "unsubscribe ptk" to majordomo@lists.stanford.edu
zentara

2004-09-20, 9:00 pm

On Sun, 19 Sep 2004 14:02:34 -0400, "Golgi !" <golgi_perl@msn.com>
wrote:

>Nice. Thanks for the test code. It works and I'll study it a bit further
>to better understand it.


Hi, here is a simpler example which is clearer.

#!/usr/bin/perl
use warnings;
use strict;
use Tk;

my $mw = MainWindow->new();

my $count = 0;

# To have a program wait until a variable's value is
# changed, call waitVariable:
$mw->after(5000,[sub{$count++}]);

$mw->waitVariable(\$count);
# event loop will wait here until $count changes

my $mw1 = MainWindow->new();

MainLoop;
__END__


--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com