Skip to content

Instantly share code, notes, and snippets.

@bavardage
Created June 25, 2009 20:34
Show Gist options
  • Save bavardage/136149 to your computer and use it in GitHub Desktop.
Save bavardage/136149 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import curses
import signal
import traceback
import time
DIGIT_WIDTH = 5
DIGIT_HEIGHT = 5
DIGIT_SPACING = 2
'''
_0_0_._0_0_0_
'''
width = 7*DIGIT_SPACING + 6*DIGIT_WIDTH
height = 2*DIGIT_SPACING + DIGIT_HEIGHT
# numbers, list of coords in (y,x)
digits = [
[
"#####",
"# #",
"# #",
"# #",
"#####"
],
[
" # ",
" ## ",
" # ",
" # ",
" ### ",
],
[
"#####",
" #",
"#####",
"# ",
"#####",
],
[
"#####",
" #",
" ####",
" #",
"#####",
],
[
"# #",
"# #",
"#####",
" #",
" #",
],
[
"#####",
"# ",
"#####",
" #",
"#####",
],
[
"#####",
"# ",
"#####",
"# #",
"#####",
],
[
"#####",
" #",
" #",
" #",
" #",
],
[
"#####",
"# #",
"#####",
"# #",
"#####",
],
[
"#####",
"# #",
"#####",
" #",
" #",
],
[
"",
"",
"",
"",
" # ",
],
]
def draw_digit(win, digit, y, x):
sections = digits[digit]
position = 0
for section in sections:
xpos = x
for char in section:
if char == ' ':
win.addstr(position+y, xpos, ' ', curses.color_pair(0))
else:
win.addstr(position+y, xpos, ' ', curses.color_pair(1))
xpos += 1
position += 1
def draw_time(win, digits):
h,w = win.getmaxyx()
x_pos = (w - width) / 2
x_pos += DIGIT_SPACING
y_pos = 1
digits.insert(2, 10) #add in the point
for d in digits:
draw_digit(win, d, y_pos, x_pos)
x_pos += (DIGIT_SPACING + DIGIT_WIDTH)
def tick(win):
tm = time.localtime()
t = ks = tm.tm_hour*3600 + tm.tm_min*60 + tm.tm_sec
a = ks/10000; ks -= a*10000
b = ks/1000; ks -= b*1000
c = ks/100; ks -= c*100
d = ks/10; ks -= d*10
e = ks
draw_time(win, [a,b,c,d,e])
return t
def init_screen():
screen = curses.initscr()
curses.noecho()
curses.cbreak()
screen.clear()
def main(screen):
curses.curs_set(0) #hide cursor
screen.nodelay(1) # don't wait for input
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)
def screen_resize(*args):
print "LOLOLOLOL"
screen.erase()
screen.refresh()
signal.signal(signal.SIGWINCH, screen_resize)
screen.hline(0,0,curses.ACS_BULLET, width)
screen.hline(DIGIT_HEIGHT+1,0,curses.ACS_BULLET, width)
screen.vline(1,0,curses.ACS_BULLET, DIGIT_HEIGHT)
screen.vline(1,width-1,curses.ACS_BULLET, DIGIT_HEIGHT)
t = None
while True:
newtime = tick(screen)
if t != newtime:
screen.refresh()
t = newtime
c = screen.getch()
if c == ord('q'):
break
time.sleep(0.5)
if __name__ == '__main__':
curses.wrapper(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment