From b3667c5af6f4c6458a4b52e407899e20e8e93b0c Mon Sep 17 00:00:00 2001 From: Henrik Rentz Date: Mon, 18 Aug 2025 14:55:32 +0200 Subject: [PATCH] =?UTF-8?q?optische=20=C3=84nderungen=20an=20der=20Oberfl?= =?UTF-8?q?=C3=A4che?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gui.py | 832 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 452 insertions(+), 380 deletions(-) diff --git a/gui.py b/gui.py index caec143..c7f497e 100644 --- a/gui.py +++ b/gui.py @@ -28,7 +28,6 @@ class ZeitErfassungApp: messagebox.showinfo("Gespeichert", f"Pfad gespeichert:\n{config.SERVER_EXCEL}") # --------------------------- Konstruktor ------------------------------ - def __init__(self, root: tk.Tk): self.root = root self.root.title("Zeiterfassung MERZ") @@ -142,12 +141,15 @@ class ZeitErfassungApp: main_card.pack(fill="both", expand=True, padx=12, pady=(0, 12)) # ---------------- Eingabebereich mit schwarzem Rahmen ---------------- - # Außenrahmen (schwarzer Strich) + Innenabstand - input_wrap = tk.Frame(main_card, bg=self.card, highlightthickness=2, highlightbackground="#000000") + input_wrap = tk.Frame(main_card, bg=self.card, highlightthickness=3, highlightbackground="#000000") input_wrap.pack(fill="x", padx=12, pady=(12, 8)) inner = tk.Frame(input_wrap, bg=self.card) inner.pack(fill="x", padx=10, pady=8) + inner.grid_columnconfigure(0, weight=0) + inner.grid_columnconfigure(1, weight=1) + inner.grid_columnconfigure(2, weight=0) + # Grid: Label | Entry (dehnbar) | Start-Button inner.grid_columnconfigure(0, weight=0) inner.grid_columnconfigure(1, weight=1) @@ -163,9 +165,451 @@ class ZeitErfassungApp: self.start_button_inline = ttk.Button(inner, text="Start", command=self.start_vorgang, style="Accent.TButton") self.start_button_inline.grid(row=0, column=2, sticky="e", padx=(10, 0)) - # ---------------- Liste + Scrollbar ---------------- - list_frame = ttk.Frame(main_card, style="Card.TFrame") - list_frame.pack(fill="both", expand=True, padx=12, pady=(0, 12)) + # ---------------- Liste + Scrollbar (mit Überschrift + schwarzem Rahmen) ---------------- + list_wrap = tk.Frame(main_card, bg=self.card, highlightthickness=3, highlightbackground="black") + list_wrap.pack(fill="both", expand=True, padx=12, pady=(0, 12)) + + # Kopfzeile + header = tk.Frame(list_wrap, bg=self.card) + header.pack(fill="x", padx=8, pady=(8, 0)) + + # Spalten-Layout: passe die weights an, wenn du andere Breiten willst + header.grid_columnconfigure(0, weight=12) # Maschine + header.grid_columnconfigure(1, weight=10) # Bearb.-Nr. + header.grid_columnconfigure(2, weight=18) # Start + header.grid_columnconfigure(3, weight=18) # Stopp + header.grid_columnconfigure(4, weight=8) # Dauer + header.grid_columnconfigure(5, weight=34) # Kommentar + + def H(txt, col): + tk.Label(header, text=txt, bg=self.card, fg=self.text, + font=("Segoe UI", 10, "bold"), anchor="w").grid(row=0, column=col, sticky="ew", padx=(0, 8)) + + H("Maschine", 0) + H("Bearb.-Nr.", 1) + H("Start", 2) + H("Stopp", 3) + H("Dauer", 4) + H("Kommentar", 5) + + # dünne Linie unter der Kopfzeile + tk.Frame(list_wrap, height=1, bg="#000000").pack(fill="x", padx=8, pady=(4, 8)) + + # eigentlicher Listenbereich + list_frame = tk.Frame(list_wrap, bg=self.card) + list_frame.pack(fill="both", expand=True, padx=8, pady=(0, 8)) + + scrollbar = ttk.Scrollbar(list_frame, orient="vertical") + scrollbar.pack(side="right", fill="y") + + self.listbox = tk.Listbox( + list_frame, + width=100, + font=("Segoe UI", 10), + activestyle="none", + borderwidth=0, + highlightthickness=0, + bg=self.card, + fg=self.text, + selectbackground="#D0E7FF", + selectforeground=self.text + ) + self.listbox.pack(side="left", fill="both", expand=True) + self.listbox.config(yscrollcommand=scrollbar.set) + scrollbar.config(command=self.listbox.yview) + + + # ---------------- Aktionsleiste unten ---------------- + actions = ttk.Frame(main_card, style="Toolbar.TFrame") + actions.pack(fill="x", padx=12, pady=(0, 12)) + + # Stop mit Kommentar + wrap1 = tk.Frame(actions, highlightthickness=3, highlightbackground="black", bd=0) + wrap1.pack(side="left", padx=2, pady=2) + ttk.Button(wrap1, text="Stop mit Kommentar", command=self.stoppe_auswahl).pack() + + # Auswahl löschen + wrap2 = tk.Frame(actions, highlightthickness=3, highlightbackground="black", bd=0) + wrap2.pack(side="left", padx=2, pady=2) + ttk.Button(wrap2, text="Auswahl löschen", command=self.loesche_auswahl).pack() + + # Alles zurücksetzen + wrap3 = tk.Frame(actions, highlightthickness=3, highlightbackground="black", bd=0) + wrap3.pack(side="left", padx=2, pady=2) + ttk.Button(wrap3, text="Alles zurücksetzen", command=self.reset, style="Danger.TButton").pack() + + # Export TXT + wrap4 = tk.Frame(actions, highlightthickness=3, highlightbackground="black", bd=0) + wrap4.pack(side="right", padx=2, pady=2) + ttk.Button( + wrap4, + text="Export TXT", + command=lambda: self._with_busy(lambda: exportiere_txt(self.vorgaenge, self.berechne_dauer_min), toast="TXT exportiert") + ).pack() + + # Export Excel + wrap5 = tk.Frame(actions, highlightthickness=3, highlightbackground="black", bd=0) + wrap5.pack(side="right", padx=2, pady=2) + ttk.Button( + wrap5, + text="Export Excel", + command=lambda: self._with_busy(lambda: exportiere_excel(self.vorgaenge, self.berechne_dauer_min), toast="Excel exportiert") + ).pack() + + + # ------------------------------ Menü --------------------------------- + + def _build_menu(self): + menubar = tk.Menu(self.root) + + # Optionen + optionen_menu = tk.Menu(menubar, tearoff=0) + darstellung_menu = tk.Menu(optionen_menu, tearoff=0) + darstellung_menu.add_command(label="Theme wechseln", command=self._open_theme_window) + + optionen_menu.add_command(label="Projekt") + optionen_menu.add_command(label="Extras") + optionen_menu.add_command(label="Bearbeitungs-Excel festlegen…", command=self._set_excel_path) + optionen_menu.add_cascade(label="Darstellung", menu=darstellung_menu) + menubar.add_cascade(label="Optionen", menu=optionen_menu) + + # Bearbeiten + bearbeiten_menu = tk.Menu(menubar, tearoff=0) + bearbeiten_menu.add_command(label="Bearbeitungstabelle öffnen", command=self.oeffne_excel_datei) + menubar.add_cascade(label="Bearbeiten", menu=bearbeiten_menu) + + self.root.config(menu=menubar) + + # --------------------------- Busy/Toast UI ---------------------------- + + def _create_busy_overlay(self): + # halbtransparente Überlagerung (vereinfachte Variante ohne echte Alpha) + self._overlay = tk.Frame(self.root, bg="#000000") + self._overlay.place_forget() + + inner = tk.Frame(self._overlay, bg=self.card, highlightthickness=1, highlightbackground=self.border) + inner.place(relx=0.5, rely=0.5, anchor="center") + inner.configure(padx=20, pady=14) + + lbl = tk.Label(inner, text="Bitte warten…", bg=self.card, fg=self.text, font=("Segoe UI", 11, "bold")) + lbl.pack(pady=(0, 8)) + + self._pbar = ttk.Progressbar(inner, mode="indeterminate", length=240, style="Thin.Horizontal.TProgressbar") + self._pbar.pack() + + # Toast (kleine Meldung unten rechts) + self._toast = tk.Label(self.root, text="", bg="#222222", fg="white", + font=("Segoe UI", 10), padx=10, pady=6) + + # --------------------------- Aktionen/Logik --------------------------- + + def start_vorgang(self): + nummer = self.maschinennummer.get().strip() + if not nummer: + messagebox.showerror("Fehler", "Bitte Maschinennummer eingeben.") + return + + # INTEGRA-Suche + bearb_num, fehler = finde_integra_nummern(nummer) + if fehler: + messagebox.showwarning("INTEGRA-Suche", fehler) + kommentar = "" # keine Bearbeitungsnummer gefunden + else: + kommentar = f"{bearb_num}: " + + self.vorgaenge.append({ + "nummer": nummer, + "start": datetime.now(), + "stopp": None, + "kommentar": kommentar + }) + speichere_daten(self.vorgaenge) + self.aktualisiere_liste() + + def stoppe_auswahl(self): + index = self.listbox.curselection() + if not index: + messagebox.showwarning("Hinweis", "Bitte wähle einen Vorgang aus.") + return + + vorgang = self.vorgaenge[index[0]] + if vorgang["stopp"]: + messagebox.showinfo("Hinweis", "Dieser Vorgang wurde bereits gestoppt.") + return + + benutzer_kommentar = simpledialog.askstring("Kommentar", "Kommentar zum Vorgang:") + vorgang["stopp"] = datetime.now() + + # Kommentar an Bearbeitungsnummer anhängen (falls vorhanden) + if vorgang["kommentar"]: + if benutzer_kommentar: + vorgang["kommentar"] = f"{vorgang['kommentar']} {benutzer_kommentar}" + else: + vorgang["kommentar"] = benutzer_kommentar if benutzer_kommentar else "" + + speichere_daten(self.vorgaenge) + self.aktualisiere_liste() + + def loesche_auswahl(self): + index = self.listbox.curselection() + if not index: + messagebox.showwarning("Hinweis", "Bitte wähle einen Vorgang aus.") + return + + if messagebox.askyesno("Löschen", "Bist du sicher, dass du den ausgewählten Vorgang löschen willst?"): + del self.vorgaenge[index[0]] + speichere_daten(self.vorgaenge) + self.aktualisiere_liste() + messagebox.showinfo("Gelöscht", "Der ausgewählte Vorgang wurde gelöscht.") + + def reset(self): + if messagebox.askyesno("Zurücksetzen", "Bist du sicher, dass du alle Daten löschen willst?"): + self.vorgaenge.clear() + self.maschinennummer.set("") + reset_daten() + self.aktualisiere_liste() + messagebox.showinfo("Zurückgesetzt", "Alle Daten wurden gelöscht.") + + def oeffne_excel_datei(self): + if not config.SERVER_EXCEL: + messagebox.showerror("Fehler", "Kein Pfad zur Bearbeitungs-Excel gesetzt.\nOptionen → „Bearbeitungs-Excel festlegen…“") + return + if not os.path.exists(config.SERVER_EXCEL): + messagebox.showerror("Fehler", f"Excel-Datei nicht gefunden:\n{config.SERVER_EXCEL}") + return + try: + os.startfile(config.SERVER_EXCEL) # Windows + except AttributeError: + # Fallback für andere Systeme + import subprocess, sys + if sys.platform == "darwin": + subprocess.call(["open", config.SERVER_EXCEL]) + else: + subprocess.call(["xdg-open", config.SERVER_EXCEL]) + + # ------------------------- Anzeige / Darstellung ---------------------- + + def berechne_dauer_min(self, start: datetime, stopp: datetime) -> float: + return round((stopp - start).total_seconds() / 60, 2) + + def aktualisiere_liste(self): + self.listbox.delete(0, tk.END) + for v in self.vorgaenge: + start_str = v["start"].strftime(DATUM_FORMAT) if v["start"] else "" + if v["stopp"]: + stopp_str = v["stopp"].strftime(DATUM_FORMAT) + dauer_str = f"{self.berechne_dauer_min(v['start'], v['stopp'])} Min" + else: + stopp_str = "Läuft..." + dauer_str = "" + + bearb_nummer = v.get("bearbeitungsnummer", "") + kommentar = v["kommentar"] if v["kommentar"] else "" + + # Anzeige: Nummer | Bearb.-Nr. | Start | Stopp | Dauer | Kommentar + eintrag = f"{v['nummer']} | {bearb_nummer} | {start_str} | {stopp_str} | {dauer_str} | {kommentar}" + self.listbox.insert(tk.END, eintrag) + + # ------------------------------ Themes -------------------------------- + + def _open_theme_window(self): + # Hinweis: Das Layout ist auf hell optimiert. Umschalten möglich, aber rein optisch. + theme_window = tk.Toplevel(self.root) + theme_window.title("Darstellung") + theme_window.geometry("260x150") + theme_window.configure(bg=self.bg_color) + + theme_var = tk.StringVar(value="light") # default: light + + def apply_theme(): + val = theme_var.get() + if val == "dark": + messagebox.showinfo("Info", "Dark Mode ist aktuell nur eingeschränkt unterstützt (UI ist für hell optimiert).") + theme_window.destroy() + + tk.Radiobutton( + theme_window, text="Light (empfohlen)", variable=theme_var, value="light", + bg=self.bg_color, fg=self.fg_color, selectcolor="#FFFFFF" + ).pack(pady=(12, 4)) + tk.Radiobutton( + theme_window, text="Dark (experimentell)", variable=theme_var, value="dark", + bg=self.bg_color, fg=self.fg_color, selectcolor="#FFFFFF" + ).pack() + ttk.Button(theme_window, text="Anwenden", command=apply_theme).pack(pady=12) + +"""import os +import tkinter as tk +import tkinter.ttk as ttk +from tkinter import messagebox, simpledialog +from datetime import datetime +from PIL import Image, ImageTk +from storage import lade_daten, speichere_daten, reset_daten +from export import exportiere_txt, exportiere_excel +from integra_lookup import finde_integra_nummern +from config import LOGO_PATH, DATUM_FORMAT +import config + + +class ZeitErfassungApp: + # ---------------------- Optionen / Einstellungen ---------------------- + + def _set_excel_path(self): + from tkinter import filedialog + pfad = filedialog.askopenfilename( + title="Bearbeitungs-Excel wählen", + filetypes=[ + ("Excel", "*.xlsx *.xlsm *.xlsb *.xls"), + ("Alle Dateien", "*.*") + ], + ) + if pfad: + config.set_server_excel(pfad) + messagebox.showinfo("Gespeichert", f"Pfad gespeichert:\n{config.SERVER_EXCEL}") + + # --------------------------- Konstruktor ------------------------------ + def __init__(self, root: tk.Tk): + self.root = root + self.root.title("Zeiterfassung MERZ") + self.root.geometry("900x560") + + # Fenstericon setzen (ICO bevorzugt, PNG geht auf manchen Systemen auch) + try: + icon_path = LOGO_PATH + if icon_path.lower().endswith(".ico"): + self.root.iconbitmap(icon_path) + else: + img = Image.open(icon_path) + icon_img = ImageTk.PhotoImage(img) + self.root.iconphoto(True, icon_img) + self._icon_ref = icon_img + except Exception as e: + print(f"Fenstericon konnte nicht gesetzt werden: {e}") + + # Daten + self.vorgaenge = lade_daten() + + # Grundfarben (helle Palette) + self.bg_color = "#F5F5F7" + self.fg_color = "#1D1D1F" + self.root.configure(bg=self.bg_color) + + # UI aufbauen + self._build_gui() + self._build_menu() + self._create_busy_overlay() + self.aktualisiere_liste() + + # ↵ Enter startet den Vorgang + self.root.bind("", lambda e: self.start_vorgang()) + + # --------------------------- Apple-Style ------------------------------ + + def _apply_apple_style(self): + self.bg = "#F5F5F7" # Fensterhintergrund + self.card = "#FFFFFF" # Karten/Flächen + self.border = "#E5E5EA" + self.text = "#1D1D1F" + self.subtext = "#3A3A3C" + self.blue = "#0A84FF" # Akzent + self.blue_hover = "#147CFF" + self.blue_pressed = "#0068DA" + self.neutral_hover = "#F2F2F7" + + style = ttk.Style() + style.theme_use("default") + + # Globale Schrift + style.configure(".", background=self.bg, foreground=self.text, font=("Segoe UI", 11)) + + # Karten / Toolbar + style.configure("Card.TFrame", background=self.card, borderwidth=1, relief="solid") + style.configure("Toolbar.TFrame", background=self.bg) + + # Labels + style.configure("TLabel", background=self.bg, foreground=self.text, font=("Segoe UI", 11)) + style.configure("Title.TLabel", background=self.bg, foreground=self.text, font=("Segoe UI", 16, "bold")) + style.configure("Secondary.TLabel", background=self.bg, foreground=self.subtext) + + # Entry + style.configure("TEntry", fieldbackground=self.card, background=self.card, foreground=self.text) + + # Neutraler Button + style.configure("TButton", background=self.card, foreground=self.text, padding=(12, 8), + borderwidth=1, relief="flat") + style.map("TButton", + background=[("active", self.neutral_hover)], + relief=[("pressed", "sunken")]) + + # Primär-Button (sichtbarere States) + style.configure("Accent.TButton", background=self.blue, foreground="#FFFFFF", + padding=(14, 9), borderwidth=0, relief="flat") + style.map("Accent.TButton", + background=[("active", self.blue_hover), ("pressed", self.blue_pressed)]) + + # Danger-Button (optional nutzbar) + style.configure("Danger.TButton", background="#FF3B30", foreground="white", + padding=(12, 8), borderwidth=0, relief="flat") + style.map("Danger.TButton", + background=[("active", "#FF554D"), ("pressed", "#D92A21")]) + + # Progressbar + style.configure("Thin.Horizontal.TProgressbar", troughcolor=self.card, background=self.blue) + + # ---------------------------- GUI-Aufbau ------------------------------ + + def _build_gui(self): + self._apply_apple_style() + + # Toolbar oben + toolbar = ttk.Frame(self.root, style="Toolbar.TFrame") + toolbar.pack(fill="x", padx=12, pady=(8, 12)) + + # Logo + Titel + try: + logo_img = Image.open(LOGO_PATH).resize((32, 32), Image.LANCZOS) + self.logo = ImageTk.PhotoImage(logo_img) + ttk.Label(toolbar, image=self.logo, style="TLabel").pack(side="left", padx=(0, 8)) + except Exception: + pass + + ttk.Label(toolbar, text="Zeiterfassung", style="Title.TLabel").pack(side="left") + ttk.Label(toolbar, text="", style="TLabel").pack(side="left", expand=True) # Spacer + + # Hauptkarte + main_card = ttk.Frame(self.root, style="Card.TFrame") + main_card.pack(fill="both", expand=True, padx=12, pady=(0, 12)) + + # ---------------- Eingabebereich mit schwarzem Rahmen ---------------- + input_wrap = tk.Frame(main_card, bg=self.card, highlightthickness=3, highlightbackground="000000") + input_wrap.pack(fill="x", padx=12, pady=(12, 8)) + inner = tk.Frame(input_wrap, bg=self.card) + inner.pack(fill="x", padx=10, pady=8) + + inner.grid_columnconfigure(0, weight=0) + inner.grid_columnconfigure(1, weight=1) + inner.grid_columnconfigure(2, weight=0) + + # Grid: Label | Entry (dehnbar) | Start-Button + inner.grid_columnconfigure(0, weight=0) + inner.grid_columnconfigure(1, weight=1) + inner.grid_columnconfigure(2, weight=0) + + self.maschinennummer = tk.StringVar() + + ttk.Label(inner, text="Maschinennummer:").grid(row=0, column=0, sticky="w", padx=(0, 10)) + self.entry = ttk.Entry(inner, textvariable=self.maschinennummer) + self.entry.grid(row=0, column=1, sticky="ew") # füllt bis rechts + self.entry.focus_set() + + self.start_button_inline = ttk.Button(inner, text="Start", command=self.start_vorgang, style="Accent.TButton") + self.start_button_inline.grid(row=0, column=2, sticky="e", padx=(10, 0)) + + # ---------------- Liste + Scrollbar (auch mit schwarzem Rahmen) ---------------- + list_wrap = tk.Frame(main_card, bg=self.card, highlightthickness=3, highlightbackground="000000") + list_wrap.pack(fill="both", expand=True, padx=12, pady=(0, 12)) + + list_frame = tk.Frame(list_wrap, bg=self.card) + list_frame.pack(fill="both", expand=True, padx=8, pady=8) scrollbar = ttk.Scrollbar(list_frame, orient="vertical") scrollbar.pack(side="right", fill="y") @@ -187,6 +631,7 @@ class ZeitErfassungApp: self.listbox.config(yscrollcommand=scrollbar.set) scrollbar.config(command=self.listbox.yview) + # ---------------- Aktionsleiste unten ---------------- actions = ttk.Frame(main_card, style="Toolbar.TFrame") actions.pack(fill="x", padx=12, pady=(0, 12)) @@ -380,377 +825,4 @@ class ZeitErfassungApp: bg=self.bg_color, fg=self.fg_color, selectcolor="#FFFFFF" ).pack() ttk.Button(theme_window, text="Anwenden", command=apply_theme).pack(pady=12) - - -""" -import os -import tkinter as tk -import tkinter.ttk as ttk -from tkinter import messagebox, simpledialog -from datetime import datetime -from PIL import Image, ImageTk - -from storage import lade_daten, speichere_daten, reset_daten -from export import exportiere_txt, exportiere_excel -from integra_lookup import finde_integra_nummern -from config import LOGO_PATH, DATUM_FORMAT -import config - - -class ZeitErfassungApp: - # ---------------------- Optionen / Einstellungen ---------------------- - def _set_excel_path(self): - from tkinter import filedialog - pfad = filedialog.askopenfilename( - title="Bearbeitungs-Excel wählen", - filetypes=[ - ("Excel", "*.xlsx *.xlsm *.xlsb *.xls"), - ("Alle Dateien", "*.*") - ], - ) - if pfad: - config.set_server_excel(pfad) - messagebox.showinfo("Gespeichert", f"Pfad gespeichert:\n{config.SERVER_EXCEL}") - - # --------------------------- Konstruktor ------------------------------ - - def __init__(self, root: tk.Tk): - self.root = root - self.root.title("Zeiterfassung MERZ") - self.root.geometry("900x560") - - # Fenstericon setzen (ICO bevorzugt, PNG geht auf manchen Systemen auch) - try: - icon_path = LOGO_PATH - if icon_path.lower().endswith(".ico"): - self.root.iconbitmap(icon_path) - else: - img = Image.open(icon_path) - icon_img = ImageTk.PhotoImage(img) - self.root.iconphoto(True, icon_img) - self._icon_ref = icon_img - except Exception as e: - print(f"Fenstericon konnte nicht gesetzt werden: {e}") - - # Daten - self.vorgaenge = lade_daten() - - # Grundfarben (helle Palette) - self.bg_color = "#F5F5F7" - self.fg_color = "#1D1D1F" - - self.root.configure(bg=self.bg_color) - - # UI aufbauen - self._build_gui() - self._build_menu() - self._create_busy_overlay() - self.aktualisiere_liste() - - # --------------------------- Apple-Style ------------------------------ - - def _apply_apple_style(self): - self.bg = "#F5F5F7" # Fensterhintergrund - self.card = "#FFFFFF" # Karten/Flächen - self.border = "#E5E5EA" - self.text = "#1D1D1F" - self.subtext = "#3A3A3C" - self.blue = "#0A84FF" # Akzent - self.blue_hover = "#147CFF" - self.blue_pressed = "#0068DA" - self.neutral_hover = "#F2F2F7" - - style = ttk.Style() - style.theme_use("default") - - # Globale Schrift - style.configure(".", background=self.bg, foreground=self.text, font=("Segoe UI", 11)) - - # Karten / Toolbar - style.configure("Card.TFrame", background=self.card, borderwidth=1, relief="solid") - style.configure("Toolbar.TFrame", background=self.bg) - - # Labels - style.configure("TLabel", background=self.bg, foreground=self.text, font=("Segoe UI", 11)) - style.configure("Title.TLabel", background=self.bg, foreground=self.text, font=("Segoe UI", 16, "bold")) - style.configure("Secondary.TLabel", background=self.bg, foreground=self.subtext) - - # Entry - style.configure("TEntry", fieldbackground=self.card, background=self.card, foreground=self.text) - - # Neutraler Button - style.configure("TButton", background=self.card, foreground=self.text, padding=(12, 8), - borderwidth=1, relief="flat") - style.map("TButton", - background=[("active", self.neutral_hover)], - relief=[("pressed", "sunken")]) - - # Primär-Button (sichtbarere States) - style.configure("Accent.TButton", background=self.blue, foreground="#FFFFFF", - padding=(14, 9), borderwidth=0, relief="flat") - style.map("Accent.TButton", - background=[("active", self.blue_hover), ("pressed", self.blue_pressed)]) - - # Danger-Button (optional nutzbar) - style.configure("Danger.TButton", background="#FF3B30", foreground="white", - padding=(12, 8), borderwidth=0, relief="flat") - style.map("Danger.TButton", - background=[("active", "#FF554D"), ("pressed", "#D92A21")]) - - # Progressbar - style.configure("Thin.Horizontal.TProgressbar", troughcolor=self.card, background=self.blue) - - # ---------------------------- GUI-Aufbau ------------------------------ - def _build_gui(self): - self._apply_apple_style() - - # Toolbar oben - toolbar = ttk.Frame(self.root, style="Toolbar.TFrame") - toolbar.pack(fill="x", padx=12, pady=(8, 12)) - - # Logo + Titel - try: - logo_img = Image.open(LOGO_PATH).resize((32, 32), Image.LANCZOS) - self.logo = ImageTk.PhotoImage(logo_img) - ttk.Label(toolbar, image=self.logo, style="TLabel").pack(side="left", padx=(0, 8)) - except Exception: - pass - - ttk.Label(toolbar, text="Zeiterfassung", style="Title.TLabel").pack(side="left") - ttk.Label(toolbar, text="", style="TLabel").pack(side="left", expand=True) # Spacer - - # Primäraktion - self.start_button = ttk.Button(toolbar, text="Start", command=self.start_vorgang, style="Accent.TButton") - self.start_button.pack(side="right") - - # Hauptkarte - main_card = ttk.Frame(self.root, style="Card.TFrame") - main_card.pack(fill="both", expand=True, padx=12, pady=(0, 12)) - - # Eingabezeile - row = ttk.Frame(main_card, style="Card.TFrame") - row.pack(fill="x", padx=12, pady=12) - - self.maschinennummer = tk.StringVar() - ttk.Label(row, text="Maschinennummer:").pack(side="left", padx=(0, 8)) - entry = ttk.Entry(row, textvariable=self.maschinennummer, width=40) - entry.pack(side="left") - entry.focus_set() - - - # Liste + Scrollbar - list_frame = ttk.Frame(main_card, style="Card.TFrame") - list_frame.pack(fill="both", expand=True, padx=12, pady=(0, 12)) - - scrollbar = ttk.Scrollbar(list_frame, orient="vertical") - scrollbar.pack(side="right", fill="y") - - self.listbox = tk.Listbox( - list_frame, - width=100, - font=("Segoe UI", 10), - activestyle="none", - borderwidth=0, - highlightthickness=0, - bg=self.card, - fg=self.text, - selectbackground="#D0E7FF", - selectforeground=self.text - ) - self.listbox.pack(side="left", fill="both", expand=True) - - self.listbox.config(yscrollcommand=scrollbar.set) - scrollbar.config(command=self.listbox.yview) - - # Aktionsleiste unten - actions = ttk.Frame(main_card, style="Toolbar.TFrame") - actions.pack(fill="x", padx=12, pady=(0, 12)) - - ttk.Button(actions, text="Stop mit Kommentar", command=self.stoppe_auswahl).pack(side="left") - ttk.Button(actions, text="Auswahl löschen", command=self.loesche_auswahl).pack(side="left", padx=(8, 0)) - ttk.Button(actions, text="Alles zurücksetzen", command=self.reset, style="Danger.TButton").pack(side="left", padx=(8, 0)) - ttk.Button(actions, text="Export TXT", - command=lambda: self._with_busy(lambda: exportiere_txt(self.vorgaenge, self.berechne_dauer_min), - toast="TXT exportiert")).pack(side="right") - ttk.Button(actions, text="Export Excel", - command=lambda: self._with_busy(lambda: exportiere_excel(self.vorgaenge, self.berechne_dauer_min), - toast="Excel exportiert")).pack(side="right", padx=(0, 8)) - - # ------------------------------ Menü --------------------------------- - - def _build_menu(self): - menubar = tk.Menu(self.root) - - # Optionen - optionen_menu = tk.Menu(menubar, tearoff=0) - darstellung_menu = tk.Menu(optionen_menu, tearoff=0) - darstellung_menu.add_command(label="Theme wechseln", command=self._open_theme_window) - - optionen_menu.add_command(label="Projekt") - optionen_menu.add_command(label="Extras") - optionen_menu.add_command(label="Bearbeitungs-Excel festlegen…", command=self._set_excel_path) - optionen_menu.add_cascade(label="Darstellung", menu=darstellung_menu) - menubar.add_cascade(label="Optionen", menu=optionen_menu) - - # Bearbeiten - bearbeiten_menu = tk.Menu(menubar, tearoff=0) - bearbeiten_menu.add_command(label="Bearbeitungstabelle öffnen", command=self.oeffne_excel_datei) - menubar.add_cascade(label="Bearbeiten", menu=bearbeiten_menu) - - self.root.config(menu=menubar) - - # --------------------------- Busy/Toast UI ---------------------------- - - def _create_busy_overlay(self): - # halbtransparente Überlagerung (ohne echte Alpha auf Widgets) - self._overlay = tk.Frame(self.root, bg="#000000") # dunkler Schleier - self._overlay.place_forget() # erst mal verstecken - - inner = tk.Frame(self._overlay, bg=self.card, highlightthickness=1, highlightbackground=self.border) - inner.place(relx=0.5, rely=0.5, anchor="center") - inner.configure(padx=20, pady=14) - - lbl = tk.Label(inner, text="Bitte warten…", bg=self.card, fg=self.text, font=("Segoe UI", 11, "bold")) - lbl.pack(pady=(0, 8)) - - self._pbar = ttk.Progressbar(inner, mode="indeterminate", length=240, style="Thin.Horizontal.TProgressbar") - self._pbar.pack() - - # Toast (kleine Meldung unten rechts) - self._toast = tk.Label(self.root, text="", bg="#222222", fg="white", - font=("Segoe UI", 10), padx=10, pady=6) - - def start_vorgang(self): - nummer = self.maschinennummer.get().strip() - if not nummer: - messagebox.showerror("Fehler", "Bitte Maschinennummer eingeben.") - return - - # INTEGRA-Suche - bearb_num, fehler = finde_integra_nummern(nummer) - if fehler: - messagebox.showwarning("INTEGRA-Suche", fehler) - kommentar = "" # keine Bearbeitungsnummer gefunden - else: - kommentar = f"{bearb_num}: " - - self.vorgaenge.append({ - "nummer": nummer, - "start": datetime.now(), - "stopp": None, - "kommentar": kommentar - }) - speichere_daten(self.vorgaenge) - self.aktualisiere_liste() - - def stoppe_auswahl(self): - index = self.listbox.curselection() - if not index: - messagebox.showwarning("Hinweis", "Bitte wähle einen Vorgang aus.") - return - - vorgang = self.vorgaenge[index[0]] - if vorgang["stopp"]: - messagebox.showinfo("Hinweis", "Dieser Vorgang wurde bereits gestoppt.") - return - - benutzer_kommentar = simpledialog.askstring("Kommentar", "Kommentar zum Vorgang:") - vorgang["stopp"] = datetime.now() - - # Kommentar an Bearbeitungsnummer anhängen (falls vorhanden) - if vorgang["kommentar"]: - if benutzer_kommentar: - vorgang["kommentar"] = f"{vorgang['kommentar']} {benutzer_kommentar}" - else: - vorgang["kommentar"] = benutzer_kommentar if benutzer_kommentar else "" - - speichere_daten(self.vorgaenge) - self.aktualisiere_liste() - - def loesche_auswahl(self): - index = self.listbox.curselection() - if not index: - messagebox.showwarning("Hinweis", "Bitte wähle einen Vorgang aus.") - return - - if messagebox.askyesno("Löschen", "Bist du sicher, dass du den ausgewählten Vorgang löschen willst?"): - del self.vorgaenge[index[0]] - speichere_daten(self.vorgaenge) - self.aktualisiere_liste() - messagebox.showinfo("Gelöscht", "Der ausgewählte Vorgang wurde gelöscht.") - - def reset(self): - if messagebox.askyesno("Zurücksetzen", "Bist du sicher, dass du alle Daten löschen willst?"): - self.vorgaenge.clear() - self.maschinennummer.set("") - reset_daten() - self.aktualisiere_liste() - messagebox.showinfo("Zurückgesetzt", "Alle Daten wurden gelöscht.") - - def oeffne_excel_datei(self): - if not config.SERVER_EXCEL: - messagebox.showerror("Fehler", "Kein Pfad zur Bearbeitungs‑Excel gesetzt.\nOptionen → „Bearbeitungs‑Excel festlegen…“") - return - if not os.path.exists(config.SERVER_EXCEL): - messagebox.showerror("Fehler", f"Excel-Datei nicht gefunden:\n{config.SERVER_EXCEL}") - return - try: - os.startfile(config.SERVER_EXCEL) # Windows - except AttributeError: - # Fallback für andere Systeme - import subprocess, sys - if sys.platform == "darwin": - subprocess.call(["open", config.SERVER_EXCEL]) - else: - subprocess.call(["xdg-open", config.SERVER_EXCEL]) - - # ------------------------- Anzeige / Darstellung ---------------------- - - def berechne_dauer_min(self, start: datetime, stopp: datetime) -> float: - return round((stopp - start).total_seconds() / 60, 2) - - def aktualisiere_liste(self): - self.listbox.delete(0, tk.END) - for v in self.vorgaenge: - start_str = v["start"].strftime(DATUM_FORMAT) if v["start"] else "" - if v["stopp"]: - stopp_str = v["stopp"].strftime(DATUM_FORMAT) - dauer_str = f"{self.berechne_dauer_min(v['start'], v['stopp'])} Min" - else: - stopp_str = "Läuft..." - dauer_str = "" - - bearb_nummer = v.get("bearbeitungsnummer", "") - kommentar = v["kommentar"] if v["kommentar"] else "" - - # Anzeige: Nummer | Bearb.-Nr. | Start | Stopp | Dauer | Kommentar - eintrag = f"{v['nummer']} | {bearb_nummer} | {start_str} | {stopp_str} | {dauer_str} | {kommentar}" - self.listbox.insert(tk.END, eintrag) - - # ------------------------------ Themes -------------------------------- - - def _open_theme_window(self): - # Hinweis: Das Layout ist auf hell optimiert. Umschalten möglich, aber rein optisch. - theme_window = tk.Toplevel(self.root) - theme_window.title("Darstellung") - theme_window.geometry("260x150") - theme_window.configure(bg=self.bg_color) - - theme_var = tk.StringVar(value="light") # default: light - - def apply_theme(): - val = theme_var.get() - if val == "dark": - messagebox.showinfo("Info", "Dark Mode ist aktuell nur eingeschränkt unterstützt (UI ist für hell optimiert).") - theme_window.destroy() - - tk.Radiobutton( - theme_window, text="Light (empfohlen)", variable=theme_var, value="light", - bg=self.bg_color, fg=self.fg_color, selectcolor="#FFFFFF" - ).pack(pady=(12, 4)) - tk.Radiobutton( - theme_window, text="Dark (experimentell)", variable=theme_var, value="dark", - bg=self.bg_color, fg=self.fg_color, selectcolor="#FFFFFF" - ).pack() - ttk.Button(theme_window, text="Anwenden", command=apply_theme).pack(pady=12) - """ \ No newline at end of file +""" \ No newline at end of file