mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Cover browser: Allow customizing the text that appears under the covers with a template in Preferences->Look & Feel->Cover browser
This commit is contained in:
parent
ba8c06fedf
commit
4a3a104c4c
@ -442,6 +442,7 @@ class DB(object):
|
|||||||
defs['virt_libs_hidden'] = defs['virt_libs_order'] = ()
|
defs['virt_libs_hidden'] = defs['virt_libs_order'] = ()
|
||||||
defs['update_all_last_mod_dates_on_start'] = False
|
defs['update_all_last_mod_dates_on_start'] = False
|
||||||
defs['field_under_covers_in_grid'] = 'title'
|
defs['field_under_covers_in_grid'] = 'title'
|
||||||
|
defs['cover_browser_title_template'] = '{title}'
|
||||||
|
|
||||||
# Migrate the bool tristate tweak
|
# Migrate the bool tristate tweak
|
||||||
defs['bools_are_tristate'] = \
|
defs['bools_are_tristate'] = \
|
||||||
|
@ -84,18 +84,41 @@ if pictureflow is not None:
|
|||||||
self.is_cover_browser_visible = is_cover_browser_visible
|
self.is_cover_browser_visible = is_cover_browser_visible
|
||||||
self.model.modelReset.connect(self.reset, type=Qt.QueuedConnection)
|
self.model.modelReset.connect(self.reset, type=Qt.QueuedConnection)
|
||||||
self.ignore_image_requests = True
|
self.ignore_image_requests = True
|
||||||
|
self.template_inited = False
|
||||||
|
|
||||||
|
def init_template(self, db):
|
||||||
|
self.template_cache = {}
|
||||||
|
self.template_error_reported = False
|
||||||
|
self.template = db.pref('cover_browser_title_template', '{title}')
|
||||||
|
self.template_is_title = self.template == '{title}'
|
||||||
|
|
||||||
def count(self):
|
def count(self):
|
||||||
return self.model.count()
|
return self.model.count()
|
||||||
|
|
||||||
def caption(self, index):
|
def caption(self, index):
|
||||||
|
if self.ignore_image_requests:
|
||||||
|
return ''
|
||||||
|
ans = ''
|
||||||
try:
|
try:
|
||||||
ans = self.model.title(index)
|
db = self.model.db.new_api
|
||||||
if not ans:
|
if not self.template_inited:
|
||||||
ans = ''
|
self.init_template(db)
|
||||||
ans = ans.replace('&', '&&')
|
if self.template_is_title:
|
||||||
except:
|
ans = self.model.title(index)
|
||||||
ans = ''
|
else:
|
||||||
|
book_id = self.model.id(index)
|
||||||
|
mi = db.get_proxy_metadata(book_id)
|
||||||
|
try:
|
||||||
|
ans = mi.formatter.safe_format(self.template, mi, _('TEMPLATE ERROR'), mi, template_cache=self.template_cache)
|
||||||
|
except Exception:
|
||||||
|
if not self.template_error_reported:
|
||||||
|
self.template_error_reported = True
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
ans = ''
|
||||||
|
ans = (ans or '').replace('&', '&&')
|
||||||
|
except Exception:
|
||||||
|
return ''
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def subtitle(self, index):
|
def subtitle(self, index):
|
||||||
|
@ -16,6 +16,7 @@ from PyQt5.Qt import (
|
|||||||
QWidget, QSizePolicy, QBrush, QPixmap, QSize, QPushButton, QVBoxLayout)
|
QWidget, QSizePolicy, QBrush, QPixmap, QSize, QPushButton, QVBoxLayout)
|
||||||
|
|
||||||
from calibre import human_readable
|
from calibre import human_readable
|
||||||
|
from calibre.gui2.dialogs.template_dialog import TemplateDialog
|
||||||
from calibre.gui2.preferences import ConfigWidgetBase, test_widget, CommaSeparatedList
|
from calibre.gui2.preferences import ConfigWidgetBase, test_widget, CommaSeparatedList
|
||||||
from calibre.gui2.preferences.look_feel_ui import Ui_Form
|
from calibre.gui2.preferences.look_feel_ui import Ui_Form
|
||||||
from calibre.gui2 import config, gprefs, qt_app, open_local_file, question_dialog
|
from calibre.gui2 import config, gprefs, qt_app, open_local_file, question_dialog
|
||||||
@ -170,10 +171,12 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
r('cover_flow_queue_length', config, restart_required=True)
|
r('cover_flow_queue_length', config, restart_required=True)
|
||||||
r('cover_browser_reflections', gprefs)
|
r('cover_browser_reflections', gprefs)
|
||||||
r('show_rating_in_cover_browser', gprefs)
|
r('show_rating_in_cover_browser', gprefs)
|
||||||
|
r('cover_browser_title_template', db.prefs)
|
||||||
r('emblem_size', gprefs)
|
r('emblem_size', gprefs)
|
||||||
r('emblem_position', gprefs, choices=[
|
r('emblem_position', gprefs, choices=[
|
||||||
(_('Left'), 'left'), (_('Top'), 'top'), (_('Right'), 'right'), (_('Bottom'), 'bottom')])
|
(_('Left'), 'left'), (_('Top'), 'top'), (_('Right'), 'right'), (_('Bottom'), 'bottom')])
|
||||||
r('book_list_extra_row_spacing', gprefs)
|
r('book_list_extra_row_spacing', gprefs)
|
||||||
|
self.cover_browser_title_template_button.clicked.connect(self.edit_cb_title_template)
|
||||||
|
|
||||||
def get_esc_lang(l):
|
def get_esc_lang(l):
|
||||||
if l == 'en':
|
if l == 'en':
|
||||||
@ -335,6 +338,12 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
self.opt_cover_grid_width.setValue(0)
|
self.opt_cover_grid_width.setValue(0)
|
||||||
self.opt_cover_grid_height.setValue(0)
|
self.opt_cover_grid_height.setValue(0)
|
||||||
|
|
||||||
|
def edit_cb_title_template(self):
|
||||||
|
t = TemplateDialog(self, self.opt_cover_browser_title_template.text(), fm=self.gui.current_db.field_metadata)
|
||||||
|
t.setWindowTitle(_('Edit template for caption'))
|
||||||
|
if t.exec_():
|
||||||
|
self.opt_cover_browser_title_template.setText(t.rule[1])
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
ConfigWidgetBase.initialize(self)
|
ConfigWidgetBase.initialize(self)
|
||||||
font = gprefs['font']
|
font = gprefs['font']
|
||||||
@ -501,6 +510,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
gui.library_view.refresh_book_details()
|
gui.library_view.refresh_book_details()
|
||||||
gui.cover_flow.setShowReflections(gprefs['cover_browser_reflections'])
|
gui.cover_flow.setShowReflections(gprefs['cover_browser_reflections'])
|
||||||
gui.cover_flow.setPreserveAspectRatio(gprefs['cb_preserve_aspect_ratio'])
|
gui.cover_flow.setPreserveAspectRatio(gprefs['cb_preserve_aspect_ratio'])
|
||||||
|
gui.cover_flow.template_inited = False
|
||||||
gui.library_view.refresh_row_sizing()
|
gui.library_view.refresh_row_sizing()
|
||||||
gui.grid_view.refresh_settings()
|
gui.grid_view.refresh_settings()
|
||||||
|
|
||||||
|
@ -940,10 +940,10 @@ if you never want subcategories</string>
|
|||||||
<string>Cover Browser</string>
|
<string>Cover Browser</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QGridLayout" name="gridLayout_11">
|
<layout class="QGridLayout" name="gridLayout_11">
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="5" column="1">
|
||||||
<widget class="QCheckBox" name="opt_separate_cover_flow">
|
<widget class="QLineEdit" name="opt_cover_browser_title_template">
|
||||||
<property name="text">
|
<property name="toolTip">
|
||||||
<string>Show cover &browser in a separate window (needs restart)</string>
|
<string>The template used to generate the text below the covers. Uses the same syntax as save templates. Defaults to just the book title.</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -957,7 +957,7 @@ if you never want subcategories</string>
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="0" colspan="2">
|
<item row="8" column="0" colspan="2">
|
||||||
<spacer name="verticalSpacer_4">
|
<spacer name="verticalSpacer_4">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@ -970,37 +970,48 @@ if you never want subcategories</string>
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="4" column="0">
|
||||||
|
<widget class="QCheckBox" name="opt_show_rating_in_cover_browser">
|
||||||
|
<property name="text">
|
||||||
|
<string>Show book &rating in cover browser</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="0">
|
||||||
|
<widget class="QLabel" name="label_23">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Template for caption:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>opt_cover_browser_title_template</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="2">
|
||||||
|
<widget class="QPushButton" name="cover_browser_title_template_button">
|
||||||
|
<property name="text">
|
||||||
|
<string>Template editor</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1" colspan="2">
|
||||||
<widget class="QSpinBox" name="opt_cover_flow_queue_length"/>
|
<widget class="QSpinBox" name="opt_cover_flow_queue_length"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="0" colspan="2">
|
<item row="6" column="0" colspan="3">
|
||||||
<widget class="QCheckBox" name="opt_cb_fullscreen">
|
<widget class="QCheckBox" name="opt_cb_fullscreen">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>When showing cover browser in separate window, show it &fullscreen</string>
|
<string>When showing cover browser in separate window, show it &fullscreen</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="0" colspan="2">
|
<item row="0" column="0" colspan="3">
|
||||||
<widget class="QLabel" name="fs_help_msg">
|
<widget class="QCheckBox" name="opt_separate_cover_flow">
|
||||||
<property name="styleSheet">
|
|
||||||
<string notr="true">margin-left: 1.5em</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>You can press the %s keys to toggle full screen mode.</string>
|
<string>Show cover &browser in a separate window (needs restart)</string>
|
||||||
</property>
|
|
||||||
<property name="wordWrap">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="3" column="0" colspan="3">
|
||||||
<widget class="QCheckBox" name="opt_cover_browser_reflections">
|
|
||||||
<property name="text">
|
|
||||||
<string>Show &reflections in the cover browser</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="0" colspan="2">
|
|
||||||
<widget class="QCheckBox" name="opt_cb_preserve_aspect_ratio">
|
<widget class="QCheckBox" name="opt_cb_preserve_aspect_ratio">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Show covers in their original aspect ratio instead of resizing
|
<string>Show covers in their original aspect ratio instead of resizing
|
||||||
@ -1011,10 +1022,23 @@ them to all have the same width and height</string>
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="0">
|
<item row="2" column="0" colspan="3">
|
||||||
<widget class="QCheckBox" name="opt_show_rating_in_cover_browser">
|
<widget class="QCheckBox" name="opt_cover_browser_reflections">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Show book &rating in cover browser</string>
|
<string>Show &reflections in the cover browser</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="7" column="0" colspan="3">
|
||||||
|
<widget class="QLabel" name="fs_help_msg">
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">margin-left: 1.5em</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>You can press the %s keys to toggle full screen mode.</string>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user