mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'master' of https://github.com/cbhaley/calibre
Fixes #2009304 [[Enhancement Request] Display Calculated Text Column like Comments in Book Details](https://bugs.launchpad.net/calibre/+bug/2009304)
This commit is contained in:
commit
355cc1b24c
@ -127,7 +127,8 @@ def mi_to_html(
|
||||
name = field
|
||||
name += ':'
|
||||
disp = metadata['display']
|
||||
if metadata['datatype'] == 'comments' or field == 'comments':
|
||||
if (metadata['datatype'] == 'comments' or field == 'comments'
|
||||
or disp.get('composite_show_in_comments', '')):
|
||||
val = getattr(mi, field)
|
||||
if val:
|
||||
ctype = disp.get('interpret_as') or 'html'
|
||||
@ -155,7 +156,7 @@ def mi_to_html(
|
||||
'<td class="title">%s</td><td class="rating value" '
|
||||
'style=\'font-family:"%s"\'>%s</td>'%(
|
||||
name, rating_font, star_string)))
|
||||
elif metadata['datatype'] == 'composite':
|
||||
elif metadata['datatype'] == 'composite' and not disp.get('composite_show_in_comments', ''):
|
||||
val = getattr(mi, field)
|
||||
if val:
|
||||
val = force_unicode(val)
|
||||
|
@ -117,6 +117,7 @@ class CreateCustomColumn(QDialog):
|
||||
for t in self.column_types:
|
||||
self.column_type_box.addItem(self.column_types[t]['text'])
|
||||
self.column_type_box.currentIndexChanged.connect(self.datatype_changed)
|
||||
self.composite_in_comments_box.stateChanged.connect(self.composite_show_in_comments_clicked)
|
||||
|
||||
if not self.editing_col:
|
||||
self.datatype_changed()
|
||||
@ -146,11 +147,20 @@ class CreateCustomColumn(QDialog):
|
||||
self.column_types))
|
||||
self.column_type_box.setCurrentIndex(column_numbers[ct])
|
||||
self.column_type_box.setEnabled(False)
|
||||
|
||||
self.datatype_changed()
|
||||
|
||||
if ct == 'datetime':
|
||||
if c['display'].get('date_format', None):
|
||||
self.format_box.setText(c['display'].get('date_format', ''))
|
||||
elif ct in ['composite', '*composite']:
|
||||
self.composite_box.setText(c['display'].get('composite_template', ''))
|
||||
if c['display'].get('composite_show_in_comments', ''):
|
||||
self.composite_in_comments_box.setChecked(True)
|
||||
idx = max(0, self.composite_heading_position.findData(c['display'].get('heading_position', 'hide')))
|
||||
self.composite_heading_position.setCurrentIndex(idx)
|
||||
else:
|
||||
self.composite_in_comments_box.setChecked(False)
|
||||
sb = c['display'].get('composite_sort', 'text')
|
||||
vals = ['text', 'number', 'date', 'bool']
|
||||
if sb in vals:
|
||||
@ -202,7 +212,6 @@ class CreateCustomColumn(QDialog):
|
||||
elif ct not in ('composite', '*composite'):
|
||||
self.default_value.setText(dv)
|
||||
|
||||
self.datatype_changed()
|
||||
if ct in ['text', 'composite', 'enumeration']:
|
||||
self.use_decorations.setChecked(c['display'].get('use_decorations', False))
|
||||
elif ct == '*text':
|
||||
@ -445,6 +454,24 @@ class CreateCustomColumn(QDialog):
|
||||
':select(beam)}">Beam book</a></pre> '
|
||||
'will generate a link to the book on the Beam e-books site.') + '</p>')
|
||||
l.addWidget(cch)
|
||||
l.addStretch()
|
||||
add_row(None, l)
|
||||
l = QHBoxLayout()
|
||||
self.composite_in_comments_box = cmc = QCheckBox(_("Show with comments in book details"))
|
||||
cmc.setToolTip('Tooltip')
|
||||
l.addWidget(cmc)
|
||||
self.composite_heading_position = chp = QComboBox(self)
|
||||
for k, text in (
|
||||
('hide', _('No heading')),
|
||||
('above', _('Show heading above the text')),
|
||||
('side', _('Show heading to the side of the text'))
|
||||
):
|
||||
chp.addItem(text, k)
|
||||
chp.setToolTip(_('Choose whether or not the column heading is shown in the Book\n'
|
||||
'details panel and, if shown, where'))
|
||||
self.composite_heading_position_label = la = QLabel(_('Column heading:'))
|
||||
l.addWidget(la), l.addWidget(chp)
|
||||
l.addStretch()
|
||||
add_row(None, l)
|
||||
|
||||
# Default value
|
||||
@ -463,6 +490,24 @@ class CreateCustomColumn(QDialog):
|
||||
if clicked:
|
||||
self.bool_button_group.setFocusProxy(button)
|
||||
|
||||
def composite_show_in_comments_clicked(self, state):
|
||||
if state == 2: # Qt.CheckState.Checked but passed as an int
|
||||
self.composite_sort_by.setEnabled(False)
|
||||
self.composite_sort_by_label.setEnabled(False)
|
||||
self.composite_make_category.setEnabled(False)
|
||||
self.composite_contains_html.setEnabled(False)
|
||||
self.composite_heading_position.setEnabled(True)
|
||||
self.composite_heading_position_label.setEnabled(True)
|
||||
self.composite_heading_position.setCurrentIndex(0)
|
||||
else:
|
||||
self.composite_sort_by.setEnabled(True)
|
||||
self.composite_sort_by_label.setEnabled(True)
|
||||
self.composite_make_category.setEnabled(True)
|
||||
self.composite_contains_html.setEnabled(True)
|
||||
self.composite_heading_position.setEnabled(False)
|
||||
self.composite_heading_position_label.setEnabled(False)
|
||||
self.composite_heading_position.setCurrentIndex(0)
|
||||
|
||||
def datatype_changed(self, *args):
|
||||
try:
|
||||
col_type = self.column_types[self.column_type_box.currentIndex()]['datatype']
|
||||
@ -522,9 +567,13 @@ class CreateCustomColumn(QDialog):
|
||||
'after the decimal point and thousands separated by commas.') + '</p>'
|
||||
)
|
||||
self.format_label.setText(l), self.format_default_label.setText(dl)
|
||||
for x in ('in_comments_box', 'heading_position', 'heading_position_label'):
|
||||
getattr(self, 'composite_'+x).setVisible(col_type == 'composite')
|
||||
for x in ('box', 'default_label', 'label', 'sort_by', 'sort_by_label',
|
||||
'make_category', 'contains_html'):
|
||||
getattr(self, 'composite_'+x).setVisible(col_type in ['composite', '*composite'])
|
||||
getattr(self, 'composite_'+x).setVisible(col_type in ('composite', '*composite'))
|
||||
self.composite_heading_position.setEnabled(False)
|
||||
|
||||
for x in ('box', 'default_label', 'colors', 'colors_label'):
|
||||
getattr(self, 'enum_'+x).setVisible(col_type == 'enumeration')
|
||||
for x in ('value_label', 'value'):
|
||||
@ -609,12 +658,21 @@ class CreateCustomColumn(QDialog):
|
||||
if not str(self.composite_box.text()).strip():
|
||||
return self.simple_error('', _('You must enter a template for '
|
||||
'composite columns'))
|
||||
if self.composite_in_comments_box.isChecked():
|
||||
display_dict = {'composite_template':str(self.composite_box.text()).strip(),
|
||||
'composite_show_in_comments': self.composite_in_comments_box.isChecked(),
|
||||
'heading_position': self.composite_heading_position.currentData(),
|
||||
'composite_show_in_comments': True,
|
||||
}
|
||||
else:
|
||||
display_dict = {'composite_template':str(self.composite_box.text()).strip(),
|
||||
'composite_sort': ['text', 'number', 'date', 'bool']
|
||||
[self.composite_sort_by.currentIndex()],
|
||||
'make_category': self.composite_make_category.isChecked(),
|
||||
'contains_html': self.composite_contains_html.isChecked(),
|
||||
'composite_show_in_comments': False,
|
||||
}
|
||||
|
||||
elif col_type == 'enumeration':
|
||||
if not str(self.enum_box.text()).strip():
|
||||
return self.simple_error('', _('You must enter at least one '
|
||||
|
Loading…
x
Reference in New Issue
Block a user