mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Enhancement #1977681: additional display options for custom yes/no column
This commit is contained in:
parent
f192171922
commit
f500c9a45b
@ -827,11 +827,15 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
return None
|
return None
|
||||||
return by if val else bn
|
return by if val else bn
|
||||||
else:
|
else:
|
||||||
|
if m['display'].get('bools_show_icons', True):
|
||||||
def func(idx):
|
def func(idx):
|
||||||
val = force_to_bool(fffunc(field_obj, idfunc(idx)))
|
val = force_to_bool(fffunc(field_obj, idfunc(idx)))
|
||||||
if val is None:
|
if val is None:
|
||||||
return None if bt else bn
|
return None if bt else bn
|
||||||
return by if val else bn
|
return by if val else bn
|
||||||
|
else:
|
||||||
|
def func(idx):
|
||||||
|
return None
|
||||||
elif field == 'size':
|
elif field == 'size':
|
||||||
sz_mult = 1/(1024**2)
|
sz_mult = 1/(1024**2)
|
||||||
|
|
||||||
@ -910,6 +914,14 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
except (TypeError, ValueError, AttributeError, IndexError, KeyError):
|
except (TypeError, ValueError, AttributeError, IndexError, KeyError):
|
||||||
pass
|
pass
|
||||||
return (val)
|
return (val)
|
||||||
|
elif dt == 'bool':
|
||||||
|
if m['display'].get('bools_show_text', False):
|
||||||
|
def func(idx):
|
||||||
|
v = fffunc(field_obj, idfunc(idx))
|
||||||
|
return (None if v is None else (_('Yes') if v else _('No')))
|
||||||
|
else:
|
||||||
|
def func(idx):
|
||||||
|
return(None)
|
||||||
else:
|
else:
|
||||||
def func(idx):
|
def func(idx):
|
||||||
return None
|
return None
|
||||||
|
@ -451,7 +451,9 @@ class BooksView(QTableView): # {{{
|
|||||||
ac.setCheckable(True)
|
ac.setCheckable(True)
|
||||||
ac.setChecked(True)
|
ac.setChecked(True)
|
||||||
if col not in ('ondevice', 'inlibrary') and \
|
if col not in ('ondevice', 'inlibrary') and \
|
||||||
(not self.model().is_custom_column(col) or self.model().custom_columns[col]['datatype'] not in ('bool',)):
|
(not self.model().is_custom_column(col) or
|
||||||
|
(self._model.custom_columns[col]['datatype'] != 'bool' or
|
||||||
|
self._model.custom_columns[col]['display'].get('bools_show_text', False))):
|
||||||
m = ans.addMenu(_('Change text alignment for %s') % name)
|
m = ans.addMenu(_('Change text alignment for %s') % name)
|
||||||
m.setIcon(QIcon.ic('format-justify-center.png'))
|
m.setIcon(QIcon.ic('format-justify-center.png'))
|
||||||
al = self._model.alignment_map.get(col, 'left')
|
al = self._model.alignment_map.get(col, 'left')
|
||||||
|
@ -13,7 +13,7 @@ from functools import partial
|
|||||||
from qt.core import (
|
from qt.core import (
|
||||||
QDialog, Qt, QColor, QIcon, QVBoxLayout, QLabel, QGridLayout,
|
QDialog, Qt, QColor, QIcon, QVBoxLayout, QLabel, QGridLayout,
|
||||||
QDialogButtonBox, QWidget, QLineEdit, QHBoxLayout, QComboBox,
|
QDialogButtonBox, QWidget, QLineEdit, QHBoxLayout, QComboBox,
|
||||||
QCheckBox, QSpinBox
|
QCheckBox, QSpinBox, QRadioButton, QGroupBox
|
||||||
)
|
)
|
||||||
|
|
||||||
from calibre.gui2 import error_dialog
|
from calibre.gui2 import error_dialog
|
||||||
@ -173,6 +173,15 @@ class CreateCustomColumn(QDialog):
|
|||||||
self.comments_type.setCurrentIndex(idx)
|
self.comments_type.setCurrentIndex(idx)
|
||||||
elif ct == 'rating':
|
elif ct == 'rating':
|
||||||
self.allow_half_stars.setChecked(bool(c['display'].get('allow_half_stars', False)))
|
self.allow_half_stars.setChecked(bool(c['display'].get('allow_half_stars', False)))
|
||||||
|
elif ct == 'bool':
|
||||||
|
icon = bool(c['display'].get('bools_show_icons', True))
|
||||||
|
txt = bool(c['display'].get('bools_show_text', False))
|
||||||
|
if icon and txt:
|
||||||
|
self.bool_show_both_button.setChecked(True)
|
||||||
|
elif icon:
|
||||||
|
self.bool_show_icon_button.setChecked(True)
|
||||||
|
else:
|
||||||
|
self.bool_show_text_button.setChecked(True)
|
||||||
|
|
||||||
# Default values
|
# Default values
|
||||||
dv = c['display'].get('default_value', None)
|
dv = c['display'].get('default_value', None)
|
||||||
@ -315,6 +324,24 @@ class CreateCustomColumn(QDialog):
|
|||||||
d.setToolTip(_("Optional text describing what this column is for"))
|
d.setToolTip(_("Optional text describing what this column is for"))
|
||||||
add_row(_("D&escription:"), d)
|
add_row(_("D&escription:"), d)
|
||||||
|
|
||||||
|
# bool formatting
|
||||||
|
h1 = QHBoxLayout()
|
||||||
|
self.bool_show_icon_button = QRadioButton('Icon')
|
||||||
|
h1.addWidget(self.bool_show_icon_button)
|
||||||
|
self.bool_show_text_button = QRadioButton('Text')
|
||||||
|
h1.addWidget(self.bool_show_text_button)
|
||||||
|
self.bool_show_both_button = QRadioButton('Both')
|
||||||
|
h1.addWidget(self.bool_show_both_button)
|
||||||
|
self.bool_button_group = QGroupBox()
|
||||||
|
self.bool_button_group.setLayout(h1)
|
||||||
|
h = QHBoxLayout()
|
||||||
|
h.addWidget(self.bool_button_group)
|
||||||
|
self.bool_button_group_label = la = QLabel(_('Choose whether an icon, text, or both is shown in the book list'))
|
||||||
|
la.setWordWrap(True)
|
||||||
|
h.addWidget(la)
|
||||||
|
h.setStretch(1, 10)
|
||||||
|
self.bool_show_label = add_row(_('Show:'), h)
|
||||||
|
|
||||||
# Date/number formatting
|
# Date/number formatting
|
||||||
h = QHBoxLayout()
|
h = QHBoxLayout()
|
||||||
self.format_box = fb = QLineEdit(self)
|
self.format_box = fb = QLineEdit(self)
|
||||||
@ -493,6 +520,7 @@ class CreateCustomColumn(QDialog):
|
|||||||
getattr(self, 'default_'+x).setVisible(col_type not in ['composite', '*composite'])
|
getattr(self, 'default_'+x).setVisible(col_type not in ['composite', '*composite'])
|
||||||
self.use_decorations.setVisible(col_type in ['text', 'composite', 'enumeration'])
|
self.use_decorations.setVisible(col_type in ['text', 'composite', 'enumeration'])
|
||||||
self.is_names.setVisible(col_type == '*text')
|
self.is_names.setVisible(col_type == '*text')
|
||||||
|
|
||||||
is_comments = col_type == 'comments'
|
is_comments = col_type == 'comments'
|
||||||
self.comments_heading_position.setVisible(is_comments)
|
self.comments_heading_position.setVisible(is_comments)
|
||||||
self.comments_heading_position_label.setVisible(is_comments)
|
self.comments_heading_position_label.setVisible(is_comments)
|
||||||
@ -500,6 +528,11 @@ class CreateCustomColumn(QDialog):
|
|||||||
self.comments_type_label.setVisible(is_comments)
|
self.comments_type_label.setVisible(is_comments)
|
||||||
self.allow_half_stars.setVisible(col_type == 'rating')
|
self.allow_half_stars.setVisible(col_type == 'rating')
|
||||||
|
|
||||||
|
is_bool = col_type == 'bool'
|
||||||
|
self.bool_button_group.setVisible(is_bool)
|
||||||
|
self.bool_button_group_label.setVisible(is_bool)
|
||||||
|
self.bool_show_label.setVisible(is_bool)
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
col = str(self.column_name_box.text()).strip()
|
col = str(self.column_name_box.text()).strip()
|
||||||
if not col:
|
if not col:
|
||||||
@ -645,6 +678,10 @@ class CreateCustomColumn(QDialog):
|
|||||||
return self.simple_error(_('Invalid default value'),
|
return self.simple_error(_('Invalid default value'),
|
||||||
_('The default value must be "Yes" or "No"'))
|
_('The default value must be "Yes" or "No"'))
|
||||||
display_dict['default_value'] = tv
|
display_dict['default_value'] = tv
|
||||||
|
show_icon = bool(self.bool_show_icon_button.isChecked()) or bool(self.bool_show_both_button.isChecked())
|
||||||
|
show_text = bool(self.bool_show_text_button.isChecked()) or bool(self.bool_show_both_button.isChecked())
|
||||||
|
display_dict['bools_show_text'] = show_text
|
||||||
|
display_dict['bools_show_icons'] = show_icon
|
||||||
|
|
||||||
if col_type in ['text', 'composite', 'enumeration'] and not is_multiple:
|
if col_type in ['text', 'composite', 'enumeration'] and not is_multiple:
|
||||||
display_dict['use_decorations'] = self.use_decorations.checkState() == Qt.CheckState.Checked
|
display_dict['use_decorations'] = self.use_decorations.checkState() == Qt.CheckState.Checked
|
||||||
|
Loading…
x
Reference in New Issue
Block a user