How to put icons in...
I'm new to Python and to Pythonista. I'm working on a program that fetches data and put the results in a view. I made a design in the UI Editor, it consists labels for textual results and Image Views for icons.
My problem is to put icons in the Image Views. I have a map consisting gifs. An ImageView icon points to the IOS images like alert_24 (the !). Can I redirect it to my map of gifs?
To put text in a label I use: v['label1'].text = placeDate
Can I do something similar to put icon therm.gif in imageview9?
Thank you very much for your help,
@cvp I pasted class GitToView into my program, made an imageview, downloaded an animated gif and displayed it. It works, the animation runs fine. But...
The gif is about 450 x 450 px, the imageview as well, the displayed version is about one/third of the original. When I move the x,y of the imageview, the gif moves with it.
I don't understand what happens in the class, so I can't solve the problem. Can you point out what I'm doing wrong? Thanks.
@Peter-S Sorry, it I don't really understand... Could you post the needed files: py, pyui if needed, gif url
Part of the py:
class GifInView(ui.View): def __init__(self,view,gif_file): self.ImageView = ui.ImageView() self.add_subview(self.ImageView) self.pil = Image.open(gif_file) wi,hi = self.pil.size wiv = view.width hiv = wiv * hi / wi self.frame = (0,0,wiv,hiv) view.add_subview(self) # In a GIF file, each frame has its own duration # assume here all frames have the same duration self.update_interval = self.pil.info['duration']/1000 self.frame_id = 0 def pil2ui(self,imgIn): with io.BytesIO() as bIO: imgIn.save(bIO, 'PNG') imgOut = ui.Image.from_data(bIO.getvalue()) del bIO return imgOut def update(self): # Display individual frames from the loaded animated GIF file self.pil.seek(self.frame_id) self.ImageView.image = self.pil2ui(self.pil) self.ImageView.content_mode = ui.CONTENT_SCALE_TO_FILL self.frame_id = self.frame_id + 1 if self.frame_id >= self.pil.n_frames: self.frame_id = 0 # knop regenradar def knopje(sender): uri = 'https://api.buienradar.nl/image/1.0/radarmapnl/gif/?hist=0&forc=36&width=550&l=1&step=1' with open('./gif/radar.gif', 'wb') as f: f.write(requests.get(uri).content) r = ui.load_view('Radar') if ui.get_screen_size() >= 768: r.present('sheet') else: r.present() GifInView(r['imageview1'],'./gif/radar.gif')
The link to the gif:
The result is an animated gif displayed, but too small for the imageview (about 1/4th).
@Peter-S As I don't have your .pyui file, I can reproduce the problem with
# knop regenradar def knopje(sender): #uri = 'https://api.buienradar.nl/image/1.0/radarmapnl/gif/?hist=0&forc=36&width=550&l=1&step=1' #with open('radar.gif', 'wb') as f: # f.write(requests.get(uri).content) #r = ui.load_view('Radar') r = ui.View() r.frame = (0,0,600,600) imageview1 = ui.ImageView(name='imageview1') imageview1.frame = (10,10,450,450) imageview1.border_width = 1 r.add_subview(imageview1) if ui.get_screen_size() >= 768: r.present('sheet') else: r.present() GifInView(r['imageview1'],'IMG_6928.GIF') knopje('test')
I search the origin but don't find actually, wait and hope 😀
Here the same result with your code for the imageview. When I bypass GifInView and load a png in my pyui with
r['imageview1'].image = ui.Image.named('./gif/image.png'), the picture fills the whole frame.
Succes, looking forward to a solution!
@Peter-S Found, shame on me 😔, sorry, put this line after self.frame = ...
self.ImageView.frame = self.frame
Delay has been long because I've problems of response time with the forum site
Fantastic view from wall to wall. Thank you very much!
And you're right, the site is pretty slow. Nevertheless, good answers are always in time...
@Peter-S I am so ashamed that I think I will change my username to hide me in the forum 🤭
@cvp Of course not, the whole code worked, it only needed a bit of pumping up the image. Thanks again!