Home > Archive > PerlTk > February 2008 > Newbie: Non-interactive status displays - HOWTO?
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 |
Newbie: Non-interactive status displays - HOWTO?
|
|
|
| I'm a perl Tk newbie trying to create a pgm to display the status of
several servers by a green/red indicator light. After going over some
howto's & examples, I'm still stumped.
All of the examples I can find are geared towards dealing with some user
interaction (clicking buttons, typing text, etc.), but I'm looking for a
non-interactive update of status lights, say when a server goes down,
stops listening on a port, etc.
Basically I'd like to know how to update a widget color based on results
from a monitoring subroutine - ie how to pass info back into the Tk
window. I tried setting a text widget to a global variable that gets
manipulated in a routine forked prior to MainLoop, but no luck.
Sooooo....can anybody provide guidance as how to pass values back into a
Tk window? Examples greatly appreciated..
TIA
| |
| Marc Dashevsky 2008-02-05, 7:11 pm |
| In article < frudnaiQNc7dADXanZ2dnUVZ_vyinZ2d@comcast
.com>, chimpdad99_NoSpam@yahoo.com
says...
> I'm a perl Tk newbie trying to create a pgm to display the status of
> several servers by a green/red indicator light. After going over some
> howto's & examples, I'm still stumped.
>
> All of the examples I can find are geared towards dealing with some user
> interaction (clicking buttons, typing text, etc.), but I'm looking for a
> non-interactive update of status lights, say when a server goes down,
> stops listening on a port, etc.
>
> Basically I'd like to know how to update a widget color based on results
> from a monitoring subroutine - ie how to pass info back into the Tk
> window. I tried setting a text widget to a global variable that gets
> manipulated in a routine forked prior to MainLoop, but no luck.
>
> Sooooo....can anybody provide guidance as how to pass values back into a
> Tk window? Examples greatly appreciated..
How about this?
use strict;
use warnings;
use Tk;
my $mw = tkinit;
my $temperature = $mw->Label(-width => 10)->pack;
my $pressure = $mw->Label(-width => 10)->pack;
my $id = $mw->repeat(500, \&checkStatus);
MainLoop;
sub checkStatus {
my $t = int(rand(100));
my $p = int(rand(100));
$temperature->configure(-text => $t, -bg => ($t > 50) ? 'red' : 'white');
$pressure->configure(-text => $p, -bg => ($p > 50) ? 'yellow' : 'white');
}
--
Go to http://MarcDashevsky.com to send me e-mail.
| |
|
| Marc Dashevsky wrote:
> In article < frudnaiQNc7dADXanZ2dnUVZ_vyinZ2d@comcast
.com>, chimpdad99_NoSpam@yahoo.com
> says...
>
>
>
> How about this?
>
> use strict;
> use warnings;
> use Tk;
>
> my $mw = tkinit;
>
> my $temperature = $mw->Label(-width => 10)->pack;
> my $pressure = $mw->Label(-width => 10)->pack;
>
> my $id = $mw->repeat(500, \&checkStatus);
> MainLoop;
>
>
> sub checkStatus {
> my $t = int(rand(100));
> my $p = int(rand(100));
> $temperature->configure(-text => $t, -bg => ($t > 50) ? 'red' : 'white');
> $pressure->configure(-text => $p, -bg => ($p > 50) ? 'yellow' : 'white');
> }
>
Exactly what I was looking for. Thank you VERY much!
| |
|
| Marc Dashevsky wrote:
> In article < frudnaiQNc7dADXanZ2dnUVZ_vyinZ2d@comcast
.com>, chimpdad99_NoSpam@yahoo.com
> says...
>
>
>
> How about this?
>
> use strict;
> use warnings;
> use Tk;
>
> my $mw = tkinit;
>
> my $temperature = $mw->Label(-width => 10)->pack;
> my $pressure = $mw->Label(-width => 10)->pack;
>
> my $id = $mw->repeat(500, \&checkStatus);
> MainLoop;
>
>
> sub checkStatus {
> my $t = int(rand(100));
> my $p = int(rand(100));
> $temperature->configure(-text => $t, -bg => ($t > 50) ? 'red' : 'white');
> $pressure->configure(-text => $p, -bg => ($p > 50) ? 'yellow' : 'white');
> }
>
Marc
One more question if you don't mind...when I added a "system("sleep
5");" line at the end of checkStatus, the display never updates. Why is
that?
Chris
| |
| smallpond 2008-02-05, 7:11 pm |
| On Feb 5, 1:06 pm, Chris <chimpdad99_NoS...@yahoo.com> wrote:
> Marc Dashevsky wrote:
>
>
>
>
>
>
>
>
>
>
>
> Marc
>
> One more question if you don't mind...when I added a "system("sleep
> 5");" line at the end of checkStatus, the display never updates. Why is
> that?
>
> Chris
Why would you sleep for 5 seconds in a routine called every 0.5
seconds?
| |
|
| smallpond wrote:
> On Feb 5, 1:06 pm, Chris <chimpdad99_NoS...@yahoo.com> wrote:
>
>
>
>
> Why would you sleep for 5 seconds in a routine called every 0.5
> seconds?
This stuff is just for testing concepts to be used later in a real pgm.
The idea was just to invoke a quick system level command for testing.
The command I'd like to do is set a var as to whether a host responds to
a ping, but this is blocking. Now, I'm trying to find a way to issue a
ping that is non-blocking, and get the results back into a var that can
set the text color.
| |
| Marc Dashevsky 2008-02-05, 7:11 pm |
| In article < xtWdnVMM4f4AODXanZ2dnUVZ_rTinZ2d@comcast
.com>, chimpdad99_NoSpam@yahoo.com
says...
> One more question if you don't mind...when I added a "system("sleep
> 5");" line at the end of checkStatus, the display never updates. Why is
> that?
I would have thought it would update after the sleep, but perhaps
the repeat() timer is getting by the sleep, since events
are not handled during sleep. As you can see using sleep with perl/Tk
has major problems. Fortunately, sleep is unnecessary because we
have repeat, after (these two are documented in Tk::after pod),
waitVariable, waitVisibility and waitWindow (these three are documented
in Tk::Widget pod).
--
Go to http://MarcDashevsky.com to send me e-mail.
| |
| Ch Lamprecht 2008-02-05, 7:11 pm |
| Chris wrote:
[color=darkred]
[color=darkred]
Hi,
if you are looking for something non-interactive, it might be enough to call
$main->update after having set the color when your ping- routine returns...
Christoph
--
use Tk;use Tk::GraphItems;$c=tkinit->Canvas->pack;push@i,Tk::GraphItems->
TextBox(text=>$_,canvas=>$c,x=>$x+=70,y=>100)for(Just=>another=>Perl=>Hacker);
Tk::GraphItems->Connector(source=>$i[$_],target=>$i[$_+1])for(0..2);
$c->repeat(30,sub{$_->move(0,4*cos($d+=3.16))for(@i)});MainLoop
| |
|
| Ch Lamprecht wrote:
> Chris wrote:
>
>
>
>
> Hi,
>
> if you are looking for something non-interactive, it might be enough to
> call
> $main->update after having set the color when your ping- routine returns...
>
> Christoph
>
>
I stumbled across that this and it does indeed seem to fix the blocking
issue.
Thx
|
|
|
|
|