awful.widget.textclock: import
[awesome.git] / lib / awful / widget / textclock.lua.in
blob622907909cc44c06cecc1f742ce1ab291e2e9b98
1 ---------------------------------------------------------------------------
2 -- @author Julien Danjou <julien@danjou.info>
3 -- @copyright 2009 Julien Danjou
4 -- @release @AWESOME_VERSION@
5 ---------------------------------------------------------------------------
7 local setmetatable = setmetatable
8 local os = os
9 local capi = { widget = widget,
10 timer = timer }
12 --- Text clock widget.
13 module("awful.widget.textclock")
15 --- Create a textclock widget. It draws the time it is in a textbox.
16 -- @param args Standard arguments for textbox widget.
17 -- @param format The time format. Default is " %a %b %d, %H:%M ".
18 -- @param timeout How often update the time. Default is 60.
19 -- @return A textbox widget.
20 function new(args, format, timeout)
21 local args = args or {}
22 local format = format or " %a %b %d, %H:%M "
23 local timeout = timeout or 60
24 args.type = "textbox"
25 local w = capi.widget(args)
26 local timer = capi.timer { timeout = timeout }
27 w.text = os.date(format)
28 timer:add_signal("timeout", function() w.text = os.date(format) end)
29 timer:start()
30 return w
31 end
33 setmetatable(_M, { __call = function(_, ...) return new(...) end })
35 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80