Tk::Clock - Clock widget with analog and digital display |
Tk::Clock - Clock widget with analog and digital display
use Tk use Tk::Clock;
$clock = $parent->Clock (?-option => <value> ...?);
$clock->config ( # These reflect the defaults 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",
useDigital => 1, digiAlign => "center", timeFont => "fixed 6", timeColor => "Red4", timeFormat => "HH:MM:SS", dateFont => "fixed 6", dateColor => "Blue4", dateFormat => "dd-mm-yy", );
This module implements a Canvas-based clock widget for perl-Tk with lots of options to change the appearance.
Both analog and digital clocks are implemented.
This is the constructor. It does accept the standard widget options plus those described in config.
Below is a description of the options/attributes currently available. Their default value is in between parenthesis.
useAnalog
) and/or the digital clock (useDigital
)
in the widget. The analog clock will always be displayed above the digital part
+----------+ | .. | \ | . \_ . | |_ Analog clock | . . | | | .. | / | 23:59:59 | --- Digital time | 31-12-09 | --- Digital date +----------+
The analog clock displays ticks, hour hand, minutes hand and second hand. The digital part displays two parts, which are configurable. By default these are time and date.
The useInfo
enables a text field between the backdrop of the analog
clock and its items. You can use this field to display personal data.
$clock->config (autoScale => 1);
When using pack
for your geometry management, be sure to pass
-expand => 1, -fill => "both"
if you plan to resize with
anaScale
or enable/disable either analog or digital after the
clock was displayed.
$clock->config (anaScale => 400);
$clock->config (ana24hour => 1);
$clock->config (useSecHand => 0);
countDown
is set to a true value, the clock will run backwards.
This is a slightly experimental feature, it will not count down to a
specific point in time, but will simply reverse the rotation, making
the analog clock run counterclockwise.
When setting timerValue
to a number of seconds, the format values
Hc
, Mc
, and Sc
will represent the hour, minute and second of
the this value. When the time reaches 0, all countdown values are
reset to 0.
# Wind back clock 4 days, 5 hours, 6 minutes and 7 seconds $clock->config (localOffset => -363967);
handColor
controls
the color for both the hour-hand and the minute-hand. secsColor
controls the color for the seconds-hand.
$clock->config ( handColor => "#7F0000", secsColor => "OrangeRed", );
$clock->config (handCenter => 1);
$clock->config (tickColor => "White");
tickFreq
controls how many ticks are shown in the analog clock.
Meaningful values for tickFreq
are 1, 5 and 15 showing all ticks, tick
every 5 minutes or the four main ticks only, though any positive integer
will do (put a tick on any tickFreq
minute).
When setting tickDiff to a true value, the major ticks will use a thicker line than the minor ticks.
$clock->config ( tickFreq => 5, tickDiff => 1, );
$clock->config (timeZone => "Europe/Amsterdam"); $clock->config (timeZone => "MET-1METDST");
mmm
and mmmm
and in
day formats ddd
and dddd
.
$clock->config (useLocale => $ENV{LC_TIME} // $ENV{LC_ALL} // $ENV{LANG} // "nl_NL.utf8");
See http://docs.moodle.org/dev/Table_of_locales for a table of locales and the Windows equivalents. Windows might not have a UTF8 version available of the required locale.
$clock->config (timeFont => "{Liberation Mono} 11");
$clock->config (timeColor => "#00ff00");
Legal timeFormat
characters are H
and HH
for 24-hour, h
and
hh
for AM/PM hour, M
and MM
for minutes, S
and SS
for
seconds, Hc
for countdown/timer hour, Mc
for countdown/timer
minutes, Sc
for countdown/timer seconds, A
for AM/PM indicator,
d
and dd
for day-of-the month, ddd
and dddd
for short and
long weekday, m
, mm
, mmm
and mmmm
for month, y
and yy
for year, w
and ww
for week-number and any separators :
, -
,
/
or space
.
$clock->config (timeFormat => "hh:MM A");
The text shown in the formats ddd
, dddd
, mmm
, and mmmm
might be
influenced by the setting of useLocale
. The fallback is locale ``C''.
$clock->config (dateFont => "-misc-fixed-*-normal--15-*-c-iso8859-1");
$clock->config (dateColor => "Navy");
$clock->config (dateFormat => "ww dd-mm");
The supported format is the same as for timeFormat
.
$clock->config (infoFont => "{DejaVu Sans Mono} 8");
$clock->config (infoColor => "Yellow");
timeFormat
and dateFormat
the content is updated
every second if enabled.
$clock->config (infoFormat => "BREITLING");
The supported format is the same as for timeFormat
.
digiAlign
are ``left'', ``center'', and ``right''.
Any other value will be interpreted as the default ``center''.
$clock->config (digiAlign => "right");
-background
attribute to the constructor, which may default to the default background
used in the perl/Tk script.
The 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;
The new ()
constructor will also accept options valid for Canvas widgets,
like -background
and -relief
.
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.
* Full support for multi-line date- and time-formats with auto-resize. * Countdown clock API, incl action when done. * Better docs for the attributes
Tk(3), Tk::Canvas(3), Tk::Widget(3), Tk::Derived(3)
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.
Copyright (C) 1999-2015 H.Merijn Brand
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Tk::Clock - Clock widget with analog and digital display |