summaryrefslogtreecommitdiffstats
path: root/clock.pm
diff options
context:
space:
mode:
authordamien <damien@mandriva.com>2001-03-03 05:39:46 +0000
committerdamien <damien@mandriva.com>2001-03-03 05:39:46 +0000
commitb8514b44c04ec66879a5e142333a2fa28401c97a (patch)
treef914aecb5ac30af6a7bae7236546db772bd6d5c5 /clock.pm
parent7c49758b6f4f7d1d27ae688da31282ec4149e749 (diff)
downloadcontrol-center-b8514b44c04ec66879a5e142333a2fa28401c97a.tar
control-center-b8514b44c04ec66879a5e142333a2fa28401c97a.tar.gz
control-center-b8514b44c04ec66879a5e142333a2fa28401c97a.tar.bz2
control-center-b8514b44c04ec66879a5e142333a2fa28401c97a.tar.xz
control-center-b8514b44c04ec66879a5e142333a2fa28401c97a.zip
updated
Diffstat (limited to 'clock.pm')
-rwxr-xr-xclock.pm47
1 files changed, 37 insertions, 10 deletions
diff --git a/clock.pm b/clock.pm
index c9033f74..5c96ae65 100755
--- a/clock.pm
+++ b/clock.pm
@@ -1,6 +1,7 @@
#!/usr/bin/perl
use Data::Dumper;
+use POSIX;
use Gtk;
init Gtk;
#use strict;
@@ -16,6 +17,7 @@ my $Radian;
my $timer;
my $midx, $midy;
my $first=1;
+my $is24;
my $window = $::isEmbedded ? new Gtk::Plug ($::XID) : new Gtk::Window -toplevel;
my $vbox = new Gtk::VBox(0,0);
$window->add($vbox);
@@ -27,7 +29,7 @@ $hbox->pack_start($calendar, 1, 1, 0);
my $vbox2 = new Gtk::VBox(0,0);
$hbox->pack_start($vbox2, 1, 1, 0);
my $drawing_area = new Gtk::DrawingArea;
-$drawing_area->size(200,200);
+$drawing_area->size(300,300);
$vbox2->pack_start($drawing_area, 1, 1, 0);
$drawing_area->set_events(['button_press_mask', 'button_release_mask', "pointer_motion_mask" ]);
$drawing_area->signal_connect ( expose_event => \&expose_event );
@@ -57,15 +59,25 @@ my $bbox = new Gtk::HButtonBox;
$bbox->set_layout(-end);
$vbox->pack_start($bbox, 1, 1, 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));
+ quit_global();
+ });
$bbox->add($button_ok );
my $button_cancel = new Gtk::Button "Cancel";
-$bbox->add($button_cancel );
my $button_reset = new Gtk::Button "Reset";
+$button_cancel->signal_connect ( clicked => sub {
+ $timer=Gtk->timeout_add(120, sub { time_to_rad(); Repaint($drawing_area) });
+ time_to_rad(); Repaint($drawing_area);
+ $button_reset->set_sensitive(0);
+ quit_global();
+ });
+$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);
$button_reset->set_sensitive(0);
- });
+ });
$bbox->add($button_reset);
$button_reset->set_sensitive(0);
@@ -80,14 +92,14 @@ sub motion_event {
$pressed or return;
if ($first) {
Gtk->timeout_remove($timer);
- $Radian = determine_radian($event->{'x'}, $event->{'y'});
+ ($Radian, $type) = determine_radian($event->{'x'}, $event->{'y'});
$button_reset->set_sensitive(1);
}
$$Radian=-atan2(($event->{'x'}-$midx),($event->{'y'}-$midy)) + $pi;
+
Repaint($widget);
-# print "AAAAAAAA" . $event->{'x'} . "\n";
-# print " -- # " . Data::Dumper->Dump([\$event], ['$event']) . "\n";
+ rad_to_time();
$first=0;
}
@@ -96,12 +108,13 @@ sub determine_radian {
my $res;
my $r;
+ my $i=0;
foreach (\$dRadians_hour, \$dRadians_min, \$dRadians_sec) {
my $d=sqrt ( ($x - ($midx + 0.70 * $radius * sin ($$_)))**2 + ($y - ($midy - 0.70 * $radius * cos ($$_)))**2 );
$res or $res=$d, $r=$_;
- $d<$res and $res=$d, $r=$_;
+ $d<$res and $res=$d, $r=$_, $i++;
}
- $r;
+ ($r, $i);
}
sub quit_global {
@@ -125,17 +138,31 @@ sub configure_event {
-1);
}
+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);
+}
+
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);
- $dRadians_min = ($min * $pi / 30.0) + ($pi * $sec / 1800.0);
+ $dRadians_hour = $hour % 12 * $pi / 6.0;
+ $dRadians_min = $min * $pi / 30.0;
$dRadians_sec = $sec * $pi / 30.0;
+ $adj_h->set_value($hour);
+ $adj_m->set_value($min);
+ $adj_s->set_value($sec);
+ $is24=$hour>12;
}
sub Repaint
{
my ($drawing_area) = @_;
+ $dRadians_hour = POSIX::floor($dRadians_hour / $pi * 6 + 0.5) * $pi / 6.0;
+ $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;
$pixmap->draw_rectangle($drawing_area->style->white_gc, 1, 0, 0,
$drawing_area->allocation->[2],
$drawing_area->allocation->[3]);