MCPcopy
hub / github.com/PySimpleGUI/PySimpleGUI / main

Function main

DemoPrograms/Demo_Multithreaded_ProgressBar.py:51–85  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49
50
51def main():
52 layout = [ [sg.Text('My Multi-threaded PySimpleGUI Program')],
53 [sg.ProgressBar(100, 'h', size=(30,20), k='-PROGRESS-', expand_x=True)],
54 [sg.Text(key='-STATUS-')],
55 [sg.Button('Go'), sg.Button('Exit')] ]
56
57 window = sg.Window('Window Title', layout, finalize=True, relative_location=(0, -300))
58 downloading, max_value = False, 0
59
60 while True: # Event Loop
61 event, values = window.read()
62 # print(event, values)
63 if event == sg.WIN_CLOSED or event == 'Exit':
64 break
65 if event == 'Go' and not downloading:
66 window.start_thread(lambda: the_thread(window), (THREAD_KEY, DL_THREAD_EXITNG))
67 # Events coming from the Thread
68 elif event[0] == THREAD_KEY:
69 if event[1] == DL_START_KEY:
70 max_value = values[event]
71 downloading = True
72 window['-STATUS-'].update('Starting download')
73 sg.one_line_progress_meter(f'Downloading {max_value} segments', 0, max_value, 1, f'Downloading {max_value} segments', )
74 window['-PROGRESS-'].update(0, max_value)
75 elif event[1] == DL_COUNT_KEY:
76 sg.one_line_progress_meter(f'Downloading {max_value} segments', values[event]+1, max_value, 1, f'Downloading {max_value} segments')
77 window['-STATUS-'].update(f'Got a new current count update {values[event]}')
78 window['-PROGRESS-'].update(values[event]+1, max_value)
79 elif event[1] == DL_END_KEY:
80 downloading = False
81 window['-STATUS-'].update('Download finished')
82 elif event[1] == DL_THREAD_EXITNG:
83 window['-STATUS-'].update('Last step - Thread has exited')
84
85 window.close()
86
87if __name__ == '__main__':
88 main()

Calls 5

readMethod · 0.95
start_threadMethod · 0.95
closeMethod · 0.95
the_threadFunction · 0.70
updateMethod · 0.45

Tested by

no test coverage detected