diff --git a/0.jpg b/0.jpg new file mode 100644 index 0000000..8c7f227 Binary files /dev/null and b/0.jpg differ diff --git a/69.jpg b/69.jpg new file mode 100644 index 0000000..6e8cedb Binary files /dev/null and b/69.jpg differ diff --git a/db.json b/db.json index d00f064..ea5d2fd 100644 --- a/db.json +++ b/db.json @@ -9,6 +9,16 @@ "birth": "24/07/2008", "id": 2, "name": "Chris" + }, + { + "birth": "11/22/33", + "id": 69, + "name": "jose" + }, + { + "birth": "15/01/1995", + "id": 12349876, + "name": "Limas" } ], "password": "pass", diff --git a/libs.py b/libs.py index 61ed77b..054583a 100644 --- a/libs.py +++ b/libs.py @@ -86,8 +86,19 @@ def add_child(child_id, name, birth): write_json('children', data['children']) def get_pic(id): - image = Image.open(f"assets/{id}.jpg") + try: + image = Image.open(f"assets/{id}.jpg") + except FileNotFoundError: + image = Image.open(f"assets/0.jpg") image.thumbnail((200, 200)) bio = io.BytesIO() image.save(bio, format="PNG") - return bio.getvalue() \ No newline at end of file + return bio.getvalue() + +def removepicbyid(id): + path = f"assets/{id}.jpg" + if os.path.exists(path): + os.remove(path) + return True + else: + return False \ No newline at end of file diff --git a/main.py b/main.py index 43783fe..ea76c97 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,7 @@ import PySimpleGUI as sg import time +import shutil + from libs import * def login(): @@ -41,19 +43,19 @@ def main_menu(): sg.theme('BlueMono') info_col = [ [sg.T('ID: '), sg.T('', key='-ID-')], - [sg.T('Name: '), sg.T('', key='-NAME-')], - [sg.T('Birth: '), sg.T('', key='-BIRTH-')], + [sg.T('Nome: '), sg.T('', key='-NAME-')], + [sg.T('Nascimento: '), sg.T('', key='-BIRTH-')], [sg.Image(data=get_pic(0), key='-IMAGE-')] ] layout = [ [sg.Listbox(values=[row[1] for row in get_children()], size=(30, 17), key='-CHILDREN-', enable_events=True), sg.Col(info_col)], - [sg.Column([[sg.Button('Add'), sg.Button('Remove')]], justification='center')] + [sg.Column([[sg.Button('Adicionar'), sg.Button('Remover', disabled=True)]], justification='center')] ] - window = sg.Window('Children App', layout, finalize=True) + window = sg.Window('IDE Cadastro', layout, finalize=True) window.set_min_size((500,350)) while True: @@ -63,44 +65,52 @@ def main_menu(): if event == '-CHILDREN-': selected = values['-CHILDREN-'] id, name, birth = get_child_by_name(selected[0]) - + + window['Remover'].update(disabled=False) window['-NAME-'].update(name) window['-BIRTH-'].update(birth) window['-ID-'].update(id) window['-IMAGE-'].update(get_pic(id)) - if event == 'Add': + if event == 'Adicionar': add_layout = [ - [sg.T('Name')], + [sg.T('Nome')], [sg.In(key='-NAME-')], - [sg.T('Birth')], + [sg.T('Nascimento')], [sg.In(key='-BIRTH-')], [sg.T('ID')], [sg.In(key='-ID-')], + [sg.T('Foto')], + [sg.In(), sg.FileBrowse(key='-PICTURE-', button_text="Navegar")], [sg.Button(button_text="OK")] ] - add_window = sg.Window('Add Child', add_layout) + add_window = sg.Window('Adicionar Criança', add_layout) add_event, add_values = add_window.read() if add_event == 'OK': + new_filename = f"assets/{add_values['-ID-']}.jpg" + picture_path = add_values['-PICTURE-'] + shutil.copy(picture_path, new_filename) 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': + if event == 'Remover': selected = values['-CHILDREN-'][0] + child_id = get_child_by_name(selected)[0] id_layout = [[sg.T(f'Você tem certeza que deseja remover {selected}?')], [sg.T(f'Essa ação é PERMANENTE e IRREVERSÍVEL!', text_color="red")], [sg.Button(button_text="OK")]] - id_window = sg.Window('Remove Child', id_layout, element_justification='c') - id_event, id_values = id_window.read() - + id_window = sg.Window('Remover Criança', id_layout, element_justification='c') + id_event, id_values = id_window.read() + if id_event == 'OK': - remove_child_by_id(get_child_by_name(selected)[0]) + remove_child_by_id(child_id) + removepicbyid(child_id) window['-CHILDREN-'].update(values=[row[1] for row in get_children()]) id_window.close() @@ -114,6 +124,6 @@ def main(): main_menu() else: print("Login unsucessful") -# main() -main_menu() +main() +# main_menu()