Fix on-fill text contrast on filled buttons, bump gatelock pin

_ui_widgets.py's _button() always set fg=self._colors.fg (near-white)
regardless of bg, so any accent/success/warning/danger-filled button
under-contrasted (measured 2.2-3.6:1 vs the 4.5:1 floor). Added
_fg_for(bg) so fg is derived from bg instead of hardcoded -- fixes every
current _button() call site structurally, not per-instance. Found and
fixed 2 more standalone instances of the same bug outside the shared
helper (_window_setup.py's demo-close button, _heat_skip.py's heat-skip
button).

Bumps gatelock to the released v0.1.1 carrying the same on_fill token
plus the warm palette rework. Regenerated workout_app's launcher icon
assets to match.

Verified: gatelock 50/50 + screen_locker 859/859 tests, both 100%
coverage; pre-commit (incl. pylint against the real v0.1.1 install) green.
This commit is contained in:
Krzysztof Rudnicki 2026-07-21 21:17:14 +02:00
parent 541db3701d
commit 6629260256
21 changed files with 90 additions and 62 deletions

View File

@ -98,7 +98,7 @@ repos:
- --jobs=4 - --jobs=4
additional_dependencies: additional_dependencies:
- pytest - pytest
- gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.1.0#subdirectory=gatelock - gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.1.1#subdirectory=gatelock
- crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.1.0#subdirectory=crdt-sync - crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.1.0#subdirectory=crdt-sync
- mcp - mcp
- pydantic - pydantic

View File

@ -7,7 +7,7 @@ requires-python = ">=3.10"
# crdt-sync: shared CRDT merge scheme + GitHub-Contents-API sync transport, # crdt-sync: shared CRDT merge scheme + GitHub-Contents-API sync transport,
# also used by diet_guard; here for phone-workout GitHub sync (Workstream C) # also used by diet_guard; here for phone-workout GitHub sync (Workstream C)
dependencies = [ dependencies = [
"gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.1.0#subdirectory=gatelock", "gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.1.1#subdirectory=gatelock",
"crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.1.0#subdirectory=crdt-sync", "crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.1.0#subdirectory=crdt-sync",
] ]

View File

@ -4,7 +4,7 @@ bandit>=1.7.0
codespell>=2.2.0 codespell>=2.2.0
coverage>=7.4.0 coverage>=7.4.0
crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.1.0#subdirectory=crdt-sync crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.1.0#subdirectory=crdt-sync
gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.1.0#subdirectory=gatelock gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.1.1#subdirectory=gatelock
mcp>=1.9 mcp>=1.9
mypy>=1.8.0 mypy>=1.8.0
pre-commit>=3.6.0 pre-commit>=3.6.0

View File

