From 0a613e98a4884e90fc272527a6f99028903f0438 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 05:50:50 +0000 Subject: [PATCH 1/4] Fix crashes when opening the event dialog and pressing S - event_add_window() drew its layout from a y_offset variable that was never initialised, so opening the Add/Edit Event dialog (clicking the timeline or editing an event) raised UnboundLocalError and closed the app. Initialise it to the same origin the click handler uses. - The S (stats) shortcut passed an undefined name, font_path, and crashed with NameError. Both were hidden from the linter by 'from utility import *'. Adds tests/test_ui_smoke.py, which opens these dialogs in a headless window. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0158w81iQPwdBuV6B2KuQKPw --- main.py | 6 ++++- tests/test_ui_smoke.py | 56 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tests/test_ui_smoke.py diff --git a/main.py b/main.py index c28c503..5ea331e 100644 --- a/main.py +++ b/main.py @@ -3506,6 +3506,10 @@ def event_add_window(pos=None, edit_event=None): content_clip_rect = pygame.Rect(win_x, win_y + 80, win_w, win_h - 150) screen.set_clip(content_clip_rect) + # Layout cursor for this frame; must match y_pos in the click handler above. + # (It was never initialised, so opening this dialog raised UnboundLocalError.) + y_offset = win_y + 90 + # --- Date Selection --- date_label_surf = font_label.render("Date", True, LABEL_COLOR) # noqa date_label_surf.set_alpha(content_alpha) @@ -5329,7 +5333,7 @@ def main_loop(): elif pe.type == pygame.KEYDOWN: if pe.key == pygame.K_s: - show_stats_popup(events, screen , font_cache , font_path , WIDTH , HEIGHT) + show_stats_popup(events, screen, font_cache, settings.get("font_path"), WIDTH, HEIGHT) elif pe.key == pygame.K_t: keys = list(THEMES.keys()) idx = keys.index(current_theme) diff --git a/tests/test_ui_smoke.py b/tests/test_ui_smoke.py new file mode 100644 index 0000000..2cc15f4 --- /dev/null +++ b/tests/test_ui_smoke.py @@ -0,0 +1,56 @@ +"""Render-level smoke tests: open real dialogs in a headless SDL window. + +These catch crashes (NameError, UnboundLocalError, ...) in drawing code that +the unit tests in test_store.py can't reach. +""" +import os +import tempfile + +import pytest + +os.environ.setdefault("SDL_VIDEODRIVER", "dummy") +os.environ.setdefault("SDL_AUDIODRIVER", "dummy") +os.environ.setdefault("FOCI_DATA_DIR", tempfile.mkdtemp(prefix="foci-test-")) + +pygame = pytest.importorskip("pygame") +main = pytest.importorskip("main") + + +class _StopDialog(Exception): + pass + + +@pytest.fixture +def stop_after_frames(monkeypatch): + """Let a modal dialog draw ``n`` frames, then break out of its loop.""" + def install(n): + state = {"frames": 0} + real_flip = pygame.display.flip + + def flip(): + real_flip() + state["frames"] += 1 + if state["frames"] >= n: + raise _StopDialog + monkeypatch.setattr(pygame.display, "flip", flip) + return state + return install + + +@pytest.mark.parametrize("edit", [False, True]) +def test_event_dialog_renders(stop_after_frames, edit): + # Regression: y_offset was never initialised, so opening the Add/Edit Event + # dialog crashed the whole app with UnboundLocalError. + main.load_settings() + existing = {"title": "Gym", "hour": 9, "minute": 0, "duration": 60, "color": [1, 2, 3], "icon": 0} + state = stop_after_frames(30) + with pytest.raises(_StopDialog): + main.event_add_window(pos=(10, 0), edit_event=existing if edit else None) + assert state["frames"] == 30 + + +def test_stats_popup_renders(stop_after_frames): + stop_after_frames(5) + with pytest.raises(_StopDialog): + main.show_stats_popup(main.events, main.screen, main.font_cache, + main.settings.get("font_path"), main.WIDTH, main.HEIGHT) From 8031f47e23434f423a5f82b90e5cf4157f98d53f Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 05:51:22 +0000 Subject: [PATCH 2/4] Add keyboard shortcuts for to-dos, calendar navigation and a help overlay To-dos can now be driven entirely from the keyboard: - Up/Down (or K/J) select a to-do, walking into open folders - Space/Enter checks it off, or opens/closes a folder - 1 / 2 / 3 schedule it for Today / Tomorrow / Someday (works on to-dos inside folders, unlike the right-click menu) - N adds a to-do, Delete removes the selected one, Esc clears selection The selected row gets a highlight ring and is scrolled into view. Calendar: Left/Right change day (or week in weekly view), Home jumps to today, W toggles the weekly view. ? or H opens a shortcuts overlay. The T theme-cycle shortcut now also saves the chosen theme. Navigation logic (visible paths, selection movement, removal) lives in foci_store.py with unit tests; key handling has headless UI tests. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0158w81iQPwdBuV6B2KuQKPw --- foci_store.py | 70 +++++++++++++ main.py | 221 ++++++++++++++++++++++++++++++++++++++--- tests/test_store.py | 51 ++++++++++ tests/test_ui_smoke.py | 69 +++++++++++++ 4 files changed, 395 insertions(+), 16 deletions(-) diff --git a/foci_store.py b/foci_store.py index cb47b35..eda7652 100644 --- a/foci_store.py +++ b/foci_store.py @@ -318,3 +318,73 @@ def todo_tag_label(item, today=None): pass labels = {"today": "Today", "tmr": "Tomorrow"} return labels.get(tag, tag), overdue + + +# --- Keyboard navigation of the to-do tree ---------------------------------- +# A "path" is a tuple of child indexes, e.g. (2,) is the third top-level item +# and (2, 0) is the first child of that folder. + +def visible_todo_paths(items, prefix=()): + """Paths of every row currently shown in the list, in display order. + + Children are included only when their folder is open, so arrow-key + navigation matches what the user sees. + """ + paths = [] + for i, item in enumerate(items): + path = prefix + (i,) + paths.append(path) + if item.get("type") == "folder" and item.get("is_open"): + paths.extend(visible_todo_paths(item.get("children", []), path)) + return paths + + +def get_todo_at(items, path): + """Return the item at ``path`` or ``None`` if the path no longer exists.""" + if not path: + return None + current = None + siblings = items + for index in path: + if not isinstance(siblings, list) or not 0 <= index < len(siblings): + return None + current = siblings[index] + siblings = current.get("children") if current.get("type") == "folder" else None + return current + + +def remove_todo_at(items, path): + """Remove and return the item at ``path`` (``None`` if it doesn't exist).""" + if get_todo_at(items, path) is None: + return None + parent = items if len(path) == 1 else get_todo_at(items, path[:-1])["children"] + return parent.pop(path[-1]) + + +def move_selection(items, current, delta): + """Move the keyboard selection ``delta`` rows up (-) or down (+). + + With no (or a stale) selection, Down starts at the first row and Up at the + last. The selection stops at the ends instead of wrapping. + """ + paths = visible_todo_paths(items) + if not paths: + return None + if current not in paths: + return paths[0] if delta > 0 else paths[-1] + index = max(0, min(len(paths) - 1, paths.index(current) + delta)) + return paths[index] + + +def clamp_selection(items, current): + """Keep a selection valid after the list changes (e.g. a delete).""" + if current is None: + return None + paths = visible_todo_paths(items) + if not paths: + return None + if current in paths: + return current + # Fall back to the nearest row at or before where the old one was. + earlier = [p for p in paths if p < current] + return earlier[-1] if earlier else paths[0] diff --git a/main.py b/main.py index 5ea331e..5703912 100644 --- a/main.py +++ b/main.py @@ -23,6 +23,11 @@ has_completed_todos, remove_completed_todos, todo_tag_label, + visible_todo_paths, + get_todo_at, + remove_todo_at, + move_selection, + clamp_selection, ) pygame.mixer.pre_init(44100, -16, 2, 2048) # Ensure high quality audio pygame.init() @@ -807,7 +812,7 @@ def get_parent_folder_name(path_str, items): -def draw_todo_items_recursive(items, y, level, mouse_pos, dragging_index_path, scroll_offset): +def draw_todo_items_recursive(items, y, level, mouse_pos, dragging_index_path, scroll_offset, path_prefix=()): """ Recursively draws to-do items and folders, handling indentation and open/closed states. Returns the new y-coordinate after drawing. @@ -828,8 +833,12 @@ def draw_todo_items_recursive(items, y, level, mouse_pos, dragging_index_path, s # Pygame's set_clip handles rendering optimizations anyway is_hovered = item_rect.collidepoint(mouse_pos) - bg_color = THEME["todo_item_hover"] if is_hovered else THEME["todo_item_bg"] + is_selected = (path_prefix + (i,)) == selected_todo_path + bg_color = THEME["todo_item_hover"] if (is_hovered or is_selected) else THEME["todo_item_bg"] pygame.draw.rect(screen, bg_color, item_rect, border_radius=8) + if is_selected: + # Keyboard-selection ring + pygame.draw.rect(screen, THEME["progress_bar"], item_rect, 2, border_radius=8) is_folder = item.get("type") == "folder" @@ -911,7 +920,10 @@ def draw_todo_items_recursive(items, y, level, mouse_pos, dragging_index_path, s # If folder is open, recurse if is_folder and item.get("is_open"): children = item.get("children", []) - current_y = draw_todo_items_recursive(children, current_y, level + 1, mouse_pos, dragging_index_path, scroll_offset) + current_y = draw_todo_items_recursive( + children, current_y, level + 1, mouse_pos, dragging_index_path, scroll_offset, + path_prefix + (i,), + ) return current_y @@ -2902,6 +2914,167 @@ def get_recursive_height(inner_items): return find_item_at_pos_recursive(item.get("children", []), (-1,-1), 0, level + 1, 0, path_str=path_parts[1]) return None, None, None +def toggle_todo_done(item): + """Check or uncheck a to-do (and any event created from it), then save.""" + item["done"] = not item.get("done", False) + if "id" in item: + for event_list in all_events.values(): + for ev in event_list: + if ev.get("todo_id") == item["id"]: + ev["done"] = item["done"] + if item["done"]: + trigger_motivational_quote(active_quotes, WIDTH, HEIGHT, get_font_wrapper(22)) + save_todos() + + +# --- Keyboard shortcuts ------------------------------------------------------- + +selected_todo_path = None # path tuple of the to-do highlighted with the keyboard + +SHORTCUTS = [ + ("To-dos", [ + ("Up / Down or K / J", "Select previous / next to-do"), + ("Space or Enter", "Check off to-do / open or close folder"), + ("1 2 3", "Schedule for Today / Tomorrow / Someday"), + ("N", "New to-do"), + ("Delete", "Delete selected to-do"), + ("Esc", "Clear selection"), + ]), + ("Calendar", [ + ("Left / Right", "Previous / next day (week in weekly view)"), + ("Home", "Jump to today"), + ("W", "Toggle weekly view"), + ]), + ("App", [ + ("S", "Today's stats"), + ("T", "Next theme"), + ("? or H", "Show this help"), + ]), +] + + +def scroll_todo_into_view(path): + """Adjust the to-do scroll offset so the keyboard-selected row is visible.""" + global todo_scroll_offset + paths = visible_todo_paths(todos) + if path not in paths: + return + row_top = paths.index(path) * 50 + widget_space = 190 if get_current_event() else 0 + visible_height = (HEIGHT - 70 - widget_space - 50) - 70 + if row_top < todo_scroll_offset: + todo_scroll_offset = row_top + elif row_top + 44 > todo_scroll_offset + visible_height: + todo_scroll_offset = row_top + 44 - visible_height + + +def handle_todo_shortcut(key): + """Handle a to-do keyboard shortcut. Returns True if the key was used.""" + global selected_todo_path, todos + + if key in (pygame.K_DOWN, pygame.K_j, pygame.K_UP, pygame.K_k): + delta = 1 if key in (pygame.K_DOWN, pygame.K_j) else -1 + selected_todo_path = move_selection(todos, selected_todo_path, delta) + if selected_todo_path: + scroll_todo_into_view(selected_todo_path) + return True + + if key == pygame.K_n: + new_todo_details = todo_add_window_v2() + if new_todo_details: + todos.append(new_todo_details) + save_todos() + selected_todo_path = (len(todos) - 1,) + scroll_todo_into_view(selected_todo_path) + return True + + if key == pygame.K_ESCAPE: + selected_todo_path = None + return True + + item = get_todo_at(todos, selected_todo_path) + if item is None: + selected_todo_path = None + return False + + is_folder = item.get("type") == "folder" + if key in (pygame.K_SPACE, pygame.K_RETURN, pygame.K_KP_ENTER): + if is_folder: + item["is_open"] = not item.get("is_open", False) + save_todos() + else: + toggle_todo_done(item) + return True + + schedule_keys = {pygame.K_1: "today", pygame.K_2: "tomorrow", pygame.K_3: "someday"} + if key in schedule_keys and not is_folder: + schedule_todo(item, schedule_keys[key]) + save_todos() + return True + + if key in (pygame.K_DELETE, pygame.K_BACKSPACE): + name = item.get("name") if is_folder else item.get("title") + if not is_folder or show_confirmation_dialog(f"Delete '{name}'?"): + remove_todo_at(todos, selected_todo_path) + save_todos() + selected_todo_path = clamp_selection(todos, selected_todo_path) + return True + + return False + + +def show_shortcuts_help(): + """Modal overlay listing every keyboard shortcut. Any key or click closes it.""" + background = screen.copy() + overlay = pygame.Surface((WIDTH, HEIGHT), pygame.SRCALPHA) + overlay.fill((0, 0, 0, 150)) + title_font = get_font_wrapper(26) + section_font = get_font_wrapper(17) + key_font = get_font_wrapper(15) + row_h, gap = 26, 14 + rows = sum(len(items) for _, items in SHORTCUTS) + win_w = min(600, WIDTH - 40) + win_h = 70 + len(SHORTCUTS) * (section_font.get_height() + gap) + rows * row_h + 50 + win = pygame.Rect(0, 0, win_w, win_h) + win.center = (WIDTH // 2, HEIGHT // 2) + clock = pygame.time.Clock() + + while True: + screen.blit(background, (0, 0)) + screen.blit(overlay, (0, 0)) + pygame.draw.rect(screen, THEME["settings_bg"], win, border_radius=18) + pygame.draw.rect(screen, THEME["hour_line"], win, 1, border_radius=18) + + title = title_font.render("Keyboard shortcuts", True, THEME["text"]) + screen.blit(title, (win.centerx - title.get_width() // 2, win.y + 20)) + y = win.y + 70 + for section, items in SHORTCUTS: + label = section_font.render(section, True, THEME["title_color"]) + screen.blit(label, (win.x + 30, y)) + y += label.get_height() + 6 + for keys, action in items: + key_surf = key_font.render(keys, True, THEME["text"]) + pill = pygame.Rect(win.x + 30, y, key_surf.get_width() + 14, row_h - 4) + pygame.draw.rect(screen, THEME["button_bg"], pill, border_radius=6) + screen.blit(key_surf, key_surf.get_rect(center=pill.center)) + action_surf = key_font.render(action, True, THEME["text"]) + screen.blit(action_surf, (win.x + 230, y + (row_h - 4 - action_surf.get_height()) // 2)) + y += row_h + y += gap - 6 + + hint = key_font.render("Press any key to close", True, THEME["title_color"]) + screen.blit(hint, (win.centerx - hint.get_width() // 2, win.bottom - 32)) + pygame.display.flip() + + for e in pygame.event.get(): + if e.type == pygame.QUIT: + pygame.quit() + sys.exit() + if e.type in (pygame.KEYDOWN, pygame.MOUSEBUTTONDOWN): + return + clock.tick(60) + + def check_or_delete_todo_at_pos(pos, scroll_offset=0): """Checks for clicks on a todo's checkbox or delete button.""" x, my = pos @@ -2936,15 +3109,7 @@ def check_or_delete_todo_at_pos(pos, scroll_offset=0): # It's a to-do, check for checkbox click checkbox_rect = pygame.Rect(item_rect.x + 8, item_rect.centery - CHECKBOX_SIZE // 2, CHECKBOX_SIZE, CHECKBOX_SIZE) if checkbox_rect.collidepoint(x, my): - item["done"] = not item.get("done", False) - if "id" in item: - for event_list in all_events.values(): - for ev in event_list: - if ev.get("todo_id") == item["id"]: - ev["done"] = item["done"] - if item["done"]: - trigger_motivational_quote(active_quotes, WIDTH, HEIGHT, get_font_wrapper(22)) - save_todos() + toggle_todo_done(item) return True return False @@ -4837,6 +5002,18 @@ def main_loop(): load_events() weekly_view = False break + elif pe.type == pygame.KEYDOWN: + if pe.key in (pygame.K_w, pygame.K_ESCAPE): + weekly_view = False + elif pe.key == pygame.K_LEFT: + current_week_start -= datetime.timedelta(weeks=1) + elif pe.key == pygame.K_RIGHT: + current_week_start += datetime.timedelta(weeks=1) + elif pe.key == pygame.K_HOME: + today = datetime.date.today() + current_week_start = today - datetime.timedelta(days=today.weekday()) + elif pe.key == pygame.K_h or pe.unicode == "?": + show_shortcuts_help() clock.tick(60) continue @@ -5332,16 +5509,28 @@ def main_loop(): resizing_event["duration"] = int(new_minutes) elif pe.type == pygame.KEYDOWN: + if handle_todo_shortcut(pe.key): + continue if pe.key == pygame.K_s: + # (used to pass an undefined `font_path` and crash the app) show_stats_popup(events, screen, font_cache, settings.get("font_path"), WIDTH, HEIGHT) elif pe.key == pygame.K_t: keys = list(THEMES.keys()) idx = keys.index(current_theme) set_theme(keys[(idx + 1) % len(keys)]) - elif pe.key == pygame.K_c: - curr = get_current_event() - # if curr: - # run_green_ring_focus_timer(curr) + settings["theme"] = keys[(idx + 1) % len(keys)] + save_settings() + elif pe.key in (pygame.K_LEFT, pygame.K_RIGHT): + selected_date += datetime.timedelta(days=-1 if pe.key == pygame.K_LEFT else 1) + load_events() + elif pe.key == pygame.K_HOME: + selected_date = datetime.date.today() + load_events() + elif pe.key == pygame.K_w: + weekly_view = True + current_week_start = selected_date - datetime.timedelta(days=selected_date.weekday()) + elif pe.key == pygame.K_h or pe.unicode == "?": + show_shortcuts_help() # --- Update and Draw Animations --- current_time = time.time() diff --git a/tests/test_store.py b/tests/test_store.py index 9788a19..f86a875 100644 --- a/tests/test_store.py +++ b/tests/test_store.py @@ -287,3 +287,54 @@ def test_app_root_does_not_depend_on_cwd(monkeypatch, tmp_path): monkeypatch.delattr("sys._MEIPASS", raising=False) monkeypatch.chdir(tmp_path) assert os.path.isfile(os.path.join(store.app_root(), "main.py")) + + +# --- keyboard navigation ---------------------------------------------------- + +def _tree(): + return [ + {"type": "todo", "title": "a"}, + {"type": "folder", "name": "F", "is_open": True, "children": [ + {"type": "todo", "title": "f1"}, + {"type": "folder", "name": "closed", "is_open": False, "children": [ + {"type": "todo", "title": "hidden"}, + ]}, + ]}, + {"type": "todo", "title": "b"}, + ] + + +def test_visible_paths_skip_closed_folders(): + assert store.visible_todo_paths(_tree()) == [(0,), (1,), (1, 0), (1, 1), (2,)] + assert store.visible_todo_paths([]) == [] + + +def test_get_todo_at(): + tree = _tree() + assert store.get_todo_at(tree, (1, 0))["title"] == "f1" + assert store.get_todo_at(tree, (1, 1, 0))["title"] == "hidden" + assert store.get_todo_at(tree, (9,)) is None + assert store.get_todo_at(tree, (0, 0)) is None # a to-do has no children + assert store.get_todo_at(tree, ()) is None + + +def test_move_selection(): + tree = _tree() + assert store.move_selection(tree, None, +1) == (0,) + assert store.move_selection(tree, None, -1) == (2,) + assert store.move_selection(tree, (1,), +1) == (1, 0) + assert store.move_selection(tree, (1, 1), +1) == (2,) # skips hidden child + assert store.move_selection(tree, (2,), +1) == (2,) # stops at the end + assert store.move_selection(tree, (0,), -1) == (0,) + assert store.move_selection([], None, +1) is None + + +def test_remove_todo_at_and_clamp(): + tree = _tree() + assert store.remove_todo_at(tree, (1, 0))["title"] == "f1" + assert store.remove_todo_at(tree, (7,)) is None + assert store.clamp_selection(tree, (1, 1)) == (1, 0) + store.remove_todo_at(tree, (2,)) + assert store.clamp_selection(tree, (2,)) == (1, 0) + assert store.clamp_selection([], (0,)) is None + assert store.clamp_selection(tree, None) is None diff --git a/tests/test_ui_smoke.py b/tests/test_ui_smoke.py index 2cc15f4..8b64413 100644 --- a/tests/test_ui_smoke.py +++ b/tests/test_ui_smoke.py @@ -54,3 +54,72 @@ def test_stats_popup_renders(stop_after_frames): with pytest.raises(_StopDialog): main.show_stats_popup(main.events, main.screen, main.font_cache, main.settings.get("font_path"), main.WIDTH, main.HEIGHT) + + +# --- keyboard shortcuts ----------------------------------------------------- + +@pytest.fixture +def sample_todos(monkeypatch): + todos = [ + {"type": "todo", "title": "a", "done": False}, + {"type": "folder", "name": "F", "is_open": True, "children": [ + {"type": "todo", "title": "f1", "done": False}, + ]}, + ] + monkeypatch.setattr(main, "todos", todos) + monkeypatch.setattr(main, "selected_todo_path", None) + monkeypatch.setattr(main, "save_todos", lambda: None) + monkeypatch.setattr(main, "trigger_motivational_quote", lambda *a, **k: None) + return todos + + +def test_arrow_keys_walk_into_open_folders(sample_todos): + for _ in range(3): + assert main.handle_todo_shortcut(pygame.K_DOWN) + assert main.selected_todo_path == (1, 0) + main.handle_todo_shortcut(pygame.K_k) + assert main.selected_todo_path == (1,) + + +def test_space_checks_off_nested_todo(sample_todos): + main.selected_todo_path = (1, 0) + assert main.handle_todo_shortcut(pygame.K_SPACE) + assert sample_todos[1]["children"][0]["done"] is True + + +def test_space_on_folder_toggles_it(sample_todos): + main.selected_todo_path = (1,) + main.handle_todo_shortcut(pygame.K_RETURN) + assert sample_todos[1]["is_open"] is False + + +def test_number_keys_schedule(sample_todos): + main.selected_todo_path = (0,) + main.handle_todo_shortcut(pygame.K_2) + assert sample_todos[0]["tag"] == "tmr" + main.handle_todo_shortcut(pygame.K_3) + assert "tag" not in sample_todos[0] + + +def test_delete_key_removes_and_keeps_selection_valid(sample_todos): + main.selected_todo_path = (1, 0) + main.handle_todo_shortcut(pygame.K_DELETE) + assert sample_todos[1]["children"] == [] + assert main.selected_todo_path == (1,) + + +def test_keys_without_selection_are_ignored(sample_todos): + assert main.handle_todo_shortcut(pygame.K_SPACE) is False + assert main.handle_todo_shortcut(pygame.K_1) is False + assert main.handle_todo_shortcut(pygame.K_ESCAPE) is True + + +def test_selected_row_is_drawn(sample_todos, monkeypatch): + main.selected_todo_path = (1, 0) + main.draw_todo_list((-100, -100)) # must not raise + + +def test_shortcuts_help_closes_on_key(monkeypatch): + pygame.event.clear() + pygame.event.post(pygame.event.Event(pygame.KEYDOWN, key=pygame.K_a, unicode="a", mod=0, scancode=0)) + main.show_shortcuts_help() # returns instead of looping forever From fb4581b9d72f552344527a7b610f475a4c5e47c5 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 05:52:05 +0000 Subject: [PATCH 3/4] Add three themes: Ocean Breeze, Lavender Dusk and Matcha Latte - Ocean Breeze: light sea-foam with a slow aqua/sky gradient - Lavender Dusk: dark twilight violet with a plum gradient - Matcha Latte: warm cream and matcha green, no gradient Adds a test that every theme defines all the colour keys the UI reads and that the day view and to-do list render with it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0158w81iQPwdBuV6B2KuQKPw --- main.py | 73 ++++++++++++++++++++++++++++++++++++++++++ tests/test_ui_smoke.py | 23 +++++++++++++ 2 files changed, 96 insertions(+) diff --git a/main.py b/main.py index 5703912..dc7ba30 100644 --- a/main.py +++ b/main.py @@ -386,6 +386,79 @@ def get_font_wrapper(size): (255, 192, 203), # Pink ], }, + "Ocean Breeze": { + "background": (236, 248, 250), # Sea-foam white + "text": (30, 60, 75), + "event_done_color": (190, 225, 215), + "event_dimmed": (205, 225, 232), + "hour_line": (190, 215, 225), + "title_color": (0, 119, 145), # Deep teal + "progress_bar": (0, 150, 170), + "current_event_dim": (150, 210, 225), + "settings_bg": (245, 252, 253), + "todo_bg": (214, 236, 242), + "todo_item_bg": (238, 248, 251), + "todo_item_hover": (226, 242, 247), + "button_bg": (200, 228, 236), + "gradient_start": (178, 235, 242), # Light aqua + "gradient_end": (204, 229, 255), # Pale sky + "use_gradient_bg": True, + "color_choices": [ + (128, 203, 196), # Seafoam + (144, 202, 249), # Sky + (255, 224, 178), # Sand + (179, 229, 252), # Shallow water + (248, 187, 208), # Coral pink + ], + }, + "Lavender Dusk": { + "background": (36, 30, 52), # Deep violet + "text": (230, 222, 245), + "event_done_color": (60, 70, 70), + "event_dimmed": (62, 54, 82), + "hour_line": (70, 60, 95), + "title_color": (200, 180, 255), + "progress_bar": (167, 139, 250), + "current_event_dim": (130, 110, 190), + "settings_bg": (44, 37, 63), + "todo_bg": (40, 33, 58), + "todo_item_bg": (54, 46, 78), + "todo_item_hover": (66, 57, 94), + "button_bg": (70, 60, 100), + "gradient_start": (45, 35, 70), # Twilight + "gradient_end": (70, 45, 85), # Plum + "use_gradient_bg": True, + "color_choices": [ + (167, 139, 250), # Lavender + (244, 143, 177), # Rose + (128, 222, 234), # Cyan glow + (255, 204, 128), # Lamp light + (129, 199, 132), # Sage + ], + }, + "Matcha Latte": { + "background": (246, 243, 232), # Warm cream + "text": (60, 66, 46), + "event_done_color": (200, 220, 180), + "event_dimmed": (226, 224, 210), + "hour_line": (222, 216, 196), + "title_color": (96, 128, 56), # Matcha green + "progress_bar": (124, 160, 82), + "current_event_dim": (190, 210, 160), + "settings_bg": (250, 248, 240), + "todo_bg": (232, 230, 212), + "todo_item_bg": (247, 245, 236), + "todo_item_hover": (238, 236, 222), + "button_bg": (220, 226, 196), + "use_gradient_bg": False, + "color_choices": [ + (174, 203, 132), # Matcha + (222, 196, 160), # Latte + (240, 214, 170), # Oat + (196, 220, 190), # Mint + (232, 190, 172), # Hojicha + ], + }, } current_theme = "Serene Morning" diff --git a/tests/test_ui_smoke.py b/tests/test_ui_smoke.py index 8b64413..f83353e 100644 --- a/tests/test_ui_smoke.py +++ b/tests/test_ui_smoke.py @@ -123,3 +123,26 @@ def test_shortcuts_help_closes_on_key(monkeypatch): pygame.event.clear() pygame.event.post(pygame.event.Event(pygame.KEYDOWN, key=pygame.K_a, unicode="a", mod=0, scancode=0)) main.show_shortcuts_help() # returns instead of looping forever + + +# --- themes ----------------------------------------------------------------- + +REQUIRED_THEME_KEYS = { + "background", "text", "event_done_color", "event_dimmed", "hour_line", + "title_color", "progress_bar", "current_event_dim", "settings_bg", + "todo_bg", "todo_item_bg", "todo_item_hover", "button_bg", "color_choices", +} + + +@pytest.mark.parametrize("name", list(main.THEMES)) +def test_every_theme_is_complete_and_renders(name, monkeypatch): + theme = main.THEMES[name] + assert REQUIRED_THEME_KEYS <= theme.keys(), REQUIRED_THEME_KEYS - theme.keys() + if theme.get("use_gradient_bg"): + assert {"gradient_start", "gradient_end"} <= theme.keys() + assert len(theme["color_choices"]) == 5 + monkeypatch.setattr(main, "THEME", theme) + monkeypatch.setattr(main, "current_theme", name) + layout = main.calculate_event_layout(main.events, main.WIDTH - main.EVENT_X - main.EVENT_RIGHT_MARGIN) + main.draw_day_view(layout) + main.draw_todo_list((-1, -1)) From 323539b626dc13e86094ee528fc6c7eaf931f8cf Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 05:52:19 +0000 Subject: [PATCH 4/4] Docs: keyboard shortcuts, new themes and acknowledgements Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0158w81iQPwdBuV6B2KuQKPw --- CHANGELOG.md | 5 +++++ README.md | 27 ++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7a5cae..75a4569 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ All notable changes to Foci are documented here. The format follows [Keep a Chan ## [Unreleased] ### Fixed +- **Opening the Add/Edit Event dialog crashed the app** (`UnboundLocalError: y_offset`). +- Pressing S for stats crashed the app (`NameError: font_path`). - **Packaged app lost all data on restart.** The one-file `.exe` wrote events, to-dos, settings and coins into PyInstaller's temporary extraction folder, which is deleted on exit. User data now lives in the OS app-data folder for packaged builds (`%APPDATA%\Foci` etc.) and stays in `assets/` when running from source. - Launching `python path/to/main.py` from a different directory couldn't find fonts, icons or the coin sprite sheet. Resources now resolve relative to the app, not the working directory. - "Schedule for Tomorrow" set the `tmr` tag and then immediately deleted it. @@ -16,6 +18,8 @@ All notable changes to Foci are documented here. The format follows [Keep a Chan - Packaged builds call `multiprocessing.freeze_support()` so the lofi player subprocess starts correctly. ### Added +- **Keyboard shortcuts** for to-dos (select, check off, schedule, add, delete) and calendar navigation, plus a ? help overlay. Suggested by Fazal. +- **Three new themes**: Ocean Breeze, Lavender Dusk and Matcha Latte. Suggested by Anaconda bro. - To-dos show a date pill (*Today*, *Tomorrow*, *on Mon*), red when overdue. - `FOCI_DATA_DIR` environment variable to choose where data is stored. - `foci_store.py`: persistence and validation split out of `main.py` so it can be tested. @@ -24,6 +28,7 @@ All notable changes to Foci are documented here. The format follows [Keep a Chan ### Changed - The built executable is named `Foci.exe` instead of `main.exe`. +- The T theme shortcut now remembers the chosen theme. ## [1.0.0] - initial release diff --git a/README.md b/README.md index a3d01ab..27dcda9 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ Both files are git-ignored and must never be committed. - **Windows SMTC integration** — registers with the system media flyout so track name appears in the tray and media keys (⏯ ⏭ ⏮) work system-wide ### Themes & fonts -- 8 built-in themes: **Serene Morning**, **Golden Hour**, **Midnight Deep**, **Cyberpunk Night**, **Forest Canopy**, **Classic Light**, **Classic Dark**, **Kyoto Spring** +- 11 built-in themes: **Serene Morning**, **Golden Hour**, **Midnight Deep**, **Cyberpunk Night**, **Forest Canopy**, **Classic Light**, **Classic Dark**, **Kyoto Spring**, and new in this release **Ocean Breeze**, **Lavender Dusk** and **Matcha Latte** (suggested by **Anaconda bro**) - Several themes feature animated slow-wave gradient backgrounds - Font picker scans `assets/` for any `.ttf` / `.otf` and previews them live (ships with Domine, Roboto, Arimo, SansCode, RobotoCondensed) @@ -155,6 +155,24 @@ Both files are git-ignored and must never be committed. ### Stats - Animated donut charts (ease-out cubic) showing tasks completed % and time focused % for the day +### Keyboard shortcuts +*Suggested by **Fazal**.* Press ? in the app to see them all. + +| Keys | Action | +|---|---| +| ↑ ↓ or K J | Select previous / next to-do (walks into open folders) | +| Space / Enter | Check off the selected to-do, or open / close a folder | +| 1 2 3 | Schedule for Today / Tomorrow / Someday | +| N | New to-do | +| Delete | Delete the selected to-do | +| Esc | Clear the selection | +| ← → | Previous / next day (week, in weekly view) | +| Home | Jump to today | +| W | Toggle weekly view | +| S | Today's stats | +| T | Next theme | +| ? / H | Show the shortcuts overlay | + ### Weekly view - 7-column overview with event cards per day; click a day to jump to it; today column is highlighted @@ -195,6 +213,13 @@ The files in `assets/` are git-ignored. Copy an `*.example.json` to get started, --- +## Acknowledgements + +Thanks to the people who've shaped Foci with their ideas: + +- **Fazal**: suggested keyboard shortcuts for getting around tasks quickly +- **Anaconda bro**: suggested the Ocean Breeze, Lavender Dusk and Matcha Latte themes + ## Contributing Bug reports, ideas and pull requests are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for setup, the project layout and how to run the tests. Changes are tracked in [CHANGELOG.md](CHANGELOG.md).