config widget changes to support combo box.

This commit is contained in:
John Schember 2014-05-24 08:02:59 -04:00
parent 189cbd41fe
commit e82b80497f
3 changed files with 46 additions and 21 deletions

View File

@ -305,20 +305,21 @@ class KINDLE2(KINDLE):
' this information to the Kindle when uploading MOBI files by' ' this information to the Kindle when uploading MOBI files by'
' USB. Note that the page numbers do not correspond to any paper' ' USB. Note that the page numbers do not correspond to any paper'
' book.'), ' 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 ' _('There are multiple ways to generate the page number information. '
'generator will produce pages that correspond better to a printed book. ' 'If a page count is given then the book will be divided into that many pages. '
'However, this method is slower and will slow down sending files ' 'Otherwise the number of pages will be approximated using one of the following '
'to the Kindle.'), 'methods.\n\n'
_('Accurate calculation method') + '* fast: 2300 characters of uncompressed text per page.\n\n'
':::' + '* accurate: Based on the number of chapters, paragraphs, and visible lines in the book. '
_('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. '
'This method is designed to simulate an average paperback book where there are 32 lines per ' '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' 'page and a maximum of 70 characters per line.\n\n'
'The "pagebreak" method uses the presense of <mbp:pagebreak> tags within the book to ' '* pagebreak: The "pagebreak" method uses the presense of <mbp:pagebreak> tags within '
'determine pages.'), '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') + _('Custom column name to retrieve page counts from') +
':::' + ':::' +
_('If you have a custom column in your library that you use to ' _('If you have a custom column in your library that you use to '
@ -329,14 +330,12 @@ class KINDLE2(KINDLE):
] ]
EXTRA_CUSTOMIZATION_DEFAULT = [ EXTRA_CUSTOMIZATION_DEFAULT = [
True, True,
False, ['fast', 'accurate', 'pagebreak'],
'accurate',
'', '',
] ]
OPT_APNX = 0 OPT_APNX = 0
OPT_APNX_ACCURATE = 1 OPT_APNX_ACCURATE_METHOD = 1
OPT_APNX_ACCURATE_METHOD = 2 OPT_APNX_CUST_COL = 2
OPT_APNX_CUST_COL = 3
# x330 on the PaperWhite # x330 on the PaperWhite
THUMBNAIL_HEIGHT = 330 THUMBNAIL_HEIGHT = 330
# x262 on the Touch. Doesn't choke on x330, though. # 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_path = '%s.apnx' % os.path.join(path, filename)
apnx_builder = APNXBuilder() apnx_builder = APNXBuilder()
try: try:
method = None method = opts.extra_customization[self.OPT_APNX_ACCURATE_METHOD]
if opts.extra_customization[self.OPT_APNX_ACCURATE]: if isinstance(method, list):
method = opts.extra_customization[self.OPT_APNX_ACCURATE_METHOD] if len(method) > 0:
method = method[0]
else:
method = None
apnx_builder.write_apnx(filepath, apnx_path, apnx_builder.write_apnx(filepath, apnx_path,
method=method, method=method,
page_count=custom_page_count) page_count=custom_page_count)

View File

@ -103,6 +103,8 @@ class DeviceConfig(object):
continue continue
if hasattr(config_widget.opt_extra_customization[i], 'isChecked'): if hasattr(config_widget.opt_extra_customization[i], 'isChecked'):
ec.append(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: else:
ec.append(unicode(config_widget.opt_extra_customization[i].text()).strip()) ec.append(unicode(config_widget.opt_extra_customization[i].text()).strip())
else: else:
@ -124,6 +126,15 @@ class DeviceConfig(object):
for i,d in enumerate(cls.EXTRA_CUSTOMIZATION_DEFAULT): for i,d in enumerate(cls.EXTRA_CUSTOMIZATION_DEFAULT):
if i >= len(opts.extra_customization): if i >= len(opts.extra_customization):
opts.extra_customization.append(d) 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 return opts
@classmethod @classmethod

View File

@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
import textwrap import textwrap
from PyQt4.Qt import (QWidget, QListWidgetItem, Qt, QVariant, QLabel, 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 import error_dialog, question_dialog
from calibre.gui2.device_drivers.configwidget_ui import Ui_ConfigWidget 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.append(QCheckBox(label_text))
self.opt_extra_customization[-1].setToolTip(tt) self.opt_extra_customization[-1].setToolTip(tt)
self.opt_extra_customization[i].setChecked(bool(settings.extra_customization[i])) 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: else:
self.opt_extra_customization.append(QLineEdit(self)) self.opt_extra_customization.append(QLineEdit(self))
l = QLabel(label_text) l = QLabel(label_text)