107 lines
3.1 KiB
Python
107 lines
3.1 KiB
Python
import PySimpleGUI as sg
|
|
|
|
import time
|
|
from libs import *
|
|
|
|
def login():
|
|
sg.theme('DarkAmber')
|
|
|
|
layout = [
|
|
[sg.Text("Nome de usuário")],
|
|
[sg.Input(key='-USERNAME-')],
|
|
[sg.Text("Senha")],
|
|
[sg.Input(key='-PASSWORD-', password_char='*')],
|
|
[sg.Text(size=(40,1), key='-TEXT-', text_color="red")],
|
|
[sg.Button('Login'), sg.Button('Sair')]
|
|
]
|
|
|
|
window = sg.Window('Login', layout)
|
|
|
|
while True:
|
|
event, values = window.read()
|
|
|
|
if event == sg.WINDOW_CLOSED or event == 'Sair':
|
|
break
|
|
|
|
if validate_login(values['-USERNAME-'], values['-PASSWORD-']):
|
|
window.close()
|
|
return True
|
|
else:
|
|
window['-TEXT-'].update('Nome de usuário ou senha incorretos!')
|
|
window.refresh()
|
|
time.sleep(2)
|
|
window['-TEXT-'].update('')
|
|
|
|
window.close()
|
|
return False
|
|
|
|
|
|
def main():
|
|
if login():
|
|
print("Login sucessful")
|
|
else:
|
|
print("Login unsucessful")
|
|
##########################################################################################
|
|
sg.theme('BlueMono')
|
|
|
|
info_col = [[sg.T('Name: '), sg.T('', key='-NAME-')],
|
|
[sg.T('Birth: '), sg.T('', key='-BIRTH-')],
|
|
[sg.T('ID: '), sg.T('', key='-ID-')]]
|
|
|
|
|
|
layout = [
|
|
[sg.Text('Children')],
|
|
[sg.Listbox(values=[row[1] for row in get_children()], size=(30, 10), key='-CHILDREN-', enable_events=True), sg.Col(info_col)],
|
|
[sg.Button('Add'), sg.Button('Remove')]
|
|
]
|
|
|
|
window = sg.Window('Children App', layout)
|
|
|
|
while True:
|
|
event, values = window.read()
|
|
if event == sg.WIN_CLOSED:
|
|
break
|
|
if event == '-CHILDREN-':
|
|
selected = values['-CHILDREN-']
|
|
id, name, birth = get_child_by_name(selected[0])
|
|
|
|
window['-NAME-'].update(name)
|
|
window['-BIRTH-'].update(birth)
|
|
window['-ID-'].update(id)
|
|
|
|
if event == 'Add':
|
|
add_layout = [
|
|
[sg.T('Name')],
|
|
[sg.In(key='-NAME-')],
|
|
[sg.T('Birth')],
|
|
[sg.In(key='-BIRTH-')],
|
|
[sg.T('ID')],
|
|
[sg.In(key='-ID-')],
|
|
[sg.Button(button_text="OK")]
|
|
]
|
|
|
|
add_window = sg.Window('Add Child', add_layout)
|
|
add_event, add_values = add_window.read()
|
|
|
|
if add_event == 'OK':
|
|
add_child(int(add_values['-ID-']), add_values['-NAME-'], add_values['-BIRTH-'])
|
|
window['-CHILDREN-'].update(values=[row[1] for row in get_children()])
|
|
add_window.close()
|
|
|
|
if event == 'Remove':
|
|
|
|
id_layout = [[sg.T('Enter ID to remove')],
|
|
[sg.In(key='-ID-')],
|
|
[sg.Button(button_text="OK")]]
|
|
|
|
id_window = sg.Window('Remove Child', id_layout)
|
|
id_event, id_values = id_window.read()
|
|
|
|
if id_event == 'OK':
|
|
remove_child_by_id(int(id_values['-ID-']))
|
|
window['-CHILDREN-'].update(values=[row[1] for row in get_children()])
|
|
|
|
id_window.close()
|
|
|
|
window.close()
|