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 = field
|
||||||
name += ':'
|
name += ':'
|
||||||
disp = metadata['display']
|
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)
|
val = getattr(mi, field)
|
||||||
if val:
|
if val:
|
||||||
ctype = disp.get('interpret_as') or 'html'
|
ctype = disp.get('interpret_as') or 'html'
|
||||||
@ -155,7 +156,7 @@ def mi_to_html(
|
|||||||
'<td class="title">%s</td><td class="rating value" '
|
'<td class="title">%s</td><td class="rating value" '
|
||||||
'style=\'font-family:"%s"\'>%s</td>'%(
|
'style=\'font-family:"%s"\'>%s</td>'%(
|
||||||
name, rating_font, star_string)))
|
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)
|
val = getattr(mi, field)
|
||||||
if val:
|
if val:
|
||||||
val = force_unicode(val)
|
val = force_unicode(val)
|
||||||
|
@ -117,6 +117,7 @@ class CreateCustomColumn(QDialog):
|
|||||||
for t in self.column_types:
|
for t in self.column_types:
|
||||||
self.column_type_box.addItem(self.column_types[t]['text'])
|
self.column_type_box.addItem(self.column_types[t]['text'])
|
||||||
self.column_type_box.currentIndexChanged.connect(self.datatype_changed)
|
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:
|
if not self.editing_col:
|
||||||
self.datatype_changed()
|
self.datatype_changed()
|
||||||
@ -146,22 +147,31 @@ class CreateCustomColumn(QDialog):
|
|||||||
self.column_types))
|
self.column_types))
|
||||||
self.column_type_box.setCurrentIndex(column_numbers[ct])
|
self.column_type_box.setCurrentIndex(column_numbers[ct])
|
||||||
self.column_type_box.setEnabled(False)
|
self.column_type_box.setEnabled(False)
|
||||||
|
|
||||||
|
self.datatype_changed()
|
||||||
|
|
||||||
if ct == 'datetime':
|
if ct == 'datetime':
|
||||||
if c['display'].get('date_format', None):
|
if c['display'].get('date_format', None):
|
||||||
self.format_box.setText(c['display'].get('date_format', ''))
|
self.format_box.setText(c['display'].get('date_format', ''))
|
||||||
elif ct in ['composite', '*composite']:
|
elif ct in ['composite', '*composite']:
|
||||||
self.composite_box.setText(c['display'].get('composite_template', ''))
|
self.composite_box.setText(c['display'].get('composite_template', ''))
|
||||||
sb = c['display'].get('composite_sort', 'text')
|
if c['display'].get('composite_show_in_comments', ''):
|
||||||
vals = ['text', 'number', 'date', 'bool']
|
self.composite_in_comments_box.setChecked(True)
|
||||||
if sb in vals:
|
idx = max(0, self.composite_heading_position.findData(c['display'].get('heading_position', 'hide')))
|
||||||
sb = vals.index(sb)
|
self.composite_heading_position.setCurrentIndex(idx)
|
||||||
else:
|
else:
|
||||||
sb = 0
|
self.composite_in_comments_box.setChecked(False)
|
||||||
self.composite_sort_by.setCurrentIndex(sb)
|
sb = c['display'].get('composite_sort', 'text')
|
||||||
self.composite_make_category.setChecked(
|
vals = ['text', 'number', 'date', 'bool']
|
||||||
c['display'].get('make_category', False))
|
if sb in vals:
|
||||||
self.composite_contains_html.setChecked(
|
sb = vals.index(sb)
|
||||||
c['display'].get('contains_html', False))
|
else:
|
||||||
|
sb = 0
|
||||||
|
self.composite_sort_by.setCurrentIndex(sb)
|
||||||
|
self.composite_make_category.setChecked(
|
||||||
|
c['display'].get('make_category', False))
|
||||||
|
self.composite_contains_html.setChecked(
|
||||||
|
c['display'].get('contains_html', False))
|
||||||
elif ct == 'enumeration':
|
elif ct == 'enumeration':
|
||||||
self.enum_box.setText(','.join(c['display'].get('enum_values', [])))
|
self.enum_box.setText(','.join(c['display'].get('enum_values', [])))
|
||||||
self.enum_colors.setText(','.join(c['display'].get('enum_colors', [])))
|
self.enum_colors.setText(','.join(c['display'].get('enum_colors', [])))
|
||||||
@ -202,7 +212,6 @@ class CreateCustomColumn(QDialog):
|
|||||||
elif ct not in ('composite', '*composite'):
|
elif ct not in ('composite', '*composite'):
|
||||||
self.default_value.setText(dv)
|
self.default_value.setText(dv)
|
||||||
|
|
||||||
self.datatype_changed()
|
|
||||||
if ct in ['text', 'composite', 'enumeration']:
|
if ct in ['text', 'composite', 'enumeration']:
|
||||||
self.use_decorations.setChecked(c['display'].get('use_decorations', False))
|
self.use_decorations.setChecked(c['display'].get('use_decorations', False))
|
||||||
elif ct == '*text':
|
elif ct == '*text':
|
||||||
@ -445,6 +454,24 @@ class CreateCustomColumn(QDialog):
|
|||||||
':select(beam)}">Beam book</a></pre> '
|
':select(beam)}">Beam book</a></pre> '
|
||||||
'will generate a link to the book on the Beam e-books site.') + '</p>')
|
'will generate a link to the book on the Beam e-books site.') + '</p>')
|
||||||
l.addWidget(cch)
|
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)
|
add_row(None, l)
|
||||||
|
|
||||||
# Default value
|
# Default value
|
||||||
@ -463,6 +490,24 @@ class CreateCustomColumn(QDialog):
|
|||||||
if clicked:
|
if clicked:
|
||||||
self.bool_button_group.setFocusProxy(button)
|
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):
|
def datatype_changed(self, *args):
|
||||||
try:
|
try:
|
||||||
col_type = self.column_types[self.column_type_box.currentIndex()]['datatype']
|
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>'
|
'after the decimal point and thousands separated by commas.') + '</p>'
|
||||||
)
|
)
|
||||||
self.format_label.setText(l), self.format_default_label.setText(dl)
|
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',
|
for x in ('box', 'default_label', 'label', 'sort_by', 'sort_by_label',
|
||||||
'make_category', 'contains_html'):
|
'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'):
|
for x in ('box', 'default_label', 'colors', 'colors_label'):
|
||||||
getattr(self, 'enum_'+x).setVisible(col_type == 'enumeration')
|
getattr(self, 'enum_'+x).setVisible(col_type == 'enumeration')
|
||||||
for x in ('value_label', 'value'):
|
for x in ('value_label', 'value'):
|
||||||
@ -609,12 +658,21 @@ class CreateCustomColumn(QDialog):
|
|||||||
if not str(self.composite_box.text()).strip():
|
if not str(self.composite_box.text()).strip():
|
||||||
return self.simple_error('', _('You must enter a template for '
|
return self.simple_error('', _('You must enter a template for '
|
||||||
'composite columns'))
|
'composite columns'))
|
||||||
display_dict = {'composite_template':str(self.composite_box.text()).strip(),
|
if self.composite_in_comments_box.isChecked():
|
||||||
'composite_sort': ['text', 'number', 'date', 'bool']
|
display_dict = {'composite_template':str(self.composite_box.text()).strip(),
|
||||||
[self.composite_sort_by.currentIndex()],
|
'composite_show_in_comments': self.composite_in_comments_box.isChecked(),
|
||||||
'make_category': self.composite_make_category.isChecked(),
|
'heading_position': self.composite_heading_position.currentData(),
|
||||||
'contains_html': self.composite_contains_html.isChecked(),
|
'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':
|
elif col_type == 'enumeration':
|
||||||
if not str(self.enum_box.text()).strip():
|
if not str(self.enum_box.text()).strip():
|
||||||
return self.simple_error('', _('You must enter at least one '
|
return self.simple_error('', _('You must enter at least one '
|
||||||
|
Loading…
x
Reference in New Issue
Block a user