You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there! I really love this project, thanks for your work!
Can you suggest, please, how can I display gifs in ImageView and handle events?
First, I tried to open gif like in python bindings example, with io.open, but ImageView displays only first (0) frame. Then I tried to open image with PIL image library and loop over frames. It worked, but I cant handle events, till frame loop is not finished, but also I would like the gif to be shown infinitely. I can do this with while loop, but, again, cant handle events.
Now, I have a code like this:
from io import BytesIO
from time import sleep
from PIL import Image
file = 'some.gif'
gif = Image.open(file)
with tg.Connection() as c:
a = tg.Activity(c, dialog=True)
lay = tg.LinearLayout(a)
e = tg.ImageView(a, lay)
button = tg.Button(a, 'Text', lay)
for ev in c.events():
print (ev.type, ev.value)
for frame in range(gif.n_frames):
gif.seek(frame)
buf = BytesIO()
gif.save(buf, format='PNG')
e.setlinearlayoutparams(0)
e.setheight(gif.height*5, px=True)
e.setwidth(gif.width*5, px=True)
e.setimage(buf.getvalue())
sleep(1.5)
It's looped over all frames only one time, and till loop is not finished, events cant be handled
The text was updated successfully, but these errors were encountered:
If you are busy doing other things in your program, you can check for events with Connection.checkevent(), or you could make a separate thread to handle the events.
After creating the issue, I also began to think about threads. But my mistake was that I started the thread inside the event loop. After your answers, I took it out of the loop and everything worked out. Thank you so much!
Hi there! I really love this project, thanks for your work!
Can you suggest, please, how can I display gifs in ImageView and handle events?
First, I tried to open gif like in python bindings example, with io.open, but ImageView displays only first (0) frame. Then I tried to open image with PIL image library and loop over frames. It worked, but I cant handle events, till frame loop is not finished, but also I would like the gif to be shown infinitely. I can do this with while loop, but, again, cant handle events.
Now, I have a code like this:
It's looped over all frames only one time, and till loop is not finished, events cant be handled
The text was updated successfully, but these errors were encountered: