def load_next(self): try: img = Image.open(self.paths[self.load_pos]) resize(img, self.thumb_h, self.thumb_w) photo = PhotoImage(img) col, row = self.column, self.row self.photos.append(photo) x, y = self.calculate_pos(self.column, self.row) photo.cid = self._canvas.create_image(x, y, image=photo) photo.index = self.load_pos self._canvas.tag_bind(photo.cid, '<Button-1>', lambda e: self.button_callback(e, photo, col, row)) self._canvas.tag_bind(photo.cid, '<Double-Button-1>', self.activate) self._canvas.addtag_withtag('photo', photo.cid) self.column += 1 self.loaded += 1 except OSError: logger.info('Could not open %s', self.paths[self.load_pos]) self.load_pos += 1 except Image.DecompressionBombWarning: self.load_pos += 1 if self.column >= self.max_columns: self.row += 1 self.column = 0 if self.load_pos < len(self.paths) - 1 and self.loaded < self.LIMIT: self.load_pos += 1 self.widget.after_idle(self.load_next) elif self.loaded >= self.LIMIT: self.loaded = 0 x, y = self.calculate_pos(self.column, self.row) button = Button(self._canvas, text='Load More', command=self.continue_loading) cid = self._canvas.create_window(x, y, window=button) self._canvas.addtag_withtag('loadbutton', cid) self._canvas['scrollregion'] = self._canvas.bbox('all')
def load_next(self): try: img = Image.open(self.paths[self.load_pos]) resize(img, self.thumb_h, self.thumb_w) photo = PhotoImage(img) col, row = self.column, self.row self.photos.append(photo) x, y = self.calculate_pos(self.column, self.row) photo.cid = self._canvas.create_image(x, y, image=photo) photo.index = self.load_pos self._canvas.tag_bind( photo.cid, '<Button-1>', lambda e: self.button_callback(e, photo, col, row)) self._canvas.tag_bind(photo.cid, '<Double-Button-1>', self.activate) self._canvas.addtag_withtag('photo', photo.cid) self.column += 1 self.loaded += 1 except OSError: logger.info('Could not open %s', self.paths[self.load_pos]) self.load_pos += 1 except Image.DecompressionBombWarning: self.load_pos += 1 if self.column >= self.max_columns: self.row += 1 self.column = 0 if self.load_pos < len(self.paths) - 1 and self.loaded < self.LIMIT: self.load_pos += 1 self.widget.after_idle(self.load_next) elif self.loaded >= self.LIMIT: self.loaded = 0 x, y = self.calculate_pos(self.column, self.row) button = Button(self._canvas, text='Load More', command=self.continue_loading) cid = self._canvas.create_window(x, y, window=button) self._canvas.addtag_withtag('loadbutton', cid) self._canvas['scrollregion'] = self._canvas.bbox('all')