mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Pull from driver-dev
This commit is contained in:
commit
a10fca0b0a
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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 '
|
||||
|
@ -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):
|
||||
@ -25,21 +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':
|
||||
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'):
|
||||
|
@ -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
|
||||
|
@ -28,6 +28,7 @@ class BulkConfig(Config):
|
||||
|
||||
self.setup_pipeline()
|
||||
|
||||
self.input_label.hide()
|
||||
self.input_formats.hide()
|
||||
|
||||
self.connect(self.output_formats, SIGNAL('currentIndexChanged(QString)'),
|
||||
|
@ -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)
|
||||
|
||||
|
@ -153,7 +153,7 @@ 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__('calibre.gui2.convert.'+name,
|
||||
fromlist=[1])
|
||||
|
@ -21,7 +21,7 @@
|
||||
<item row="0" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<widget class="QLabel" name="input_label">
|
||||
<property name="text">
|
||||
<string>&Input format:</string>
|
||||
</property>
|
||||
@ -108,8 +108,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>810</width>
|
||||
<height>492</height>
|
||||
<width>800</width>
|
||||
<height>471</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user