Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import curses
- import traceback
- import time
- DIGIT_WIDTH = 5
- DIGIT_HEIGHT = 5
- DIGIT_SPACING = 2
- POINT_SPACING = 0
- POINT_WIDTH = 5
- '''
- _0_0_._0_0_0_
- '''
- width = 5*DIGIT_SPACING + 5*DIGIT_WIDTH + 2*POINT_SPACING + POINT_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:
- win.addstr(position+y, x, section)
- position += 1
- def draw_time(win, digits):
- 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 main(screen):
- draw_time(screen, [0,1,2,1,2])
- t = None
- screen.hline(0,0,curses.ACS_BULLET, width)
- while True:
- screen.clear()
- newtime = tick(screen)
- if t != newtime:
- screen.refresh()
- t = newtime
- time.sleep(0.5)
- if __name__ == '__main__':
- curses.wrapper(main)
Add Comment
Please, Sign In to add comment