55 lines
1.5 KiB
Elixir
55 lines
1.5 KiB
Elixir
|
|
--------------------------------------------------------------------------
|
|
--# GTimeout and GIdle; tick tock...
|
|
--------------------------------------------------------------------------
|
|
|
|
include GtkEngine.e
|
|
include std/datetime.e
|
|
|
|
constant docs = `
|
|
<b><u>Timeout / Idle</u></b>
|
|
|
|
Two kinds of timers are provided: the <b><i>timeout</i></b>, which calls a routine
|
|
you supply once each x/thousands of a second, and the <b><i>idle</i></b>, which
|
|
calls your routine as often as possible whenever GTK isn't attending
|
|
to other things, like user clicks, window movements, etc.
|
|
|
|
This clock uses timeout, updating 4x per second to minimize
|
|
visible 'jitter' in the time, but using less than 10% cpu time.
|
|
|
|
Changing the source to use idle instead will use 80-95% cpu!
|
|
|
|
`
|
|
constant win = create(GtkWindow,
|
|
"border_width=10,position=1,keep_above=TRUE,$destroy=Quit")
|
|
|
|
constant panel = create(GtkBox,VERTICAL)
|
|
gtk:add(win,panel)
|
|
|
|
constant lbl1 = create(GtkLabel)
|
|
set(lbl1,"markup",docs)
|
|
gtk:add(panel,lbl1)
|
|
|
|
constant lbl2 = create(GtkLabel,"font=36")
|
|
gtk:add(panel,lbl2)
|
|
|
|
constant box = create(GtkButtonBox)
|
|
pack(panel,box)
|
|
|
|
constant btn = create(GtkButton,"gtk-quit","Quit")
|
|
gtk:add(box,btn)
|
|
|
|
constant ticker = create(GTimeout,250,_("ticktock"))
|
|
|
|
show_all(win)
|
|
main()
|
|
|
|
------------------------------------------------------------------------
|
|
function ticktock()
|
|
------------------------------------------------------------------------
|
|
set(lbl2,"text",datetime:format(now(),"%a %I:%M:%S %P"))
|
|
return 1 -- must return 1 to keep clock ticking!
|
|
end function
|
|
|
|
|