From 01d5043106dbc8d5b0a63024d0c2a81b1ee63bb9 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 3 Mar 2014 14:08:00 +0100 Subject: add clock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- examples/clock | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'examples/clock') diff --git a/examples/clock b/examples/clock index 4984213..c7d9ac2 100644 --- a/examples/clock +++ b/examples/clock @@ -5,26 +5,28 @@ import time import threading +from plugins.clock import Clock + OUTPUT, HEIGHT, YPOS, TOP = 0, 12, 24, True +clock = Clock(format = '%Y-(%m)%b-%d %T, %a w%V, %Z', utc = False, sync_to = Clock.SECONDS) + + start_ = start def start(): start_() - def clock(): - while True: - time.sleep(0.1) - time.sleep(1 - (time.time() % 1)) - if redraw(): - get_display().flush() - async(clock) + def refresh(): + if redraw(): + get_display().flush() + async(lambda : clock.continuous_sync(refresh)) semaphore = threading.Semaphore() def redraw(): if semaphore.acquire(blocking = False): - text = spawn_read('date', '+%Y-(%m)%b-%d %T, %a w%V, %Z') + text = clock.read() bar.clear() bar.draw_coloured_text(0, 10, 0, 2, text) semaphore.release() -- cgit v1.2.3-70-g09d2