Display a clock.
authorAndrew Ruthven <puck@catalyst.net.nz>
Thu, 18 Sep 2008 04:58:48 +0000 (16:58 +1200)
committerAndrew Ruthven <puck@dirk.wgtn.cat-it.co.nz>
Thu, 18 Sep 2008 04:58:48 +0000 (16:58 +1200)
lib/Display/Plugins/Clock.pm [new file with mode: 0644]

diff --git a/lib/Display/Plugins/Clock.pm b/lib/Display/Plugins/Clock.pm
new file mode 100644 (file)
index 0000000..435d644
--- /dev/null
@@ -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;