Tk-Clock

 view release on metacpan or  search on metacpan

Clock.pm  view on Meta::CPAN

#!/pro/bin/perl

package Tk::Clock;

use strict;
use warnings;

our $VERSION = "0.45";

use Carp;

use Tk;
use Tk::Widget;
use Tk::Derived;
use Tk::Canvas;

use vars qw( @ISA );
@ISA = qw/Tk::Derived Tk::Canvas/;

Construct Tk::Widget "Clock";

my $ana_base = 73;	# Size base for 100%

my %def_config = (
    timeZone	=> "",
    useLocale	=> "C",
    backDrop	=> "",

    useAnalog	=> 1,

    handColor	=> "Green4",
    secsColor	=> "Green2",
    tickColor	=> "Yellow4",
    tickFreq	=> 1,
    tickDiff	=> 0,
    useSecHand	=> 1,
    handCenter	=> 0,

    anaScale	=> 100,
    autoScale	=> 0,

    ana24hour	=> 0,
    countDown	=> 0,
    timerValue	=> 0,
    localOffset	=> 0,

    useInfo	=> 0,

    infoColor	=> "#cfb53b",
    infoFormat	=> "HH:MM:SS",
    infoFont	=> "fixed 6",

    useText	=> 0,

    textColor	=> "#c4c4c4",
    textFormat	=> " ",
    textFont	=> "fixed 6",

    time2Font	=> "fixed 6",
    time2Color	=> "Gray30",
    time2Format	=> "",
    time2TZ	=> "",

    useDigital	=> 1,

    digiAlign	=> "center",

    timeFont	=> "fixed 6",
    timeColor	=> "Red4",
    timeFormat	=> "HH:MM:SS",

    dateFont	=> "fixed 6",
    dateColor	=> "Blue4",
    dateFormat	=> "dd-mm-yy",

    fmtd	=> sub {
	sprintf "%02d-%02d-%02d", $_[3], $_[4] + 1, $_[5] + 1900;
	},

Clock.pm  view on Meta::CPAN

Any other value will be interpreted as the default "center".

  $clock->config (digiAlign => "right");

=item backDrop ("")

By default the background of the clock is controlled by the C<-background>
attribute to the constructor, which may default to the default background
used in the perl/Tk script.

The C<backDrop> attribute accepts any valid Tk::Photo object, and it will
show (part of) the image as a backdrop of the clock

  use Tk;
  use Tk::Clock;
  use Tk::Photo;
  use Tk::PNG;

  my $mainw = MainWindow->new;
  my $backd = $mainw->Photo (
      -file    => "image.png",
      );
  my $clock = $mainw->Clock (
      -relief  => "flat",
      )->pack (-expand => 1, -fill => "both");
  $clock->config (
      backDrop => $backd,
      );
  MainLoop;

=back

The C<new ()> constructor will also accept options valid for Canvas widgets,
like C<-background> and C<-relief>.

=head1 TAGS

As all of the clock is part of a Canvas, the items cannot be addressed as
Subwidgets. You can however alter presentation afterwards using the tags:

 my $clock = $mw->Clock->pack;
 $clock->itemconfigure ("date", -fill => "Red");

Currently defined tags are C<date>, C<hour>, C<info>, C<min>, C<sec>,
C<tick>, and C<time>.

=head1 BUGS

If the system load's too high, the clock might skip some seconds.

There's no check if either format will fit in the given space.

=head1 TODO

* Full support for multi-line date- and time-formats with auto-resize.
* Countdown clock API, incl action when done.
* Better docs for the attributes

=head1 SEE ALSO

Tk(3), Tk::Canvas(3), Tk::Widget(3), Tk::Derived(3)

=head1 AUTHOR

H.Merijn Brand <h.m.brand@xs4all.nl>

Thanks to Larry Wall for inventing perl.
Thanks to Nick Ing-Simmons for providing perlTk.
Thanks to Achim Bohnet for introducing me to OO (and converting
    the basics of my clock.pl to Tk::Clock.pm).
Thanks to Sriram Srinivasan for understanding OO though his Panther book.
Thanks to all CPAN providers for support of different modules to learn from.
Thanks to all who have given me feedback and weird ideas.

=head1 COPYRIGHT AND LICENSE

Copyright (C) 1999-2026 H.Merijn Brand

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut



( run in 0.429 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )