in reply to PerlTray question and adding right click exit option on tray icon
Here's an example. This shows me the current space weather as tray icon. Right click displays details (as menu entries), clicking on any of those reloads the data.
#!/usr/bin/perl -w use strict; use warnings; use strict; use warnings; use PerlTray; use Ham::Reference::Solar; my $solarstate; my $errorstate; my $lastkindex = -1; SetIcon("nostate"); my %icons = ( -2 => "errorstate", -1 => "nostate", 0 => 'k0', 1 => 'k0', 2 => 'k0', 3 => 'k0', 4 => 'k0', 5 => 'k1', 6 => 'k2', 7 => 'k3', 8 => 'k4', 9 => 'k5', ); sub internalUpdate { undef $solarstate; my $solar = new Ham::Reference::Solar; if($solar->is_error) { undef $solarstate; $errorstate = $solar->error_message; SetIcon("errorstate"); Balloon("Failed to update solar weather status", "Solar Weathe +r", "error"); $lastkindex = -2; } else { $solarstate = $solar->get_hashref; my $newk = $solarstate->{'k-index'}; if($newk != $lastkindex) { if($lastkindex >= 0 && $newk > $lastkindex) { Balloon("Geomagnetic activity has risen!", "Solar Weat +her", "warning"); } my $oldicon = $icons{$lastkindex}; my $newicon = $icons{$newk}; SetIcon($newicon); SetAnimation("0:05", 200, ($oldicon, $newicon)); $lastkindex = $newk; } } SetTimer("10:00"); } sub PopupMenu { my($default,@menu) = "*"; if(defined($solarstate)) { foreach my $key (sort keys %$solarstate) { push @menu, ["$key: " . $solarstate->{$key}, \&Timer]; } } else { push @menu, ["ERROR: $errorstate", \&Timer]; } return [ @menu, ["-------"], ["Refresh", \&Timer], ["Exit", "exit"] ]; } sub Timer { internalUpdate() } sub ToolTip {"Solar Weather Tray"} Timer();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: PerlTray question and adding right click exit option on tray icon
by zentara (Cardinal) on Jul 02, 2012 at 19:11 UTC | |
by cavac (Prior) on Jul 03, 2012 at 10:34 UTC | |
|
Re^2: PerlTray question and adding right click exit option on tray icon
by diamondsandperls (Beadle) on Jul 02, 2012 at 17:57 UTC |