refactored error message dialog
This commit is contained in:
@@ -9,7 +9,13 @@ from tkinter import messagebox
|
||||
from tkinter import ttk
|
||||
import json
|
||||
|
||||
from PyInstaller.utils.hooks import collect_data_files
|
||||
|
||||
def show_error(message_title: str, message: str, parent: tk.Tk | tk.Toplevel):
|
||||
messagebox.showwarning(
|
||||
title=message_title,
|
||||
message=message,
|
||||
parent=parent
|
||||
)
|
||||
|
||||
|
||||
class SettingsWindow(tk.Toplevel):
|
||||
@@ -32,7 +38,8 @@ class SettingsWindow(tk.Toplevel):
|
||||
|
||||
tk.Label(path_frame, text="Datenpfad JSON Datei").grid(row=0, column=0)
|
||||
tk.Entry(path_frame, textvariable=self.json_file, width=50).grid(row=1, column=0)
|
||||
tk.Button(path_frame, text="Pfad", command=lambda: self.set_json_path(self.json_file.get())).grid(row=1, column=1)
|
||||
tk.Button(path_frame, text="Pfad", command=lambda: self.set_json_path(self.json_file.get())).grid(row=1,
|
||||
column=1)
|
||||
|
||||
tk.Label(path_frame, text="Datenpfad CSV Export Datei").grid(row=2, column=0)
|
||||
tk.Entry(path_frame, textvariable=self.csv_file, width=50).grid(row=3, column=0)
|
||||
@@ -76,7 +83,9 @@ class SettingsWindow(tk.Toplevel):
|
||||
|
||||
def ok(self):
|
||||
if self.json_file.get() == "" or self.csv_file.get() == "":
|
||||
messagebox.showwarning(title="Fehlerhafte Konfiguration", message="Pfad für JSON oder CSV Datei fehlt")
|
||||
show_error(message_title="Fehlerhafte Konfiguration",
|
||||
message="Pfad für JSON oder CSV Datei fehlt",
|
||||
parent=self)
|
||||
return
|
||||
self.config.set("json", "path", self.json_file.get())
|
||||
self.config.set("csv", "path", self.csv_file.get())
|
||||
@@ -167,8 +176,10 @@ class Application:
|
||||
|
||||
# leave application if settings are bad
|
||||
if not self.config_good:
|
||||
self.show_error("Fehler Konfiguration",
|
||||
"Die Konfiguration ist fehlerhaft, bitte prüfe deine config.ini")
|
||||
show_error(message_title="Fehler Konfiguration",
|
||||
message="Die Konfiguration ist fehlerhaft, bitte prüfe deine config.ini",
|
||||
parent=self.root
|
||||
)
|
||||
sys.exit()
|
||||
|
||||
top_frame = tk.Frame(self.root)
|
||||
@@ -241,9 +252,9 @@ class Application:
|
||||
self.show_settings()
|
||||
|
||||
def show_config_error(self):
|
||||
if self.show_error("Fehlerhafte Konfiguration",
|
||||
"Konnte benötigte Parameter in config.ini nicht finden"):
|
||||
print("Fehlerhafte Konfiguration")
|
||||
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()
|
||||
@@ -364,9 +375,10 @@ class Application:
|
||||
self.address_list = json.load(f)
|
||||
self.address_list.sort(key=lambda x: (x[0], x[1]))
|
||||
except FileNotFoundError:
|
||||
self.show_error(
|
||||
show_error(
|
||||
message_title="Datei nicht gefunden",
|
||||
message=f"{self.json_file_name} nicht gefunden, erstelle leere Datei unter {self.json_path}"
|
||||
message=f"{self.json_file_name} nicht gefunden, erstelle leere Datei unter {self.json_path}",
|
||||
parent=self.root
|
||||
)
|
||||
self.address_list = [["", "firma", "name", "adresse", "plz/ort"]]
|
||||
with open(self.json_file, "w", encoding="utf-8") as f:
|
||||
@@ -379,8 +391,10 @@ class Application:
|
||||
with open(self.json_file, "w", encoding="utf-8") as f:
|
||||
json.dump(self.address_list, f, indent=4, sort_keys=True)
|
||||
except FileNotFoundError:
|
||||
self.show_error(
|
||||
message_title="Unexpected Error: File not found?!", message=f"{self.json_file_name} not found"
|
||||
show_error(
|
||||
message_title="Unexpected Error: File not found?!",
|
||||
message=f"{self.json_file_name} not found",
|
||||
parent=self.root
|
||||
)
|
||||
|
||||
def export_csv(self):
|
||||
@@ -395,7 +409,10 @@ class Application:
|
||||
del address[0]
|
||||
writer.writerow(address)
|
||||
except FileNotFoundError:
|
||||
self.show_error("Unexpected error", f"Could not write file {self.csv_file}")
|
||||
show_error(message_title="Unexpected error",
|
||||
message=f"Could not write file {self.csv_file}",
|
||||
parent=self.root
|
||||
)
|
||||
|
||||
def populate_table(self):
|
||||
self.delete_all_table_items()
|
||||
@@ -413,10 +430,6 @@ class Application:
|
||||
for item in self.table.get_children():
|
||||
self.table.delete(item)
|
||||
|
||||
@staticmethod
|
||||
def show_error(message_title: str, message: str):
|
||||
messagebox.showwarning(title=message_title, message=message)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
Application()
|
||||
|
||||
Reference in New Issue
Block a user