Compare commits
11 Commits
cda807a467
...
0.3.0b
| Author | SHA1 | Date | |
|---|---|---|---|
| c429e5c8fc | |||
| 7e4b4a0b6f | |||
| e749c6cc3f | |||
| ce032874f1 | |||
| 55091bbb87 | |||
| 8b55f74cd5 | |||
| c0aa8bc732 | |||
| 6c7113849f | |||
| 321cbc7f89 | |||
| aa5d5e6698 | |||
| 2b55aa62f0 |
@@ -1,5 +1,5 @@
|
|||||||
Package: brovski-adressetiketten
|
Package: brovski-adressetiketten
|
||||||
Version: 0.2.1b
|
Version: 0.3.0b
|
||||||
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).
|
||||||
|
|||||||
@@ -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.1b'
|
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,51 @@ 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", "6"),
|
||||||
|
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="E-Mail")
|
||||||
|
self.table.heading("6", 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 +151,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 +171,8 @@ class Application:
|
|||||||
"name": "Name",
|
"name": "Name",
|
||||||
"strasse": "Strasse",
|
"strasse": "Strasse",
|
||||||
"plzort": "Plz/Ort",
|
"plzort": "Plz/Ort",
|
||||||
"anzahl": "Anzahl"
|
"email": "E-Mail",
|
||||||
|
"anzahl": "1",
|
||||||
}
|
}
|
||||||
self.model.create_new(values)
|
self.model.create_new(values)
|
||||||
self.populate_table()
|
self.populate_table()
|
||||||
@@ -153,14 +183,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()
|
||||||
@@ -232,6 +265,8 @@ class Application:
|
|||||||
case "#5":
|
case "#5":
|
||||||
field = "plzort"
|
field = "plzort"
|
||||||
case "#6":
|
case "#6":
|
||||||
|
field = "email"
|
||||||
|
case "#7":
|
||||||
field = "anzahl"
|
field = "anzahl"
|
||||||
case _:
|
case _:
|
||||||
field = "name"
|
field = "name"
|
||||||
@@ -245,7 +280,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,24 +288,31 @@ 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_address_to_csv(address, writer)
|
||||||
if address["firma"] != "":
|
self.write_receiver_address_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 = []
|
|
||||||
for idx in range(4):
|
|
||||||
line.append(self.config.get("absender", f"{idx}"))
|
|
||||||
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,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def write_receiver_address_to_csv(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_address_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()
|
||||||
@@ -283,9 +324,20 @@ 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"],
|
|
||||||
values=(address["aktiv"], address["firma"], address["name"], address["strasse"],
|
self.table.insert(
|
||||||
address["plzort"], address["anzahl"])
|
"",
|
||||||
|
"end",
|
||||||
|
iid=address["record_id"],
|
||||||
|
values=(
|
||||||
|
address["aktiv"],
|
||||||
|
address["firma"],
|
||||||
|
address["name"],
|
||||||
|
address["strasse"],
|
||||||
|
address["plzort"],
|
||||||
|
address["email"],
|
||||||
|
address["anzahl"],
|
||||||
|
),
|
||||||
)
|
)
|
||||||
self.update_status_bar()
|
self.update_status_bar()
|
||||||
|
|
||||||
@@ -293,7 +345,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()
|
||||||
|
|
||||||
@@ -316,15 +368,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"]))
|
||||||
@@ -341,5 +400,5 @@ class Application:
|
|||||||
self.table.focus_force()
|
self.table.focus_force()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
Application()
|
Application()
|
||||||
|
|||||||
@@ -43,7 +43,21 @@ class JSONConnector(Connector):
|
|||||||
def get_all(self) -> list:
|
def get_all(self) -> list:
|
||||||
try:
|
try:
|
||||||
with open(self.json_file, "r") as f:
|
with open(self.json_file, "r") as f:
|
||||||
return json.load(f)
|
data = json.load(f)
|
||||||
|
fields = [
|
||||||
|
"aktiv",
|
||||||
|
"firma",
|
||||||
|
"name",
|
||||||
|
"strasse",
|
||||||
|
"plzort",
|
||||||
|
"email",
|
||||||
|
"anzahl",
|
||||||
|
]
|
||||||
|
for record in data:
|
||||||
|
for field in fields:
|
||||||
|
if field not in record.keys():
|
||||||
|
record[field] = ""
|
||||||
|
return data
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ class EditRecord(Window):
|
|||||||
self.name = tk.StringVar(value=record.get("name"))
|
self.name = tk.StringVar(value=record.get("name"))
|
||||||
self.strasse = tk.StringVar(value=record.get("strasse"))
|
self.strasse = tk.StringVar(value=record.get("strasse"))
|
||||||
self.plz_ort = tk.StringVar(value=record.get("plzort"))
|
self.plz_ort = tk.StringVar(value=record.get("plzort"))
|
||||||
|
self.email = tk.StringVar(value=record.get("email"))
|
||||||
self.anzahl = tk.StringVar(value=record.get("anzahl"))
|
self.anzahl = tk.StringVar(value=record.get("anzahl"))
|
||||||
|
|
||||||
edit_frame = tk.Frame(self)
|
edit_frame = tk.Frame(self)
|
||||||
@@ -57,7 +58,8 @@ class EditRecord(Window):
|
|||||||
tk.Label(edit_frame, text="Name").grid(row=0, column=2)
|
tk.Label(edit_frame, text="Name").grid(row=0, column=2)
|
||||||
tk.Label(edit_frame, text="Strasse").grid(row=0, column=3)
|
tk.Label(edit_frame, text="Strasse").grid(row=0, column=3)
|
||||||
tk.Label(edit_frame, text="Plz/Ort").grid(row=0, column=4)
|
tk.Label(edit_frame, text="Plz/Ort").grid(row=0, column=4)
|
||||||
tk.Label(edit_frame, text="Anzahl").grid(row=0, column=5)
|
tk.Label(edit_frame, text="E-Mail").grid(row=0, column=5)
|
||||||
|
tk.Label(edit_frame, text="Anzahl").grid(row=0, column=6)
|
||||||
edit_aktiv = tk.Checkbutton(edit_frame, variable=self.aktiv, onvalue="x", offvalue="")
|
edit_aktiv = tk.Checkbutton(edit_frame, variable=self.aktiv, onvalue="x", offvalue="")
|
||||||
edit_aktiv.grid(row=1, column=0)
|
edit_aktiv.grid(row=1, column=0)
|
||||||
edit_firma = tk.Entry(edit_frame, textvariable=self.firma)
|
edit_firma = tk.Entry(edit_frame, textvariable=self.firma)
|
||||||
@@ -68,8 +70,10 @@ class EditRecord(Window):
|
|||||||
edit_strasse.grid(row=1, column=3)
|
edit_strasse.grid(row=1, column=3)
|
||||||
edit_plz_ort = tk.Entry(edit_frame, textvariable=self.plz_ort)
|
edit_plz_ort = tk.Entry(edit_frame, textvariable=self.plz_ort)
|
||||||
edit_plz_ort.grid(row=1, column=4)
|
edit_plz_ort.grid(row=1, column=4)
|
||||||
|
edit_email= tk.Entry(edit_frame, textvariable=self.email)
|
||||||
|
edit_email.grid(row=1, column=5)
|
||||||
edit_anzahl = tk.Entry(edit_frame, textvariable=self.anzahl)
|
edit_anzahl = tk.Entry(edit_frame, textvariable=self.anzahl)
|
||||||
edit_anzahl.grid(row=1, column=5)
|
edit_anzahl.grid(row=1, column=6)
|
||||||
|
|
||||||
button_frame = tk.Frame(self)
|
button_frame = tk.Frame(self)
|
||||||
button_frame.pack(side=tk.TOP, pady=10)
|
button_frame.pack(side=tk.TOP, pady=10)
|
||||||
@@ -84,6 +88,7 @@ class EditRecord(Window):
|
|||||||
"name": self.name.get(),
|
"name": self.name.get(),
|
||||||
"strasse": self.strasse.get(),
|
"strasse": self.strasse.get(),
|
||||||
"plzort": self.plz_ort.get(),
|
"plzort": self.plz_ort.get(),
|
||||||
|
"email": self.email.get(),
|
||||||
"anzahl": self.anzahl.get(),
|
"anzahl": self.anzahl.get(),
|
||||||
}
|
}
|
||||||
self.model.update_record(new_record)
|
self.model.update_record(new_record)
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
0.2.1b
|
0.3.0b
|
||||||
|
|||||||
Reference in New Issue
Block a user