PDF Output: Add custom size conversion option to the GUI (it was only present on the command line before)

This commit is contained in:
Kovid Goyal 2011-12-28 09:34:52 +05:30
parent 502575375b
commit 83aab34ec5
6 changed files with 46 additions and 35 deletions

View File

@ -25,31 +25,30 @@ class PDFOutput(OutputFormatPlugin):
file_type = 'pdf'
options = set([
OptionRecommendation(name='unit', recommended_value='inch',
level=OptionRecommendation.LOW, short_switch='u', choices=UNITS.keys(),
help=_('The unit of measure. Default is inch. Choices '
'are %s '
'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. 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 '
'EG. `123x321` to specify the width and height. '
'This overrides any specified paper-size.')),
OptionRecommendation(name='orientation', recommended_value='portrait',
level=OptionRecommendation.LOW, choices=ORIENTATIONS.keys(),
help=_('The orientation of the page. Default is portrait. Choices '
'are %s') % ORIENTATIONS.keys()),
OptionRecommendation(name='preserve_cover_aspect_ratio',
recommended_value=False,
help=_('Preserve the aspect ratio of the cover, instead'
' of stretching it to fill the full first page of the'
' generated pdf.')
),
])
OptionRecommendation(name='unit', recommended_value='inch',
level=OptionRecommendation.LOW, short_switch='u', choices=UNITS.keys(),
help=_('The unit of measure. Default is inch. Choices '
'are %s '
'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. This size will be overridden when a '
'non default 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 '
'EG. `123x321` to specify the width and height. '
'This overrides any specified paper-size.')),
OptionRecommendation(name='orientation', recommended_value='portrait',
level=OptionRecommendation.LOW, choices=ORIENTATIONS.keys(),
help=_('The orientation of the page. Default is portrait. Choices '
'are %s') % ORIENTATIONS.keys()),
OptionRecommendation(name='preserve_cover_aspect_ratio',
recommended_value=False,
help=_('Preserve the aspect ratio of the cover, instead'
' of stretching it to fill the full first page of the'
' generated pdf.')),
])
def convert(self, oeb_book, output_path, input_plugin, opts, log):
self.oeb = oeb_book

View File

@ -48,7 +48,7 @@ def get_pdf_printer(opts, for_comic=False):
custom_size = get_custom_size(opts)
if opts.output_profile.short_name == 'default' or \
opts.output_profile.width > 10000:
opts.output_profile.width > 9999:
if custom_size is None:
printer.setPaperSize(paper_size(opts.paper_size))
else:

View File

@ -77,7 +77,6 @@ class Widget(QWidget):
self._options, only_existing=True)
defaults.update(specifics)
self.apply_recommendations(defaults)
self.setup_help(get_help)

View File

@ -18,14 +18,14 @@ class PluginWidget(Widget, Ui_Form):
ICON = I('mimetypes/pdf.png')
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, ['paper_size',
Widget.__init__(self, parent, ['paper_size', 'custom_size',
'orientation', 'preserve_cover_aspect_ratio'])
self.db, self.book_id = db, book_id
for x in get_option('paper_size').option.choices:
self.opt_paper_size.addItem(x)
for x in get_option('orientation').option.choices:
self.opt_orientation.addItem(x)
self.initialize_options(get_option, get_help, db, book_id)

View File

@ -40,7 +40,7 @@
<item row="1" column="1">
<widget class="QComboBox" name="opt_orientation"/>
</item>
<item row="3" column="0">
<item row="4" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -53,13 +53,26 @@
</property>
</spacer>
</item>
<item row="2" column="0" colspan="2">
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="opt_preserve_cover_aspect_ratio">
<property name="text">
<string>Preserve &amp;aspect ratio of cover</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>&amp;Custom size:</string>
</property>
<property name="buddy">
<cstring>opt_custom_size</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="opt_custom_size"/>
</item>
</layout>
</widget>
<resources/>

View File

@ -117,6 +117,6 @@ if __name__ == '__main__':
from PyQt4.Qt import QApplication
app = QApplication([])
#test_widget('Conversion', 'Input Options')
test_widget('Conversion', 'Common Options')
#test_widget('Conversion', 'Output Options')
#test_widget('Conversion', 'Common Options')
test_widget('Conversion', 'Output Options')