From e82b80497f720362824fca3e174a4c3b2c0dc4a5 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 24 May 2014 08:02:59 -0400 Subject: [PATCH] config widget changes to support combo box. --- src/calibre/devices/kindle/driver.py | 42 ++++++++++--------- src/calibre/devices/usbms/deviceconfig.py | 11 +++++ .../gui2/device_drivers/configwidget.py | 14 ++++++- 3 files changed, 46 insertions(+), 21 deletions(-) diff --git a/src/calibre/devices/kindle/driver.py b/src/calibre/devices/kindle/driver.py index be64a5045d..a36d3df112 100644 --- a/src/calibre/devices/kindle/driver.py +++ b/src/calibre/devices/kindle/driver.py @@ -305,20 +305,21 @@ class KINDLE2(KINDLE): ' this information to the Kindle when uploading MOBI files by' ' USB. Note that the page numbers do not correspond to any paper' ' book.'), - _('Use slower but more accurate page number calculation') + + _('Page count calculation method') + ':::' + - _('There are two ways to generate the page number information. Using the more accurate ' - 'generator will produce pages that correspond better to a printed book. ' - 'However, this method is slower and will slow down sending files ' - 'to the Kindle.'), - _('Accurate calculation method') + - ':::' + - _('There are multiple methods to accuratly calculate the page numbers. "accurate" which ' - 'is an estimation based on the number of chapters, paragraphs, and visible lines in the book. ' + _('There are multiple ways to generate the page number information. ' + 'If a page count is given then the book will be divided into that many pages. ' + 'Otherwise the number of pages will be approximated using one of the following ' + 'methods.\n\n' + '* fast: 2300 characters of uncompressed text per page.\n\n' + '* accurate: Based on the number of chapters, paragraphs, and visible lines in the book. ' 'This method is designed to simulate an average paperback book where there are 32 lines per ' - 'page and a maximum of 70 characters per line. \n\n' - 'The "pagebreak" method uses the presense of tags within the book to ' - 'determine pages.'), + 'page and a maximum of 70 characters per line.\n\n' + '* pagebreak: The "pagebreak" method uses the presense of tags within ' + 'the book to determine pages.\n\n' + 'Methods other than "fast" are going to be much slower. ' + 'Further, if "pagebreak" fails to determine a page count accurate will be used, and if ' + '"accurate" fails fast will be used.'), _('Custom column name to retrieve page counts from') + ':::' + _('If you have a custom column in your library that you use to ' @@ -329,14 +330,12 @@ class KINDLE2(KINDLE): ] EXTRA_CUSTOMIZATION_DEFAULT = [ True, - False, - 'accurate', + ['fast', 'accurate', 'pagebreak'], '', ] OPT_APNX = 0 - OPT_APNX_ACCURATE = 1 - OPT_APNX_ACCURATE_METHOD = 2 - OPT_APNX_CUST_COL = 3 + OPT_APNX_ACCURATE_METHOD = 1 + OPT_APNX_CUST_COL = 2 # x330 on the PaperWhite THUMBNAIL_HEIGHT = 330 # x262 on the Touch. Doesn't choke on x330, though. @@ -451,9 +450,12 @@ class KINDLE2(KINDLE): apnx_path = '%s.apnx' % os.path.join(path, filename) apnx_builder = APNXBuilder() try: - method = None - if opts.extra_customization[self.OPT_APNX_ACCURATE]: - method = opts.extra_customization[self.OPT_APNX_ACCURATE_METHOD] + method = opts.extra_customization[self.OPT_APNX_ACCURATE_METHOD] + if isinstance(method, list): + if len(method) > 0: + method = method[0] + else: + method = None apnx_builder.write_apnx(filepath, apnx_path, method=method, page_count=custom_page_count) diff --git a/src/calibre/devices/usbms/deviceconfig.py b/src/calibre/devices/usbms/deviceconfig.py index b2eadd7461..fb1ce0e939 100644 --- a/src/calibre/devices/usbms/deviceconfig.py +++ b/src/calibre/devices/usbms/deviceconfig.py @@ -103,6 +103,8 @@ class DeviceConfig(object): continue if hasattr(config_widget.opt_extra_customization[i], 'isChecked'): ec.append(config_widget.opt_extra_customization[i].isChecked()) + elif hasattr(config_widget.opt_extra_customization[i], 'currentText'): + ec.append(unicode(config_widget.opt_extra_customization[i].currentText()).strip()) else: ec.append(unicode(config_widget.opt_extra_customization[i].text()).strip()) else: @@ -124,6 +126,15 @@ class DeviceConfig(object): for i,d in enumerate(cls.EXTRA_CUSTOMIZATION_DEFAULT): if i >= len(opts.extra_customization): opts.extra_customization.append(d) + # Take the currently selected opt and put it at the front of + # the list. + if isinstance(d, list): + if not isinstance(opts.extra_customization[i], list): + o = opts.extra_customization[i] + if o in d: + d.remove(o) + d.insert(0, o) + opts.extra_customization[i] = d return opts @classmethod diff --git a/src/calibre/gui2/device_drivers/configwidget.py b/src/calibre/gui2/device_drivers/configwidget.py index 17c97b7ba0..db27613a5e 100644 --- a/src/calibre/gui2/device_drivers/configwidget.py +++ b/src/calibre/gui2/device_drivers/configwidget.py @@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en' import textwrap from PyQt4.Qt import (QWidget, QListWidgetItem, Qt, QVariant, QLabel, - QLineEdit, QCheckBox) + QLineEdit, QCheckBox, QComboBox) from calibre.gui2 import error_dialog, question_dialog from calibre.gui2.device_drivers.configwidget_ui import Ui_ConfigWidget @@ -84,6 +84,18 @@ class ConfigWidget(QWidget, Ui_ConfigWidget): self.opt_extra_customization.append(QCheckBox(label_text)) self.opt_extra_customization[-1].setToolTip(tt) self.opt_extra_customization[i].setChecked(bool(settings.extra_customization[i])) + elif isinstance(settings.extra_customization[i], list): + self.opt_extra_customization.append(QComboBox(self)) + l = QLabel(label_text) + l.setToolTip(tt) + self.opt_extra_customization[i].setToolTip(tt) + l.setBuddy(self.opt_extra_customization[i]) + for li in settings.extra_customization[i]: + print(li) + if not li: + continue + self.opt_extra_customization[i].addItem(li) + self.opt_extra_customization[i].setCurrentIndex(0) else: self.opt_extra_customization.append(QLineEdit(self)) l = QLabel(label_text)