109 lines
3.9 KiB
Python
109 lines
3.9 KiB
Python
import curses
|
|
from datetime import datetime
|
|
from .utils import init_colors
|
|
|
|
def draw_add_alarm(stdscr, alarm_draft):
|
|
"""Draw the add alarm screen"""
|
|
if alarm_draft is None:
|
|
alarm_draft = {
|
|
'hour': datetime.now().hour,
|
|
'minute': datetime.now().minute,
|
|
'name': 'New Alarm',
|
|
'enabled': True,
|
|
'date': None,
|
|
'weekdays': [],
|
|
'current_weekday': 0,
|
|
'editing_name': False,
|
|
'temp_name': '',
|
|
'selected_item': 0 # Added to handle selection
|
|
}
|
|
|
|
init_colors()
|
|
height, width = stdscr.getmaxyx()
|
|
|
|
# Center the form vertically with good spacing
|
|
form_y = height // 2 - 8
|
|
|
|
# Title
|
|
title = "Add New Alarm"
|
|
stdscr.attron(curses.color_pair(1) | curses.A_BOLD)
|
|
stdscr.addstr(form_y, width // 2 - len(title) // 2, title)
|
|
stdscr.attroff(curses.color_pair(1) | curses.A_BOLD)
|
|
|
|
def draw_field(y, label, value, is_selected):
|
|
label_str = f"{label}: "
|
|
x = width // 2 - (len(label_str) + len(str(value))) // 2
|
|
stdscr.attron(curses.color_pair(1))
|
|
stdscr.addstr(y, x, label_str)
|
|
stdscr.attroff(curses.color_pair(1))
|
|
|
|
# Draw value (highlighted if selected)
|
|
if is_selected:
|
|
stdscr.attron(curses.color_pair(2)) # Highlighted selection
|
|
stdscr.addstr(y, x + len(label_str), str(value))
|
|
if is_selected:
|
|
stdscr.attroff(curses.color_pair(2))
|
|
|
|
# Get selected_item either from alarm_draft or passed separately
|
|
selected_item = alarm_draft.get('selected_item', 0)
|
|
|
|
# Order: Time → Date → Weekdays → Name → Enabled
|
|
draw_field(form_y + 2, "Time", f"{alarm_draft['hour']:02d}:{alarm_draft['minute']:02d}",
|
|
selected_item == 0 or selected_item == 1)
|
|
|
|
# Date Selection
|
|
date_y = form_y + 4
|
|
if alarm_draft['weekdays']:
|
|
draw_field(date_y, "Date", "Repeating weekly", selected_item == 2)
|
|
else:
|
|
draw_field(date_y, "Date", alarm_draft['date'].strftime("%Y-%m-%d") if alarm_draft['date'] else "None",
|
|
selected_item == 2)
|
|
|
|
# Weekday Selection
|
|
weekday_y = form_y + 6
|
|
weekday_label = "Repeat: "
|
|
label_x = width // 2 - 20 # Adjust this value to move the entire "Repeat" section left or right
|
|
|
|
# Draw the "Repeat: " label once
|
|
stdscr.attron(curses.color_pair(1))
|
|
stdscr.addstr(weekday_y, label_x, weekday_label)
|
|
stdscr.attroff(curses.color_pair(1))
|
|
|
|
# Draw weekdays starting right after the label
|
|
weekday_x = label_x + len(weekday_label)
|
|
weekday_names = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
|
for i, day in enumerate(weekday_names):
|
|
x_pos = weekday_x + i * 4 # Space between weekdays
|
|
is_selected = (selected_item == 3 and i == alarm_draft.get('current_weekday', 0))
|
|
is_active = i in alarm_draft.get('weekdays', [])
|
|
|
|
if is_selected:
|
|
stdscr.attron(curses.color_pair(2)) # Highlight current selection
|
|
elif is_active:
|
|
stdscr.attron(curses.color_pair(1) | curses.A_BOLD) # Selected weekday
|
|
else:
|
|
stdscr.attron(curses.color_pair(1))
|
|
|
|
stdscr.addstr(weekday_y, x_pos, day)
|
|
|
|
if is_selected:
|
|
stdscr.attroff(curses.color_pair(2))
|
|
elif is_active:
|
|
stdscr.attroff(curses.color_pair(1) | curses.A_BOLD)
|
|
else:
|
|
stdscr.attroff(curses.color_pair(1))
|
|
|
|
# Name field
|
|
draw_field(form_y + 8, "Name", alarm_draft['name'], selected_item == 4)
|
|
|
|
# Enabled Toggle
|
|
status_y = form_y + 10
|
|
enabled_str = "● Enabled" if alarm_draft['enabled'] else "○ Disabled"
|
|
draw_field(status_y, "Status", enabled_str, selected_item == 5)
|
|
|
|
# Instructions
|
|
instructions = "j/k: Change h/l: Move Space: Toggle Enter: Save Esc: Cancel"
|
|
stdscr.attron(curses.color_pair(1))
|
|
stdscr.addstr(height - 2, width // 2 - len(instructions) // 2, instructions)
|
|
stdscr.attroff(curses.color_pair(1))
|