updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / moonphase-applet / moonphase-applet.pl
blob4177035721f97077c92655b66877cac866530703
1 #!/usr/bin/env perl
2 #MoonPhase-Applet (Harvie 2oo9)
4 use strict;
5 use warnings;
6 use Astro::MoonPhase;
7 use Gtk2 -init;
9 my $icons = '/usr/share/icons/moonphase-icons'; #directory with moon phase icons
11 sub timediff {
12 my $t = $_[0];
13 my $days = int($t/(60*60*24)); $t %=(60*60*24);
14 my $hours = int($t/(60*60)); $t %=(60*60);
15 my $mins = int($t/(60)); $t %=(60);
16 return $days."d ".$hours."h ".$mins."m ".$t."s";
20 my $statusicon = Gtk2::StatusIcon->new();
21 #$statusicon->signal_connect(activate => sub { Gtk2->main_quit; }); #exit on click...
23 opendir(my $dir,$icons);
24 my @filenames = readdir($dir);
25 closedir($dir);
27 @filenames = sort(@filenames); shift(@filenames); shift(@filenames); #remove . and ..
28 #@filenames = sort(sub {$b cmp $a}, @filenames); pop(@filenames); pop(@filenames); #reversed
30 my @phase_name = ("NEW MOON", "FIRST QUARTER", "FULL MOON", "LAST QUARTER");
32 $SIG{'ALRM'} = sub {
33 my $time = time(); #seconds_since_1970
34 my ($MoonPhase, $MoonIllum, $MoonAge, $MoonDist, $MoonAng, $SunDist, $SunAng) = phase($time);
35 #$MoonPhase = ($MoonPhase+0.5)%1;
36 my $imgno = int(( (($MoonPhase*@filenames)+.5)%@filenames )+.5);
37 my $img = $filenames[$imgno];
39 my $prediction = '';
40 my ($phase, @times) = phaselist(time(), (time()+60*60*24*31));
41 while (@times) {
42 my $phasetime = shift(@times);
43 $prediction .= "$phase_name[$phase] coming at:\n ".scalar(localtime($phasetime))." (".timediff($phasetime-$time)." remaining)\n";
44 $phase = ($phase + 1) % 4;
47 my $tooltip = "Astro::MoonPhase Applet (by harvie 2oo9)\n".
48 "Local time is: ".scalar(localtime($time))."\n\n".
49 "$prediction\n".
50 "MoonPhase = ".($MoonPhase * 100)." %\n".
51 "MoonIllum = ".($MoonIllum * 100)." %\n".
52 "MoonAge = $MoonAge days\n".
53 "MoonDist = $MoonDist km\n".
54 "MoonAng = $MoonAng degrees\n".
55 "SunDist = $SunDist km\n".
56 "SunAng = $SunAng degrees\n".
57 "Icon = $img ($imgno/".scalar(@filenames)." images total)\n\n".
58 "See man Astro::MoonPhase for explanation\n".
59 "Tip: You can make fullmoon gathering with friends each month.\n";
60 $img = "$icons/$img";
62 print "\033[2J\033[0;0H$tooltip";
64 $statusicon->set_tooltip_text($tooltip);
65 $statusicon->set_from_file($img);
67 alarm(1);
69 alarm(1);
71 Gtk2->main;