From 90c542e069281f79dee10bf209a412f9fc6a8762 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Sun, 22 Nov 2026 16:25:40 +0100 Subject: [PATCH] Audit icons: add 1-word hover tooltips Todo: fe70b845 --- .pre-commit-config.yaml | 4 +- pyproject.toml | 4 +- requirements.txt | 4 +- screen_locker/_glyphs.py | 15 ++++++ screen_locker/_heat_skip.py | 3 ++ screen_locker/_tooltip.py | 47 +++++++++++++++++++ screen_locker/_ui_widgets.py | 4 ++ screen_locker/tests/test_tooltip.py | 45 ++++++++++++++++++ .../workout_app/pubspec.lock | 26 +++++----- .../workout_app/pubspec.yaml | 6 +-- 10 files changed, 136 insertions(+), 22 deletions(-) create mode 100644 screen_locker/_tooltip.py create mode 100644 screen_locker/tests/test_tooltip.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b937b45..c3ce112 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -146,7 +146,7 @@ repos: - earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.23.0#subdirectory=earned_time - freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.3#subdirectory=freedays - sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.6#subdirectory=sickdays - - kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.3.1#subdirectory=kuhy_credit + - kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.3.2#subdirectory=kuhy_credit # Same pin as workout_app/tools/render_finish_chime.sh installs. - music_theory @ git+https://github.com/kuhyx/utils@music-theory-v0.1.0#subdirectory=music_theory - mcp>=2,<3 @@ -170,7 +170,7 @@ repos: - earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.23.0#subdirectory=earned_time - freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.3#subdirectory=freedays - sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.6#subdirectory=sickdays - - kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.3.1#subdirectory=kuhy_credit + - kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.3.2#subdirectory=kuhy_credit - mcp>=2,<3 - pydantic diff --git a/pyproject.toml b/pyproject.toml index 47907ab..6b0640b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,9 +11,9 @@ dependencies = [ "crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.11.1#subdirectory=crdt-sync", "freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.3#subdirectory=freedays", "earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.23.0#subdirectory=earned_time", - "kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.3.1#subdirectory=kuhy_credit", + "kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.3.2#subdirectory=kuhy_credit", "holds @ git+https://github.com/kuhyx/utils@holds-v0.1.0#subdirectory=holds", - "sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.6#subdirectory=sickdays", + "sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.8#subdirectory=sickdays", ] [project.scripts] diff --git a/requirements.txt b/requirements.txt index 010bf91..a08403c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.23.0#subdirector freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.3#subdirectory=freedays gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.16.0#subdirectory=gatelock holds @ git+https://github.com/kuhyx/utils@holds-v0.1.0#subdirectory=holds -kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.3.1#subdirectory=kuhy_credit +kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.3.2#subdirectory=kuhy_credit mcp==2.3.0 mypy==2.4.1 pre-commit==4.7.0 @@ -23,7 +23,7 @@ pytest-xdist==3.8.0 # module imports it itself, so it is declared rather than assumed. requests==2.34.2 ruff==0.17.6 -sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.6#subdirectory=sickdays +sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.8#subdirectory=sickdays types-requests==2.33.0.20261030 # Direct dependency since the Firebase session stream (_session_stream) catches # urllib3's own errors on the long-lived SSE read; requests pulls it in, but diff --git a/screen_locker/_glyphs.py b/screen_locker/_glyphs.py index 2c52fad..e22665a 100644 --- a/screen_locker/_glyphs.py +++ b/screen_locker/_glyphs.py @@ -38,6 +38,21 @@ UNLOCK: Final = "□" # the lock stood down OPTIONAL: Final = "◇" # Tue-Thu: a workout is optional today GIFT: Final = "+" # an earned reward, always followed by its amount +# Button glyph text -> the one hover word (textgate tooltip exception). Keys +# are the exact strings passed to the locker's buttons. +TOOLTIP: Final[dict[str, str]] = { + PHONE: "Phone", + FORM: "Manual", + RETRY: "Retry", + CLOSE: "Close", + BACK: "Back", + SKIP: "Skip", + SICK: "Sick", + OK: "Submit", + f"{GO} {LIFT}": "Workout", + GO: "Workout", +} + # Startup phone-check status -> the glyph that replaces its sentence. STATUS_GLYPH: Final[dict[str, str]] = { "too_short": SHORT, diff --git a/screen_locker/_heat_skip.py b/screen_locker/_heat_skip.py index 21bcaf0..29dce97 100644 --- a/screen_locker/_heat_skip.py +++ b/screen_locker/_heat_skip.py @@ -10,6 +10,7 @@ from gatelock import LockConfig, bind_activate, bind_cancel from screen_locker._constants import HEAT_SKIP_CITY, HEAT_SKIP_TEMP_THRESHOLD from screen_locker._credit import place_credit +from screen_locker._tooltip import attach_tooltip if TYPE_CHECKING: from collections.abc import Callable @@ -83,6 +84,7 @@ def build_heat_skip_content( **_COLORS.focus_kwargs(), ) skip_button.pack(side="left", padx=_COLORS.space("sm")) + attach_tooltip(skip_button, "Skip") decline_button = tk.Button( btn_frame, @@ -99,6 +101,7 @@ def build_heat_skip_content( **_COLORS.focus_kwargs(), ) decline_button.pack(side="left", padx=_COLORS.space("sm")) + attach_tooltip(decline_button, "Workout") # This modal grabs input and sits fullscreen with no window decoration, so # the keyboard is the only way out for a pointerless user. It used to diff --git a/screen_locker/_tooltip.py b/screen_locker/_tooltip.py new file mode 100644 index 0000000..08ce383 --- /dev/null +++ b/screen_locker/_tooltip.py @@ -0,0 +1,47 @@ +"""One-word hover tooltips for glyph-only Tk buttons (textgate tooltip exception). + +kuhy allows ONE word naming what an icon means, shown only on hover. The tip +is a Label placed inside the button's own window on and destroyed on + or a click, so no screen paints it until the pointer is on the button. + +Not a Toplevel: on a lock surface gatelock's recovery tick disowns any popup +window within a second (see tests/test_no_popup_widgets.py), so the tip has +to live in the same window as the button it names. +""" + +from __future__ import annotations + +import tkinter as tk + +from screen_locker import _glyphs as g + +_OFFSET = 16 # px below-right of the pointer, so the tip never covers it + + +def tooltip_word(glyph_text: str) -> str | None: + """Return the hover word for a button's glyph text, or None to skip it.""" + return g.TOOLTIP.get(glyph_text) + + +def attach_tooltip(widget: tk.Widget, word: str) -> None: + """Show ``word`` beside the pointer while it hovers ``widget``.""" + tip: list[tk.Label] = [] + + def show(event: tk.Event) -> None: + hide(event) + window = widget.winfo_toplevel() + label = tk.Label(window, text=word) + label.place( + x=event.x_root - window.winfo_rootx() + _OFFSET, + y=event.y_root - window.winfo_rooty() + _OFFSET, + ) + label.lift() + tip.append(label) + + def hide(_event: tk.Event) -> None: + while tip: + tip.pop().destroy() + + widget.bind("", show, add="+") + widget.bind("", hide, add="+") + widget.bind("", hide, add="+") diff --git a/screen_locker/_ui_widgets.py b/screen_locker/_ui_widgets.py index f48f91e..2882ef9 100644 --- a/screen_locker/_ui_widgets.py +++ b/screen_locker/_ui_widgets.py @@ -7,6 +7,7 @@ from typing import TYPE_CHECKING from gatelock import bind_activate +from screen_locker._tooltip import attach_tooltip, tooltip_word from screen_locker._ui_form_fields import UIFormFieldsMixin, disable_paste if TYPE_CHECKING: @@ -163,8 +164,11 @@ class UIWidgetsMixin(UIFormFieldsMixin): ) # Every per-monitor copy, not just `.first` -- one flow paints N screens # and the user may be looking at any of them. + word = tooltip_word(text) for button in buttons: bind_activate(button) + if word is not None: + attach_tooltip(button, word) return buttons def _button_row(self) -> FrameGroup: diff --git a/screen_locker/tests/test_tooltip.py b/screen_locker/tests/test_tooltip.py new file mode 100644 index 0000000..ca429f4 --- /dev/null +++ b/screen_locker/tests/test_tooltip.py @@ -0,0 +1,45 @@ +"""One-word hover tooltips on the glyph buttons.""" + +from __future__ import annotations + +import re +from unittest.mock import MagicMock, patch + +from screen_locker import _glyphs as g +from screen_locker._tooltip import attach_tooltip, tooltip_word + +_WORD = re.compile(r"^[A-Za-z][A-Za-z-]{0,19}$") + + +def test_every_tooltip_is_one_word() -> None: + """Every hover word is one word of at most 20 characters.""" + assert g.TOOLTIP + for word in g.TOOLTIP.values(): + assert _WORD.match(word), word + + +def test_unknown_glyph_has_no_tooltip() -> None: + """A glyph outside the map gets no tooltip; a mapped one gets its word.""" + assert tooltip_word("zzz") is None + assert tooltip_word(g.RETRY) == "Retry" + + +def test_hover_shows_and_leave_hides_the_word() -> None: + """Enter places the word inside the button's own window; Leave destroys it.""" + widget = MagicMock() + window = widget.winfo_toplevel.return_value + window.winfo_rootx.return_value = 4 + window.winfo_rooty.return_value = 6 + handlers = {} + widget.bind.side_effect = lambda seq, fn, add: handlers.__setitem__(seq, fn) + attach_tooltip(widget, "Retry") + assert set(handlers) == {"", "", ""} + event = MagicMock(x_root=10, y_root=20) + with patch("screen_locker._tooltip.tk") as tk_mod: + handlers[""](event) + label = tk_mod.Label.return_value + tk_mod.Label.assert_called_once_with(window, text="Retry") + label.place.assert_called_once_with(x=22, y=30) + tk_mod.Toplevel.assert_not_called() + handlers[""](event) + label.destroy.assert_called_once() diff --git a/stronglift_replacement/workout_app/pubspec.lock b/stronglift_replacement/workout_app/pubspec.lock index d6fac76..d86afa2 100644 --- a/stronglift_replacement/workout_app/pubspec.lock +++ b/stronglift_replacement/workout_app/pubspec.lock @@ -206,11 +206,11 @@ packages: dependency: "direct main" description: path: data_transfer_flutter - ref: "data_transfer_flutter-v0.2.3" - resolved-ref: bb2f92f459283a29ad4864cf37704cc5f749cc6d + ref: "data_transfer_flutter-v0.2.4" + resolved-ref: "5c2effe7d1148830c9e273e47a272791dc17509e" url: "https://github.com/kuhyx/utils" source: git - version: "0.2.3" + version: "0.2.4" dbus: dependency: transitive description: @@ -295,10 +295,10 @@ packages: dependency: transitive description: name: file_picker - sha256: c3780977700b8962c3b9b6a9aa4e2c988956893d70d4a4fa2d7adf4ec9b9eaee + sha256: "5b99250437a4d34ee2cdc0686924452103540eaa1c248094b63f07f9d7216f6c" url: "https://pub.dev" source: hosted - version: "13.4.0" + version: "13.4.1" file_picker_darwin: dependency: transitive description: @@ -311,10 +311,10 @@ packages: dependency: transitive description: name: file_picker_linux - sha256: "9215ee8c672508cdd9a325202669f849e1baac883658626b3abed5d7777e6a4b" + sha256: cf3889644e8e54551f5c3a4f98b6b6ef5f0ef85c07d2a0c1a969538983be2f9b url: "https://pub.dev" source: hosted - version: "2.0.4" + version: "2.0.5" file_picker_platform_interface: dependency: transitive description: @@ -660,11 +660,11 @@ packages: dependency: "direct main" description: path: "kuhy_credit/flutter" - ref: "kuhy-credit-v0.3.1" - resolved-ref: "2352c177232a4b4594573a3b1126697ef32851f7" + ref: "kuhy-credit-v0.3.2" + resolved-ref: adeb40f68e1d6c701da43e396fc46bffa3ef10c7 url: "https://github.com/kuhyx/utils" source: git - version: "0.3.1" + version: "0.3.2" latlong2: dependency: "direct main" description: @@ -1139,11 +1139,11 @@ packages: dependency: "direct main" description: path: sync_settings_ui - ref: "sync_settings_ui-v0.8.4" - resolved-ref: "15ef5b44f186cea0ab163cc88cb8743c51d58247" + ref: "sync_settings_ui-v0.8.5" + resolved-ref: abfb596d7ce2f28acfefbd55e7b3227257325261 url: "https://github.com/kuhyx/utils" source: git - version: "0.8.4" + version: "0.8.5" synchronized: dependency: transitive description: diff --git a/stronglift_replacement/workout_app/pubspec.yaml b/stronglift_replacement/workout_app/pubspec.yaml index 944e1ff..1fcd270 100644 --- a/stronglift_replacement/workout_app/pubspec.yaml +++ b/stronglift_replacement/workout_app/pubspec.yaml @@ -20,7 +20,7 @@ dependencies: data_transfer_flutter: git: url: https://github.com/kuhyx/utils - ref: data_transfer_flutter-v0.2.3 + ref: data_transfer_flutter-v0.2.4 path: data_transfer_flutter # Persistent tile cache for the run map (flutter_map_cache talks to dio). dio: 5.11.1 @@ -53,7 +53,7 @@ dependencies: kuhy_credit: git: url: https://github.com/kuhyx/utils - ref: kuhy-credit-v0.3.1 + ref: kuhy-credit-v0.3.2 path: kuhy_credit/flutter latlong2: 0.10.1 material_ui: 1.11.1 @@ -76,7 +76,7 @@ dependencies: sync_settings_ui: git: url: https://github.com/kuhyx/utils - ref: sync_settings_ui-v0.8.4 + ref: sync_settings_ui-v0.8.5 path: sync_settings_ui url_launcher: 6.3.3 uuid: 4.6.0