13 Commits

6 changed files with 158 additions and 66 deletions

View File

@@ -1,8 +1,22 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e
if [ "$VIRTUAL_ENV" == "" ] if [ "$VIRTUAL_ENV" == "" ]
then then
if [ ! -d "./venv/bin" ]; then
echo "venv not found, trying to create one"
python3 -m venv venv
fi
source venv/bin/activate source venv/bin/activate
fi fi
if [[ ! $(pip3 freeze | grep pyinstaller) ]];
then
echo "pyinstaller not found"
pip3 install -r requirements.txt
fi
version=$(cat version.txt) version=$(cat version.txt)
echo "current version set to: $version" echo "current version set to: $version"
new_version="" new_version=""

View File

@@ -1,5 +1,5 @@
Package: brovski-adressetiketten Package: brovski-adressetiketten
Version: 0.2.0b Version: 0.2.4b
Maintainer: Ovski Maintainer: Ovski
Architecture: all Architecture: all
Description: manage csv files for glables address labels Description: Manage and export addresses to csv. Can be used with glabels (example included in the source).

5
requirements.txt Normal file
View File

@@ -0,0 +1,5 @@
altgraph==0.17.4
packaging==25.0
pyinstaller==6.16.0
pyinstaller-hooks-contrib==2025.9
setuptools==80.9.0

View File

