diff --git a/src/calibre/gui2/custom_column_widgets.py b/src/calibre/gui2/custom_column_widgets.py index bc55707ac5..10a2bd82ab 100644 --- a/src/calibre/gui2/custom_column_widgets.py +++ b/src/calibre/gui2/custom_column_widgets.py @@ -286,7 +286,7 @@ class Float(Int): self.widgets = [QLabel(label_string(self.col_metadata['name']), parent)] self.finish_ui_setup(parent, ClearingDoubleSpinBox) self.editor.setRange(-1000000., float(100000000)) - self.editor.setDecimals(2) + self.editor.setDecimals(self.col_metadata['display'].get('decimals', 2)) class Rating(Base): @@ -1098,7 +1098,7 @@ class BulkFloat(BulkInt): def setup_ui(self, parent): self.make_widgets(parent, QDoubleSpinBox) self.main_widget.setRange(-1000000., float(100000000)) - self.main_widget.setDecimals(2) + self.main_widget.setDecimals(self.col_metadata['display'].get('decimals', 2)) self.finish_ui_setup(parent) def set_to_undefined(self): diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index 5e5c02f25a..ec63a282c8 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -553,7 +553,7 @@ class CcNumberDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{ editor = ClearingDoubleSpinBox(parent) editor.setSpecialValueText(_('Undefined')) editor.setRange(-1000000., 100000000.) - editor.setDecimals(2) + editor.setDecimals(m.custom_columns[col]['display'].get('decimals', 2)) return editor def setModelData(self, editor, model, index): diff --git a/src/calibre/gui2/preferences/create_custom_column.py b/src/calibre/gui2/preferences/create_custom_column.py index 312fb1f3e7..df8bab0cbd 100644 --- a/src/calibre/gui2/preferences/create_custom_column.py +++ b/src/calibre/gui2/preferences/create_custom_column.py @@ -13,7 +13,7 @@ from functools import partial from qt.core import ( QDialog, Qt, QColor, QIcon, QVBoxLayout, QLabel, QGridLayout, QDialogButtonBox, QWidget, QLineEdit, QHBoxLayout, QComboBox, - QCheckBox + QCheckBox, QSpinBox ) from calibre.gui2 import error_dialog @@ -197,6 +197,7 @@ class CreateCustomColumn(QDialog): elif ct == '*text': self.is_names.setChecked(c['display'].get('is_names', False)) self.description_box.setText(c['display'].get('description', '')) + self.decimals_box.setValue(min(9, max(1, c['display'].get('decimals', 2)))) all_colors = [str(s) for s in list(QColor.colorNames())] self.enum_colors_label.setToolTip('

' + ', '.join(all_colors) + '

') @@ -323,6 +324,19 @@ class CreateCustomColumn(QDialog): h.addWidget(la) self.format_label = add_row('', h) + # Float number of decimal digits + h = QHBoxLayout() + self.decimals_box = fb = QSpinBox(self) + fb.setRange(1, 9) + h.addWidget(fb) + self.decimals_default_label = la = QLabel(_('This controls the number of decimal ' + 'digits you can enter when editing ' + 'this column using the GUI. The ' + 'value can be between 1 and 9')) + la.setWordWrap(True) + h.addWidget(la) + self.decimals_label = add_row(_('Decimals when editing'), h) + # Template self.composite_box = cb = TemplateLineEditor(self) self.composite_default_label = cdl = QLabel(_("Default: (nothing)")) @@ -420,6 +434,7 @@ class CreateCustomColumn(QDialog): needs_format = col_type in ('datetime', 'int', 'float') for x in ('box', 'default_label', 'label'): getattr(self, 'format_'+x).setVisible(needs_format) + getattr(self, 'decimals_'+x).setVisible(col_type == 'float') if needs_format: if col_type == 'datetime': l, dl = _('&Format for dates'), _('Default: dd MMM yyyy.') @@ -591,6 +606,8 @@ class CreateCustomColumn(QDialog): display_dict = {'number_format':str(self.format_box.text()).strip()} else: display_dict = {'number_format': None} + if col_type == 'float': + display_dict['decimals'] = self.decimals_box.value() if default_val: try: if col_type == 'int': @@ -743,8 +760,10 @@ class CreateNewCustomColumn: 'enum_values': a string containing comma-separated valid values for an enumeration 'enum_colors': a string containing comma-separated colors for an enumeration 'use_decorations': True or False -- should check marks be displayed + float columns: + 'decimals': the number of decimal digits to allow when editing (int). Range: 1 - 9 float and int columns: - 'number_format': the format to apply for the column + 'number_format': the format to apply when displaying the column rating columns: 'allow_half_stars': True or False -- are half-stars allowed text columns: