added a double click function
All checks were successful
Potlatch Loggers Organization/ComputerKeeper/pipeline/head This commit looks good
All checks were successful
Potlatch Loggers Organization/ComputerKeeper/pipeline/head This commit looks good
This commit is contained in:
parent
801d3b4b1d
commit
e2cc3e305f
27
main.py
27
main.py
@ -4,11 +4,15 @@ from copy import deepcopy
|
|||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
from tinydb import TinyDB, Query
|
from tinydb import TinyDB, Query
|
||||||
|
|
||||||
|
TABLE=None
|
||||||
|
WINDOW=None
|
||||||
|
|
||||||
# Define the window's contents
|
# Define the window's contents
|
||||||
colum_lut = ["Serial Number","Brand","Grade","Name"]
|
colum_lut = ["Serial Number","Brand","Grade","Name"]
|
||||||
layout = [[sg.Menu([['File', ['Open', 'Save', 'Add Computer','Remove Computer']]])],
|
layout = [[sg.Menu([['File', ['Open', 'Save', 'Add Computer','Remove Computer']]])],
|
||||||
[sg.Table([["word","Yes"]],colum_lut,key = "table")],
|
[sg.Text("search"), sg.Input(s=(35,))],
|
||||||
|
[sg.Input(s=(19,)),sg.Input(s=(6,)),sg.Input(s=(6,)),sg.Input(s=(4,))],
|
||||||
|
[sg.Table([["word","Yes"]],colum_lut,key = "table", enable_events=True)],
|
||||||
[sg.Text("Serial Number")],
|
[sg.Text("Serial Number")],
|
||||||
[sg.Input(key='Serial Number')],
|
[sg.Input(key='Serial Number')],
|
||||||
[sg.Text("Brand")],
|
[sg.Text("Brand")],
|
||||||
@ -30,6 +34,15 @@ add_computer_layout = [[sg.Text("Serial Number")],
|
|||||||
[sg.Input(key='Name')],
|
[sg.Input(key='Name')],
|
||||||
[sg.Button('Add Computer'),]]
|
[sg.Button('Add Computer'),]]
|
||||||
|
|
||||||
|
def double_click(event):
|
||||||
|
"""
|
||||||
|
Additional event for double-click on header
|
||||||
|
event: class event
|
||||||
|
"""
|
||||||
|
region = TABLE.identify("region", event.x, event.y)
|
||||||
|
if region == 'heading': # Only care double-clock on headings
|
||||||
|
cid = int(TABLE.identify_column(event.x)[1:])-1 # check which column clicked
|
||||||
|
WINDOW.write_event_value("-TABLE-DOUBLE-CLICK-", cid)
|
||||||
|
|
||||||
def add_computer():
|
def add_computer():
|
||||||
window = sg.Window('Add Computer', deepcopy(add_computer_layout))
|
window = sg.Window('Add Computer', deepcopy(add_computer_layout))
|
||||||
@ -43,6 +56,7 @@ def add_computer():
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Core of ComputerKeeper - The Main Application."""
|
"""Core of ComputerKeeper - The Main Application."""
|
||||||
|
global TABLE,WINDOW
|
||||||
db= TinyDB("./db.json")
|
db= TinyDB("./db.json")
|
||||||
Computer = []
|
Computer = []
|
||||||
for item in db.all():
|
for item in db.all():
|
||||||
@ -52,7 +66,12 @@ def main():
|
|||||||
Computer.append(The_Device)
|
Computer.append(The_Device)
|
||||||
# Create the window
|
# Create the window
|
||||||
window = sg.Window('Window Title', layout, finalize=True)
|
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-1>', double_click, add='+')
|
||||||
|
TABLE=table
|
||||||
|
|
||||||
|
|
||||||
# Display and interact with the Window using an Event Loop
|
# Display and interact with the Window using an Event Loop
|
||||||
while True:
|
while True:
|
||||||
@ -73,6 +92,12 @@ def main():
|
|||||||
query = Query()
|
query = Query()
|
||||||
db.remove(query["Serial Number"] == serial)
|
db.remove(query["Serial Number"] == serial)
|
||||||
window["table"].update(existing_table)
|
window["table"].update(existing_table)
|
||||||
|
elif event == '-TABLE-DOUBLE-CLICK-':
|
||||||
|
column = values[event]
|
||||||
|
print(f'Click on column {column}')
|
||||||
|
# Sort data on the table by the value of column
|
||||||
|
# then update window['-TABLE-'].update(values=new_data)
|
||||||
|
|
||||||
|
|
||||||
# Finish up by removing from the screen
|
# Finish up by removing from the screen
|
||||||
window.close()
|
window.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user