From 3c7ae38f81318c56cabf04f1b8d480ce62a41a52 Mon Sep 17 00:00:00 2001 From: magical Date: Sat, 3 Feb 2024 20:21:29 -0800 Subject: [PATCH] restore GUI event loop --- GUI.py | 136 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 70 insertions(+), 66 deletions(-) diff --git a/GUI.py b/GUI.py index 5699e43..08a41ba 100644 --- a/GUI.py +++ b/GUI.py @@ -231,74 +231,78 @@ def main_window(debug): fileName = str() finishGenerating = False oldNum = str() - (event, values) = window.read() - if event == ui.WINDOW_CLOSED: - pass - elif event == 'Num': - if len(values['Num']) > 3: - window['Num'].update(oldNum) - for x in range(4): - if x < len(values['Num']) or values['Num'][x] not in '0123456789': + while True: + (event, values) = window.read() + if event == ui.WINDOW_CLOSED: + break + + elif event == 'Num': + if len(values['Num']) > 3: window['Num'].update(oldNum) - - oldNum = values['Num'] - # continue - if event == 'Generate': - basegame = ui.popup_get_file('Choose base game', no_titlebar=True, file_types=[('GBA File', '*.gba')], history=True, history_setting_filename=os.path.join('.', 'settings.json')) - if basegame == '': - ui.popup('Please select a Metroid Fusion (U) rom.', title='No source rom selected') - if basegame != None and basegame != '': - checksum = fileHash(basegame) - if checksum != 1819625372: - ui.popup('Only Metroid Fusion (U) is supported.\nCheck the CRC32 value: it should be 6C75479C', title='Bad Checksum') - else: - values.update({ - 'Debug': debug }) - threading.Thread(target=rando_thread, args=[window, values], daemon=True).start() - window['Difficulty'].update(disabled=True) - window['MajorMinor'].update(disabled=True) - window['MissilesWithoutMainData'].update(disabled=True) - window['PowerBombsWithoutBombs'].update(disabled=True) - window['DamageRuns'].update(disabled=True) - window['SplitSecurity'].update(disabled=True) - window['SectorShuffle'].update(disabled=True) - window['HideItems'].update(disabled=True) - window['Seed'].update(disabled=True) - window['RaceSeed'].update(disabled=True) - window['Num'].update(disabled=True) - window['Patch'].update(disabled=True) - window['Generate'].update(disabled=True) - if generating: - ui.popup_animated(ui.DEFAULT_BASE64_LOADING_GIF, 'Generating game, please wait...', time_between_frames=20) - window.Refresh() - # continue - if finishGenerating: - ui.popup_animated(None) - if failedgen: - ui.popup('Could not generate a game with the current settings. Try changing your settings.', title='Metroid Fusion Open Randomizer') - elif randoerror: - ui.popup('An error occurred, no game was generated.', title='Error') - elif ui.Input.get(window['Num']) != '': - if int(ui.Input.get(window['Num'])) > 1: - ui.popup('Multiple games have been added to the seeds folder.', title='Success!') + for x in range(4): + if x < len(values['Num']): + if values['Num'][x] not in '0123456789': + window['Num'].update(oldNum) + break + else: + oldNum = values['Num'] + + elif event == 'Generate': + basegame = ui.popup_get_file('Choose base game', no_titlebar=True, file_types=[('GBA File', '*.gba')], history=True, history_setting_filename=os.path.join('.', 'settings.json')) + if basegame == '': + ui.popup('Please select a Metroid Fusion (U) rom.', title='No source rom selected') + if basegame != None and basegame != '': + checksum = fileHash(basegame) + if checksum != 1819625372: + ui.popup('Only Metroid Fusion (U) is supported.\nCheck the CRC32 value: it should be 6C75479C', title='Bad Checksum') + else: + values.update({ + 'Debug': debug }) + threading.Thread(target=rando_thread, args=[window, values], daemon=True).start() + window['Difficulty'].update(disabled=True) + window['MajorMinor'].update(disabled=True) + window['MissilesWithoutMainData'].update(disabled=True) + window['PowerBombsWithoutBombs'].update(disabled=True) + window['DamageRuns'].update(disabled=True) + window['SplitSecurity'].update(disabled=True) + window['SectorShuffle'].update(disabled=True) + window['HideItems'].update(disabled=True) + window['Seed'].update(disabled=True) + window['RaceSeed'].update(disabled=True) + window['Num'].update(disabled=True) + window['Patch'].update(disabled=True) + window['Generate'].update(disabled=True) + + if generating: + ui.popup_animated(ui.DEFAULT_BASE64_LOADING_GIF, 'Generating game, please wait...', time_between_frames=20) + window.Refresh() + + elif finishGenerating: + ui.popup_animated(None) + if failedgen: + ui.popup('Could not generate a game with the current settings. Try changing your settings.', title='Metroid Fusion Open Randomizer') + elif randoerror: + ui.popup('An error occurred, no game was generated.', title='Error') + elif ui.Input.get(window['Num']) != '': + if int(ui.Input.get(window['Num'])) > 1: + ui.popup('Multiple games have been added to the seeds folder.', title='Success!') + else: + ui.popup('{}\nhas been added to the seeds folder.'.format(fileName), title='Success!') else: ui.popup('{}\nhas been added to the seeds folder.'.format(fileName), title='Success!') - else: - ui.popup('{}\nhas been added to the seeds folder.'.format(fileName), title='Success!') - window['Difficulty'].update(disabled=False) - window['MajorMinor'].update(disabled=False) - window['MissilesWithoutMainData'].update(disabled=False) - window['PowerBombsWithoutBombs'].update(disabled=False) - window['DamageRuns'].update(disabled=False) - window['SplitSecurity'].update(disabled=False) - window['SectorShuffle'].update(disabled=False) - window['HideItems'].update(disabled=False) - window['Seed'].update(disabled=False) - window['RaceSeed'].update(disabled=False) - window['Num'].update(disabled=False) - window['Patch'].update(disabled=False) - window['Generate'].update(disabled=False) - finishGenerating = False - # continue + window['Difficulty'].update(disabled=False) + window['MajorMinor'].update(disabled=False) + window['MissilesWithoutMainData'].update(disabled=False) + window['PowerBombsWithoutBombs'].update(disabled=False) + window['DamageRuns'].update(disabled=False) + window['SplitSecurity'].update(disabled=False) + window['SectorShuffle'].update(disabled=False) + window['HideItems'].update(disabled=False) + window['Seed'].update(disabled=False) + window['RaceSeed'].update(disabled=False) + window['Num'].update(disabled=False) + window['Patch'].update(disabled=False) + window['Generate'].update(disabled=False) + finishGenerating = False window.close()