Sep-22-2021, 07:52 AM
Hello,
Please see my finished code below, I'm looking for suggestions of features to add and how to make it better :)
Please see my finished code below, I'm looking for suggestions of features to add and how to make it better :)
import PySimpleGUI as sg import csv from csv import reader import sqlite3 sg.theme("DarkAmber") entry = [] equipm = [] a = "" t = [810,390] p = ("") admins = [["Admin","Administrator"],["Admin","OneTwoTree"]] con = sqlite3.connect(r'equipment.db') # FIGURE OUT HOW TO ACCESS SHARED DRIVE !# cur = con.cursor() def startup(): for row in cur.execute('SELECT * FROM user_equipment'): entry.append(row) login() def login(): global b layout0 = [[sg.T("")],[sg.T("Username")],[sg.InputText(key = "usr")],[sg.T("Password")],[sg.InputText(key = "pwd")],[sg.Button("OK", bind_return_key = True)]] window0 = sg.Window("Equipment Portal", layout0, location=(t[0],t[1]), size = (600,500),finalize = True) event,values = window0.read() t.clear() while True: if event == sg.WIN_CLOSED: break if event == "OK": u = window0.CurrentLocation() t.append(u[0]) t.append(u[1]) b = str(values['usr']) c = str(values['pwd']) if b in admins[0] and c in admins[1]: window0.close() main() break if b not in admins or c not in admins: sg.popup('Invalid Login.','Please try again.', location = (t[0],t[1])) window0.close() login() break def main(): layout1 = [[sg.T("")],[sg.Button("Out Equipment"),sg.Button("User List"),sg.Button("New Entry")]] window1 = sg.Window("Equipment Portal", layout1,location=(t[0],t[1]), size = (600,500), finalize = True) event, values = window1.read() t.clear() while True: if event == sg.WIN_CLOSED: con.close() break if event == "User List": u = window1.CurrentLocation() t.append(u[0]) t.append(u[1]) window1.close() user_list() break if event == "Out Equipment": u = window1.CurrentLocation() t.append(u[0]) t.append(u[1]) window1.close() out_equipment() break if event == "New Entry": u = window1.CurrentLocation() t.append(u[0]) t.append(u[1]) window1.close() new_entry() break def user_list(): entry.clear() for row in cur.execute('select * from user_equipment'): entry.append(row) user = [] user.append(entry[0][1]) x = 0 global a for x in range(len(entry)): if entry[x][1] not in user: user.append(entry[x][1]) x += 1 x += 1 user_list1 = [[sg.T("")],[sg.Button("Out Equipment"),sg.Button("User List"),sg.Button("New Entry")],[sg.T("")], [sg.Listbox(values=user,size = (30,10),key = "userid")],[sg.Button("Select", bind_return_key = True)]] window2 = sg.Window("Equipment Portal", user_list1,location=(t[0],t[1]), size = (600,500), finalize = True) event, values = window2.read() t.clear() while True: if event == sg.WIN_CLOSED: con.close() break if event == "User List": u = window2.CurrentLocation() t.append(u[0]) t.append(u[1]) window2.close() user_list() break if event == "Out Equipment": u = window2.CurrentLocation() t.append(u[0]) t.append(u[1]) window2.close() out_equipment() break if event == "New Entry": u = window2.CurrentLocation() t.append(u[0]) t.append(u[1]) window2.close() new_entry() break if event == "Select": a = str(values['userid']) u = window2.CurrentLocation() t.append(u[0]) t.append(u[1]) window2.close() user_equip() break def user_equip(): equip = [] serial = [] x = 0 global a for x in range(len(entry)): if a[2:5] in entry[x][1]: equip.append(entry[x][2]) serial.append(entry[x][3]) x += 1 user_list2 = [[sg.T("")],[sg.Button("Out Equipment"),sg.Button("User List"),sg.Button("New Entry")],[sg.T(a)],[sg.T("Type"),sg.T(" "),sg.T("Serial")], [sg.Listbox(values=equip,size = (10,10),key = "user_equip"),sg.Listbox(values=serial,size=(33,10),key = "D")],[sg.T("")],[sg.T("")],[sg.T("An equipment return form must be filled out, scanned and saved.")],[sg.T("Select the serial number of the returned item.")],[sg.Button("Return")]] window3 = sg.Window("Equipment Portal", user_list2,location=(t[0],t[1]), size = (600,500), finalize = True) event, values = window3.read() t.clear() while True: if event == sg.WIN_CLOSED: con.close() break if event == "User List": u = window3.CurrentLocation() t.append(u[0]) t.append(u[1]) window3.close() user_list() break if event == "Out Equipment": u = window3.CurrentLocation() t.append(u[0]) t.append(u[1]) window3.close() out_equipment() break if event == "New Entry": u = window3.CurrentLocation() t.append(u[0]) t.append(u[1]) window3.close() new_entry() break if event == "Return": entry.clear() for row in cur.execute('select * from user_equipment'): entry.append(row) z = str(values["D"]) u = window3.CurrentLocation() t.append(u[0]) t.append(u[1]) for y in range(len(entry)): if z[2:-2] == entry[y][3]: cur.execute('delete from user_equipment where serial="'+str(entry[y][3])+'";') con.commit() window3.close() entry.clear() login() break def new_entry(): new_ntr = [[sg.T("")],[sg.Button("Out Equipment"),sg.Button("User List"),sg.Button("New Entry")],[sg.T("")], [sg.T("Name")],[sg.InputText(key = "A")],[sg.T("Equipment Type")],[sg.Combo(values = ("Monitor","Desktop","Laptop","Mobile"),size=(15,15),key = "B")],[sg.T("Serial")],[sg.InputText(key = "C")],[sg.T("")],[sg.T("")], [sg.T("")],[sg.T("An issue form must also be filled out, scanned, and saved.")],[sg.Button("Save", bind_return_key = True)]] window5 = sg.Window("Equipment Portal", new_ntr,location = (t[0],t[1]), size = (600,500), finalize = True) event, values = window5.read() t.clear() while True: if event == sg.WIN_CLOSED: con.close() break if event == "User List": u = window5.CurrentLocation() t.append(u[0]) t.append(u[1]) window5.close() user_list() break if event == "Out Equipment": u = window5.CurrentLocation() t.append(u[0]) t.append(u[1]) window5.close() out_equipment() break if event == "New Entry": u = window5.CurrentLocation() t.append(u[0]) t.append(u[1]) window5.close() new_entry() break if event == "Save": entry.clear() for row in cur.execute('select * from user_equipment'): entry.append(row) x = values["A"] y = values["B"] z = values["C"] a = int(len(entry)+1) cur.execute('insert into user_equipment values('+ str(a) + ',"' + x + '","' + y + '","' + z + '");') con.commit() entry.clear() u = window5.CurrentLocation() t.append(u[0]) t.append(u[1]) window5.close() startup() break def out_equipment(): entry.clear() for row in cur.execute('select * from user_equipment'): entry.append(row) mob = 0 des = 0 lap = 0 mon = 0 global p global equipm equip = [] for x in range(len(entry)): if "Mon" in entry[x][2]: mon += 1 if "Des" in entry[x][2]: des += 1 if "Lap" in entry[x][2]: lap += 1 if "Mob" in entry[x][2]: mob += 1 out_equip = [[sg.T("")],[sg.Button("Out Equipment"),sg.Button("User List"),sg.Button("New Entry")],[sg.T("")], [sg.T("Monitors"),sg.T(" "),sg.T("Desktops"),sg.T(" "),sg.T("Laptops"),sg.T(" "),sg.T("Mobiles")], [sg.T(" " +str(mon)+ " "),sg.T(" " +str(des)+ " "),sg.T(" " +str(lap)+ " "),sg.T(" " +str(mob))],[sg.T("")],[sg.T("")],[sg.T("")],[sg.T("")], [sg.Combo(values = ("Monitor","Desktop","Laptop","Mobile"),default_value=("Filter by"),key = "filterby"),sg.T(p)],[sg.Button("Filter"),sg.Listbox(values = equipm, size = (35,10))]] window4 = sg.Window("Equipment Portal", out_equip,location=(t[0],t[1]), size = (600,500), finalize = True) event, values = window4.read() t.clear() while True: if event == sg.WIN_CLOSED: con.close() break if event == "User List": u = window4.CurrentLocation() t.append(u[0]) t.append(u[1]) window4.close() user_list() break if event == "Out Equipment": u = window4.CurrentLocation() t.append(u[0]) t.append(u[1]) window4.close() out_equipment() break if event == "New Entry": u = window4.CurrentLocation() t.append(u[0]) t.append(u[1]) window4.close() new_entry() break if event == "Filter": equipm = [] z = values["filterby"] p = values["filterby"] for x in range(len(entry)): if z in entry[x]: equipm.append(entry[x][1]) equipm.append(entry[x][3]) x += 1 u = window4.CurrentLocation() t.append(u[0]) t.append(u[1]) window4.close() out_equipment() break startup()
while dad_has_cigs == True: happiness = True if dad_has_cigs == False: print("Dad come home!") happiness = not happiness break