diff options
author | damien <damien@mandriva.com> | 2001-03-03 20:18:05 +0000 |
---|---|---|
committer | damien <damien@mandriva.com> | 2001-03-03 20:18:05 +0000 |
commit | ac53906dc45ffaf83f5a9c7a1f63515842ac1422 (patch) | |
tree | fb1d8dfd5e159e47af6942070db055a7965d8204 /clock.pm | |
parent | 355dfd6be1a2c9773a9e6ed72903cda12a2c7c7b (diff) | |
download | control-center-ac53906dc45ffaf83f5a9c7a1f63515842ac1422.tar control-center-ac53906dc45ffaf83f5a9c7a1f63515842ac1422.tar.gz control-center-ac53906dc45ffaf83f5a9c7a1f63515842ac1422.tar.bz2 control-center-ac53906dc45ffaf83f5a9c7a1f63515842ac1422.tar.xz control-center-ac53906dc45ffaf83f5a9c7a1f63515842ac1422.zip |
updated
Diffstat (limited to 'clock.pm')
-rwxr-xr-x | clock.pm | 52 |
1 files changed, 32 insertions, 20 deletions
@@ -44,16 +44,22 @@ my $hbox2 = new Gtk::HBox(1,0); $hbox11->pack_start($hbox2, 0, 0, 0); my $adj_h = new Gtk::Adjustment 0.0, 0.0, 23.0, 1.0, 5.0, 0.0; my $spinner_h = new Gtk::SpinButton $adj_h, 0, 0; -$spinner_h->set_wrap(1); $hbox2->pack_start($spinner_h, 0, 0, 0); +$spinner_h->set_wrap(1); +$spinner_h->signal_connect ( activate => \&spinned); +$spinner_h->signal_connect ( button_release_event => \&spinned); my $adj_m = new Gtk::Adjustment 0.0, 0.0, 59.0, 1.0, 5.0, 0.0; my $spinner_m = new Gtk::SpinButton $adj_m, 0, 0; -$spinner_m->set_wrap(1); $hbox2->pack_start($spinner_m, 0, 0, 0); +$spinner_m->set_wrap(1); +$spinner_m->signal_connect ( activate => \&spinned ); +$spinner_m->signal_connect ( button_release_event => \&spinned ); my $adj_s = new Gtk::Adjustment 0.0, 0.0, 59.0, 1.0, 5.0, 0.0; my $spinner_s = new Gtk::SpinButton $adj_s, 0, 0; -$spinner_s->set_wrap(1); $hbox2->pack_start($spinner_s, 0, 0, 0); +$spinner_s->set_wrap(1); +$spinner_s->signal_connect ( activate => \&spinned ); +$spinner_s->signal_connect ( button_release_event => \&spinned ); my $bbox = new Gtk::HButtonBox; $bbox->set_layout(-end); @@ -69,26 +75,33 @@ my $button_reset = new Gtk::Button "Reset"; $button_cancel->signal_connect ( clicked => sub { quit_global(); Gtk->timeout_remove($timer); - $timer=Gtk->timeout_add(120, sub { time_to_rad(); Repaint($drawing_area) }); - time_to_rad(); Repaint($drawing_area); + $timer=Gtk->timeout_add(120, sub { time_to_rad(localtime(time)); Repaint($drawing_area) }); + time_to_rad(localtime(time)); Repaint($drawing_area); $button_reset->set_sensitive(0); }); $bbox->add($button_cancel ); $button_reset->signal_connect ( clicked => sub { - $timer=Gtk->timeout_add(120, sub { time_to_rad(); Repaint($drawing_area) }); - time_to_rad(); Repaint($drawing_area); + $timer=Gtk->timeout_add(120, sub { time_to_rad(localtime(time)); Repaint($drawing_area) }); + time_to_rad(localtime(time)); Repaint($drawing_area); $button_reset->set_sensitive(0); }); $bbox->add($button_reset); $button_reset->set_sensitive(0); $window->show_all; -$timer=Gtk->timeout_add(120, sub { time_to_rad(); Repaint($drawing_area) }); +$timer=Gtk->timeout_add(120, sub { time_to_rad(localtime(time)); Repaint($drawing_area) }); Gtk->main_iteration while Gtk->events_pending; $::isEmbedded and kill USR2, $::CCPID; Gtk->main; +sub spinned { + Gtk->timeout_remove($timer); + $button_reset->set_sensitive(1); + 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 motion_event { my ($widget, $event) = @_; @@ -143,14 +156,14 @@ 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($dRadians_hour * 6 / $pi); - $adj_m->set_value($dRadians_min*30/$pi); - $adj_s->set_value($dRadians_sec*30/$pi); + $adj_h->set_value(POSIX::floor($dRadians_hour * 6 / $pi));#$dRadians_hour * 6 / $pi); + $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) = localtime(time);# 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) = @_;# now_tm = localtime (&now); + $dRadians_hour = $hour % 12 * $pi / 6.0; # + ($pi * $min / 360.0); $dRadians_min = $min * $pi / 30.0; $dRadians_sec = $sec * $pi / 30.0; $adj_h->set_value($hour); @@ -159,13 +172,12 @@ sub time_to_rad { $is24=$hour>12; } -sub Repaint -{ +sub Repaint { my ($drawing_area) = @_; - my $dRadians_hour_real = POSIX::floor($dRadians_hour / $pi*6 + 0.5) * $pi/6.0 + $dRadians_min / 12; - $dRadians_min = POSIX::floor($dRadians_min / $pi * 30 + 0.5) * $pi / 30.0; - $dRadians_sec = POSIX::floor($dRadians_sec / $pi * 30 + 0.5) * $pi / 30.0; + my $dRadians_hour_real = POSIX::floor($dRadians_hour / $pi*6 ) * $pi/6.0 + $dRadians_min / 12; + my $dRadians_min_real = POSIX::floor($dRadians_min / $pi * 30 ) * $pi / 30.0; + my $dRadians_sec_real = POSIX::floor($dRadians_sec / $pi * 30 ) * $pi / 30.0; $pixmap->draw_rectangle($drawing_area->style->white_gc, 1, 0, 0, $drawing_area->allocation->[2], $drawing_area->allocation->[3]); @@ -182,8 +194,8 @@ sub Repaint my $dRadians; foreach ([$gray_gc, 5], [$black_gc, 0]) { DrawHour ($pixmap, $_->[0], $midx, $midy, $dRadians_hour_real, $_->[1]); - DrawMin ($pixmap, $_->[0], $midx, $midy, $dRadians_min, $_->[1]); - DrawSec ($pixmap, $_->[0], $midx, $midy, $dRadians_sec, $_->[1]); + DrawMin ($pixmap, $_->[0], $midx, $midy, $dRadians_min_real, $_->[1]); + DrawSec ($pixmap, $_->[0], $midx, $midy, $dRadians_sec_real, $_->[1]); } $drawing_area->draw(undef); 1; |