Mehrere Akten mit Liste, Formular und Dokumentansicht, Portraet, Statusstempel bei gefallen und vermisst, Vorschlagslisten fuer 22 Fraktionen samt Dienstgraden. Datenmodell in akte_modell.py ohne tkinter, Vorlagen in akte_vorlagen.py. Speichern atomar mit Sicherung, Loeschen ueber einen Papierkorb-Ordner. Neue Abhaengigkeit Pillow. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
229 lines
9.8 KiB
Python
229 lines
9.8 KiB
Python
"""
|
|
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 ctypes
|
|
import ctypes.wintypes as wintypes
|
|
import tkinter as tk
|
|
from tkinter import ttk
|
|
|
|
|
|
def dunkle_titelleiste(fenster):
|
|
"""
|
|
Dunkle Titelleiste fuer ein beliebiges Fenster, auch fuer Dialoge.
|
|
|
|
Windows zeichnet sie sonst hell. Attribut 20 gilt fuer aktuelle
|
|
Windows-Versionen, 19 fuer aeltere. Danach muss das Fenster einmal neu
|
|
gezeichnet werden, sonst bleibt die alte Farbe stehen.
|
|
"""
|
|
try:
|
|
fenster.update_idletasks()
|
|
hwnd = ctypes.windll.user32.GetParent(fenster.winfo_id()) or fenster.winfo_id()
|
|
an = ctypes.c_int(1)
|
|
for attribut in (20, 19):
|
|
if ctypes.windll.dwmapi.DwmSetWindowAttribute(
|
|
wintypes.HWND(hwnd), ctypes.c_uint(attribut),
|
|
ctypes.byref(an), ctypes.sizeof(an)) == 0:
|
|
fenster.withdraw()
|
|
fenster.deiconify()
|
|
return True
|
|
except Exception:
|
|
pass
|
|
return False
|
|
|
|
|
|
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)])
|
|
# Tabellen und Scrollbalken (Modul Akte)
|
|
style.configure("Treeview", background=PANEL, fieldbackground=PANEL,
|
|
foreground=FG, bordercolor=LINE, lightcolor=PANEL,
|
|
darkcolor=PANEL, rowheight=24, font=FONT_UI)
|
|
style.map("Treeview",
|
|
background=[("selected", OLIVE)],
|
|
foreground=[("selected", "#12150f")])
|
|
style.configure("Treeview.Heading", background=BG, foreground=FG_DIM,
|
|
bordercolor=LINE, lightcolor=BG, darkcolor=BG,
|
|
font=FONT_BOLD, relief="flat")
|
|
style.map("Treeview.Heading", background=[("active", PANEL_HI)])
|
|
style.configure("Vertical.TScrollbar", background=PANEL, troughcolor=BG,
|
|
bordercolor=LINE, arrowcolor=FG_DIM, lightcolor=PANEL,
|
|
darkcolor=PANEL)
|
|
style.map("Vertical.TScrollbar", background=[("active", PANEL_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)
|