recreated json file handling as connector model, fixing #10 and introducing #8 and #7

This commit is contained in:
2025-04-28 00:18:22 +02:00
parent dc27197129
commit 9ea44933a6
3 changed files with 113 additions and 98 deletions

View File

@@ -3,6 +3,7 @@ from configparser import NoSectionError, NoOptionError
from tkinter import font, filedialog, messagebox
from config import Config
from connector import JSONConnector
def show_error(message_title: str, message: str, parent: tk.Tk | tk.Toplevel):
@@ -25,27 +26,28 @@ class Window(tk.Toplevel):
self._destroy_window()
def _destroy_window(self):
self.parent.populate_table()
self.root.update()
self.destroy()
class EditRecord(Window):
def __init__(self, parent, root: tk.Tk, data: tuple):
def __init__(self, parent, root: tk.Tk, record_id: int):
super().__init__(parent, root)
self.bind("<Return>", self._update)
self.data = data
self.model = JSONConnector()
record = self.model.get_by_id(record_id)
button_width = 8
self.title("Adresse bearbeiten")
self.aktiv = tk.StringVar()
self.firma = tk.StringVar()
self.name = tk.StringVar()
self.strasse = tk.StringVar()
self.plz_ort = tk.StringVar()
self.field_list = [self.aktiv, self.firma, self.name, self.strasse, self.plz_ort]
for argument, field in zip(self.data, self.field_list):
field.set(argument)
self.record_id = tk.IntVar(value=record_id)
self.aktiv = tk.StringVar(value=record.get("aktiv"))
self.firma = tk.StringVar(value=record.get("firma"))
self.name = tk.StringVar(value=record.get("name"))
self.strasse = tk.StringVar(value=record.get("strasse"))
self.plz_ort = tk.StringVar(value=record.get("plzort"))
edit_frame = tk.Frame(self)
edit_frame.pack(side=tk.TOP, fill=tk.X, pady=20, padx=20)
@@ -71,7 +73,15 @@ class EditRecord(Window):
tk.Button(button_frame, text="Abbrechen", command=self.close_window, width=button_width).pack(side=tk.LEFT)
def _update(self, event = None):
self.parent.update_record(self.field_list)
new_record = {
"record_id": self.record_id.get(),
"aktiv": self.aktiv.get(),
"firma": self.firma.get(),
"name": self.name.get(),
"strasse": self.strasse.get(),
"plzort": self.plz_ort.get(),
}
self.model.update_record(new_record)
self.close_window()