Pull from driver-dev

This commit is contained in:
Kovid Goyal 2009-05-08 09:39:45 -07:00
commit a10fca0b0a
11 changed files with 23 additions and 37 deletions

View File

@ -23,7 +23,7 @@ class DeviceConfig(object):
@classmethod @classmethod
def config_widget(cls): def config_widget(cls):
from calibre.gui2.device_drivers.configwidget import ConfigWidget from calibre.gui2.device_drivers.configwidget import ConfigWidget
cw = ConfigWidget(cls._configProxy(), cls.FORMATS) cw = ConfigWidget(cls.settings(), cls.FORMATS)
return cw return cw
@classmethod @classmethod

View File

@ -11,7 +11,7 @@ __docformat__ = 'restructuredtext en'
import struct import struct
from calibre.ebooks.pdb.formatwriter import FormatWriter 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.mobi.palmdoc import compress_doc
from calibre.ebooks.pdb.header import PdbHeaderBuilder from calibre.ebooks.pdb.header import PdbHeaderBuilder
@ -45,7 +45,7 @@ class Writer(FormatWriter):
def _generate_text(self, spine): def _generate_text(self, spine):
txt_writer = TxtWriter(TxtNewlines('system').newline, self.log) txt_writer = TxtWriter(TxtNewlines('system').newline, self.log)
txt = txt_writer.dump(spine, TxtMetadata()) txt = txt_writer.dump(spine)
txt_length = len(txt) txt_length = len(txt)

View File

@ -11,7 +11,7 @@ __docformat__ = 'restructuredtext en'
import struct, zlib import struct, zlib
from calibre.ebooks.pdb.formatwriter import FormatWriter 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 from calibre.ebooks.pdb.header import PdbHeaderBuilder
MAX_RECORD_SIZE = 8192 MAX_RECORD_SIZE = 8192
@ -50,7 +50,7 @@ class Writer(FormatWriter):
def _generate_text(self, spine): def _generate_text(self, spine):
txt_writer = TxtWriter(TxtNewlines('system').newline, self.log) txt_writer = TxtWriter(TxtNewlines('system').newline, self.log)
txt = txt_writer.dump(spine, TxtMetadata()) txt = txt_writer.dump(spine)
txt_length = len(txt) txt_length = len(txt)

View File

