[ Enhancement] Propagate exceptions on update_animation(self, source, time_between_frames=0)
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 35/100
Piste de recherche
Commencez dans PySimpleGUI.py, au niveau de la classe Image et de update_animation, en particulier dans la boucle de chargement des frames animées et sa gestion des exceptions. Exécutez le reproducteur threading fourni pour observer le chemin d’erreur actuel. C’est terminé lorsque l’exception tkinter sous-jacente est propagée au lieu d’être masquée par la logique de chargement des frames.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Enhancement
Operating System
Windows
PySimpleGUI Port (tkinter, Qt, Wx, Web)
tkinter
Versions
PySimpleGUI long version = 4.59.0 Released 5-Apr-2022
PySimpleGUI Version 4.59.0
tcl ver = 8.6 tkinter version = 8.6
Python Version 3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)]
tcl detailed version = 8.6.12
Your Experience In Months or Years (optional)
Years Python programming experience 2
Years Programming experience overall 8
Have used another Python GUI Framework? no
Anything else you think would be helpful?
Troubleshooting
These items may solve your problem. Please check those you've done by changing - [ ] to - [X]
- Searched main docs for your problem www.PySimpleGUI.org
- Looked for Demo Programs that are similar to your goal. It is recommend you use the Demo Browser! Demos.PySimpleGUI.org
- None of your GUI code was generated by an AI algorithm like GPT
- If not tkinter - looked for Demo Programs for specific port
- For non tkinter - Looked at readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
- Run your program outside of your debugger (from a command line)
- Searched through Issues (open and closed) to see if already reported Issues.PySimpleGUI.org
- Have upgraded to the latest release of PySimpleGUI on PyPI (lastest official version)
- Tried using the PySimpleGUI.py file on GitHub. Your problem may have already been fixed but not released
Detailed Description
Basically, the update_animation(...) method returns "Exception has occurred: ZeroDivisionError" when i run it on a different thread and that (at least for me) does not make any sense...the error description not the implementation.
Exception is generated here ( code from PySimpleGUI.py, class Image(Element), method update_animation ) :
if time_between_frames:
if (now - self.LastFrameTime) * 1000 > time_between_frames:
self.LastFrameTime = now
self.CurrentFrameNumber = (self.CurrentFrameNumber + 1) % self.TotalAnimatedFrames
else: # don't reshow the frame again if not time for new frame
return
else:
self.CurrentFrameNumber = (self.CurrentFrameNumber + 1) % self.TotalAnimatedFrames
image = self.AnimatedFrames[self.CurrentFrameNumber]
try: # needed in case the window was closed with an "X"
self.tktext_label.configure(image=image, width=image.width(), heigh=image.height())
except Exception as e:
print('Exception in update_animation', e)
at
self.CurrentFrameNumber = (self.CurrentFrameNumber + 1) % self.TotalAnimatedFrames
but actually it's a propagation of :
for i in range(1000):
if type(source) is not bytes:
try:
self.AnimatedFrames.append(tk.PhotoImage(file=source, format='gif -index %i' % (i)))
except Exception as e:
break
else:
try:
self.AnimatedFrames.append(tk.PhotoImage(data=source, format='gif -index %i' % (i)))
except Exception as e:
break
few lines higher.
The error comes from:
try:
self.AnimatedFrames.append(tk.PhotoImage(file=source, format='gif -index %i' % (i)))
except Exception as e:
break
and is tkinter telling me that:
RuntimeError('main thread is not in main loop')
That is way more explanatory.
My suggestion is that these kind of errors should be propagated all the way up instead of try/catch and hiding them.
Code To Duplicate
import PySimpleGUI as sg
from threading import Thread
global new_thr
new_thr=None
def launch_thr():
new_thr = Thread(target=update_image, args=[working_window])
new_thr.start()
def update_image(working_window,):
while True:
working_window["-IMAGE_GIF-"].update_animation(work_gif, time_between_frames=250)
work_gif=r'GUI_Launcher\Images\work.gif'
test_in_progress=[
[sg.Text("Please be patient...", expand_x=True, expand_y=True, font="courier 13 bold")],
[sg.Image(source=work_gif, size=(375,375), key="-IMAGE_GIF-")],
[sg.Text("... I am working for you", expand_x=True, expand_y=True, font="courier 13 bold")]
]
working_window = sg.Window("Test in progress", layout=test_in_progress, size=(800,600), return_keyboard_events=True, finalize=True)
while True:
if new_thr is None:
launch_thr()
str="do stuff"
Screenshot, Sketch, or Drawing
Watcha Makin?
A gui to launch sessions of Robot Framework. This problem occured when i tried to implement an animation when tests are running.
- Langage dominant
- Python
- Étoiles
- 13.8k
- Forks
- 1.8k
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de PySimpleGUI/PySimpleGUI
-
Bug Done - Install Dev Build (see docs for how) Platform Specific Issue - Linux Port - TK
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
PySimpleGUI/PySimpleGUI#6904 · 15 commentaires ·
-
Bug Demo Programs Done - Install Dev Build (see docs for how) Interoperability Port - TK workaround available
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
PySimpleGUI/PySimpleGUI#6900 · 1 commentaire ·
-
Done - Install Dev Build (see docs for how) enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
PySimpleGUI/PySimpleGUI#3251 · 12 commentaires ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 74/100
PySimpleGUI/PySimpleGUI#6906 · 1 commentaire · 1 réaction ·
-
Bug Done - Install Dev Build (see docs for how) Port - TK
Difficulté 3/5 1-2 jours Accessibilité débutants 45/100
PySimpleGUI/PySimpleGUI#6902 · 1 commentaire ·
Toutes les issues de PySimpleGUI/PySimpleGUI
Issues similaires
-
essnmx good first issue
Difficulté 1/5 Moins d'une heure Accessibilité débutants 95/100
-
[Feature] 奇物选择添加优先级 Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
syfoud/Simulated_Scepter#174 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Giskard-AI/giskard-oss#2840 · 1 commentaire ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success Ouvertearea: repo bug perceived difficulty: 2
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
yeti-platform/yeti#1380 ·