I'm trying to have a loading gif playing in a widows while the code execute calculation.
I've read this post : Updating Popup.Animated to play gif until external task is completed (PYSimpleGUI)
But it doesn't apply to my case since I'm not trying to use sg.PopupAnimated
.
What I want to do is update the displayed widows by animating the gif, until the code ends and the windows close.
I'm sure it has something to do with the loop but I cannot figure out what.
Here is my code :
layout4 = [[sg.Image(r'C:\Users\...\Pictures\img.png'), sg.Text('Please wait')],
[sg.Image(r'C:\Users\...\Pictures\animation.gif', size = (120,120), key = "Prog_bar")]]
window4 = sg.Window("HAL 220").Layout(layout4)
event, values = window4.Read()
while True:
window4.FindElement("Prog_bar").UpdateAnimation("animation.gif",time_between_frames=100)
if event is None :
break
# ===== That would be the section of the code with the function and the loop =====
def main(alpha, alg_type):
""" Set the variables for the loop """
futures = []
e = ProcessPoolExecutor(8) # Processes is almost 8 times faster in this cases than ThreadPoolExecutor
if alg_type == "O":
F = FFR_ME
elif alg_type == "NO":
F = FFR_ME_NO
else :
raise TypeError("Algortithm type selected does not exist. Must be 'O' or 'NO'")
""" Loop over the different task summarized in the tab 'N_tab' during the MPO_PROC step. """
for task in N_tab["TASK_NUMBER"]:
""" Declare variables N, n , f based on the previous calculations """
N = int(N_tab.loc[N_tab["TASK_NUMBER"] == task, "N_Task"])
n = int(N_tab.loc[N_tab["TASK_NUMBER"] == task, "n_i"])
f = int(N_tab.loc[N_tab["TASK_NUMBER"] == task, "F"])
"""" Implement the function using the concurrent.future module for multiprocessing. """
future = e.submit(F, N, n, f, alpha)
futures.append(future)
results = [ff.result() for ff in futures]
for i in range(len(results)):
f = int(N_tab.loc[i, "F"])
N_tab.loc[i,"LBound"] = results[i][0][f]
N_tab.loc[i,"UBound"] = results[i][1][f]
N_tab.loc[i,"ME"] = (N_tab.loc[i,"UBound"] - N_tab.loc[i,"LBound"])/\
(2*N_tab.loc[i,"N_Task"])
N_tab.loc[i,"FFR"] = (N_tab.loc[i,"LBound"] + (N_tab.loc[i,"UBound"] - N_tab.loc[i,"LBound"])/2)/\
N_tab.loc[i,"N_Task"]
if __name__ == "__main__":
main(alpha, alg_type)
# ====== End of the section end of the calculation
window4.close()
Thank you