fancy clock
This commit is contained in:
121
bin/clockcurses
121
bin/clockcurses
@@ -22,20 +22,65 @@ ascii_digits = {
|
||||
":": " . . ",
|
||||
}
|
||||
|
||||
|
||||
fancy_digits = {
|
||||
"0": "╒═╕│ ││ ││ │╘═╛",
|
||||
"1": " ╕ │ │ │ ╧ ",
|
||||
"2": "╒═╕ │╒═╛│ ╘═╛",
|
||||
"3": "╒═╕ │ ═╡ │╘═╛",
|
||||
"4": "╤ │ │╘═╡ │ ╧",
|
||||
"5": "╒═╕│ ╘═╕ │╘═╛",
|
||||
"6": "╒╕ │ ╞═╕│ │╘═╛",
|
||||
"7": "╒═╕ │ ╪ │ ╛",
|
||||
"8": "╒═╕│ │╞═╡│ │╘═╛",
|
||||
"9": "╒═╕│ │╘═╡ │ ╘╛",
|
||||
":": " ° ° ",
|
||||
"0": ("▗▄▖"
|
||||
"█ █"
|
||||
"█ █"
|
||||
"█ █"
|
||||
"▝▀▘"),
|
||||
"1": ("▗▄ "
|
||||
" █ "
|
||||
" █ "
|
||||
" █ "
|
||||
"▝▀▘"),
|
||||
"2": ("▗▄▖"
|
||||
"▘ █"
|
||||
" ▟▘"
|
||||
"▟▘ "
|
||||
"▀▀▀"),
|
||||
|
||||
"3": ("▗▄▖"
|
||||
"▘ █"
|
||||
" ▜▌"
|
||||
"▖ █"
|
||||
"▝▀▘"),
|
||||
"4": (" ▗▖"
|
||||
"▗▜▌"
|
||||
"▌▐▌"
|
||||
"▀▜▛"
|
||||
" ▀▀"),
|
||||
"5": ("▄▄▄"
|
||||
"█ "
|
||||
"▀▀▙"
|
||||
"▖ █"
|
||||
"▝▀▘"),
|
||||
"6": ("▗▄▖"
|
||||
"█ ▝"
|
||||
"█▀▙"
|
||||
"█ █"
|
||||
"▝▀▘"),
|
||||
"7": ("▄▄▄"
|
||||
" █"
|
||||
" ▐▌"
|
||||
" █ "
|
||||
"▝▘ "),
|
||||
#▖ ▗ ▘ ▙ ▚ ▛ ▜ ▝ ▞ ▟ █ ▀ ▄ ▌ ▐
|
||||
"8": ("▗▄▖"
|
||||
"█ █"
|
||||
"▟▀▙"
|
||||
"█ █"
|
||||
"▝▀▘"),
|
||||
"9": ("▗▄▖"
|
||||
"█ █"
|
||||
"▜▄█"
|
||||
"▖ █"
|
||||
"▝▀▘"),
|
||||
":": " ▗ ▝ ",
|
||||
}
|
||||
|
||||
# ~ ░ ▒ ▓
|
||||
|
||||
|
||||
def termsize():
|
||||
rows, columns = os.popen("stty size", "r").read().split()
|
||||
@@ -62,17 +107,19 @@ def drawcircle(win, cy, cx, r):
|
||||
alpha = 2.0 * math.pi * a / precision
|
||||
dy = int(round(cy - float(r) * math.cos(alpha)))
|
||||
dx = int(round(cx + 2.0 * float(r) * math.sin(alpha)))
|
||||
saddstr(win, dy, dx, ".")
|
||||
saddstr(win, dy, dx, "·")
|
||||
return
|
||||
|
||||
|
||||
def drawline(win, cy, cx, a, s, r, char, attr=None):
|
||||
prec = 2
|
||||
points = {}
|
||||
for l in range(int(r * prec)):
|
||||
if l > s:
|
||||
ly = int(round(cy - float(l) * math.cos(a) / prec))
|
||||
lx = int(round(cx + 2.0 * float(l) * math.sin(a) / prec))
|
||||
saddstr(win, ly, lx, char, attr)
|
||||
ly = cy - float(l) * math.cos(a) / prec
|
||||
lx = cx + 2.0 * float(l) * math.sin(a) / prec
|
||||
iy,ix = int(round(ly)), int(round(lx))
|
||||
saddstr(win, iy,ix, char, attr)
|
||||
|
||||
return
|
||||
|
||||
@@ -91,7 +138,7 @@ def drawsplitstr(win, y, x, st):
|
||||
ls = list(st)
|
||||
for r in range(5):
|
||||
rs = 3 * r
|
||||
saddstr(win, y + r, x, ls[rs] + ls[rs + 1] + ls[rs + 2])
|
||||
saddstr(win, y + r, x, ls[rs] + ls[rs + 1] + ls[rs + 2], curses.A_BOLD)
|
||||
return
|
||||
|
||||
|
||||
@@ -110,11 +157,14 @@ def drawdigital(win, y, x, t, ascii=False):
|
||||
drawdigit(win, y, x + 4 * c, hrs[c], ascii=ascii)
|
||||
|
||||
|
||||
def readinput(win):
|
||||
def readinput(win, timeout):
|
||||
started = time.time()
|
||||
try:
|
||||
input = win.getch()
|
||||
if input in [ord(x) for x in ["x", "X", "q", "Q"]]:
|
||||
return "x"
|
||||
while time.time() - timeout < started:
|
||||
input = win.getch()
|
||||
if input in [ord(x) for x in ["x", "X", "q", "Q"]]:
|
||||
return "x"
|
||||
time.sleep(0.01)
|
||||
except:
|
||||
return ""
|
||||
return ""
|
||||
@@ -134,45 +184,48 @@ def main():
|
||||
curses.curs_set(0)
|
||||
curses.start_color()
|
||||
curses.use_default_colors()
|
||||
stdscr.nodelay(2)
|
||||
for i in range(0, curses.COLORS):
|
||||
curses.init_pair(i + 1, i, -1)
|
||||
start_t = time.time()
|
||||
try:
|
||||
# rows,columns = termsize()
|
||||
curses.cbreak()
|
||||
while 1:
|
||||
rows, columns = stdscr.getmaxyx()
|
||||
cy, cx, r = centerpoint(rows, columns)
|
||||
stdscr.clear()
|
||||
t = time.localtime()
|
||||
now = time.time()
|
||||
t = time.localtime(now)
|
||||
if options.timer:
|
||||
t_new = time.time() - start_t
|
||||
t_new = now - start_t
|
||||
t_m, t_s = divmod(t_new, 60)
|
||||
t_h, t_m = divmod(t_m, 60)
|
||||
f = 1- t_new %1
|
||||
else:
|
||||
f = now % 1
|
||||
t_s = float(t.tm_sec)
|
||||
t_m = float(t.tm_min)
|
||||
t_h = float(t.tm_hour)
|
||||
alphas = math.pi * t_s / 30.0
|
||||
alphas = math.pi * (f+t_s) / 30.0
|
||||
alpham = math.pi * t_m / 30.0 + alphas / 60.0
|
||||
alphah = math.pi * t_h / 6.0 + alpham / 12.0
|
||||
if options.seconds:
|
||||
drawline(stdscr, cy, cx, alphas, 1, r / 2, "s", curses.color_pair(2))
|
||||
drawline(stdscr, cy, cx, alpham, 1, int(round(r * 0.8) / 2), "m", curses.color_pair(3))
|
||||
drawline(stdscr, cy, cx, alphah, 1, int(round(r * 0.5) / 2), "HH", curses.color_pair(7))
|
||||
stdscr.addstr(cy, cx, "o")
|
||||
drawcircle(stdscr, cy, cx, r / 2)
|
||||
if options.seconds:
|
||||
drawline(stdscr, cy, cx, alphas, 1, r / 2, "■", curses.color_pair(2))
|
||||
drawline(stdscr, cy, cx, alpham, 1, int(round(r * 0.9) / 2), "█", curses.color_pair(3))
|
||||
drawline(stdscr, cy, cx, alphah, 1, int(round(r * 0.7) / 2), "█", curses.color_pair(7))
|
||||
stdscr.addstr(cy, cx, "█")
|
||||
|
||||
for h in range(12):
|
||||
drawline(stdscr, cy, cx, math.pi * h / 6.0, r, 1 + r / 2, "O")
|
||||
drawline(stdscr, cy, cx, math.pi * h / 6.0, r, 1 + r / 2, "@")
|
||||
if options.timer:
|
||||
drawdigital(stdscr, 1, 1, timer_struct(t_h, t_m, t_s), options.ascii)
|
||||
drawdigital(stdscr, 7, 1, t, options.ascii)
|
||||
else:
|
||||
drawdigital(stdscr, 1, 1, t, options.ascii)
|
||||
stdscr.refresh()
|
||||
# time.sleep(options.refresh)
|
||||
signal.signal(signal.SIGALRM, readinput)
|
||||
signal.alarm(int(options.refresh))
|
||||
userinput = readinput(stdscr)
|
||||
userinput = readinput(stdscr, options.refresh)
|
||||
if userinput == "x":
|
||||
curses.nocbreak()
|
||||
stdscr.keypad(0)
|
||||
@@ -193,7 +246,7 @@ Display a clockface
|
||||
"""
|
||||
parser = OptionParser(usage=usage)
|
||||
parser.add_option("-s", action="store_true", dest="seconds", default=False, help="Show seconds [%default]")
|
||||
parser.add_option("-r", type="int", dest="refresh", default=3, help="Refresh rate in seconds [%default]")
|
||||
parser.add_option("-r", type="float", dest="refresh", default=3, help="Refresh rate in seconds [%default]")
|
||||
parser.add_option(
|
||||
"-t", action="store_true", dest="timer", default=False, help="Timer instead of current time [%default]"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user