本文整理匯總了Python中calibre.gui2.library.caches.ThumbnailCache.set_database方法的典型用法代碼示例。如果您正苦於以下問題:Python ThumbnailCache.set_database方法的具體用法?Python ThumbnailCache.set_database怎麽用?Python ThumbnailCache.set_database使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類calibre.gui2.library.caches.ThumbnailCache
的用法示例。
在下文中一共展示了ThumbnailCache.set_database方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: GridView
# 需要導入模塊: from calibre.gui2.library.caches import ThumbnailCache [as 別名]
# 或者: from calibre.gui2.library.caches.ThumbnailCache import set_database [as 別名]
#.........這裏部分代碼省略.........
self.delegate.calculate_spacing()
self.setSpacing(self.delegate.spacing)
self.set_color()
self.set_thumbnail_cache_image_size()
cs = gprefs['cover_grid_disk_cache_size']
if (cs*(1024**2)) != self.thumbnail_cache.max_size:
self.thumbnail_cache.set_size(cs)
self.update_memory_cover_cache_size()
def set_thumbnail_cache_image_size(self):
dpr = self.device_pixel_ratio
self.thumbnail_cache.set_thumbnail_size(
int(dpr * self.delegate.cover_size.width()), int(dpr*self.delegate.cover_size.height()))
def resizeEvent(self, ev):
self._ncols = None
self.resize_timer.start()
return QListView.resizeEvent(self, ev)
def update_memory_cover_cache_size(self):
try:
sz = self.delegate.item_size
except AttributeError:
return
rows, cols = self.width() // sz.width(), self.height() // sz.height()
num = (rows + 1) * (cols + 1)
limit = max(100, num * max(2, gprefs['cover_grid_cache_size_multiple']))
if limit != self.delegate.cover_cache.limit:
self.delegate.cover_cache.set_limit(limit)
def shown(self):
self.update_memory_cover_cache_size()
if self.render_thread is None:
self.thumbnail_cache.set_database(self.gui.current_db)
self.render_thread = Thread(target=self.render_covers)
self.render_thread.daemon = True
self.render_thread.start()
def render_covers(self):
q = self.delegate.render_queue
while True:
book_id = q.get()
try:
if book_id is None:
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
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)
示例2: GridView
# 需要導入模塊: from calibre.gui2.library.caches import ThumbnailCache [as 別名]
# 或者: from calibre.gui2.library.caches.ThumbnailCache import set_database [as 別名]
#.........這裏部分代碼省略.........
self.setSpacing(self.delegate.spacing)
if size_changed:
self.delegate.cover_cache.clear()
if gprefs['cover_grid_spacing'] != self.delegate.original_spacing:
self.delegate.calculate_spacing()
self.setSpacing(self.delegate.spacing)
self.set_color()
if size_changed:
dpr = self.device_pixel_ratio
self.thumbnail_cache.set_thumbnail_size(int(dpr * self.delegate.cover_size.width()), int(dpr*self.delegate.cover_size.height()))
cs = gprefs['cover_grid_disk_cache_size']
if (cs*(1024**2)) != self.thumbnail_cache.max_size:
self.thumbnail_cache.set_size(cs)
self.update_memory_cover_cache_size()
def resizeEvent(self, ev):
self.resize_timer.start()
return QListView.resizeEvent(self, ev)
def update_memory_cover_cache_size(self):
try:
sz = self.delegate.item_size
except AttributeError:
return
rows, cols = self.width() // sz.width(), self.height() // sz.height()
num = (rows + 1) * (cols + 1)
limit = max(100, num * max(2, gprefs['cover_grid_cache_size_multiple']))
if limit != self.delegate.cover_cache.limit:
self.delegate.cover_cache.set_limit(limit)
def shown(self):
self.update_memory_cover_cache_size()
if self.render_thread is None:
self.thumbnail_cache.set_database(self.gui.current_db)
self.render_thread = Thread(target=self.render_covers)
self.render_thread.daemon = True
self.render_thread.start()
def render_covers(self):
q = self.delegate.render_queue
while True:
book_id = q.get()
try:
if book_id is None:
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: