autofixes lazyvim, fixed coffee counter

This commit is contained in:
2026-03-08 23:54:27 +01:00
parent 8b55f74cd5
commit 55091bbb87

View File

@@ -21,7 +21,7 @@ class Application:
y_offset = 200
width = 1050
height = 700
VERSION = '0.2.3b'
VERSION = "0.2.3b"
title = f"Brovski Adress-Etiketten Verwaltung {VERSION}"
self.root = tk.Tk(className="BrovskiAdressEtiketten")
@@ -56,10 +56,11 @@ class Application:
# leave application if settings are bad
if not self.config_good:
show_error(message_title="Fehler Konfiguration",
message="Die Konfiguration ist fehlerhaft, bitte prüfe deine config.ini",
parent=self.root
)
show_error(
message_title="Fehler Konfiguration",
message="Die Konfiguration ist fehlerhaft, bitte prüfe deine config.ini",
parent=self.root,
)
sys.exit()
# frames
@@ -72,27 +73,50 @@ class Application:
# top buttons
button_width = 8
tk.Button(top_frame, text="Insert", command=self.insert_record, width=button_width).pack(side=tk.LEFT)
tk.Button(top_frame, text="Delete", command=self.delete_record, width=button_width).pack(side=tk.LEFT)
tk.Button(top_frame, text="Export CSV", command=self.export_csv, width=button_width).pack(side=tk.LEFT)
tk.Button(top_frame, text="Toggle Aktiv", command=self.toggle_active, width=button_width).pack(side=tk.LEFT)
tk.Checkbutton(top_frame, text="Filter aktiv", variable=self.filter_active, command=self.populate_table).pack(
side=tk.LEFT)
tk.Button(top_frame, text="Quit", command=self.on_close, width=button_width).pack(side=tk.RIGHT)
tk.Button(top_frame, text="Settings", command=self.show_settings, width=button_width).pack(side=tk.RIGHT)
tk.Button(
top_frame, text="Insert", command=self.insert_record, width=button_width
).pack(side=tk.LEFT)
tk.Button(
top_frame, text="Delete", command=self.delete_record, width=button_width
).pack(side=tk.LEFT)
tk.Button(
top_frame, text="Export CSV", command=self.export_csv, width=button_width
).pack(side=tk.LEFT)
tk.Button(
top_frame,
text="Toggle Aktiv",
command=self.toggle_active,
width=button_width,
).pack(side=tk.LEFT)
tk.Checkbutton(
top_frame,
text="Filter aktiv",
variable=self.filter_active,
command=self.populate_table,
).pack(side=tk.LEFT)
tk.Button(
top_frame, text="Quit", command=self.on_close, width=button_width
).pack(side=tk.RIGHT)
tk.Button(
top_frame, text="Settings", command=self.show_settings, width=button_width
).pack(side=tk.RIGHT)
# table content
scrollbar = ttk.Scrollbar(data_frame, orient=tk.VERTICAL)
self.table = ttk.Treeview(data_frame, yscrollcommand=scrollbar.set, columns=("0", "1", "2", "3", "4", "5"),
show="headings")
self.table = ttk.Treeview(
data_frame,
yscrollcommand=scrollbar.set,
columns=("0", "1", "2", "3", "4", "5"),
show="headings",
)
scrollbar.config(command=self.table.yview)
self.table.heading('0', text="Aktiv")
self.table.column('0', anchor=tk.CENTER, width=0)
self.table.heading('1', text="Firma")
self.table.heading('2', text="Name")
self.table.heading('3', text="Strasse")
self.table.heading('4', text="Plz/Ort")
self.table.heading('5', text="Anzahl")
self.table.heading("0", text="Aktiv")
self.table.column("0", anchor=tk.CENTER, width=0)
self.table.heading("1", text="Firma")
self.table.heading("2", text="Name")
self.table.heading("3", text="Strasse")
self.table.heading("4", text="Plz/Ort")
self.table.heading("5", text="Anzahl")
self.table.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
scrollbar.pack(side=tk.LEFT, fill=tk.Y)
@@ -126,9 +150,11 @@ class Application:
self.show_settings()
def show_config_error(self):
show_error(message_title="Fehlerhafte Konfiguration",
message="Konnte benötigte Parameter in config.ini nicht finden",
parent=self.root)
show_error(
message_title="Fehlerhafte Konfiguration",
message="Konnte benötigte Parameter in config.ini nicht finden",
parent=self.root,
)
def on_close(self):
self.root.destroy()
@@ -144,7 +170,7 @@ class Application:
"name": "Name",
"strasse": "Strasse",
"plzort": "Plz/Ort",
"anzahl": "1"
"anzahl": "1",
}
self.model.create_new(values)
self.populate_table()
@@ -155,14 +181,17 @@ class Application:
return
if len(self.table.selection()) > 1:
show_error(message_title="Mehrere Adressen ausgewählt",
message="Es können nur einzelne Adressen gelöscht werden",
parent=self.root)
show_error(
message_title="Mehrere Adressen ausgewählt",
message="Es können nur einzelne Adressen gelöscht werden",
parent=self.root,
)
return
if messagebox.askyesno(
"Eintrag löschen?",
"Willst du diesen Eintrag wirklich löschen?\nDies kann nicht rückgängig gemacht werden"):
"Eintrag löschen?",
"Willst du diesen Eintrag wirklich löschen?\nDies kann nicht rückgängig gemacht werden",
):
self.model.delete_by_id(self.current_record)
self.deselect_tree()
@@ -212,7 +241,7 @@ class Application:
self.edit_selected_record()
def enter_button(self, event):
self.edit_selected_record()
self.edit_selected_record()
def click_on_header(self, event):
column = self.table.identify_column(event.x)
@@ -247,7 +276,6 @@ class Application:
self.current_record = int(self.table.focus())
self.open_window_edit_records(self.current_record)
def export_csv(self):
try:
with open(self.csv_file, "w", encoding="utf-8") as f:
@@ -259,10 +287,11 @@ class Application:
self.write_sender_to_csv(address, writer)
self.write_receiver_to_csv(address, writer)
except FileNotFoundError:
show_error(message_title="Unexpected error",
message=f"Could not write file {self.csv_file}",
parent=self.root
)
show_error(
message_title="Unexpected error",
message=f"Could not write file {self.csv_file}",
parent=self.root,
)
def write_receiver_to_csv(self, address: dict, csv_writer: _csv.writer):
receiver_line = []
@@ -290,17 +319,26 @@ class Application:
# skip inactive records if filter is true
if self.filter_active.get() and address["aktiv"] != "x":
continue
self.table.insert('', 'end', iid=address["record_id"],
values=(address["aktiv"], address["firma"], address["name"], address["strasse"],
address["plzort"], address["anzahl"])
)
self.table.insert(
"",
"end",
iid=address["record_id"],
values=(
address["aktiv"],
address["firma"],
address["name"],
address["strasse"],
address["plzort"],
address["anzahl"],
),
)
self.update_status_bar()
def export_table_to_address_list(self):
self.address_list.clear()
for child in self.table.get_children():
self.address_list.append([])
for value in self.table.item(child)['values']:
for value in self.table.item(child)["values"]:
self.address_list[-1].append(value)
self.update_status_bar()
@@ -326,7 +364,8 @@ class Application:
self.statusbar.set(
f"Adressen: {self.length_address_list} | "
f"Aktive Adressen: {self.length_address_list_active} | "
f"Total Kaffee: {self.count_coffee}")
f"Total Kaffee: {self.count_coffee}"
)
def _count_address_records(self):
self.length_address_list = len(self.address_list)
@@ -335,7 +374,7 @@ class Application:
for address in self.address_list:
if address["aktiv"] == "x":
count += 1
count_coffee += count_coffee + int(address["anzahl"])
count_coffee += int(address["anzahl"])
self.length_address_list_active = count
self.count_coffee = count_coffee
@@ -354,5 +393,5 @@ class Application:
self.table.focus_force()
if __name__ == '__main__':
if __name__ == "__main__":
Application()