def GetImage(self, picture): key = picture.GetKey() if key not in self._wxImgCache: pilImg = PILBackend.GetThumbnail(picture, width=ImageCache.SIZE) wxImg = wx.Image(PILBackend.ImageToStream(pilImg), wx.BITMAP_TYPE_JPEG) self._wxImgCache[key] = wxImg return self._wxImgCache[key]
def __ThumbToQuery(self, picId, pic): pilThumb = PILBackend.GetThumbnail(pic, height=120) thumbWidth, thumbHeight = pilThumb.size thumbData = pilThumb.tobytes() query = "INSERT INTO `thumbnail` (" \ "picture_id, width, height, data" \ ") VALUES (" \ "?, ?, ?, ?" \ ");" values = (picId, thumbWidth, thumbHeight, thumbData) return query, values
def GetPreviewThumb(self): if not self.Load(): return None img = None pics = self._project.GetPictures() imgCount = len(pics) if imgCount > 0: picIdx = random.randint(0, imgCount - 1) pic = pics[picIdx] if os.path.exists(pic.GetFilename()): img = PILBackend.GetThumbnail(pic, width=136, height=70) if pic.IsDummy(): img = None return img
def run(self): while self.active: pic = None try: pic = self.queue.pop(0) except IndexError: time.sleep(0.1) continue pilImg = PILBackend.GetThumbnail(pic, height=ImageCache.THUMB_SIZE) self.imgCache.RegisterPicture(pic, pilImg) if self.imgCache.win: evt = ThumbnailReadyEvent(pic) wx.PostEvent(self.imgCache.win, evt)
def __LoadThumbnail(self, pic, picId): ImageCache().RegisterPicture(pic) return thumbNail = None if self.__fileRev >= 3: cur = self.__GetCursor() cur.execute("SELECT * FROM `thumbnail` WHERE picture_id=?", (picId,)) row = cur.fetchone() if row: thumbWidth = row["width"] thumbHeight = row["height"] thumbData = row["data"] thumbNail = PILBackend.ImageFromBuffer((thumbWidth, thumbHeight), thumbData) if thumbNail is None: thumbNail = PILBackend.GetThumbnail(pic, height=120) ImageCache().RegisterPicture(pic, thumbNail)