Zdravim.
Snazim sa spravne pouzivat threading spojeny s GUI. Mam ale pocit ze nieco je zle.
Idea je taka ze nastartujem thready potom sa nastartuje GUI a to nasledne skusa ci je thread aktivny ak nie tak ho znova nastartuje. Ale mam pocit ze nieco je zle resp. slo by to vyriesit elegantnejsie. Vie niekto poradit ako sa to ma "spravne" riesit?
layout = [[sg.Output(size=(80,10))],
[sg.Button('Exit')],[sg.Button('Debug ON/OFF'), sg.Button('Movement monitoring ON/OFF')]]
window = sg.Window('Shifter V 1.0', layout)
#XML_domino.XML_To_DB(Model, Batch)
#Start Thereading
S1t = threading.Thread(target=Stage_1, args=("task",))
S1t.start()
S2t = threading.Thread(target=Stage_2, args=("task",))
S2t.start()
S3t = threading.Thread(target=Stage_3, args=("task",))
S3t.start()
while 1:
#Connect to SQL
if(SQL_Status == False):
connect_to_database()
if(SQL_Status == True and RFID_Status == False):
connect_to_RFID()
if(SQL_Status == True and RFID_Status == True):
check()
if S1t.is_alive() is False:
S1t = threading.Thread(target=Stage_1, args=("task",))
S1t.start()
if S2t.is_alive() is False:
S2t = threading.Thread(target=Stage_2, args=("task",))
S2t.start()
if S3t.is_alive() is False:
S3t = threading.Thread(target=Stage_3, args=("task",))
S3t.start()
window.Refresh()
(event, value) = window.Read(timeout=1)
if event == 'Debug ON/OFF':
if enable_debug == 'True':
enable_debug = 'False'
print('Debug Mode OFF')
else:
enable_debug = 'True'
if event == 'Movement monitoring ON/OFF':
if debug_only_movement == 'True':
debug_only_movement = 'False'
print('Movement monitoring OFF')
else:
debug_only_movement = 'True'
print('Movement monitoring ON')
if event == sg.WIN_CLOSED or event == 'Exit':
break