Preferences UI for configuring emblems to be displayed in the cover grid, next to covers

This commit is contained in:
Kovid Goyal 2014-07-29 14:30:32 +05:30
parent de26f1e9a3
commit ba07a4c5f9
4 changed files with 478 additions and 396 deletions

View File

@ -407,6 +407,7 @@ class DB(object):
defs['categories_using_hierarchy'] = []
defs['column_color_rules'] = []
defs['column_icon_rules'] = []
defs['cover_grid_icon_rules'] = []
defs['grouped_search_make_user_categories'] = []
defs['similar_authors_search_key'] = 'authors'
defs['similar_authors_match_kind'] = 'match_any'

View File

@ -278,24 +278,31 @@ class ConditionEditor(QWidget): # {{{
class RuleEditor(QDialog): # {{{
@property
def doing_multiple(self):
return hasattr(self, 'multiple_icon_cb') and self.multiple_icon_cb.isChecked()
def __init__(self, fm, pref_name, parent=None):
QDialog.__init__(self, parent)
self.fm = fm
if pref_name == 'column_color_rules':
self.rule_kind = 'color'
rule_text = _('coloring')
else:
rule_text = _('column coloring')
elif pref_name == 'column_icon_rules':
self.rule_kind = 'icon'
rule_text = _('icon')
rule_text = _('column icon')
elif pref_name == 'cover_grid_icon_rules':
self.rule_kind = 'emblem'
rule_text = _('cover grid emblem')
self.setWindowIcon(QIcon(I('format-fill-color.png')))
self.setWindowTitle(_('Create/edit a column {0} rule').format(rule_text))
self.setWindowTitle(_('Create/edit a {0} rule').format(rule_text))
self.l = l = QGridLayout(self)
self.setLayout(l)
self.l1 = l1 = QLabel(_('Create a column {0} rule by'
self.l1 = l1 = QLabel(_('Create a {0} rule by'
' filling in the boxes below'.format(rule_text)))
l.addWidget(l1, 0, 0, 1, 8)
@ -303,12 +310,12 @@ class RuleEditor(QDialog): # {{{
self.f1.setFrameShape(QFrame.HLine)
l.addWidget(self.f1, 1, 0, 1, 8)
self.l2 = l2 = QLabel(_('Set the'))
self.l2 = l2 = QLabel(_('Add the emblem:') if self.rule_kind == 'emblem' else _('Set the'))
l.addWidget(l2, 2, 0)
if self.rule_kind == 'color':
l.addWidget(QLabel(_('color')))
else:
elif self.rule_kind == 'icon':
self.kind_box = QComboBox(self)
for tt, t in icon_rule_kinds:
self.kind_box.addItem(tt, t)
@ -317,6 +324,8 @@ class RuleEditor(QDialog): # {{{
'If you choose composed icons and multiple rules match, then all the'
' matching icons will be combined, otherwise the icon from the'
' first rule to match will be used.')))
else:
pass
self.l3 = l3 = QLabel(_('of the column:'))
l.addWidget(l3, 2, 2)
@ -326,17 +335,12 @@ class RuleEditor(QDialog): # {{{
self.l4 = l4 = QLabel(_('to'))
l.addWidget(l4, 2, 4)
if self.rule_kind == 'emblem':
l3.setVisible(False), self.column_box.setVisible(False), l4.setVisible(False)
if self.rule_kind == 'color':
self.color_box = ColorButton(parent=self)
self.color_label = QLabel('Sample text Sample text')
self.color_label.setTextFormat(Qt.RichText)
l.addWidget(self.color_box, 2, 5)
l.addWidget(self.color_label, 2, 6)
l.addItem(QSpacerItem(10, 10, QSizePolicy.Expanding), 2, 7)
else:
def create_filename_box(folder='cc_icons'):
self.filename_box = QComboBox()
d = os.path.join(config_dir, 'cc_icons')
d = os.path.join(config_dir, folder)
self.icon_file_names = []
if os.path.exists(d):
for icon_file in os.listdir(d):
@ -346,6 +350,25 @@ class RuleEditor(QDialog): # {{{
self.icon_file_names.append(icon_file)
self.icon_file_names.sort(key=sort_key)
if self.rule_kind == 'color':
self.color_box = ColorButton(parent=self)
self.color_label = QLabel('Sample text Sample text')
self.color_label.setTextFormat(Qt.RichText)
l.addWidget(self.color_box, 2, 5)
l.addWidget(self.color_label, 2, 6)
l.addItem(QSpacerItem(10, 10, QSizePolicy.Expanding), 2, 7)
elif self.rule_kind == 'emblem':
create_filename_box()
self.update_filename_box()
self.filename_button = QPushButton(QIcon(I('document_open.png')),
_('&Add new image'))
l.addWidget(self.filename_box)
l.addWidget(self.filename_button, 2, 6)
l.addWidget(QLabel(_('(Images should be square-ish)')), 2, 7)
l.setColumnStretch(7, 10)
else:
create_filename_box()
vb = QVBoxLayout()
self.multiple_icon_cb = QCheckBox(_('Choose more than one icon'))
vb.addWidget(self.multiple_icon_cb)
@ -420,7 +443,7 @@ class RuleEditor(QDialog): # {{{
self.update_icon_filenames_in_box()
def update_filename_box(self):
doing_multiple = self.multiple_icon_cb.isChecked()
doing_multiple = self.doing_multiple
model = QStandardItemModel()
self.filename_box.setModel(model)
@ -477,7 +500,7 @@ class RuleEditor(QDialog): # {{{
except:
import traceback
traceback.print_exc()
if self.multiple_icon_cb.isChecked():
if self.doing_multiple:
if icon_name not in self.rule_icon_files:
self.rule_icon_files.append(icon_name)
self.update_icon_filenames_in_box()
@ -490,7 +513,7 @@ class RuleEditor(QDialog): # {{{
return
def get_filenames_from_box(self):
if self.multiple_icon_cb.isChecked():
if self.doing_multiple:
model = self.filename_box.model()
fnames = []
for i in range(1, model.rowCount()):
@ -504,7 +527,7 @@ class RuleEditor(QDialog): # {{{
def update_icon_filenames_in_box(self):
if self.rule_icon_files:
if not self.multiple_icon_cb.isChecked():
if not self.doing_multiple:
idx = self.filename_box.findText(self.rule_icon_files[0])
if idx >= 0:
self.filename_box.setCurrentIndex(idx)
@ -528,7 +551,8 @@ class RuleEditor(QDialog): # {{{
if rule.color:
self.color_box.color = rule.color
else:
for i,tup in enumerate(icon_rule_kinds):
if self.rule_kind == 'icon':
for i, tup in enumerate(icon_rule_kinds):
if kind == tup[1]:
self.kind_box.setCurrentIndex(i)
break
@ -602,7 +626,7 @@ class RuleEditor(QDialog): # {{{
kind = unicode(self.kind_box.itemData(
self.kind_box.currentIndex()).toString())
else:
kind = 'color'
kind = self.rule_kind
return kind, col, r
# }}}
@ -761,8 +785,8 @@ class RulesModel(QAbstractListModel): # {{{
continue
break
return (
_('<li>If the <b>%(col)s</b> column <b>%(action)s</b> value: <b>%(val)s</b>') %
dict(col=c, action=action_name, val=prepare_string_for_xml(v)))
_('<li>If the <b>%(col)s</b> column <b>%(action)s</b> value: <b>%(val)s</b>') % dict(
col=c, action=action_name, val=prepare_string_for_xml(v)))
# }}}
@ -824,20 +848,27 @@ class EditRules(QWidget): # {{{
self.fm = fm
self.mi = mi
if pref_name == 'column_color_rules':
self.l1.setText('<p>'+_(
text = _(
'You can control the color of columns in the'
' book list by creating "rules" that tell calibre'
' what color to use. Click the Add Rule button below'
' to get started.<p>You can <b>change an existing rule</b> by'
' double clicking it.'))
else:
self.l1.setText('<p>'+_(
' double clicking it.')
elif pref_name == 'column_icon_rules':
text = _(
'You can add icons to columns in the'
' book list by creating "rules" that tell calibre'
' what icon to use. Click the Add Rule button below'
' to get started.<p>You can <b>change an existing rule</b> by'
' double clicking it.'))
' double clicking it.')
elif pref_name == 'cover_grid_icon_rules':
text = _('You can add emblems (small icons) that are displayed on the side of covers'
' in the cover grid by creating "rules" that tell calibre'
' what image to use. Click the Add Rule button below'
' to get started.<p>You can <b>change an existing rule</b> by'
' double clicking it.')
# self.add_advanced_button.setVisible(False)
self.l1.setText('<p>'+ text)
def add_rule(self):
d = RuleEditor(self.model.fm, self.pref_name)

