Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
ImageView.load_from_url in Pythonista Keyboard
-
import ui import keyboard urls = ['http://img.shouji.sogou.com/wapdl/expression/expr_img/2015/201506/20150618/2015061815315008035400.gif', 'http://img.shouji.sogou.com/wapdl/hole/201902/27/expr/2019022710232319713700.gif', 'https://img04.sogoucdn.com/app/a/100540022/2018062515213728242220.gif', 'http://img02.sogoucdn.com/app/a/100540022/2017102615140366466896.gif', 'http://img.shouji.sogou.com/wapdl/hole/201812/13/expr/2018121317560406459300.gif', 'http://img.shouji.sogou.com/wapdl/hole/201712/20/expr/2017122011245048885500.gif', 'https://img02.sogoucdn.com/app/a/100540022/2020031511055081334362.gif', 'https://img04.sogoucdn.com/app/a/100540022/2017112518121024670038.gif'] class MatrixView (ui.View): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) load = ui.ButtonItem() load.title = 'Load' load.action = self.load self.urls = urls self.right_button_items = [load] self.background_color = 'white' self.sv = ui.ScrollView(frame=self.bounds, flex='WH') self.add_subview(self.sv) self.ivs = [] for item in enumerate(self.urls): iv = ui.ImageView() iv.content_mode = ui.CONTENT_SCALE_ASPECT_FIT self.ivs.append(iv) self.sv.add_subview(iv) def load(self, sender): for url, iv in zip(self.urls, self.ivs): iv.load_from_url(url) def layout(self): col = 4 y = gap = 6 w = h = (self.bounds.w - (col + 1) * gap) / col for index, iv in enumerate(self.ivs): if index and index % col == 0: y = y + gap + h x = gap + (index % col) * (gap + w) iv.frame = (x, y, w, h) self.sv.content_size = (0, y+h) if __name__ == '__main__': frame = 0, 0, *ui.get_screen_size() MatrixView(frame=frame).present()
The above code works fine in the main interface, but some pictures will not be displayed when running in the Pythonista keyboard.Is this problem also related to the asynchronous problem of the load_from_url Method?
-
My testing shows same resault. i found this on Apple
im assuming its a resource allocation. my ipad only allows 183MB memory per appthats open, seems kinda low but its what its set to lol, so i can only imagine the 3rd party keyboard is signifacantly lower. you can change thevplist
value for this using xCode. you will need a developer account for this if im correct.Memory limits for running app extensions are significantly lower than the memory limits imposed on a foreground app. On both platforms, the system may aggressively terminate extensions because users want to return to their main goal in the host app. Some extensions may have lower memory limits than others: For example, widgets must be especially efficient because users are likely to have several widgets open at the same time.
Your app extension doesn’t own the main run loop, so it’s crucial that you follow the established rules for good behavior in main run loops. For example, if your extension blocks the main run loop, it can create a bad user experience in another extension or app.
Keep in mind that the GPU is a shared resource in the system. App extensions do not get top priority for shared resources; for example, a Today widget that runs a graphics-intensive game might give users a bad experience. The system is likely to terminate such an extension because of memory pressure. Functionality that makes heavy use of system resources is appropriate for an app, not an app extension.
-
def load(self, sender): def get_data(): for url, iv in zip(self.urls, self.ivs): yield requests.get(url).content, iv for data, iv in get_data(): iv.image = ui.Image.from_data(data)
But I replaced ImageView.load_from_url with ui.Image.from_data,everything is fine.the resource allocation problem caused by displaying the gif file?
-
@stephen
I try to display less images by change the self.urlsself.urls = urls[:2]
It still the same.
-
@mieq said:
def load(self, sender): def get_data(): for url, iv in zip(self.urls, self.ivs): yield requests.get(url).content, iv for data, iv in get_data(): iv.image = ui.Image.from_data(data)
But I replaced ImageView.load_from_url with ui.Image.from_data,everything is fine.the resource allocation problem caused by displaying the gif file?
Im Assuming the memory alocation is different for animations. I found alot of reports on gif animations not closing thier stream on loop end and would contenue to build memory alocation. some even after dismissing (changing to new gif) wouldnt release memory used.
some reports have people getting over a GB just my letting a gif run for x time. i figure IOS detects this prior to fully opening and closes the gif before opening to memory.
appears that gifly is bad at providing these 'broken' files but i dont think its really anyones fault lol