@ -5,15 +5,17 @@ from __future__ import annotations
import logging import logging
import tkinter as tk import tkinter as tk
from gatelock import LockConfig
from screen_locker._constants import HEAT_SKIP_CITY, HEAT_SKIP_TEMP_THRESHOLD from screen_locker._constants import HEAT_SKIP_CITY, HEAT_SKIP_TEMP_THRESHOLD
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
_BG = "#1a1a1a" # Sourced from the shared gatelock LockConfig (unified-design-system) instead
_FG_MAIN = "#ff9900" # of a locally-invented token block -- this was the one file in the package
_FG_SUB = "#cccccc" # that already knew centralizing tokens was worth doing; now it points at
_BTN_SKIP = "#cc4400" # the actual shared source instead of its own unshared copy.
_BTN_NO = "#333333" _COLORS = LockConfig()
_FONT = "monospace" _FONT = "monospace"
@ -33,22 +35,22 @@ class HeatSkipMixin:
# This window is destroyed before the main GateRoot is created. # This window is destroyed before the main GateRoot is created.
root = tk.Tk() root = tk.Tk()
root.title("Extreme Heat") root.title("Extreme Heat")
root.configure(bg=_BG) root.configure(bg=_COLORS.bg)
root.attributes("-fullscreen", True) root.attributes("-fullscreen", True)
root.attributes("-topmost", True) root.attributes("-topmost", True)
root.grab_set() root.grab_set()
root.focus_force() root.focus_force()
# Content centred on the fullscreen canvas # Content centred on the fullscreen canvas
outer = tk.Frame(root, bg=_BG) outer = tk.Frame(root, bg=_COLORS.bg)
outer.place(relx=0.5, rely=0.5, anchor="center") outer.place(relx=0.5, rely=0.5, anchor="center")
tk.Label( tk.Label(
outer, outer,
text="☀ Too hot to workout?", text="☀ Too hot to workout?",
font=(_FONT, 18, "bold"), font=(_FONT, 18, "bold"),
bg=_BG, bg=_COLORS.bg,
fg=_FG_MAIN, fg=_COLORS.warning,
).pack(pady=(0, 10)) ).pack(pady=(0, 10))
tk.Label( tk.Label(
@ -57,20 +59,20 @@ class HeatSkipMixin:
f"{HEAT_SKIP_CITY}: {temp:.0f}°C" f"{HEAT_SKIP_CITY}: {temp:.0f}°C"
f" (threshold: {HEAT_SKIP_TEMP_THRESHOLD}°C)" f" (threshold: {HEAT_SKIP_TEMP_THRESHOLD}°C)"
), ),
font=(_FONT, 13), font=(_FONT, 16),
bg=_BG, bg=_COLORS.bg,
fg=_FG_SUB, fg=_COLORS.muted,
).pack(pady=6) ).pack(pady=6)
tk.Label( tk.Label(
outer, outer,
text="Skip today's workout due to extreme heat?", text="Skip today's workout due to extreme heat?",
font=(_FONT, 12), font=(_FONT, 16),
bg=_BG, bg=_COLORS.bg,
fg=_FG_SUB, fg=_COLORS.muted,
).pack(pady=(6, 0)) ).pack(pady=(6, 0))
btn_frame = tk.Frame(outer, bg=_BG) btn_frame = tk.Frame(outer, bg=_COLORS.bg)
btn_frame.pack(pady=28) btn_frame.pack(pady=28)
def _on_skip() -> None: def _on_skip() -> None:
@ -85,12 +87,12 @@ class HeatSkipMixin:
btn_frame, btn_frame,
text="Skip workout", text="Skip workout",
command=_on_skip, command=_on_skip,
bg=_BTN_SKIP, bg=_COLORS.warning,
fg="white", fg=_COLORS.on_fill,
activebackground="#aa3300", activebackground=_COLORS.warning,
font=(_FONT, 11), font=(_FONT, 14),
padx=14, padx=16,
pady=5, pady=8,
relief="flat", relief="flat",
).pack(side="left", padx=12) ).pack(side="left", padx=12)
@ -98,12 +100,12 @@ class HeatSkipMixin:
btn_frame, btn_frame,
text="No, I'll workout", text="No, I'll workout",
command=_on_no, command=_on_no,
bg=_BTN_NO, bg=_COLORS.field_bg,
fg="white", fg=_COLORS.fg,
activebackground="#444444", activebackground=_COLORS.field_bg,
font=(_FONT, 11), font=(_FONT, 14),
padx=14, padx=16,
pady=5, pady=8,
relief="flat", relief="flat",
).pack(side="left", padx=12) ).pack(side="left", padx=12)

View File