@@ -1,3 +1,4 @@
import _csv
import csv import csv
import os import os
import sys import sys
@@ -20,7 +21,7 @@ class Application:
y_offset = 200 y_offset = 200
width = 1050 width = 1050
height = 700 height = 700
VERSION = '0.2.0b' VERSION = "0.2.3b"
title = f"Brovski Adress-Etiketten Verwaltung {VERSION}" title = f"Brovski Adress-Etiketten Verwaltung {VERSION}"
self.root = tk.Tk(className="BrovskiAdressEtiketten") self.root = tk.Tk(className="BrovskiAdressEtiketten")
@@ -51,12 +52,14 @@ class Application:
self.statusbar = tk.StringVar() self.statusbar = tk.StringVar()
self.length_address_list = None self.length_address_list = None
self.length_address_list_active = None self.length_address_list_active = None
self.count_coffee = 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",
message="Die Konfiguration ist fehlerhaft, bitte prüfe deine config.ini", message="Die Konfiguration ist fehlerhaft, bitte prüfe deine config.ini",
parent=self.root parent=self.root,
) )
sys.exit() sys.exit()
@@ -70,27 +73,50 @@ class Application:
# top buttons # 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(
tk.Button(top_frame, text="Delete", command=self.delete_record, width=button_width).pack(side=tk.LEFT) top_frame, text="Insert", command=self.insert_record, width=button_width
tk.Button(top_frame, text="Export CSV", command=self.export_csv, width=button_width).pack(side=tk.LEFT) ).pack(side=tk.LEFT)
tk.Button(top_frame, text="Toggle Aktiv", command=self.toggle_active, width=button_width).pack(side=tk.LEFT) tk.Button(
tk.Checkbutton(top_frame, text="Filter aktiv", variable=self.filter_active, command=self.populate_table).pack( top_frame, text="Delete", command=self.delete_record, width=button_width
side=tk.LEFT) ).pack(side=tk.LEFT)
tk.Button(top_frame, text="Quit", command=self.on_close, width=button_width).pack(side=tk.RIGHT) tk.Button(
tk.Button(top_frame, text="Settings", command=self.show_settings, width=button_width).pack(side=tk.RIGHT) 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 # table content
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", "5"), self.table = ttk.Treeview(
show="headings") data_frame,
yscrollcommand=scrollbar.set,
columns=("0", "1", "2", "3", "4", "5"),
show="headings",
)
scrollbar.config(command=self.table.yview) scrollbar.config(command=self.table.yview)
self.table.heading('0', text="Aktiv") self.table.heading("0", text="Aktiv")
self.table.column('0', anchor=tk.CENTER, width=0) self.table.column("0", anchor=tk.CENTER, width=0)
self.table.heading('1', text="Firma") self.table.heading("1", text="Firma")
self.table.heading('2', text="Name") self.table.heading("2", text="Name")
self.table.heading('3', text="Strasse") self.table.heading("3", text="Strasse")
self.table.heading('4', text="Plz/Ort") self.table.heading("4", text="Plz/Ort")
self.table.heading('5', text="Anzahl") self.table.heading("5", text="Anzahl")
self.table.pack(side=tk.LEFT, fill=tk.BOTH, expand=True) self.table.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
scrollbar.pack(side=tk.LEFT, fill=tk.Y) scrollbar.pack(side=tk.LEFT, fill=tk.Y)
@@ -124,9 +150,11 @@ class Application:
self.show_settings() self.show_settings()
def show_config_error(self): def show_config_error(self):
show_error(message_title="Fehlerhafte Konfiguration", show_error(
message_title="Fehlerhafte Konfiguration",
message="Konnte benötigte Parameter in config.ini nicht finden", message="Konnte benötigte Parameter in config.ini nicht finden",
parent=self.root) parent=self.root,
)
def on_close(self): def on_close(self):
self.root.destroy() self.root.destroy()
@@ -142,7 +170,7 @@ class Application:
"name": "Name", "name": "Name",
"strasse": "Strasse", "strasse": "Strasse",
"plzort": "Plz/Ort", "plzort": "Plz/Ort",
"anzahl": "Anzahl" "anzahl": "1",
} }
self.model.create_new(values) self.model.create_new(values)
self.populate_table() self.populate_table()
@@ -153,14 +181,17 @@ class Application:
return return
if len(self.table.selection()) > 1: if len(self.table.selection()) > 1:
show_error(message_title="Mehrere Adressen ausgewählt", show_error(
message_title="Mehrere Adressen ausgewählt",
message="Es können nur einzelne Adressen gelöscht werden", message="Es können nur einzelne Adressen gelöscht werden",
parent=self.root) parent=self.root,
)
return return
if messagebox.askyesno( if messagebox.askyesno(
"Eintrag löschen?", "Eintrag löschen?",
"Willst du diesen Eintrag wirklich löschen?\nDies kann nicht rückgängig gemacht werden"): "Willst du diesen Eintrag wirklich löschen?\nDies kann nicht rückgängig gemacht werden",
):
self.model.delete_by_id(self.current_record) self.model.delete_by_id(self.current_record)
self.deselect_tree() self.deselect_tree()
@@ -245,7 +276,6 @@ class Application:
self.current_record = int(self.table.focus()) self.current_record = int(self.table.focus())
self.open_window_edit_records(self.current_record) self.open_window_edit_records(self.current_record)
def export_csv(self): def export_csv(self):
try: try:
with open(self.csv_file, "w", encoding="utf-8") as f: with open(self.csv_file, "w", encoding="utf-8") as f:
@@ -254,26 +284,30 @@ class Application:
if address["aktiv"] != "x": if address["aktiv"] != "x":
continue continue
for index in range(int(address["anzahl"])): for index in range(int(address["anzahl"])):
line = [] self.write_sender_to_csv(address, writer)
if address["firma"] != "": self.write_receiver_to_csv(address, writer)
line.append(address["firma"])
line.append(address["name"])
line.append(address["strasse"])
line.append(address["plzort"])
writer.writerow(line)
# todo: add "absender" to config parameters
line = []
line.append("Absender:")
line.append("Matthias Braun")
line.append("Wolfacherweg 1")
line.append("5724 Dürrenäsch")
writer.writerow(line)
except FileNotFoundError: except FileNotFoundError:
show_error(message_title="Unexpected error", show_error(
message_title="Unexpected error",
message=f"Could not write file {self.csv_file}", message=f"Could not write file {self.csv_file}",
parent=self.root parent=self.root,
) )
def write_receiver_to_csv(self, address: dict, csv_writer: _csv.writer):
receiver_line = []
if address["firma"] != "":
receiver_line.append(address["firma"])
receiver_line.append(address["name"])
receiver_line.append(address["strasse"])
receiver_line.append(address["plzort"])
csv_writer.writerow(receiver_line)
def write_sender_to_csv(self, address: dict, csv_writer: _csv.writer):
sender_line = []
for idx in range(4):
sender_line.append(self.config.get("absender", f"{idx}"))
csv_writer.writerow(sender_line)
def populate_table(self, reload=True): def populate_table(self, reload=True):
if reload: if reload:
self.address_list = self.model.get_all() self.address_list = self.model.get_all()
@@ -285,9 +319,18 @@ class Application:
# skip inactive records if filter is true # skip inactive records if filter is true
if self.filter_active.get() and address["aktiv"] != "x": if self.filter_active.get() and address["aktiv"] != "x":
continue continue
self.table.insert('', 'end', iid=address["record_id"], self.table.insert(
values=(address["aktiv"], address["firma"], address["name"], address["strasse"], "",
address["plzort"], address["anzahl"]) "end",
iid=address["record_id"],
values=(
address["aktiv"],
address["firma"],
address["name"],
address["strasse"],
address["plzort"],
address["anzahl"],
),
) )
self.update_status_bar() self.update_status_bar()
@@ -295,7 +338,7 @@ class Application:
self.address_list.clear() self.address_list.clear()
for child in self.table.get_children(): for child in self.table.get_children():
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() self.update_status_bar()
@@ -318,15 +361,22 @@ class Application:
def update_status_bar(self): def update_status_bar(self):
self._count_address_records() self._count_address_records()
self.statusbar.set(f"Adressen: {self.length_address_list} | Aktive Adressen: {self.length_address_list_active}") self.statusbar.set(
f"Adressen: {self.length_address_list} | "
f"Aktive Adressen: {self.length_address_list_active} | "
f"Total Kaffee: {self.count_coffee}"
)
def _count_address_records(self): def _count_address_records(self):
self.length_address_list = len(self.address_list) self.length_address_list = len(self.address_list)
count = 0 count = 0
count_coffee = 0
for address in self.address_list: for address in self.address_list:
if address["aktiv"] == "x": if address["aktiv"] == "x":
count += 1 count += 1
count_coffee += int(address["anzahl"])
self.length_address_list_active = count self.length_address_list_active = count
self.count_coffee = count_coffee
def first_sort_after_start(self): def first_sort_after_start(self):
self.address_list.sort(key=lambda x: (x["firma"], x["name"])) self.address_list.sort(key=lambda x: (x["firma"], x["name"]))
@@ -343,5 +393,5 @@ class Application:
self.table.focus_force() self.table.focus_force()
if __name__ == '__main__': if __name__ == "__main__":
Application() Application()

