72 lines
2.6 KiB
Python
72 lines
2.6 KiB
Python
import curses
|
|
from datetime import datetime
|
|
from .utils import init_colors, draw_big_digit
|
|
from .big_digits import BIG_DIGITS
|
|
|
|
class MainClockView:
|
|
def __init__(self):
|
|
"""Initialize the main clock view"""
|
|
self.digit_width = 14 # Width of each digit pattern in the big clock display
|
|
|
|
def draw(self, stdscr):
|
|
"""Draw the main clock screen"""
|
|
init_colors()
|
|
height, width = stdscr.getmaxyx()
|
|
current_time = datetime.now()
|
|
|
|
self._draw_big_time(stdscr, current_time, height, width)
|
|
self._draw_date(stdscr, current_time, height, width)
|
|
self._draw_menu(stdscr, height, width)
|
|
|
|
def handle_input(self, key):
|
|
"""Handle user input and return the next view name or None to stay"""
|
|
if key == ord('a'):
|
|
return 'ADD_ALARM'
|
|
elif key == ord('s'):
|
|
return 'LIST_ALARMS'
|
|
elif key == ord('q'):
|
|
return 'QUIT'
|
|
return None
|
|
|
|
def _draw_big_time(self, stdscr, current_time, height, width):
|
|
"""Draw the big time display"""
|
|
time_str = current_time.strftime("%H:%M:%S")
|
|
total_width = self.digit_width * len(time_str)
|
|
start_x = self._center_x(width, total_width)
|
|
start_y = self._center_y(height, 7) - 4 # 7 is the height of digits
|
|
|
|
# Draw each digit in green
|
|
stdscr.attron(curses.color_pair(1))
|
|
for i, digit in enumerate(time_str):
|
|
self._draw_digit(stdscr, start_y, start_x + i * self.digit_width, digit)
|
|
stdscr.attroff(curses.color_pair(1))
|
|
|
|
def _draw_date(self, stdscr, current_time, height, width):
|
|
"""Draw the current date"""
|
|
date_str = current_time.strftime("%Y-%m-%d")
|
|
date_x = self._center_x(width, len(date_str))
|
|
date_y = height // 2 + 4
|
|
|
|
stdscr.attron(curses.color_pair(2))
|
|
stdscr.addstr(date_y, date_x, date_str)
|
|
stdscr.attroff(curses.color_pair(2))
|
|
|
|
def _draw_menu(self, stdscr, height, width):
|
|
"""Draw the menu options"""
|
|
menu_str = "A: Add Alarm S: List Alarms Q: Quit"
|
|
menu_x = self._center_x(width, len(menu_str))
|
|
stdscr.addstr(height - 2, menu_x, menu_str)
|
|
|
|
def _draw_digit(self, stdscr, y, x, digit):
|
|
"""Draw a single big digit"""
|
|
# Delegate to the existing draw_big_digit utility function
|
|
draw_big_digit(stdscr, y, x, digit)
|
|
|
|
def _center_x(self, width, text_width):
|
|
"""Calculate x coordinate to center text horizontally"""
|
|
return (width - text_width) // 2
|
|
|
|
def _center_y(self, height, text_height):
|
|
"""Calculate y coordinate to center text vertically"""
|
|
return (height - text_height) // 2
|