@ -35,16 +35,16 @@ class UIWidgetsMixin:
text: str, text: str,
*, *,
font_size: int = 36, font_size: int = 36,
color: str = "white", color: str | None = None,
pady: int = 20, pady: int = 20,
) -> tk.Label: ) -> tk.Label:
"""Create and pack a bold label in the container.""" """Create and pack a bold label in the container."""
label = tk.Label( label = tk.Label(
self.container, self.container,
text=text, text=text,
font=("Arial", font_size, "bold"), font=(self._colors.font_family, font_size, "bold"),
fg=color, fg=color or self._colors.fg,
bg="#1a1a1a", bg=self._colors.bg,
) )
label.pack(pady=pady) label.pack(pady=pady)
return label return label
@ -54,20 +54,38 @@ class UIWidgetsMixin:
text: str, text: str,
*, *,
font_size: int = 18, font_size: int = 18,
color: str = "white", color: str | None = None,
pady: int = 10, pady: int = 10,
) -> tk.Label: ) -> tk.Label:
"""Create and pack a non-bold text label in the container.""" """Create and pack a non-bold text label in the container."""
label = tk.Label( label = tk.Label(
self.container, self.container,
text=text, text=text,
font=("Arial", font_size), font=(self._colors.font_family, font_size),
fg=color, fg=color or self._colors.fg,
bg="#1a1a1a", bg=self._colors.bg,
) )
label.pack(pady=pady) label.pack(pady=pady)
return label return label
def _fg_for(self, bg: str) -> str:
"""Return the correct label color for a widget with background `bg`.
The four filled semantic surfaces (accent/success/warning/danger)
all sit in the same mid-light lightness band, so `fg` (near-white,
meant for the neutral `bg`/`field_bg` surfaces) under-contrasts on
every one of them -- `on_fill` (dark) is required instead. Deriving
this from `bg` means a new filled-button call site can't reintroduce
the bug by omission.
"""
fills = {
self._colors.accent,
self._colors.success,
self._colors.warning,
self._colors.danger,
}
return self._colors.on_fill if bg in fills else self._colors.fg
def _button( def _button(
self, self,
parent: tk.Widget, parent: tk.Widget,
@ -77,21 +95,29 @@ class UIWidgetsMixin:
command: Callable[[], None], command: Callable[[], None],
width: int = 10, width: int = 10,
) -> tk.Button: ) -> tk.Button:
"""Create a styled button (caller must pack).""" """Create a styled button (caller must pack).
Padding follows the shared 2x horizontal:vertical ratio (rule 22);
`relief="flat"` is the one depth technique every button in the app
uses now (rule 27), matching what `_heat_skip.py` already did alone.
"""
return tk.Button( return tk.Button(
parent, parent,
text=text, text=text,
font=("Arial", 24, "bold"), font=(self._colors.font_family, 24, "bold"),
bg=bg, bg=bg,
fg="white", fg=self._fg_for(bg),
width=width, width=width,
command=command, command=command,
cursor="hand2" if self.demo_mode else "", cursor="hand2" if self.demo_mode else "",
relief="flat",
padx=24,
pady=12,
) )
def _button_row(self) -> tk.Frame: def _button_row(self) -> tk.Frame:
"""Create and pack a horizontal button container.""" """Create and pack a horizontal button container."""
frame = tk.Frame(self.container, bg="#1a1a1a") frame = tk.Frame(self.container, bg=self._colors.bg)
frame.pack(pady=20) frame.pack(pady=20)
return frame return frame
@ -103,24 +129,24 @@ class UIWidgetsMixin:
variable: tk.StringVar, variable: tk.StringVar,
) -> None: ) -> None:
"""Add a label + single-line entry pair, with paste disabled.""" """Add a label + single-line entry pair, with paste disabled."""
row = tk.Frame(parent, bg="#1a1a1a") row = tk.Frame(parent, bg=self._colors.bg)
row.pack(pady=5, fill="x") row.pack(pady=8, fill="x")
tk.Label( tk.Label(
row, row,
text=label, text=label,
font=("Arial", 14), font=(self._colors.font_family, 14),
fg="white", fg=self._colors.fg,
bg="#1a1a1a", bg=self._colors.bg,
anchor="w", anchor="w",
).pack(side="top", anchor="w") ).pack(side="top", anchor="w")
entry = tk.Entry( entry = tk.Entry(
row, row,
textvariable=variable, textvariable=variable,
width=50, width=50,
font=("Arial", 14), font=(self._colors.font_family, 14),
bg="#2a2a2a", bg=self._colors.field_bg,
fg="white", fg=self._colors.fg,
insertbackground="white", insertbackground=self._colors.fg,
) )
entry.pack(side="top", anchor="w", pady=2) entry.pack(side="top", anchor="w", pady=4)
disable_paste(entry) disable_paste(entry)

