Audit icons: add 1-word hover tooltips

Todo: fe70b845
This commit is contained in:
Krzysztof Rudnicki 2026-11-22 16:25:40 +01:00
parent 5c1bfb93ec
commit 90c542e069
10 changed files with 136 additions and 22 deletions

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -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,

View File

@ -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

47
screen_locker/_tooltip.py Normal file
View File

@ -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 <Enter> and destroyed on
<Leave> 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("<Enter>", show, add="+")
widget.bind("<Leave>", hide, add="+")
widget.bind("<ButtonPress>", hide, add="+")

View File

@ -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:

View File

@ -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) == {"<Enter>", "<Leave>", "<ButtonPress>"}
event = MagicMock(x_root=10, y_root=20)
with patch("screen_locker._tooltip.tk") as tk_mod:
handlers["<Enter>"](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["<Leave>"](event)
label.destroy.assert_called_once()

View File

@ -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:

View File

@ -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