Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Host status icon (Win32)

by crenz (Priest)
on Apr 02, 2003 at 17:46 UTC ( [id://247538]=CUFP: print w/replies, xml ) Need Help??

Unfortunately, my Zaurus likes to go to sleep rather quickly. So when trying to copy over a new file that I just downloaded, more often than not the network connection is already gone. That's why I decided to have a little utility to monitor the status by pinging the Zaurus every second. Of course, it can be used to monitor any host (if it's not in your local network, you should set the timeout higher).

This is a bit of a hack, and only works because Win32::GUI has a "feature" that allows you to delete notifyicons by adding another icon with the same data. If anyone knows a more elegant solution, please do tell me about it. I'd also like to be able to embed the icons as data, rather reading them from external files. (You can download my somewhat boring icons if you like.)

#!/usr/bin/perl # 2003/03/15, 2003/04/02 crenz@web42.com # display icon indicating whether zaurus is alive # only works due to weird Win32::GUI behaviour -- a notifyicon # will be deleted if another one with the same text and id is # created use strict; use warnings; use vars qw(*Timer_Timer *DeadIcon_Click *DeadIcon_RightClick *AliveIcon_Click *AliveIcon_RightClick); use Win32::GUI; use Net::Ping; # or use Win32::PingICMP my $hostname = $ARGV[0] || 'zaurus'; # or use '192.168.3.2' my $timer_itvl = 1000; my $off = Win32::GUI::Icon->new("zaurus_off.ico"); my $on = Win32::GUI::Icon->new("zaurus_on.ico"); my $frame; my $isAlive = 0; my $iconID = 0; # low timeout, since we're in "local network" (USB connection) my $p = Net::Ping->new("icmp", .2); sub isAliveOrDead { $p->ping($hostname); # for testing: -r 'c:\projects\z.txt'; } sub sayDead { $frame->AddNotifyIcon( -icon => $off, -id => $iconID, -name => 'DeadIcon', -tip => "$hostname Is Dead"); $isAlive = 0; } sub sayAlive { $frame->AddNotifyIcon( -icon => $on, -id => $iconID, -name => 'AliveIcon', -tip => "$hostname Is Alive"); $isAlive = 1; } sub toggle { if ($isAlive) { sayAlive; $iconID++; sayDead; } else { sayDead; $iconID++; sayAlive; } } sub check { toggle if $isAlive != isAliveOrDead; } sub quit { -1; } $frame = Win32::GUI::Window->new( -name => 'Main', -title => 'ZaurusAlive', -width => 100, -height => 100); sayDead; check; $frame->AddTimer("Timer", $timer_itvl); *Timer_Timer = \✓ # force check on click; alternatively set to \&toggle for debugging *DeadIcon_Click = \✓ *AliveIcon_Click = \✓ *DeadIcon_RightClick = \&quit; *AliveIcon_RightClick = \&quit; # note that the frame is never shown -- we only want the icon Win32::GUI::Dialog;

Replies are listed 'Best First'.
Re: Host status icon (Win32)
by beretboy (Chaplain) on Apr 06, 2003 at 03:04 UTC
    Am I to understand that this displays a icon in the system tray?

    "Sanity is the playground of the unimaginative" -Unknown

      Yes. Sorry if I didn't make this clear enough. These icons are called "notify icons" under Win32 (because the area is called "notification area").

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://247538]
Approved by sschneid
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (1)
As of 2024-04-25 00:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found