made everything modular
This commit is contained in:
45
app/simulation/ui/dtc.py
Normal file
45
app/simulation/ui/dtc.py
Normal file
@@ -0,0 +1,45 @@
|
||||
# =============================
|
||||
# app/simulation/ui/dtc.py
|
||||
# =============================
|
||||
|
||||
from __future__ import annotations
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from typing import Dict, Any
|
||||
from app.simulation.ui import UITab
|
||||
|
||||
DTC_LIST = [
|
||||
("P0300", "Random/Multiple Cylinder Misfire"),
|
||||
("P0130", "O2 Sensor Circuit (Bank1-Sensor1)"),
|
||||
("C0035", "Wheel Speed Sensor LF"),
|
||||
("U0121", "Lost Communication With ABS")
|
||||
]
|
||||
|
||||
class DtcTab(UITab):
|
||||
NAME = "dtc"
|
||||
TITLE = "Fehlercodes"
|
||||
PRIO = 10
|
||||
def __init__(self, parent, sim):
|
||||
self.sim = sim
|
||||
self.frame = ttk.Frame(parent, padding=8)
|
||||
self.vars: Dict[str, tk.BooleanVar] = {}
|
||||
row = 0
|
||||
ttk.Label(self.frame, text="Diagnose-Flags (Demo)", style="Header.TLabel").grid(row=row, column=0, sticky="w"); row += 1
|
||||
for code, label in DTC_LIST:
|
||||
var = tk.BooleanVar(value=False)
|
||||
ttk.Checkbutton(self.frame, text=f"{code} – {label}", variable=var).grid(row=row, column=0, sticky="w")
|
||||
self.vars[code] = var; row += 1
|
||||
ttk.Button(self.frame, text="Alle löschen", command=self.clear_all).grid(row=row, column=0, sticky="w", pady=(8,0))
|
||||
|
||||
def clear_all(self):
|
||||
for v in self.vars.values(): v.set(False)
|
||||
|
||||
def save_into_config(self, out: Dict[str, Any]) -> None:
|
||||
out.setdefault("dtc", {})
|
||||
out["dtc"].update({code: bool(v.get()) for code, v in self.vars.items()})
|
||||
|
||||
def load_from_config(self, cfg: Dict[str, Any]) -> None:
|
||||
dtc = cfg.get("dtc", {})
|
||||
for code, v in self.vars.items():
|
||||
v.set(bool(dtc.get(code, False)))
|
||||
self.sim.load_config(cfg)
|
Reference in New Issue
Block a user