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
additional_dependencies:
- 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
- mcp
- pydantic

View File

@ -7,7 +7,7 @@ requires-python = ">=3.10"
# crdt-sync: shared CRDT merge scheme + GitHub-Contents-API sync transport,
# also used by diet_guard; here for phone-workout GitHub sync (Workstream C)
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",
]

View File

@ -4,7 +4,7 @@ bandit>=1.7.0
codespell>=2.2.0
coverage>=7.4.0
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
mypy>=1.8.0
pre-commit>=3.6.0

View File

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

View File

@ -35,16 +35,16 @@ class UIWidgetsMixin:
text: str,
*,
font_size: int = 36,
color: str = "white",
color: str | None = None,
pady: int = 20,
) -> tk.Label:
"""Create and pack a bold label in the container."""
label = tk.Label(
self.container,
text=text,
font=("Arial", font_size, "bold"),
fg=color,
bg="#1a1a1a",
font=(self._colors.font_family, font_size, "bold"),
fg=color or self._colors.fg,
bg=self._colors.bg,
)
label.pack(pady=pady)
return label
@ -54,20 +54,38 @@ class UIWidgetsMixin:
text: str,
*,
font_size: int = 18,
color: str = "white",
color: str | None = None,
pady: int = 10,
) -> tk.Label:
"""Create and pack a non-bold text label in the container."""
label = tk.Label(
self.container,
text=text,
font=("Arial", font_size),
fg=color,
bg="#1a1a1a",
font=(self._colors.font_family, font_size),
fg=color or self._colors.fg,
bg=self._colors.bg,
)
label.pack(pady=pady)
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(
self,
parent: tk.Widget,
@ -77,21 +95,29 @@ class UIWidgetsMixin:
command: Callable[[], None],
width: int = 10,
) -> 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(
parent,
text=text,
font=("Arial", 24, "bold"),
font=(self._colors.font_family, 24, "bold"),
bg=bg,
fg="white",
fg=self._fg_for(bg),
width=width,
command=command,
cursor="hand2" if self.demo_mode else "",
relief="flat",
padx=24,
pady=12,
)
def _button_row(self) -> tk.Frame:
"""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)
return frame
@ -103,24 +129,24 @@ class UIWidgetsMixin:
variable: tk.StringVar,
) -> None:
"""Add a label + single-line entry pair, with paste disabled."""
row = tk.Frame(parent, bg="#1a1a1a")
row.pack(pady=5, fill="x")
row = tk.Frame(parent, bg=self._colors.bg)
row.pack(pady=8, fill="x")
tk.Label(
row,
text=label,
font=("Arial", 14),
fg="white",
bg="#1a1a1a",
font=(self._colors.font_family, 14),
fg=self._colors.fg,
bg=self._colors.bg,
anchor="w",
).pack(side="top", anchor="w")
entry = tk.Entry(
row,
textvariable=variable,
width=50,
font=("Arial", 14),
bg="#2a2a2a",
fg="white",
insertbackground="white",
font=(self._colors.font_family, 14),
bg=self._colors.field_bg,
fg=self._colors.fg,
insertbackground=self._colors.fg,
)
entry.pack(side="top", anchor="w", pady=2)
entry.pack(side="top", anchor="w", pady=4)
disable_paste(entry)

View File

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

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

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#1B1D21</color>
</resources>
</resources>

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">
<rect width="1024" height="1024" fill="#1B1D21"/>
<g fill="none" stroke="#FF4444" stroke-width="72" stroke-linecap="round" stroke-linejoin="round" transform="translate(0,0)">
<rect width="1024" height="1024" fill="#211D1B"/>
<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 364 356 L 364 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">
<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 364 356 L 364 668"/>
<path d="M 660 356 L 660 668"/>

Before

Width:  |  Height:  |  Size: 413 B

After

Width:  |  Height:  |  Size: 413 B