Andreas Rozek Hints for Reading List of Recent Changes Guestbook Entry Contact the Author  Deutsche Version  HomePage Previous Topic Next Topic  First Page of Current Topic Next Page Previous Page

TkLua Chime

Like Clock, the Chime example is among the first Lua programs used to test the proper (and continuous) function of the author's TkLua distribution for Win32 platforms. The program offers a digital time display in addition to a chime (on every hour or half hour) with "prewarn function". If desired, the chime produces an audible alarm (which helps the author not to waste too much time browsing the web).


Screenshot of the TkLua example program "Chime"

Technical Description

The digital time display forms the primary part of the graphical user interface - a Checkbutton reflects the current audible alarm setting and a status line informs about the time left to the next warning (five minutes before an actual alarm) or to the next chime (on every hour and half hour), resp..

The digital time display consists of five label widgets (tklabel) showing images for any digit and the (blinking) colon between hours and minutes display. The figure below shows any raster images used for that purpose:

Function "processTick" forms the heart of the program: invoked once per second, the alternative display of a visible or invisible colon indicates a properly functioning program. If need be (i.e., usually once per minute), the function also updates time and status display according to the actual time. Additionally, on every hour and half hour (as well as five minutes before) the Tk command "bell" is used to produce an audible signal.

Apart from the "main program", "Chime" contains the following global functions (in alphabetical order):

  • processTick (required)
    will be invoked once per second and alternatively draws either a visible or an invisible colon. Should the time (given in minutes and seconds) have changed since the last invocation, the function additionally updates the time display;

  • showTime (hours,minutes)
    loads the time display label widgets with the images needed to show a particular digit;

  • updateUserInterface (hours,minutes)
    updates the status line underneath the time display with a hint at the next warning or alarm. If need be (and if that function has been enabled by the user), the routine uses the Tk command "bell" to produce an audible alarm tone;

Similar to the situation in "Clock", the simplicity of the internal timer function sometimes causes "Chime" also to "skip" a second - however, this behaviour doesn't affect the proper function of the program.

Source Code

The source code of this program is available for download:

In addition, all files required for the complete Chime example (this includes the source code as well) are available as a single ZIP archive:

References

[1] Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes
Reference Manual of the Programming Language Lua 4.0
(see http://www.lua.org/manual)
the reference manual contains any relevant information about the language itself, the set of standard libraries and its interface to the run-time environment;
[2] Waldemar Celes
tklua - Binding Tk to Lua
(see http://www.tecgraf.puc-rio.br/~celes/tklua/)
TkLua provides support for Tk widgets (allowing to construct graphical user interfaces) from within Lua scripts. The given web page describes the "basic concepts" behind TkLua and explains how to use it from within Lua scripts;
[3] Christian Vogler
TkLua (4.0a1)
(see http://www.cis.upenn.edu/~cvogler/lua/tklua.html)
since the original distribution of TkLua [2] has been developed for Lua versions prior to 4.0, Christian Vogler ported TkLua to the new Lua 4.0 API;
[4] Tcl/Tk 8.3.4 Manual
(see http://www.scriptics.com/man/tcl8.3/)
if you plan to use TkLua for your Lua script, you will hardly survive without the Tcl/Tk documentation - it can be viewed online at the given address (unless you already downloaded the Tcl/Tk distribution onto your system and installed it there);

Disclaimer

Please, consider also the author's Disclaimer!

http://www.Andreas-Rozek.de/Lua/Examples/Chime/index_en.html    (last Modification: 14.04.2002)