diff --git a/main.py b/main.py index 138a518..9b0a891 100644 --- a/main.py +++ b/main.py @@ -57,20 +57,24 @@ def add_computer(): window.close() return values -def main(): - """Core of ComputerKeeper - The Main Application.""" - global TABLE,WINDOW - db= TinyDB("./db.json") +def format_table(table_list): Computer = [] - for item in db.all(): + for item in table_list: The_Device = [] for colum in colum_lut: The_Device.append(item[colum]) Computer.append(The_Device) + return Computer + +def main(): + """Core of ComputerKeeper - The Main Application.""" + global TABLE,WINDOW + db= TinyDB("./db.json") + computer = format_table(db.all()) # Create the window window = sg.Window('Window Title', layout, finalize=True) WINDOW=window - window["table"].update(Computer) + window["table"].update(computer) table = window['table'].Widget table.bind('', double_click, add='+') TABLE=table @@ -100,11 +104,11 @@ def main(): print(f'Click on column {column}') # Sort data on the table by the value of column # then update window['-TABLE-'].update(values=new_data) - else: - print(event, values[event]) + elif event.find("filter") != -1: filter_database = lambda s: s.lower().find(values[event].lower()) != -1 Computers=Query() - print(db.search(Computers[event[7:]].test(filter_database))) + result=db.search(Computers[event[7:]].test(filter_database)) + window["table"].update(format_table(result)) # Finish up by removing from the screen