mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-11 16:53:57 +01:00
Sixth batch of the 250-line sweep. All six gate sources named for this batch are now under cap, plus _gate_layout_probe.py, which this batch's import rewiring pulled into the changeset (over-cap count 38 -> 31). _gatelock_ui.py 477 -> 174 (palette/leaf-helper hub) _gate_layout_probe.py 346 -> 196 _gatelock_groups.py 308 -> 137 _gatelock_calendar_ui 295 -> 77 _gatelock_calendar.py 286 -> 210 _gatelock.py 263 -> 238 _gatelock_mealflow.py 259 -> 207 New siblings: _gatelock_fields (input widgets), _gatelock_layout (assembly), _gatelock_widgetgroups (per-widget mirroring), _gatelock_calendar_types (bundles/palette), _gatelock_calendar_widgets (History builders), _gatelock_dashboard and _gatelock_budgetedit (mixins), _gatelock_lockfile (the stdlib-only flock), _gate_focus_probe and _gate_measurement. The load-bearing part is the test seam, not the line counts. `_gate_fixtures._GATE_TK_MODULES` patches `tk` on a hand-listed tuple, and that list fails OPEN: a widget builder split into a new sibling that nobody adds to it builds *real* Tk widgets against fake parents. Neither existing detector sees that -- check_patch_targets.py only validates paths that still resolve, and the ~8s runtime only catches network calls. It bit twice during this split (real StringVars from make_calendar_vars returned MagicMocks instead of the asserted text), so test_gate_tk_modules.py now asserts the invariant directly: every module binding `tk` is in the patch set or named in _NO_WIDGETS with a reason. It caught a pre-existing gap too -- _gatelock_support was never in the set. Same fail-open shape drove two other choices: `escape_tab_trap` is a call-time indirection so the keyboard test's patch of `_escape_text_tab_trap` still bites, and the flock pair moved with its conftest patch target updated in the same edit (that one fails closed). build_layout is imported from _gatelock_layout directly rather than re-exported lazily, which avoids both a cycle and an import-outside-toplevel suppression. Verified: 703 Python tests / 100% branch coverage, the 5 layout-fits tests under xvfb, 555 Flutter tests (unchanged), flutter analyze clean, check_patch_targets 0, `sync` 0 (403 entries), pre-commit clean, and `gate --demo` renders both tabs with live dashboard data. ~/.local/share/diet_guard byte-identical across the batch (gate timer paused, restored after). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RA9ynjqXPnexRQnR5oAuCC
80 lines
2.4 KiB
Python
80 lines
2.4 KiB
Python
"""``ttk`` theming for the gate's History tab, and its public surface.
|
|
|
|
Split across three modules to keep each under the repo's 250-line limit:
|
|
:mod:`._gatelock_calendar_types` holds the data bundles, constants and
|
|
palette, :mod:`._gatelock_calendar_widgets` builds the widgets, and this
|
|
module owns the ``ttk.Notebook`` theming.
|
|
|
|
Everything the tab's controller (:mod:`._gatelock_calendar`) needs is
|
|
re-exported here, because that module already imports all seven names from
|
|
this one. The ``ttk`` import is also load-bearing beyond theming: the test
|
|
suite patches ``_gatelock_calendar_ui.ttk`` with a fake, so this module must
|
|
keep binding ``ttk`` at module level.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from tkinter import ttk
|
|
from typing import TYPE_CHECKING
|
|
|
|
from diet_guard._gatelock_calendar_types import (
|
|
_ACCENT,
|
|
_COLORS,
|
|
_DECEMBER,
|
|
_DEFAULT_BUDGET_KCAL,
|
|
_FIELD_BG,
|
|
_JANUARY,
|
|
_MONTH_AFTER_DECEMBER,
|
|
CalendarCallbacks,
|
|
CalendarVars,
|
|
CalendarWidgets,
|
|
make_calendar_vars,
|
|
)
|
|
from diet_guard._gatelock_calendar_widgets import build_calendar_frame
|
|
from diet_guard._gatelock_spacing import MD, SM
|
|
from diet_guard._gatelock_ui import BG, FG
|
|
|
|
if TYPE_CHECKING:
|
|
import tkinter as tk
|
|
|
|
__all__ = [
|
|
"_DECEMBER",
|
|
"_DEFAULT_BUDGET_KCAL",
|
|
"_JANUARY",
|
|
"_MONTH_AFTER_DECEMBER",
|
|
"CalendarCallbacks",
|
|
"CalendarVars",
|
|
"CalendarWidgets",
|
|
"_style_notebook",
|
|
"build_calendar_frame",
|
|
"make_calendar_vars",
|
|
]
|
|
|
|
|
|
def _style_notebook(root: tk.Misc) -> None:
|
|
"""Theme the ``ttk.Notebook`` tab strip to match the gate's dark palette.
|
|
|
|
``ttk`` widgets ignore plain ``bg=``/``fg=`` -- unlike every other widget
|
|
here, they only take color from a named ``ttk.Style``. Without this the
|
|
tab strip renders in the OS's default (light) ttk theme regardless of how
|
|
dark the rest of the gate is. ``clam`` is used because it is the ttk
|
|
theme that reliably honors ``.configure()`` overrides cross-platform; the
|
|
built-in ``default``/``alt`` themes on some platforms ignore custom tab
|
|
colors.
|
|
"""
|
|
style = ttk.Style(root)
|
|
style.theme_use("clam")
|
|
style.configure("TNotebook", background=BG, borderwidth=0)
|
|
style.configure(
|
|
"TNotebook.Tab",
|
|
background=_FIELD_BG,
|
|
foreground=FG,
|
|
padding=(MD, SM),
|
|
borderwidth=0,
|
|
)
|
|
style.map(
|
|
"TNotebook.Tab",
|
|
background=[("selected", _ACCENT)],
|
|
foreground=[("selected", _COLORS.on_fill)],
|
|
)
|