5 Commits

Author SHA1 Message Date
bbdbaadb92 filtering inactive records 2025-04-27 12:22:25 +02:00
ad66988e09 sorting of columns was not nice, should be better now 2025-04-27 11:54:32 +02:00
3fd0147158 implemented status bar covering #8 2025-04-27 00:33:10 +02:00
aec7770e74 added statusbar with stringvar 2025-04-27 00:24:30 +02:00
d16aefe20f refactoring 2025-04-27 00:21:12 +02:00

View File

@@ -32,6 +32,8 @@ class Application:
self.address_list = [] self.address_list = []
self.current_record: int | None = None self.current_record: int | None = None
self.sort_order = False self.sort_order = False
self.last_sort_field = "#3"
self.filter_active = tk.BooleanVar(value=False)
# init paths to json and csv file # init paths to json and csv file
self.json_file_name = "brovski-adress-etiketten-verwaltung.json" self.json_file_name = "brovski-adress-etiketten-verwaltung.json"
@@ -42,6 +44,11 @@ class Application:
self.json_file = os.path.join(self.json_path, self.json_file_name) self.json_file = os.path.join(self.json_path, self.json_file_name)
self.csv_file = os.path.join(self.csv_path, self.csv_file_name) self.csv_file = os.path.join(self.csv_path, self.csv_file_name)
# status bar content
self.statusbar = tk.StringVar()
self.length_address_list = None
self.length_address_list_active = None
# leave application if settings are bad # leave application if settings are bad
if not self.config_good: if not self.config_good:
show_error(message_title="Fehler Konfiguration", show_error(message_title="Fehler Konfiguration",
@@ -50,19 +57,25 @@ class Application:
) )
sys.exit() sys.exit()
# frames
top_frame = tk.Frame(self.root) top_frame = tk.Frame(self.root)
top_frame.pack(side=tk.TOP, fill=tk.X) top_frame.pack(side=tk.TOP, fill=tk.X)
data_frame = tk.Frame(self.root, bg="teal")
data_frame.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
bottom_frame = tk.Frame(self.root)
bottom_frame.pack(side=tk.BOTTOM, fill=tk.X)
# top buttons
button_width = 8 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="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="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="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.Button(top_frame, text="Toggle Aktiv", command=self.toggle_active, width=button_width).pack(side=tk.LEFT)
tk.Checkbutton(top_frame, text="Filter aktive", 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="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="Settings", command=self.show_settings, width=button_width).pack(side=tk.RIGHT)
data_frame = tk.Frame(self.root, bg="teal") # table content
data_frame.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
scrollbar = ttk.Scrollbar(data_frame, orient=tk.VERTICAL) scrollbar = ttk.Scrollbar(data_frame, orient=tk.VERTICAL)
self.table = ttk.Treeview(data_frame, yscrollcommand=scrollbar.set, columns=("0", "1", "2", "3", "4"), self.table = ttk.Treeview(data_frame, yscrollcommand=scrollbar.set, columns=("0", "1", "2", "3", "4"),
show="headings") show="headings")
@@ -80,8 +93,13 @@ class Application:
self.table.bind("<Return>", self.mouse_click_double) self.table.bind("<Return>", self.mouse_click_double)
self.table.bind("<Double-1>", self.mouse_click_double) self.table.bind("<Double-1>", self.mouse_click_double)
# bottom status bar
tk.Label(bottom_frame, textvariable=self.statusbar).pack(side=tk.LEFT)
self._load_json_file() self._load_json_file()
self.first_sort_after_start()
self.root.mainloop() self.root.mainloop()
def load_config(self): def load_config(self):
@@ -184,25 +202,17 @@ class Application:
def click_on_header(self, event): def click_on_header(self, event):
column = self.table.identify_column(event.x) column = self.table.identify_column(event.x)
match column: if self.last_sort_field == column:
case "#1": self.sort_order = False if self.sort_order else True
self.address_list.sort(key=lambda x: x[int(column[-1]) - 1], reverse=self.sort_order) else:
self.populate_table() self.sort_order = False
case "#2": self.last_sort_field = column
self.address_list.sort(key=lambda x: x[int(column[-1]) - 1], reverse=self.sort_order) self.address_list.sort(key=lambda x: (x[int(column[-1]) - 1]), reverse=self.sort_order)
self.populate_table()
case "#3": # special case company sort
self.address_list.sort(key=lambda x: x[int(column[-1]) - 1], reverse=self.sort_order) if column == "#2":
self.populate_table() self.address_list.sort(key=lambda x: (x[1], x[2]), reverse=self.sort_order)
case "#4": self.populate_table()
self.address_list.sort(key=lambda x: x[int(column[-1]) - 1], reverse=self.sort_order)
self.populate_table()
case "#5":
self.address_list.sort(key=lambda x: x[int(column[-1]) - 1], reverse=self.sort_order)
self.populate_table()
case _:
print(column)
self.sort_order = not self.sort_order
def click_on_cell(self): def click_on_cell(self):
self.current_record = self.table.focus() self.current_record = self.table.focus()
@@ -257,7 +267,11 @@ class Application:
def populate_table(self): def populate_table(self):
self.delete_all_table_items() self.delete_all_table_items()
for index, item in enumerate(self.address_list): for index, item in enumerate(self.address_list):
# skip inactive records if filter is true
if self.filter_active.get() and item[0] != "x":
continue
self.table.insert('', 'end', iid=index, values=item) self.table.insert('', 'end', iid=index, values=item)
self.update_status_bar()
def export_table_to_address_list(self): def export_table_to_address_list(self):
self.address_list.clear() self.address_list.clear()
@@ -265,6 +279,7 @@ class Application:
self.address_list.append([]) 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.address_list[-1].append(value)
self.update_status_bar()
def delete_all_table_items(self): def delete_all_table_items(self):
for item in self.table.get_children(): for item in self.table.get_children():
@@ -283,7 +298,21 @@ class Application:
window.wait_visibility() window.wait_visibility()
window.grab_set() window.grab_set()
def update_status_bar(self):
self._count_address_records()
self.statusbar.set(f"Adressen: {self.length_address_list} | Aktive Adressen: {self.length_address_list_active}")
def _count_address_records(self):
self.length_address_list = len(self.address_list)
count = 0
for address in self.address_list:
if address[0] == "x":
count += 1
self.length_address_list_active = count
def first_sort_after_start(self):
self.address_list.sort(key=lambda x: (x[1], x[2]))
self.populate_table()
if __name__ == '__main__': if __name__ == '__main__':