View File

@ -27,7 +27,7 @@ class WindowSetupMixin:
def _setup_verify_window(self) -> None: def _setup_verify_window(self) -> None:
"""Configure window for post-sick-day workout verification.""" """Configure window for post-sick-day workout verification."""
self.root.geometry("600x400") self.root.geometry("600x400")
self.root.configure(bg="#1a1a1a", cursor="arrow") self.root.configure(bg=self._colors.bg, cursor="arrow")
self.root.protocol("WM_DELETE_WINDOW", self.close) self.root.protocol("WM_DELETE_WINDOW", self.close)
def _setup_demo_close_button(self) -> None: def _setup_demo_close_button(self) -> None:
@ -35,9 +35,9 @@ class WindowSetupMixin:
close_btn = tk.Button( close_btn = tk.Button(
self.root, self.root,
text="✕ Close Demo", text="✕ Close Demo",
font=("Arial", 12), font=(self._colors.font_family, 12),
bg="#ff4444", bg=self._colors.danger,
fg="white", fg=self._colors.on_fill,
command=self.close, command=self.close,
cursor="hand2", cursor="hand2",
) )
@ -46,5 +46,5 @@ class WindowSetupMixin:
def _setup_relaxed_day_window(self) -> None: def _setup_relaxed_day_window(self) -> None:
"""Configure a small non-locking window for the optional Tue-Thu prompt.""" """Configure a small non-locking window for the optional Tue-Thu prompt."""
self.root.geometry("700x450") self.root.geometry("700x450")
self.root.configure(bg="#1a1a1a", cursor="arrow") self.root.configure(bg=self._colors.bg, cursor="arrow")
self.root.protocol("WM_DELETE_WINDOW", self.close) self.root.protocol("WM_DELETE_WINDOW", self.close)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1016 B

After

Width:  |  Height:  |  Size: 1012 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 620 B

After

Width:  |  Height:  |  Size: 639 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@ -1,6 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 1024 1024"> <svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 1024 1024">
<rect width="1024" height="1024" fill="#1B1D21"/> <rect width="1024" height="1024" fill="#211D1B"/>
<g fill="none" stroke="#FF4444" stroke-width="72" stroke-linecap="round" stroke-linejoin="round" transform="translate(0,0)"> <g fill="none" stroke="#B8862E" stroke-width="72" stroke-linecap="round" stroke-linejoin="round" transform="translate(0,0)">
<path d="M 268 512 L 756 512"/> <path d="M 268 512 L 756 512"/>
<path d="M 364 356 L 364 668"/> <path d="M 364 356 L 364 668"/>
<path d="M 660 356 L 660 668"/> <path d="M 660 356 L 660 668"/>

Before

Width:  |  Height:  |  Size: 465 B

After

Width:  |  Height:  |  Size: 465 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB

View File

@ -1,5 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 1024 1024"> <svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 1024 1024">
<g fill="none" stroke="#FF4444" stroke-width="72" stroke-linecap="round" stroke-linejoin="round" transform="translate(0,0)"> <g fill="none" stroke="#B8862E" stroke-width="72" stroke-linecap="round" stroke-linejoin="round" transform="translate(0,0)">
<path d="M 268 512 L 756 512"/> <path d="M 268 512 L 756 512"/>
<path d="M 364 356 L 364 668"/> <path d="M 364 356 L 364 668"/>
<path d="M 660 356 L 660 668"/> <path d="M 660 356 L 660 668"/>

Before

Width:  |  Height:  |  Size: 413 B

After

Width:  |  Height:  |  Size: 413 B