-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·68 lines (50 loc) · 1.42 KB
/
main.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/python3
import traceback
import curses
from curses import wrapper
import time
seconds = 0
minutes = 0
hours = 0
def update(window):
updateTime()
updateScreen(window)
def updateTime():
global seconds, minutes, hours
seconds += 1
if seconds >= 60:
seconds = 0
minutes += 1
elif minutes >= 60:
minutes = 0
hours += 1
def updateScreen(window):
global seconds
window.clear()
window.border()
(maxY, maxX) = window.getmaxyx()
window.addstr(maxY//2 - 2 ,maxX//2 - 3, ': :')
window.addstr(maxY//2 - 2 ,maxX//2 - 6,str(hours).zfill(2), curses.A_DIM)
window.addstr(maxY//2 - 2 ,maxX//2 - 1,str(minutes).zfill(2),)
window.addstr(maxY//2 - 2 ,maxX//2 + 4,str(seconds).zfill(2), curses.A_BOLD)
window.addstr(maxY//2,maxX//2 - 11,'|' + 20*' ' + '|', curses.A_BOLD)
window.addstr(maxY//2,maxX//2 - 10,(seconds//3 + 1)*' ', curses.A_REVERSE)
window.addstr(maxY - 2,maxX//2 - 7,'q : quit, r: reset')
window.refresh()
def resetTimer():
global seconds, minutes, hours
seconds, minutes, hours = 0, 0, 0
def main(window):
global seconds, minutes, hours
curses.curs_set(0)
window.nodelay(True)
ch = ''
while True:
update(window)
curses.napms(1000)
ch = window.getch()
if ch == ord('r'):
resetTimer()
elif ch == ord('q'):
break
wrapper(main)