From f7e0d6ccf3c43de3d71ca471e2a0796be7021823 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Tue, 12 Apr 2022 13:57:37 +0100 Subject: [PATCH] Enhancement #1968559: Show tooltips on bool and bool-like columns --- src/calibre/gui2/library/models.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index 36587a608d..22e512ea47 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -764,6 +764,7 @@ class BooksModel(QAbstractTableModel): # {{{ def build_data_convertors(self): rating_fields = {} + bool_fields = set() def renderer(field, decorator=False): idfunc = self.db.id @@ -775,6 +776,7 @@ class BooksModel(QAbstractTableModel): # {{{ dt = m['datatype'] if decorator == 'bool': + bool_fields.add(field) bt = self.db.new_api.pref('bools_are_tristate') bn = self.bool_no_icon by = self.bool_yes_icon @@ -895,14 +897,23 @@ class BooksModel(QAbstractTableModel): # {{{ def stars_tooltip(func, allow_half=True): def f(idx): - ans = val = int(func(idx)) + val = int(func(idx)) ans = str(val // 2) if allow_half and val % 2: ans += '.5' return _('%s stars') % ans return f + + def bool_tooltip(key): + def f(idx): + return self.db.new_api.fast_field_for(self.db.new_api.fields[key], + self.db.id(idx)) + return f + for f, allow_half in iteritems(rating_fields): tc[f] = stars_tooltip(self.dc[f], allow_half) + for f in bool_fields: + tc[f] = bool_tooltip(f) # build a index column to data converter map, to remove the string lookup in the data loop self.column_to_dc_map = [self.dc[col] for col in self.column_map] self.column_to_tc_map = [tc[col] for col in self.column_map]