本文整理汇总了Python中calibre.gui2.library.caches.ThumbnailCache.invalidate方法的典型用法代码示例。如果您正苦于以下问题:Python ThumbnailCache.invalidate方法的具体用法?Python ThumbnailCache.invalidate怎么用?Python ThumbnailCache.invalidate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calibre.gui2.library.caches.ThumbnailCache
的用法示例。
在下文中一共展示了ThumbnailCache.invalidate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GridView
# 需要导入模块: from calibre.gui2.library.caches import ThumbnailCache [as 别名]
# 或者: from calibre.gui2.library.caches.ThumbnailCache import invalidate [as 别名]
#.........这里部分代码省略.........
continue
try:
self.render_cover(book_id)
except:
import traceback
traceback.print_exc()
finally:
q.task_done()
def render_cover(self, book_id):
if self.ignore_render_requests.is_set():
return
dpr = self.device_pixel_ratio
page_width = int(dpr * self.delegate.cover_size.width())
page_height = int(dpr * self.delegate.cover_size.height())
tcdata, timestamp = self.thumbnail_cache[book_id]
use_cache = False
if timestamp is None:
# Not in cache
has_cover, cdata, timestamp = self.model().db.new_api.cover_or_cache(book_id, 0)
else:
has_cover, cdata, timestamp = self.model().db.new_api.cover_or_cache(book_id, timestamp)
if has_cover and cdata is None:
# The cached cover is fresh
cdata = tcdata
use_cache = True
if has_cover:
p = QImage()
p.loadFromData(cdata, CACHE_FORMAT if cdata is tcdata else 'JPEG')
p.setDevicePixelRatio(dpr)
if p.isNull() and cdata is tcdata:
# Invalid image in cache
self.thumbnail_cache.invalidate((book_id,))
self.update_item.emit(book_id)
return
cdata = None if p.isNull() else p
if not use_cache: # cache is stale
if cdata is not None:
width, height = p.width(), p.height()
scaled, nwidth, nheight = fit_image(
width, height, page_width, page_height)
if scaled:
if self.ignore_render_requests.is_set():
return
p = p.scaled(nwidth, nheight, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
p.setDevicePixelRatio(dpr)
cdata = p
# update cache
if cdata is None:
self.thumbnail_cache.invalidate((book_id,))
else:
try:
self.thumbnail_cache.insert(book_id, timestamp, image_to_data(cdata))
except EncodeError as err:
self.thumbnail_cache.invalidate((book_id,))
prints(err)
except Exception:
import traceback
traceback.print_exc()
elif tcdata is not None:
# Cover was removed, but it exists in cache, remove from cache
self.thumbnail_cache.invalidate((book_id,))
self.delegate.cover_cache.set(book_id, cdata)
self.update_item.emit(book_id)
示例2: GridView
# 需要导入模块: from calibre.gui2.library.caches import ThumbnailCache [as 别名]
# 或者: from calibre.gui2.library.caches.ThumbnailCache import invalidate [as 别名]
#.........这里部分代码省略.........
return
if self.ignore_render_requests.is_set():
continue
try:
self.render_cover(book_id)
except:
import traceback
traceback.print_exc()
finally:
q.task_done()
def render_cover(self, book_id):
if self.ignore_render_requests.is_set():
return
tcdata, timestamp = self.thumbnail_cache[book_id]
use_cache = False
if timestamp is None:
# Not in cache
has_cover, cdata, timestamp = self.model().db.new_api.cover_or_cache(book_id, 0)
else:
has_cover, cdata, timestamp = self.model().db.new_api.cover_or_cache(book_id, timestamp)
if has_cover and cdata is None:
# The cached cover is fresh
cdata = tcdata
use_cache = True
if has_cover:
p = QImage()
p.loadFromData(cdata, CACHE_FORMAT if cdata is tcdata else 'JPEG')
dpr = self.device_pixel_ratio
p.setDevicePixelRatio(dpr)
if p.isNull() and cdata is tcdata:
# Invalid image in cache
self.thumbnail_cache.invalidate((book_id,))
self.update_item.emit(book_id)
return
cdata = None if p.isNull() else p
if not use_cache: # cache is stale
if cdata is not None:
width, height = p.width(), p.height()
scaled, nwidth, nheight = fit_image(
width, height, int(dpr * self.delegate.cover_size.width()), int(dpr * self.delegate.cover_size.height()))
if scaled:
if self.ignore_render_requests.is_set():
return
p = p.scaled(nwidth, nheight, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
p.setDevicePixelRatio(dpr)
cdata = p
# update cache
if cdata is None:
self.thumbnail_cache.invalidate((book_id,))
else:
try:
self.thumbnail_cache.insert(book_id, timestamp, image_to_data(cdata))
except EncodeError as err:
self.thumbnail_cache.invalidate((book_id,))
prints(err)
except Exception:
import traceback
traceback.print_exc()
elif tcdata is not None:
# Cover was removed, but it exists in cache, remove from cache
self.thumbnail_cache.invalidate((book_id,))
self.delegate.cover_cache.set(book_id, cdata)
self.update_item.emit(book_id)