File: clock.lua

package info (click to toggle)
lua-gtk 0.9%2B20100528-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,176 kB
  • ctags: 1,934
  • sloc: ansic: 9,571; sh: 373; makefile: 241
file content (36 lines) | stat: -rwxr-xr-x 751 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#! /usr/bin/env lua
-- vim:sw=4:sts=4
-- Example by Michael Kolodziejczyk

require "gtk"

win = gtk.window_new(gtk.WINDOW_TOPLEVEL)
win:set_size_request(230, 100)
win:set_title("Clock")
win:connect('destroy', gtk.main_quit)

function onTimeout(ar)
    local lbl = ar.lbl
    lbl:set_markup('<span font="36">' .. os.date('%H:%M:%S') .. '</span>')
    return true
end

lbl = gtk.label_new ""
onTimeoutClosure = gnome.closure(onTimeout)
onTimeoutArg = gnome.void_ptr{ lbl=lbl }
onTimeout(onTimeoutArg)
timer = glib.timeout_add(1000, onTimeoutClosure, onTimeoutArg)
collectgarbage "collect"

win:add(lbl)
win:show_all()
gtk.main()

onTimeoutClosure = nil
onTimeoutArg = nil
lbl = nil
win = nil
collectgarbage "collect"
print(gnome.get_vwrapper_count())