@ -35,7 +35,8 @@ class PDFOutput(OutputFormatPlugin):
'Note: This does not override the unit for margins!' % UNITS.keys())), 'Note: This does not override the unit for margins!' % UNITS.keys())),
OptionRecommendation(name='paper_size', recommended_value='letter', OptionRecommendation(name='paper_size', recommended_value='letter',
level=OptionRecommendation.LOW, choices=PAPER_SIZES.keys(), 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())), 'are %s' % PAPER_SIZES.keys())),
OptionRecommendation(name='custom_size', recommended_value=None, OptionRecommendation(name='custom_size', recommended_value=None,
help=_('Custom size of the document. Use the form widthxheight ' help=_('Custom size of the document. Use the form widthxheight '

View File

@ -8,7 +8,7 @@ import os
from calibre.customize.conversion import OutputFormatPlugin, \ from calibre.customize.conversion import OutputFormatPlugin, \
OptionRecommendation 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 from calibre.ebooks.metadata import authors_to_string
class TXTOutput(OutputFormatPlugin): class TXTOutput(OutputFormatPlugin):
@ -25,21 +25,11 @@ class TXTOutput(OutputFormatPlugin):
'Use \'old_mac\' for compatibility with Mac OS 9 and earlier. ' 'Use \'old_mac\' for compatibility with Mac OS 9 and earlier. '
'For Mac OS X use \'unix\'. \'system\' will default to the newline ' 'For Mac OS X use \'unix\'. \'system\' will default to the newline '
'type used by this OS.' % sorted(TxtNewlines.NEWLINE_TYPES.keys()))), '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): def convert(self, oeb_book, output_path, input_plugin, opts, log):
metadata = TxtMetadata()
if opts.prepend_metadata.lower() == 'true':
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) writer = TxtWriter(TxtNewlines(opts.newline).newline, log)
txt = writer.dump(oeb_book.spine, metadata) txt = writer.dump(oeb_book.spine)
close = False close = False
if not hasattr(output_path, 'write'): if not hasattr(output_path, 'write'):

View File

@ -19,7 +19,7 @@ class TxtWriter(object):
self.newline = newline self.newline = newline
self.log = log self.log = log
def dump(self, spine, metadata): def dump(self, spine):
out = u'' out = u''
for item in spine: for item in spine:
content = unicode(item) content = unicode(item)
@ -32,12 +32,6 @@ class TxtWriter(object):
content = self.specified_newlines(content) content = self.specified_newlines(content)
out += 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 # Put two blank lines at end of file
end = out[-3 * len(self.newline):] end = out[-3 * len(self.newline):]
for i in range(3 - end.count(self.newline)): for i in range(3 - end.count(self.newline)):
@ -145,8 +139,3 @@ class TxtNewlines(object):
def __init__(self, newline_type): def __init__(self, newline_type):
self.newline = self.NEWLINE_TYPES.get(newline_type.lower(), os.linesep) self.newline = self.NEWLINE_TYPES.get(newline_type.lower(), os.linesep)
class TxtMetadata(object):
def __init__(self):
self.title = None
self.author = None

View File

@ -28,6 +28,7 @@ class BulkConfig(Config):
self.setup_pipeline() self.setup_pipeline()
self.input_label.hide()
self.input_formats.hide() self.input_formats.hide()
self.connect(self.output_formats, SIGNAL('currentIndexChanged(QString)'), self.connect(self.output_formats, SIGNAL('currentIndexChanged(QString)'),

View File

@ -20,9 +20,14 @@ class PluginWidget(Widget, Ui_Form):
self.db, self.book_id = db, book_id self.db, self.book_id = db, book_id
self.initialize_options(get_option, get_help, db, book_id) self.initialize_options(get_option, get_help, db, book_id)
default = self.opt_format.currentText()
global format_model global format_model
if format_model is None: if format_model is None:
format_model = BasicComboModel(FORMAT_WRITERS.keys()) format_model = BasicComboModel(FORMAT_WRITERS.keys())
self.format_model = format_model self.format_model = format_model
self.opt_format.setModel(self.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)

View File

@ -153,7 +153,7 @@ class Config(ResizableDialog, Ui_Dialog):
except ImportError: except ImportError:
pass pass
input_widget = None input_widget = None
name = self.plumber.input_plugin.name.lower().replace(' ', '_') name = 'calibre.gui2.convert.%s' % self.plumber.input_plugin.name.lower().replace(' ', '_')
try: try:
input_widget = __import__('calibre.gui2.convert.'+name, input_widget = __import__('calibre.gui2.convert.'+name,
fromlist=[1]) fromlist=[1])

View File

@ -21,7 +21,7 @@
<item row="0" column="0" colspan="2"> <item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="input_label">
<property name="text"> <property name="text">
<string>&amp;Input format:</string> <string>&amp;Input format:</string>
</property> </property>
@ -108,8 +108,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>810</width> <width>800</width>
<height>492</height> <height>471</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">

View File

@ -10,14 +10,14 @@ from calibre.gui2.device_drivers.configwidget_ui import Ui_ConfigWidget
class ConfigWidget(QWidget, Ui_ConfigWidget): class ConfigWidget(QWidget, Ui_ConfigWidget):
def __init__(self, config, all_formats): def __init__(self, settings, all_formats):
QWidget.__init__(self) QWidget.__init__(self)
Ui_ConfigWidget.__init__(self) Ui_ConfigWidget.__init__(self)
self.setupUi(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)) disabled_formats = list(set(all_formats).difference(format_map))
for format in format_map + disabled_formats: for format in format_map + disabled_formats:
item = QListWidgetItem(format, self.columns) item = QListWidgetItem(format, self.columns)