aboutsummaryrefslogtreecommitdiffstats
path: root/examples/clock
blob: 4984213bb9a550a7369fca4c682cb49bb5327179 (plain) (blame)
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
# -*- python -*-

# A simple xpybar configuration example of a clock

import time
import threading


OUTPUT, HEIGHT, YPOS, TOP = 0, 12, 24, True


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)


semaphore = threading.Semaphore()
def redraw():
    if semaphore.acquire(blocking = False):
        text = spawn_read('date', '+%Y-(%m)%b-%d %T, %a w%V, %Z')
        bar.clear()
        bar.draw_coloured_text(0, 10, 0, 2, text)
        semaphore.release()
        return True
    return False