View File

@ -11,7 +11,7 @@ from functools import partial
from PyQt4.Qt import (
QApplication, QFont, QFontInfo, QFontDialog, QColorDialog, QPainter,
QAbstractListModel, Qt, QIcon, QKeySequence, QColor, pyqtSignal,
QWidget, QSizePolicy, QBrush, QPixmap, QSize, QPushButton)
QWidget, QSizePolicy, QBrush, QPixmap, QSize, QPushButton, QVBoxLayout)
from calibre import human_readable
from calibre.gui2.preferences import ConfigWidgetBase, test_widget, CommaSeparatedList
@ -240,6 +240,11 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.tabWidget.addTab(self.icon_rules,
QIcon(I('icon_choose.png')), _('Column icons'))
self.grid_rules = EditRules(self.emblems_tab)
self.grid_rules.changed.connect(self.changed_signal)
self.emblems_tab.setLayout(QVBoxLayout())
self.emblems_tab.layout().addWidget(self.grid_rules)
self.tabWidget.setCurrentIndex(0)
keys = [QKeySequence('F11', QKeySequence.PortableText), QKeySequence(
'Ctrl+Shift+F', QKeySequence.PortableText)]
@ -320,6 +325,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
mi=None
self.edit_rules.initialize(db.field_metadata, db.prefs, mi, 'column_color_rules')
self.icon_rules.initialize(db.field_metadata, db.prefs, mi, 'column_icon_rules')
self.grid_rules.initialize(db.field_metadata, db.prefs, mi, 'cover_grid_icon_rules')
self.set_cg_color(gprefs['cover_grid_color'])
self.set_cg_texture(gprefs['cover_grid_texture'])
self.update_aspect_ratio()
@ -365,6 +371,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.display_model.restore_defaults()
self.edit_rules.clear()
self.icon_rules.clear()
self.grid_rules.clear()
self.changed_signal.emit()
self.set_cg_color(gprefs.defaults['cover_grid_color'])
self.set_cg_texture(gprefs.defaults['cover_grid_texture'])
@ -453,6 +460,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.display_model.commit()
self.edit_rules.commit(self.gui.current_db.prefs)
self.icon_rules.commit(self.gui.current_db.prefs)
self.grid_rules.commit(self.gui.current_db.prefs)
gprefs['cover_grid_color'] = tuple(self.cg_bg_widget.bcol.getRgb())[:3]
gprefs['cover_grid_texture'] = self.cg_bg_widget.btex
return rr

