From eccb70cede67d608164b51f9393958bea79fcfc2 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Fri, 22 Oct 2010 10:00:24 +0100 Subject: [PATCH] Fix bulk edit of bool columns when the tristate tweak is set to no --- src/calibre/gui2/custom_column_widgets.py | 33 ++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/custom_column_widgets.py b/src/calibre/gui2/custom_column_widgets.py index 3be4c19d17..3103d7c459 100644 --- a/src/calibre/gui2/custom_column_widgets.py +++ b/src/calibre/gui2/custom_column_widgets.py @@ -429,7 +429,38 @@ class BulkBase(Base): self.db.set_custom_bulk(book_ids, val, num=self.col_id, notify=notify) class BulkBool(BulkBase, Bool): - pass + + def get_initial_value(self, book_ids): + value = None + for book_id in book_ids: + val = self.db.get_custom(book_id, num=self.col_id, index_is_id=True) + if tweaks['bool_custom_columns_are_tristate'] == 'no' and val is None: + val = False + if value is not None and value != val: + return None + value = val + return value + + def setup_ui(self, parent): + self.widgets = [QLabel('&'+self.col_metadata['name']+':', parent), + QComboBox(parent)] + w = self.widgets[1] + items = [_('Yes'), _('No'), _('Undefined')] + icons = [I('ok.png'), I('list_remove.png'), I('blank.png')] + for icon, text in zip(icons, items): + w.addItem(QIcon(icon), text) + + def setter(self, val): + val = {None: 2, False: 1, True: 0}[val] + self.widgets[1].setCurrentIndex(val) + + def commit(self, book_ids, notify=False): + val = self.gui_val + val = self.normalize_ui_val(val) + if val != self.initial_val: + if tweaks['bool_custom_columns_are_tristate'] == 'no' and val is None: + val = False + self.db.set_custom_bulk(book_ids, val, num=self.col_id, notify=notify) class BulkInt(BulkBase, Int): pass