From 4694adb9234ea3fc5497d805fa9a6a7b6dc6493c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 20 May 2012 10:35:16 +0530 Subject: [PATCH] Set a different background color when choosing formats to not delete as opposed to choosing format to delete. Fixes #1001741 (Enhancement - Remove Book Formats) --- src/calibre/gui2/actions/delete.py | 7 ++++--- src/calibre/gui2/dialogs/select_formats.py | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/actions/delete.py b/src/calibre/gui2/actions/delete.py index 5f9e58d7b8..7a5115865f 100644 --- a/src/calibre/gui2/actions/delete.py +++ b/src/calibre/gui2/actions/delete.py @@ -116,7 +116,7 @@ class DeleteAction(InterfaceAction): for action in list(self.delete_menu.actions())[1:]: action.setEnabled(enabled) - def _get_selected_formats(self, msg, ids): + def _get_selected_formats(self, msg, ids, exclude=False): from calibre.gui2.dialogs.select_formats import SelectFormats c = Counter() db = self.gui.library_view.model().db @@ -125,7 +125,7 @@ class DeleteAction(InterfaceAction): if fmts_: for x in frozenset([x.lower() for x in fmts_.split(',')]): c[x] += 1 - d = SelectFormats(c, msg, parent=self.gui) + d = SelectFormats(c, msg, parent=self.gui, exclude=exclude) if d.exec_() != d.Accepted: return None return d.selected_formats @@ -162,7 +162,8 @@ class DeleteAction(InterfaceAction): return fmts = self._get_selected_formats( '

'+_('Choose formats not to be deleted.

Note that ' - 'this will never remove all formats from a book.'), ids) + 'this will never remove all formats from a book.'), ids, + exclude=True) if fmts is None: return for id in ids: diff --git a/src/calibre/gui2/dialogs/select_formats.py b/src/calibre/gui2/dialogs/select_formats.py index 3bff955545..0d43864816 100644 --- a/src/calibre/gui2/dialogs/select_formats.py +++ b/src/calibre/gui2/dialogs/select_formats.py @@ -47,7 +47,7 @@ class Formats(QAbstractListModel): class SelectFormats(QDialog): - def __init__(self, fmt_count, msg, single=False, parent=None): + def __init__(self, fmt_count, msg, single=False, parent=None, exclude=False): QDialog.__init__(self, parent) self._l = QVBoxLayout(self) self.setLayout(self._l) @@ -57,6 +57,10 @@ class SelectFormats(QDialog): self._l.addWidget(self._m) self.formats = Formats(fmt_count) self.fview = QListView(self) + if exclude: + self.fview.setStyleSheet(''' + QListView { background-color: #FAE7B5} + ''') self._l.addWidget(self.fview) self.fview.setModel(self.formats) self.fview.setSelectionMode(self.fview.SingleSelection if single else