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:
parent
ae30f47ba5
commit
f49e9a3ed0
8 changed files with 295 additions and 189 deletions
187
theme.py
Normal file
187
theme.py
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
"""
|
||||
Erscheinungsbild von Squad Manager: Farben, Schriften, ttk-Stil und die
|
||||
segmentierte Pegelanzeige.
|
||||
|
||||
Eigene Datei, damit mehrere Module (Funk, Akte) denselben Stil nutzen,
|
||||
ohne sich gegenseitig zu importieren.
|
||||
"""
|
||||
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
|
||||
|
||||
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")
|
||||
FONT_NAV = ("Segoe UI Semibold", 11)
|
||||
|
||||
|
||||
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)])
|
||||
# Hauptreiter (FUNK, AKTE): ohne Kasten, nur Schrift - so heben sie sich
|
||||
# als uebergeordnete Ebene von den umrahmten Unterreitern ab.
|
||||
style.configure("Haupt.TNotebook", background=BG, bordercolor=BG,
|
||||
lightcolor=BG, darkcolor=BG, tabmargins=(0, 0, 0, 0))
|
||||
style.configure("Haupt.TNotebook.Tab", background=BG, foreground=FG_DIM,
|
||||
bordercolor=BG, lightcolor=BG, darkcolor=BG,
|
||||
padding=(4, 6, 26, 6), font=FONT_NAV)
|
||||
# clam gibt dem gewaehlten Reiter eine eigene Innenabstand-Regel. Ohne
|
||||
# die padding-Zeile erbt dieser Stil sie, und die Schrift springt beim
|
||||
# Umschalten um einige Pixel.
|
||||
style.map("Haupt.TNotebook.Tab",
|
||||
padding=[("selected", (4, 6, 26, 6))],
|
||||
background=[("selected", BG), ("active", BG)],
|
||||
lightcolor=[("selected", BG)],
|
||||
darkcolor=[("selected", BG)],
|
||||
bordercolor=[("selected", BG)],
|
||||
foreground=[("selected", OLIVE_HI), ("active", FG)],
|
||||
expand=[("selected", (0, 0, 0, 0))])
|
||||
|
||||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue