Stufe 1: Hauptreiter FUNK und AKTE, Stil in theme.py (3.4)

- Farben, Schriften, ttk-Stil und Pegelanzeige liegen jetzt in theme.py,
  damit mehrere Module denselben Stil nutzen, ohne sich gegenseitig zu
  importieren
- Zwei Reiterebenen: FUNK (Mikrofon, Tasten und Verhalten) und AKTE; die
  Statusleiste bleibt fuer alle Module sichtbar
- Zuletzt gewaehlter Hauptreiter wird gespeichert
- akte.py als Platzhalter, damit das Update 3.3 -> 3.4 bereits neue
  Dateien mitliefert
- clam-Innenabstand fuer gewaehlte Hauptreiter festgesetzt, die Schrift
  sprang sonst um 4 Pixel
- Build nimmt theme.py und akte.py mit; Doku nachgezogen

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-09-10 18:27:04 +02:00
parent ae30f47ba5
commit f49e9a3ed0
8 changed files with 295 additions and 189 deletions

View file

@ -50,8 +50,16 @@ from tkinter import ttk, messagebox # noqa: E402
import numpy as np # noqa: E402
import sounddevice as sd # noqa: E402
from theme import ( # noqa: E402
BG, PANEL, PANEL_HI, LINE, FG, FG_DIM, OLIVE, OLIVE_HI, AMBER,
AMBER_HELL, AMBER_DUNKEL, RED, GREEN_TX,
FONT_UI, FONT_BOLD, FONT_TITLE, FONT_MONO, FONT_STATUS,
apply_tactical_theme, LevelMeter,
)
import akte # noqa: E402
APP_NAME = "Squad Manager"
VERSION = "3.3"
VERSION = "3.4"
CONFIG_PATH = Path(os.getenv("APPDATA", ".")) / "SquadManager" / "config.json"
LOG_PATH = CONFIG_PATH.parent / "error.log"
# Bis Version 3.2 hiess das Programm "Squad Voice Activation"
@ -432,166 +440,6 @@ def get_foreground_process_name():
kernel32.CloseHandle(handle)
# ---------------------------------------------------------------------------
# Erscheinungsbild - gedeckte Militaerfarben, dunkler Untergrund
# ---------------------------------------------------------------------------
BG = "#151814" # Fensterhintergrund, fast schwarz mit Gruenstich
PANEL = "#1e231b" # Flaechen, Eingabefelder
PANEL_HI = "#2a3125" # Hover, ausgewaehlter Reiter
LINE = "#3d4634" # Rahmen und Trennlinien
FG = "#c9cec0" # Standardtext, helles Khaki
FG_DIM = "#7f8874" # Nebentext
OLIVE = "#6e8b3d" # Akzent, Fortschritt
OLIVE_HI = "#8cb04d" # heller Akzent
AMBER = "#d9a441" # Hinweise, Schwellenmarke
AMBER_HELL = "#e8bb63" # Mauskontakt auf der Hinweisleiste
AMBER_DUNKEL = "#2b2416" # Untergrund der Hinweisleiste
RED = "#b4472f" # Sperre, Fehler
GREEN_TX = "#9ed23f" # Sendebereit
FONT_UI = ("Segoe UI", 9)
FONT_BOLD = ("Segoe UI Semibold", 9)
FONT_TITLE = ("Segoe UI", 17, "bold")
FONT_MONO = ("Consolas", 9)
FONT_STATUS = ("Consolas", 13, "bold")
def apply_tactical_theme(root):
"""Dunkles, gedecktes Farbschema im Stil der Spieloberflaeche."""
root.configure(bg=BG)
style = ttk.Style(root)
# "clam" ist das einzige mitgelieferte Thema, das sich durchgaengig
# umfaerben laesst - "vista" ignoriert die meisten Farbangaben.
style.theme_use("clam")
style.configure(".", background=BG, foreground=FG, font=FONT_UI,
bordercolor=LINE, darkcolor=PANEL, lightcolor=PANEL,
troughcolor=PANEL, focuscolor=OLIVE)
style.configure("TFrame", background=BG)
style.configure("TLabel", background=BG, foreground=FG)
style.configure("Dim.TLabel", foreground=FG_DIM)
style.configure("Mono.TLabel", font=FONT_MONO, foreground=FG)
style.configure("Title.TLabel", font=FONT_TITLE, foreground=FG)
style.configure("Sub.TLabel", foreground=FG_DIM)
style.configure("TLabelframe", background=BG, bordercolor=LINE,
relief="solid", borderwidth=1)
style.configure("TLabelframe.Label", background=BG, foreground=OLIVE_HI,
font=FONT_BOLD)
style.configure("TButton", background=PANEL, foreground=FG,
bordercolor=LINE, relief="solid", borderwidth=1,
padding=(12, 6), font=FONT_UI)
style.map("TButton",
background=[("pressed", OLIVE), ("active", PANEL_HI),
("disabled", PANEL)],
foreground=[("disabled", FG_DIM)],
bordercolor=[("active", OLIVE)])
style.configure("Accent.TButton", background=OLIVE, foreground="#12150f",
font=FONT_BOLD, bordercolor=OLIVE_HI)
style.map("Accent.TButton",
background=[("pressed", OLIVE), ("active", OLIVE_HI),
("disabled", PANEL)],
foreground=[("disabled", FG_DIM)])
for widget in ("TCombobox", "TSpinbox", "TEntry"):
style.configure(widget, fieldbackground=PANEL, background=PANEL,
foreground=FG, bordercolor=LINE, arrowcolor=OLIVE_HI,
insertcolor=FG, selectbackground=OLIVE,
selectforeground="#12150f", padding=4)
style.map(widget,
fieldbackground=[("readonly", PANEL), ("disabled", BG)],
foreground=[("disabled", FG_DIM)],
bordercolor=[("focus", OLIVE)])
# Die aufklappende Liste einer Combobox ist ein klassisches Tk-Widget
# und muss ueber die Optionsdatenbank eingefaerbt werden.
root.option_add("*TCombobox*Listbox.background", PANEL)
root.option_add("*TCombobox*Listbox.foreground", FG)
root.option_add("*TCombobox*Listbox.selectBackground", OLIVE)
root.option_add("*TCombobox*Listbox.selectForeground", "#12150f")
root.option_add("*TCombobox*Listbox.font", FONT_UI)
style.configure("TCheckbutton", background=BG, foreground=FG,
indicatorcolor=PANEL, indicatorrelief="solid")
style.map("TCheckbutton",
background=[("active", BG)],
indicatorcolor=[("selected", OLIVE_HI), ("active", PANEL_HI)],
foreground=[("disabled", FG_DIM)])
style.configure("TNotebook", background=BG, bordercolor=LINE,
tabmargins=(2, 4, 2, 0))
style.configure("TNotebook.Tab", background="#10120f", foreground=FG_DIM,
bordercolor=LINE, lightcolor="#10120f",
darkcolor="#10120f", padding=(20, 9), font=FONT_BOLD)
style.map("TNotebook.Tab",
background=[("selected", PANEL_HI), ("active", PANEL)],
lightcolor=[("selected", PANEL_HI)],
darkcolor=[("selected", PANEL_HI)],
foreground=[("selected", OLIVE_HI), ("active", FG)],
expand=[("selected", (0, 0, 0, 0))])
# Der Schieberegler von clam ist standardmaessig hell und wuerde aus
# dem Schema fallen.
style.configure("Horizontal.TScale", background=BG, troughcolor="#10120f",
bordercolor=LINE, lightcolor=OLIVE, darkcolor=OLIVE)
style.map("Horizontal.TScale",
background=[("active", BG)],
lightcolor=[("active", OLIVE_HI)],
darkcolor=[("active", OLIVE_HI)])
style.configure("TSeparator", background=LINE)
return style
class LevelMeter(tk.Canvas):
"""
Segmentierte Pegelanzeige mit Schwellenmarke.
Zeigt anders als eine gewoehnliche Fortschrittsleiste, wo die
Ausloeseschwelle relativ zum Pegel liegt - genau die Information,
die man zum Einstellen braucht.
"""
SEGMENTS = 40
MAXIMUM = 0.10
def __init__(self, master, width=320, height=26):
super().__init__(master, width=width, height=height, bg=PANEL,
highlightthickness=1, highlightbackground=LINE,
bd=0)
self._level = 0.0
self._threshold = 0.025
self._active = False
self.bind("<Configure>", lambda e: self._redraw())
def update_values(self, level, threshold, active):
self._level, self._threshold, self._active = level, threshold, active
self._redraw()
def _redraw(self):
self.delete("all")
w = self.winfo_width() or int(self["width"])
h = self.winfo_height() or int(self["height"])
pad = 3
seg_w = (w - 2 * pad) / self.SEGMENTS
filled = int(min(1.0, self._level / self.MAXIMUM) * self.SEGMENTS)
thr_seg = int(min(1.0, self._threshold / self.MAXIMUM) * self.SEGMENTS)
for i in range(self.SEGMENTS):
x0 = pad + i * seg_w
x1 = x0 + seg_w - 1.5
if i < filled:
colour = OLIVE_HI if self._active else OLIVE
if i >= thr_seg and not self._active:
colour = OLIVE_HI
else:
colour = "#252b1f"
self.create_rectangle(x0, pad, x1, h - pad, fill=colour, width=0)
# Schwellenmarke
x = pad + thr_seg * seg_w
self.create_line(x, 0, x, h, fill=AMBER, width=2)
def set_dark_titlebar(root):
"""
Faerbt die Fenstertitelleiste dunkel.
@ -840,7 +688,7 @@ class VoiceActivationApp:
def __init__(self, root):
self.root = root
self.root.title(f"{APP_NAME} {VERSION}")
self.root.geometry("700x780")
self.root.geometry("700x830")
self.root.minsize(660, 480)
set_window_icon(self.root)
set_dark_titlebar(self.root)
@ -908,7 +756,7 @@ class VoiceActivationApp:
ttk.Label(header, text="SQUAD MANAGER",
style="Title.TLabel").pack(anchor="w")
ttk.Label(header, style="Sub.TLabel",
text="Haelt die Sprechtaste, solange du redest.").pack(anchor="w")
text="Sprachaktivierung und Personalakte fuer Squad.").pack(anchor="w")
ttk.Separator(self.root, orient="horizontal").pack(
fill="x", padx=18, pady=(10, 0))
@ -918,9 +766,20 @@ class VoiceActivationApp:
self._build_statusbar()
self._build_update_banner()
nb = ttk.Notebook(self.root)
# Hauptreiter je Modul. Die Statusleiste bleibt darunter fuer alle
# Module sichtbar - die Sprachaktivierung laeuft weiter, waehrend man
# zum Beispiel an einer Akte schreibt.
haupt = ttk.Notebook(self.root, style="Haupt.TNotebook")
self.haupt_nb = haupt
haupt.pack(fill="both", expand=True, padx=16, pady=(4, 8))
seite_funk = ttk.Frame(haupt)
seite_akte = ttk.Frame(haupt)
haupt.add(seite_funk, text="FUNK")
haupt.add(seite_akte, text="AKTE")
nb = ttk.Notebook(seite_funk)
self.nb = nb
nb.pack(fill="both", expand=True, padx=16, pady=8)
nb.pack(fill="both", expand=True, pady=(6, 0))
tab_main = ttk.Frame(nb)
tab_keys = ttk.Frame(nb)
nb.add(tab_main, text=" Mikrofon ")
@ -929,6 +788,9 @@ class VoiceActivationApp:
self._build_main_tab(tab_main)
self._build_keys_tab(tab_keys)
self.akte = akte.AkteSeite(seite_akte)
self.akte.pack(fill="both", expand=True)
def _build_main_tab(self, parent):
f = ttk.Frame(parent)
f.pack(fill="both", expand=True, padx=12, pady=12)
@ -1130,6 +992,7 @@ class VoiceActivationApp:
"squad_only": bool(self.squad_only_var.get()),
"pause_on_cursor": bool(self.pause_on_cursor_var.get()),
"beep": bool(self.beep_var.get()),
"modul": self.haupt_nb.index("current"),
}
def suche_update(self):
@ -1213,6 +1076,8 @@ class VoiceActivationApp:
self.beep_var):
var.trace_add("write", self._on_setting_changed)
self._autosave_job = None
self.haupt_nb.bind("<<NotebookTabChanged>>", self._on_setting_changed,
add="+")
def _on_setting_changed(self, *_):
if getattr(self, "_autosave_job", None) is not None:
@ -1286,6 +1151,10 @@ class VoiceActivationApp:
if value in MODIFIERS:
var.set(value)
modul = cfg.get("modul")
if isinstance(modul, int) and 0 <= modul < len(self.haupt_nb.tabs()):
self.haupt_nb.select(modul)
self.save_hint.config(text="Einstellungen geladen.")
# -- Audio --------------------------------------------------------------