From: Andrew Ruthven Date: Thu, 18 Sep 2008 04:58:48 +0000 (+1200) Subject: Display a clock. X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6447d995a85240dd1f03288d23f26e0f18a25643;p=picture-display.git Display a clock. --- diff --git a/lib/Display/Plugins/Clock.pm b/lib/Display/Plugins/Clock.pm new file mode 100644 index 0000000..435d644 --- /dev/null +++ b/lib/Display/Plugins/Clock.pm @@ -0,0 +1,49 @@ +package Display::Plugins::Clock; + +use Clutter; +use POSIX qw/strftime/; + +sub new { + my ($class,$stage) = @_; + + my $self = { + 'stage' => $stage, + }; + + bless ($self, $class); + $self->init(); + return $self; +} + +sub display { + my $self = shift; + + $self->{'clock'}->set_text(strftime("%H:%M %d/%m/%Y", localtime(time))); + + Glib::Timeout->add_seconds(60 - strftime(%s, localtime()), $self->can('display'), $self); + + return 0; +} + +sub init { + my $self = shift; + + $self->{'clock'} = Clutter::Label->new('Sans 20', strftime("%H:%M %d/%m/%Y", localtime(time))); + $self->{'clock'}->set_anchor_point($self->{'clock'}->get_width(), 1); + $self->{'clock'}->set_position($self->{'stage'}->get_width() - 20, 15); + $self->{'clock'}->set_color(Clutter::Color->parse('White')); + + $self->{'bg'} = Clutter::Rectangle->new(Clutter::Color->parse('Black')); + $self->{'bg'}->set_width($self->{'clock'}->get_width() + 20); + $self->{'bg'}->set_height($self->{'clock'}->get_height() + 10); + $self->{'bg'}->set_anchor_point($self->{'bg'}->get_width(), 1); + $self->{'bg'}->set_position($self->{'stage'}->get_width() - 10, 10); + $self->{'bg'}->set_opacity(100); + + $self->{'stage'}->add($self->{'bg'}); + $self->{'stage'}->add($self->{'clock'}); + + Glib::Timeout->add_seconds(60 - strftime(%s, localtime()), $self->can('display'), $self); +} + +1;