summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xclock.pm58
1 files changed, 38 insertions, 20 deletions
diff --git a/clock.pm b/clock.pm
index 425c8b1c..eb890b59 100755
--- a/clock.pm
+++ b/clock.pm
@@ -19,6 +19,7 @@ my $midx, $midy;
my $first=1;
my $is24;
my $h_old;
+my ($old_year, $old_month, $old_day);
my $window = $::isEmbedded ? new Gtk::Plug ($::XID) : new Gtk::Window -toplevel;
my $vbox = new Gtk::VBox(0,0);
$window->add($vbox);
@@ -27,6 +28,14 @@ my $hbox = new Gtk::HBox(0,0);
$vbox->pack_start($hbox, 1, 1, 0);
my $calendar = new Gtk::Calendar;
$hbox->pack_start($calendar, 1, 1, 0);
+$calendar->signal_connect ( 'month-changed' => \&cal_changed );
+$calendar->signal_connect ( 'day-selected' => \&cal_changed );
+$calendar->signal_connect ( 'day-selected-double-click' => \&cal_changed );
+$calendar->signal_connect ( 'prev-month' => \&cal_changed );
+$calendar->signal_connect ( 'next-month' => \&cal_changed );
+$calendar->signal_connect ( 'prev-year' => \&cal_changed );
+$calendar->signal_connect ( 'next-year' => \&cal_changed );
+
my $vbox2 = new Gtk::VBox(0,0);
$hbox->pack_start($vbox2, 1, 1, 0);
my $drawing_area = new Gtk::DrawingArea;
@@ -68,7 +77,17 @@ $bbox->set_layout(-end);
$vbox->pack_start($bbox, 0, 0, 5);
my $button_ok = new Gtk::Button "OK";
$button_ok->signal_connect ( clicked => sub {
- system("date -s " . $adj_h->set_value($hour) . ":" . $adj_m->set_value($min) . ":" . $adj_s->set_value($sec));
+ my ($year, $month, $day) = $calendar->get_date;
+ $month++;
+ my ($hour, $min, $sec) = ($adj_h->get_value, $adj_m->get_value, $adj_s->get_value);
+ $a = "date " .
+ ($month<10 ? "0" : "") . $month .
+ ($day<10 ? "0" : "") . $day .
+ ($hour<10 ? "0" : "") . $hour .
+ ($min<10 ? "0" : "") . $min .
+ $year . "." .
+ ($sec<10 ? "0" : "") . $sec;
+ system($a);
quit_global();
});
$bbox->add($button_ok );
@@ -79,12 +98,16 @@ $button_cancel->signal_connect ( clicked => sub {
Gtk->timeout_remove($timer);
$timer=Gtk->timeout_add(120, sub { time_to_rad(localtime(time)); Repaint($drawing_area) });
time_to_rad(localtime(time)); Repaint($drawing_area);
+ $calendar->select_month($old_month, $old_year);
+ $calendar->select_day($old_day);
$button_reset->set_sensitive(0);
});
$bbox->add($button_cancel );
$button_reset->signal_connect ( clicked => sub {
$timer=Gtk->timeout_add(120, sub { time_to_rad(localtime(time)); Repaint($drawing_area) });
time_to_rad(localtime(time)); Repaint($drawing_area);
+ $calendar->select_month($old_month, $old_year);
+ $calendar->select_day($old_day);
$button_reset->set_sensitive(0);
});
$bbox->add($button_reset);
@@ -94,32 +117,27 @@ $window->show_all;
$timer=Gtk->timeout_add(120, sub { time_to_rad(localtime(time)); Repaint($drawing_area) });
Gtk->main_iteration while Gtk->events_pending;
+$calendar->realize;
+(undef,undef,undef,$old_day,$old_month,$old_year) = localtime(time);
+$old_year += 1900;
+$calendar->select_month($old_month, $old_year);
+$calendar->select_day($old_day);
$::isEmbedded and kill USR2, $::CCPID;
Gtk->main;
+sub cal_changed {
+ $button_reset->set_sensitive(1);
+}
+
sub changed {
if ($h_old > $adj_h->get_value && $adj_h->get_value < ($is24 ? 18 : 6) && $h_old > ($is24 ? 18 : 6) && $h_old < ($is24 ? 24 : 12)) {
- print "LLLLLL $h_old " . $adj_h->get_value . " $is24\n";
$h_old= $adj_h->get_value;
$is24 = !$is24;
- print "MMMMMM $h_old " . $adj_h->get_value . " $is24\n";
}
elsif ($h_old < $adj_h->get_value && $adj_h->get_value > ($is24 ? 18 : 6) && $h_old < ($is24 ? 18 : 6) && ($adj_h->get_value-$h_old !=12 )) {
- print "llllll $h_old " . $adj_h->get_value . " $is24\n";
$h_old= $adj_h->get_value;
$is24 = !$is24;
- print "mmmmmm $h_old " . $adj_h->get_value . " $is24\n";
}
-# elsif ($h_old < $adj_h->get_value && $adj_h->get_value > 6 && $h_old < 6) {
-# print "0\n";
-# $is24 = 0;
-# }
-# $is24 and $adj_h->set_value($real_h+12);
-# $is24 or $adj_h->set_value($adj_h->get_value-12);
- $h_old=$adj_h->get_value;
-# my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
-# time_to_rad($adj_s->get_value,$adj_m->get_value,$adj_h->get_value,$mday,$mon,$year,$wday,$yday,$isdst);
-# Repaint($drawing_area);
}
sub spinned {
@@ -183,15 +201,15 @@ sub configure_event {
}
sub rad_to_time {
- my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);# now_tm = localtime (&now);
- $adj_h->set_value(POSIX::floor($dRadians_hour * 6 / $pi) + ($is24 ? 12 : 0));#$dRadians_hour * 6 / $pi);
+ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
+ $adj_h->set_value(POSIX::floor($dRadians_hour * 6 / $pi) + ($is24 ? 12 : 0));
$adj_m->set_value(POSIX::floor($dRadians_min*30/$pi));
$adj_s->set_value(POSIX::floor($dRadians_sec*30/$pi));
}
sub time_to_rad {
- my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = @_;# now_tm = localtime (&now);
- $dRadians_hour = $hour % 12 * $pi / 6.0; # + ($pi * $min / 360.0);
+ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = @_;
+ $dRadians_hour = $hour % 12 * $pi / 6.0;
$dRadians_min = $min * $pi / 30.0;
$dRadians_sec = $sec * $pi / 30.0;
$adj_h->set_value($hour);
@@ -217,7 +235,7 @@ sub Repaint {
my $black_gc = $drawing_area->style->black_gc;
foreach my $i ([\&DrawTickAt, 12], [\&DrawPointAt, 60]) { $i->[0]($pixmap, $black_gc, $gray_gc, $_, $midx, $midy) foreach (1..$i->[1]) }
my $now = time;
- my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);# now_tm = localtime (&now);
+ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $dRadians;
foreach ([$gray_gc, 5], [$black_gc, 0]) {
DrawHour ($pixmap, $_->[0], $midx, $midy, $dRadians_hour_real, $_->[1]);