View File

@ -232,6 +232,19 @@
<string>Cover Grid</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget_2">
<property name="tabPosition">
<enum>QTabWidget::West</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab_5">
<attribute name="title">
<string>Main</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label_19">
<property name="text">
@ -480,49 +493,37 @@ A value of zero means calculate automatically.</string>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>170</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="emblems_tab">
<attribute name="title">
<string>Emblems</string>
</attribute>
</widget>
<widget class="QWidget" name="tab_6">
<attribute name="title">
<string>Performance</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Caching of covers for improved performance</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="5">
<widget class="QLabel" name="label_13">
<property name="text">
<string>There are two kinds of caches that calibre uses to improve performance when rendering covers in the grid view. A disk cache that is kept on your hard disk and stores the cover thumbnails and an in memory cache used to ensure flicker free rendering of covers. For best results, keep the memory cache small and the disk cache large, unless you have a lot of extra RAM in your computer and dont mind it being used by the memory cache.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_15">
<property name="text">
<string>Number of covers to cache in &amp;memory (keep this small):</string>
</property>
<property name="buddy">
<cstring>opt_cover_grid_cache_size</cstring>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="opt_cover_grid_cache_size">
<property name="toolTip">
<string>The maximum number of covers to keep in memory. Increasing this will make rendering faster, at the cost of more memory usage.</string>
</property>
<property name="maximum">
<number>50000</number>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="label_18">
<property name="text">
<string>Maximum amount of disk space to use for caching thumbnails: </string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="opt_cover_grid_disk_cache_size">
<property name="specialValueText">
@ -539,33 +540,6 @@ A value of zero means calculate automatically.</string>
</property>
</widget>
</item>
<item row="2" column="3" colspan="2">
<widget class="QLabel" name="cover_grid_current_disk_cache">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="cover_grid_empty_cache">
<property name="text">
<string>Empty disk cache</string>
</property>
</widget>
</item>
<item row="3" column="2" colspan="3">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>310</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="cover_grid_open_cache">
<property name="text">
@ -586,11 +560,72 @@ A value of zero means calculate automatically.</string>
</property>
</spacer>
</item>
</layout>
<item row="0" column="0" colspan="5">
<widget class="QLabel" name="label_13">
<property name="text">
<string>There are two kinds of caches that calibre uses to improve performance when rendering covers in the grid view. A disk cache that is kept on your hard disk and stores the cover thumbnails and an in memory cache used to ensure flicker free rendering of covers. For best results, keep the memory cache small and the disk cache large, unless you have a lot of extra RAM in your computer and dont mind it being used by the memory cache.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<item row="2" column="3" colspan="2">
<widget class="QLabel" name="cover_grid_current_disk_cache">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="2" colspan="3">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>310</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_15">
<property name="text">
<string>Number of covers to cache in &amp;memory (keep this small):</string>
</property>
<property name="buddy">
<cstring>opt_cover_grid_cache_size</cstring>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="label_18">
<property name="text">
<string>Maximum amount of disk space to use for caching thumbnails: </string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="cover_grid_empty_cache">
<property name="text">
<string>Empty disk cache</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="opt_cover_grid_cache_size">
<property name="toolTip">
<string>The maximum number of covers to keep in memory. Increasing this will make rendering faster, at the cost of more memory usage.</string>
</property>
<property name="maximum">
<number>50000</number>
</property>
</widget>
</item>
<item row="4" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
@ -604,6 +639,13 @@ A value of zero means calculate automatically.</string>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_4">
<attribute name="icon">
<iconset resource="../../../../resources/images.qrc">