From 272e163e129cc2aa67746773130d9da3b87b37d9 Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 8 May 2009 06:55:39 -0400 Subject: [PATCH 1/6] cleanup. Pdb config honor defaults. --- src/calibre/devices/usbms/deviceconfig.py | 2 +- src/calibre/gui2/convert/bulk.py | 1 + src/calibre/gui2/convert/pdb_output.py | 5 +++++ src/calibre/gui2/convert/single.ui | 6 +++--- src/calibre/gui2/device_drivers/configwidget.py | 6 +++--- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/calibre/devices/usbms/deviceconfig.py b/src/calibre/devices/usbms/deviceconfig.py index 50d548b823..bf955e1cee 100644 --- a/src/calibre/devices/usbms/deviceconfig.py +++ b/src/calibre/devices/usbms/deviceconfig.py @@ -23,7 +23,7 @@ class DeviceConfig(object): @classmethod def config_widget(cls): from calibre.gui2.device_drivers.configwidget import ConfigWidget - cw = ConfigWidget(cls._configProxy(), cls.FORMATS) + cw = ConfigWidget(cls.settings(), cls.FORMATS) return cw @classmethod diff --git a/src/calibre/gui2/convert/bulk.py b/src/calibre/gui2/convert/bulk.py index 7bdacc26ee..10910f20a8 100644 --- a/src/calibre/gui2/convert/bulk.py +++ b/src/calibre/gui2/convert/bulk.py @@ -30,6 +30,7 @@ class BulkConfig(Config): self.setup_pipeline() + self.input_label.hide() self.input_formats.hide() self.connect(self.output_formats, SIGNAL('currentIndexChanged(QString)'), diff --git a/src/calibre/gui2/convert/pdb_output.py b/src/calibre/gui2/convert/pdb_output.py index db52db8f46..66563c3b24 100644 --- a/src/calibre/gui2/convert/pdb_output.py +++ b/src/calibre/gui2/convert/pdb_output.py @@ -20,9 +20,14 @@ class PluginWidget(Widget, Ui_Form): self.db, self.book_id = db, book_id self.initialize_options(get_option, get_help, db, book_id) + default = self.opt_format.currentText() + global format_model if format_model is None: format_model = BasicComboModel(FORMAT_WRITERS.keys()) self.format_model = format_model self.opt_format.setModel(self.format_model) + default_index = self.opt_format.findText(default) + self.opt_format.setCurrentIndex(default_index if default_index != -1 else 0) + diff --git a/src/calibre/gui2/convert/single.ui b/src/calibre/gui2/convert/single.ui index 713f7471f3..63c9e5084d 100644 --- a/src/calibre/gui2/convert/single.ui +++ b/src/calibre/gui2/convert/single.ui @@ -21,7 +21,7 @@ - + &Input format: @@ -108,8 +108,8 @@ 0 0 - 810 - 492 + 800 + 471 diff --git a/src/calibre/gui2/device_drivers/configwidget.py b/src/calibre/gui2/device_drivers/configwidget.py index 6c144d16c4..79b370d0bb 100644 --- a/src/calibre/gui2/device_drivers/configwidget.py +++ b/src/calibre/gui2/device_drivers/configwidget.py @@ -10,14 +10,14 @@ from calibre.gui2.device_drivers.configwidget_ui import Ui_ConfigWidget class ConfigWidget(QWidget, Ui_ConfigWidget): - def __init__(self, config, all_formats): + def __init__(self, settings, all_formats): QWidget.__init__(self) Ui_ConfigWidget.__init__(self) self.setupUi(self) - self.config = config + self.settings = settings - format_map = config['format_map'] + format_map = settings.format_map disabled_formats = list(set(all_formats).difference(format_map)) for format in format_map + disabled_formats: item = QListWidgetItem(format, self.columns) From b63bb797092e2cef63b83adb5eceb0160561c67b Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 8 May 2009 07:16:21 -0400 Subject: [PATCH 2/6] remove redundant txt metadata option. --- src/calibre/ebooks/txt/output.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/calibre/ebooks/txt/output.py b/src/calibre/ebooks/txt/output.py index 219e1d3111..e4b7539b72 100644 --- a/src/calibre/ebooks/txt/output.py +++ b/src/calibre/ebooks/txt/output.py @@ -25,16 +25,11 @@ class TXTOutput(OutputFormatPlugin): 'Use \'old_mac\' for compatibility with Mac OS 9 and earlier. ' 'For Mac OS X use \'unix\'. \'system\' will default to the newline ' 'type used by this OS.' % sorted(TxtNewlines.NEWLINE_TYPES.keys()))), - OptionRecommendation(name='prepend_metadata', recommended_value='false', - level=OptionRecommendation.LOW, - choices=['true', 'false'], - help=_('Write the title and author to the beginning of the file. ' - 'Default is \'true\'. Use \'false\' to disable.')), ]) def convert(self, oeb_book, output_path, input_plugin, opts, log): metadata = TxtMetadata() - if opts.prepend_metadata.lower() == 'true': + if opts.insert_metadata: metadata.author = opts.authors if opts.authors else authors_to_string([x.value for x in oeb_book.metadata.creator]) if oeb_book.metadata.creator != [] else _('Unknown') metadata.title = opts.title if opts.title else oeb_book.metadata.title[0].value if oeb_book.metadata.title != [] else _('Unknown') From 88a5527dac0d6cd63a0c86e3dfdd51a25db290c8 Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 8 May 2009 07:20:14 -0400 Subject: [PATCH 3/6] remove redundant txt metadata code. --- src/calibre/ebooks/pdb/palmdoc/writer.py | 4 ++-- src/calibre/ebooks/pdb/ztxt/writer.py | 4 ++-- src/calibre/ebooks/txt/output.py | 7 +------ src/calibre/ebooks/txt/writer.py | 13 +------------ 4 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/calibre/ebooks/pdb/palmdoc/writer.py b/src/calibre/ebooks/pdb/palmdoc/writer.py index 784eca5523..835b2c6cb3 100644 --- a/src/calibre/ebooks/pdb/palmdoc/writer.py +++ b/src/calibre/ebooks/pdb/palmdoc/writer.py @@ -11,7 +11,7 @@ __docformat__ = 'restructuredtext en' import struct from calibre.ebooks.pdb.formatwriter import FormatWriter -from calibre.ebooks.txt.writer import TxtWriter, TxtNewlines, TxtMetadata +from calibre.ebooks.txt.writer import TxtWriter, TxtNewlines from calibre.ebooks.mobi.palmdoc import compress_doc from calibre.ebooks.pdb.header import PdbHeaderBuilder @@ -45,7 +45,7 @@ class Writer(FormatWriter): def _generate_text(self, spine): txt_writer = TxtWriter(TxtNewlines('system').newline, self.log) - txt = txt_writer.dump(spine, TxtMetadata()) + txt = txt_writer.dump(spine) txt_length = len(txt) diff --git a/src/calibre/ebooks/pdb/ztxt/writer.py b/src/calibre/ebooks/pdb/ztxt/writer.py index 6e974d1a67..fd7a07d7f9 100644 --- a/src/calibre/ebooks/pdb/ztxt/writer.py +++ b/src/calibre/ebooks/pdb/ztxt/writer.py @@ -11,7 +11,7 @@ __docformat__ = 'restructuredtext en' import struct, zlib from calibre.ebooks.pdb.formatwriter import FormatWriter -from calibre.ebooks.txt.writer import TxtWriter, TxtNewlines, TxtMetadata +from calibre.ebooks.txt.writer import TxtWriter, TxtNewlines from calibre.ebooks.pdb.header import PdbHeaderBuilder MAX_RECORD_SIZE = 8192 @@ -50,7 +50,7 @@ class Writer(FormatWriter): def _generate_text(self, spine): txt_writer = TxtWriter(TxtNewlines('system').newline, self.log) - txt = txt_writer.dump(spine, TxtMetadata()) + txt = txt_writer.dump(spine) txt_length = len(txt) diff --git a/src/calibre/ebooks/txt/output.py b/src/calibre/ebooks/txt/output.py index e4b7539b72..c21c834d76 100644 --- a/src/calibre/ebooks/txt/output.py +++ b/src/calibre/ebooks/txt/output.py @@ -28,13 +28,8 @@ class TXTOutput(OutputFormatPlugin): ]) def convert(self, oeb_book, output_path, input_plugin, opts, log): - metadata = TxtMetadata() - if opts.insert_metadata: - metadata.author = opts.authors if opts.authors else authors_to_string([x.value for x in oeb_book.metadata.creator]) if oeb_book.metadata.creator != [] else _('Unknown') - metadata.title = opts.title if opts.title else oeb_book.metadata.title[0].value if oeb_book.metadata.title != [] else _('Unknown') - writer = TxtWriter(TxtNewlines(opts.newline).newline, log) - txt = writer.dump(oeb_book.spine, metadata) + txt = writer.dump(oeb_book.spine) close = False if not hasattr(output_path, 'write'): diff --git a/src/calibre/ebooks/txt/writer.py b/src/calibre/ebooks/txt/writer.py index ea613010ef..09a79d322d 100644 --- a/src/calibre/ebooks/txt/writer.py +++ b/src/calibre/ebooks/txt/writer.py @@ -19,7 +19,7 @@ class TxtWriter(object): self.newline = newline self.log = log - def dump(self, spine, metadata): + def dump(self, spine): out = u'' for item in spine: content = unicode(item) @@ -32,12 +32,6 @@ class TxtWriter(object): content = self.specified_newlines(content) out += content - # Prepend metadata - if metadata.author != None and metadata.author != '': - if metadata.title != None and metadata.title != '': - out = (u'%s%s%s%s' % (metadata.author.upper(), self.newline, self.newline, self.newline)) + out - out = (u'%s%s%s%s' % (metadata.title.upper(), self.newline, self.newline, self.newline)) + out - # Put two blank lines at end of file end = out[-3 * len(self.newline):] for i in range(3 - end.count(self.newline)): @@ -145,8 +139,3 @@ class TxtNewlines(object): def __init__(self, newline_type): self.newline = self.NEWLINE_TYPES.get(newline_type.lower(), os.linesep) - -class TxtMetadata(object): - def __init__(self): - self.title = None - self.author = None From 742e5f9f1a003988fd07e17ff3fae96b59b01102 Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 8 May 2009 07:26:21 -0400 Subject: [PATCH 4/6] GUI Convert: txt output options widget. --- src/calibre/ebooks/txt/output.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/ebooks/txt/output.py b/src/calibre/ebooks/txt/output.py index c21c834d76..adf357181c 100644 --- a/src/calibre/ebooks/txt/output.py +++ b/src/calibre/ebooks/txt/output.py @@ -8,7 +8,7 @@ import os from calibre.customize.conversion import OutputFormatPlugin, \ OptionRecommendation -from calibre.ebooks.txt.writer import TxtWriter, TxtNewlines, TxtMetadata +from calibre.ebooks.txt.writer import TxtWriter, TxtNewlines from calibre.ebooks.metadata import authors_to_string class TXTOutput(OutputFormatPlugin): From a48cefc82be3592ffb9e16c9a750011cd9271870 Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 8 May 2009 07:32:36 -0400 Subject: [PATCH 5/6] GUI Convert: fix import of input widget. --- src/calibre/gui2/convert/single.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/convert/single.py b/src/calibre/gui2/convert/single.py index eea4b6e11a..7bf3f0f6ea 100644 --- a/src/calibre/gui2/convert/single.py +++ b/src/calibre/gui2/convert/single.py @@ -153,9 +153,10 @@ class Config(ResizableDialog, Ui_Dialog): except ImportError: pass input_widget = None - name = self.plumber.input_plugin.name.lower().replace(' ', '_') + name = 'calibre.gui2.convert.%s' % self.plumber.input_plugin.name.lower().replace(' ', '_') try: - input_widget = __import__(name) + __import__(name) + input_widget = sys.modules[name] pw = input_widget.PluginWidget pw.ICON = ':/images/forward.svg' pw.HELP = _('Options specific to the input format.') From 91ca2cc9277fbf7f09faca28ac8ecbc7d7490d1a Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 8 May 2009 07:48:20 -0400 Subject: [PATCH 6/6] GUI Convert: pdf output options widget. --- src/calibre/ebooks/pdf/output.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/pdf/output.py b/src/calibre/ebooks/pdf/output.py index 0cc73931f4..bed5342bb4 100644 --- a/src/calibre/ebooks/pdf/output.py +++ b/src/calibre/ebooks/pdf/output.py @@ -35,7 +35,8 @@ class PDFOutput(OutputFormatPlugin): 'Note: This does not override the unit for margins!' % UNITS.keys())), OptionRecommendation(name='paper_size', recommended_value='letter', level=OptionRecommendation.LOW, choices=PAPER_SIZES.keys(), - help=_('The size of the paper. Default is letter. Choices ' + help=_('The size of the paper. This size will be overridden when an ' + 'output profile is used. Default is letter. Choices ' 'are %s' % PAPER_SIZES.keys())), OptionRecommendation(name='custom_size', recommended_value=None, help=_('Custom size of the document. Use the form widthxheight '