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?