View File

@@ -93,18 +93,23 @@ class EditRecord(Window):
class SettingsWindow(Window): class SettingsWindow(Window):
def __init__(self, parent, root: tk.Tk, config: Config): def __init__(self, parent, root: tk.Tk, config: Config):
super().__init__(parent, root) super().__init__(parent, root)
self.geometry(f"500x330+{self.root.winfo_x() + 20}+{self.root.winfo_y() + 20}") width = 500
height = 630
self.geometry(f"{width}x{height}+{self.root.winfo_x() + 20}+{self.root.winfo_y() + 20}")
self.config = config self.config = config
self.json_file = tk.StringVar() self.json_file = tk.StringVar()
self.csv_file = tk.StringVar() self.csv_file = tk.StringVar()
self.absender_line = [tk.StringVar() for idx in range(4)]
title = font.Font(family='Ubuntu Mono', size=20, weight=font.BOLD) title = font.Font(family='Ubuntu Mono', size=20, weight=font.BOLD)
tk.Label(self, text="Einstellungen", font=title).pack(pady=20) tk.Label(self, text="Einstellungen", font=title).pack(pady=20)
path_frame = tk.Frame(self)
path_frame.pack(pady=(10, 40))
tk.Label(path_frame, text="Datenpfad JSON Datei").grid(row=0, column=0) tk.Label(self, text="Datenpfad JSON Datei").pack()
path_frame = tk.Frame(self)
path_frame.pack(pady=(10, 10))
tk.Entry(path_frame, textvariable=self.json_file, width=50).grid(row=1, 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, tk.Button(path_frame, text="Pfad", command=lambda: self.set_json_path(self.json_file.get())).grid(row=1,
column=1) column=1)
@@ -113,6 +118,13 @@ class SettingsWindow(Window):
tk.Entry(path_frame, textvariable=self.csv_file, width=50).grid(row=3, column=0) tk.Entry(path_frame, textvariable=self.csv_file, width=50).grid(row=3, column=0)
tk.Button(path_frame, text="Pfad", command=lambda: self.set_csv_path(self.csv_file.get())).grid(row=3, column=1) tk.Button(path_frame, text="Pfad", command=lambda: self.set_csv_path(self.csv_file.get())).grid(row=3, column=1)
absender_frame = tk.Frame(self)
absender_frame.pack(pady=(10, 40))
tk.Label(absender_frame, text="Absender").pack(side=tk.TOP)
for idx in range(4):
tk.Entry(absender_frame, textvariable=self.absender_line[idx], width=50).pack(side=tk.TOP)
bottom_frame = tk.Frame(self) bottom_frame = tk.Frame(self)
bottom_frame.pack() bottom_frame.pack()
tk.Button(bottom_frame, text="Ok", command=self.ok).pack(side=tk.LEFT) tk.Button(bottom_frame, text="Ok", command=self.ok).pack(side=tk.LEFT)
@@ -149,6 +161,15 @@ class SettingsWindow(Window):
except NoOptionError: except NoOptionError:
self.config.set("csv", "path", "") self.config.set("csv", "path", "")
for idx in range(4):
try:
self.absender_line[idx].set(self.config.get(f"absender", f"{idx}"))
except NoSectionError:
self.config.add_section(f"line")
self.config.set("line", f"{idx}", "")
except NoOptionError:
self.config.set("line", f"{idx}", "")
def ok(self): def ok(self):
if self.json_file.get() == "" or self.csv_file.get() == "": if self.json_file.get() == "" or self.csv_file.get() == "":
show_error(message_title="Fehlerhafte Konfiguration", show_error(message_title="Fehlerhafte Konfiguration",
@@ -157,6 +178,8 @@ class SettingsWindow(Window):
return return
self.config.set("json", "path", self.json_file.get()) self.config.set("json", "path", self.json_file.get())
self.config.set("csv", "path", self.csv_file.get()) self.config.set("csv", "path", self.csv_file.get())
for i in range(4):
self.config.set("absender", f"{i}", f"{self.absender_line[i].get()}")
self.close_window() self.close_window()
def cancel(self): def cancel(self):

View File

@@ -1 +1 @@
0.2.0b 0.2.4b