Skip to content

Commit

Permalink
add: functionality for update and delete buttons, fix record.valid()
Browse files Browse the repository at this point in the history
  • Loading branch information
ObsidianPresidium committed Dec 2, 2023
1 parent f1997e8 commit f38cc03
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions danskcargo/danskcargo_gui_classed.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import tkinter as tk
from tkinter import ttk
import tkinter.messagebox as tkmsg
import danskcargo_sql as dcsql
from danskcargo_data import Container, Aircraft, Transport

Expand Down Expand Up @@ -30,6 +31,7 @@ def __init__(self, category_name):
self.entries = []
self.category_name = category_name
self.classparam = eval(category_name.capitalize())
# endregion globals

# region gui
self.root_frame = tk.LabelFrame(main_window, text=category_name.capitalize())
Expand All @@ -56,17 +58,17 @@ def __init__(self, category_name):
self.button_frame.grid(row=2, column=0, padx=padx, pady=pady)
self.button_create = tk.Button(self.button_frame, text="Create")
self.button_create.grid(row=0, column=0, padx=padx, pady=pady)
self.button_update = tk.Button(self.button_frame, text="Update")
self.button_update = tk.Button(self.button_frame, text="Update", command=self.update)
self.button_update.grid(row=0, column=1, padx=padx, pady=pady)
self.button_delete = tk.Button(self.button_frame, text="Delete")
self.button_delete = tk.Button(self.button_frame, text="Delete", command=self.delete)
self.button_delete.grid(row=0, column=2, padx=padx, pady=pady)
self.button_clear = tk.Button(self.button_frame, text="Clear Entry Boxes", command=self.clear_entries)
self.button_clear.grid(row=0, column=3, padx=padx, pady=pady)
# endregion gui

categories.append(self)

def read_container_entries(self):
def read_entries(self):
out_tuple = ()
for entry in self.entries:
out_tuple += (entry.get(),)
Expand All @@ -75,11 +77,16 @@ def read_container_entries(self):

def write_entries(self, values):
if len(values) != 0:
if len(values) != len(self.entries):
raise ValueError("There are either too many or too few values to insert into the entries in this category!")
if self.classparam != Container: # containers have the weather entry also, we need to circumvent an error
if len(values) != len(self.entries):
raise ValueError("There are either too many or too few values to insert into the entries in this category!")

for entry in enumerate(self.entries):
entry[1].insert(0, values[entry[0]])
for entry in enumerate(self.entries):
entry[1].insert(0, values[entry[0]])
else:
self.entries[0].insert(0, values[0])
self.entries[1].insert(0, values[1])
self.entries[2].insert(0, values[2])

def clear_entries(self):
for entry in self.entries:
Expand All @@ -94,9 +101,8 @@ def edit_tree(self, event):
def read_table(self):
count = 0
result = dcsql.select_all(self.classparam)
print(result[0])
for record in result:
if record.valid("ALL"):
if record.valid():
if count % 2 == 0:
self.tree.insert(parent="", index="end", iid=str(count), text="", values=record.convert_to_tuple(), tags=("evenrow",))
else:
Expand All @@ -110,6 +116,15 @@ def refresh_tree(self):
self.empty_tree()
self.read_table()

def update(self):
dcsql.update_record(self.classparam, self.read_entries())
self.refresh_tree()

def delete(self):
dcsql.delete_soft(self.classparam, self.read_entries())
self.clear_entries()
self.refresh_tree()


class CategoryContainer(Category):
def __init__(self):
Expand Down Expand Up @@ -205,6 +220,9 @@ def __init__(self):
entry_aircraftid = tk.Entry(self.edit_frame, width=4)
entry_aircraftid.grid(row=1, column=3, padx=padx, pady=pady)

self.entries = [entry_id, entry_date, entry_containerid, entry_aircraftid]


container = CategoryContainer()
aircraft = CategoryAircraft()
transport = CategoryTransport()
Expand Down

0 comments on commit f38cc03

Please sign in to comment.