Compare commits
7 Commits
6c7113849f
...
0.3.0b
| Author | SHA1 | Date | |
|---|---|---|---|
| c429e5c8fc | |||
| 7e4b4a0b6f | |||
| e749c6cc3f | |||
| ce032874f1 | |||
| 55091bbb87 | |||
| 8b55f74cd5 | |||
| c0aa8bc732 |
@@ -1,5 +1,5 @@
|
||||
Package: brovski-adressetiketten
|
||||
Version: 0.2.2b
|
||||
Version: 0.3.0b
|
||||
Maintainer: Ovski
|
||||
Architecture: all
|
||||
Description: Manage and export addresses to csv. Can be used with glabels (example included in the source).
|
||||
|
||||
@@ -21,7 +21,7 @@ class Application:
|
||||
y_offset = 200
|
||||
width = 1050
|
||||
height = 700
|
||||
VERSION = '0.2.2b'
|
||||
VERSION = "0.2.3b"
|
||||
title = f"Brovski Adress-Etiketten Verwaltung {VERSION}"
|
||||
|
||||
self.root = tk.Tk(className="BrovskiAdressEtiketten")
|
||||
@@ -52,13 +52,15 @@ class Application:
|
||||
self.statusbar = tk.StringVar()
|
||||
self.length_address_list = None
|
||||
self.length_address_list_active = None
|
||||
self.count_coffee = None
|
||||
|
||||
# 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
|
||||
@@ -71,27 +73,51 @@ 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", "6"),
|
||||
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="E-Mail")
|
||||
self.table.heading("6", text="Anzahl")
|
||||
self.table.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
|
||||
scrollbar.pack(side=tk.LEFT, fill=tk.Y)
|
||||
|
||||
@@ -125,9 +151,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()
|
||||
@@ -143,7 +171,8 @@ class Application:
|
||||
"name": "Name",
|
||||
"strasse": "Strasse",
|
||||
"plzort": "Plz/Ort",
|
||||
"anzahl": "Anzahl"
|
||||
"email": "E-Mail",
|
||||
"anzahl": "1",
|
||||
}
|
||||
self.model.create_new(values)
|
||||
self.populate_table()
|
||||
@@ -154,14 +183,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()
|
||||
@@ -211,7 +243,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)
|
||||
@@ -233,6 +265,8 @@ class Application:
|
||||
case "#5":
|
||||
field = "plzort"
|
||||
case "#6":
|
||||
field = "email"
|
||||
case "#7":
|
||||
field = "anzahl"
|
||||
case _:
|
||||
field = "name"
|
||||
@@ -246,7 +280,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:
|
||||
@@ -255,15 +288,17 @@ class Application:
|
||||
if address["aktiv"] != "x":
|
||||
continue
|
||||
for index in range(int(address["anzahl"])):
|
||||
self.write_sender_to_csv(address, writer)
|
||||
self.write_receiver_to_csv(address, writer)
|
||||
self.write_sender_address_to_csv(address, writer)
|
||||
self.write_receiver_address_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):
|
||||
@staticmethod
|
||||
def write_receiver_address_to_csv(address: dict, csv_writer: _csv.writer):
|
||||
receiver_line = []
|
||||
if address["firma"] != "":
|
||||
receiver_line.append(address["firma"])
|
||||
@@ -272,7 +307,7 @@ class Application:
|
||||
receiver_line.append(address["plzort"])
|
||||
csv_writer.writerow(receiver_line)
|
||||
|
||||
def write_sender_to_csv(self, address: dict, csv_writer: _csv.writer):
|
||||
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}"))
|
||||
@@ -289,17 +324,28 @@ 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["email"],
|
||||
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()
|
||||
|
||||
@@ -322,15 +368,22 @@ class Application:
|
||||
|
||||
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}")
|
||||
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):
|
||||
self.length_address_list = len(self.address_list)
|
||||
count = 0
|
||||
count_coffee = 0
|
||||
for address in self.address_list:
|
||||
if address["aktiv"] == "x":
|
||||
count += 1
|
||||
count_coffee += int(address["anzahl"])
|
||||
self.length_address_list_active = count
|
||||
self.count_coffee = count_coffee
|
||||
|
||||
def first_sort_after_start(self):
|
||||
self.address_list.sort(key=lambda x: (x["firma"], x["name"]))
|
||||
@@ -347,5 +400,5 @@ class Application:
|
||||
self.table.focus_force()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
Application()
|
||||
|
||||
@@ -43,7 +43,21 @@ class JSONConnector(Connector):
|
||||
def get_all(self) -> list:
|
||||
try:
|
||||
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:
|
||||
return []
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ class EditRecord(Window):
|
||||
self.name = tk.StringVar(value=record.get("name"))
|
||||
self.strasse = tk.StringVar(value=record.get("strasse"))
|
||||
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"))
|
||||
|
||||
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="Strasse").grid(row=0, column=3)
|
||||
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.grid(row=1, column=0)
|
||||
edit_firma = tk.Entry(edit_frame, textvariable=self.firma)
|
||||
@@ -68,8 +70,10 @@ class EditRecord(Window):
|
||||
edit_strasse.grid(row=1, column=3)
|
||||
edit_plz_ort = tk.Entry(edit_frame, textvariable=self.plz_ort)
|
||||
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.grid(row=1, column=5)
|
||||
edit_anzahl.grid(row=1, column=6)
|
||||
|
||||
button_frame = tk.Frame(self)
|
||||
button_frame.pack(side=tk.TOP, pady=10)
|
||||
@@ -84,6 +88,7 @@ class EditRecord(Window):
|
||||
"name": self.name.get(),
|
||||
"strasse": self.strasse.get(),
|
||||
"plzort": self.plz_ort.get(),
|
||||
"email": self.email.get(),
|
||||
"anzahl": self.anzahl.get(),
|
||||
}
|
||||
self.model.update_record(new_record)
|
||||
|
||||
@@ -1 +1 @@
|
||||
0.2.2b
|
||||
0.3.0b
|
||||
|
||||
Reference in New Issue
Block a user