From cfc14e774ff66a004382af0a1d4f27aebcdd83ef Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sun, 17 Mar 2024 10:20:19 +0000 Subject: [PATCH 1/2] Small change to commit d84b1e2 to be a little safer. --- src/calibre/gui2/library/alternate_views.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/calibre/gui2/library/alternate_views.py b/src/calibre/gui2/library/alternate_views.py index 6bbb19ddaf..cd0fee3c3a 100644 --- a/src/calibre/gui2/library/alternate_views.py +++ b/src/calibre/gui2/library/alternate_views.py @@ -972,6 +972,7 @@ class GridView(QListView): cache_valid = None else: # A cover is in the cache. Check whether it is up to date. + # Note that if tcdata is not None then it is already a PIL image. has_cover, tcdata, timestamp = db.new_api.cover_or_cache(book_id, timestamp, as_what='pil_image') if has_cover: @@ -1012,12 +1013,6 @@ class GridView(QListView): if cover_tuple.has_cover: # cdata contains either the resized thumbnail, the full cover.jpg # rendered as a PIL image, or None if cover.jpg isn't valid - if cdata.getbbox() is None and cover_tuple.cache_valid: - # Something wrong with the cover data in the cache. Remove it - # from the cache and queue it to render again. - tc.invalidate((book_id,)) - self.render_queue.put(book_id) - return None if not cover_tuple.cache_valid: # The cover isn't in the cache, is stale, or isn't a valid # image. We might have the image from cover.jpg, in which case @@ -1052,6 +1047,20 @@ class GridView(QListView): # The cover data isn't valid. Remove it from the cache tc.invalidate((book_id,)) else: + # Test to see if there is something wrong with the cover data in + # the cache. If so, remove it from the cache and queue it to + # render again. It isn't clear that this can ever happen. One + # possibility is if different versions of calibre are used + # interchangeably. + def getbbox(img): + try: + return img.getbbox() + except Exception: + return None + if getbbox(cdata) is None: + tc.invalidate((book_id,)) + self.render_queue.put(book_id) + return None # The data from the cover cache is valid and is already a thumb. thumb = cdata else: From d674a8e45690b306b4d30cc7fef105e82dadcfdb Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sun, 17 Mar 2024 11:10:08 +0000 Subject: [PATCH 2/2] Don't display an empty custom column group box when all custom columns are deselected in Look & feel / Edit metadata --- src/calibre/gui2/custom_column_widgets.py | 7 ++++++- src/calibre/gui2/metadata/single.py | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/custom_column_widgets.py b/src/calibre/gui2/custom_column_widgets.py index 0fb9f193a8..2a8203827a 100644 --- a/src/calibre/gui2/custom_column_widgets.py +++ b/src/calibre/gui2/custom_column_widgets.py @@ -874,6 +874,11 @@ def get_field_list(db, use_defaults=False, pref_data_override=None): return [(k,v) for k,v in result.items()] +def get_custom_columns_to_display_in_editor(db): + return list([k[0] for k in + get_field_list(db, use_defaults=db.prefs['edit_metadata_ignore_display_order']) if k[1]]) + + def populate_metadata_page(layout, db, book_id, bulk=False, two_column=False, parent=None): def widget_factory(typ, key): if bulk: @@ -886,7 +891,7 @@ def populate_metadata_page(layout, db, book_id, bulk=False, two_column=False, pa fm = db.field_metadata # Get list of all non-composite custom fields. We must make widgets for these - cols = [k[0] for k in get_field_list(db, use_defaults=db.prefs['edit_metadata_ignore_display_order']) if k[1]] + cols = get_custom_columns_to_display_in_editor(db) # This deals with the historical behavior where comments fields go to the # bottom, starting on the left hand side. If a comment field is moved to # somewhere else then it isn't moved to either side. diff --git a/src/calibre/gui2/metadata/single.py b/src/calibre/gui2/metadata/single.py index 2e05348c13..ceaa5efbdb 100644 --- a/src/calibre/gui2/metadata/single.py +++ b/src/calibre/gui2/metadata/single.py @@ -19,7 +19,8 @@ from calibre.constants import ismacos from calibre.ebooks.metadata import authors_to_string, string_to_authors from calibre.ebooks.metadata.book.base import Metadata from calibre.gui2 import error_dialog, gprefs, pixmap_to_data -from calibre.gui2.custom_column_widgets import Comments, populate_metadata_page +from calibre.gui2.custom_column_widgets import ( + Comments, populate_metadata_page, get_custom_columns_to_display_in_editor) from calibre.gui2.dialogs.confirm_delete import confirm from calibre.gui2.metadata.basic_widgets import ( AuthorsEdit, AuthorSortEdit, BuddyLabel, CommentsEdit, Cover, DateEdit, @@ -121,7 +122,7 @@ class MetadataSingleDialogBase(QDialog): self.create_basic_metadata_widgets() - if len(self.db.custom_column_label_map): + if len(get_custom_columns_to_display_in_editor(self.db)): self.create_custom_metadata_widgets() self.comments_edit_state_at_apply = {self.comments:None}