Fix Comin Input default settings not being used when bulk converting comics

This commit is contained in:
Kovid Goyal 2010-08-14 22:41:00 -06:00
parent a81bb5737a
commit 3b3cc6959f
22 changed files with 68 additions and 31 deletions

View File

@ -16,18 +16,39 @@ from calibre.ebooks.conversion.config import load_defaults, \
save_defaults as save_defaults_, \ save_defaults as save_defaults_, \
load_specifics, GuiRecommendations load_specifics, GuiRecommendations
from calibre import prepare_string_for_xml from calibre import prepare_string_for_xml
from calibre.customize.ui import plugin_for_input_format
def config_widget_for_input_plugin(plugin):
name = plugin.name.lower().replace(' ', '_')
try:
return __import__('calibre.gui2.convert.'+name,
fromlist=[1])
except ImportError:
pass
def bulk_defaults_for_input_format(fmt):
plugin = plugin_for_input_format(fmt)
if plugin is not None:
w = config_widget_for_input_plugin(plugin)
if w is not None:
return load_defaults(w.COMMIT_NAME)
return {}
class Widget(QWidget): class Widget(QWidget):
TITLE = _('Unknown') TITLE = _('Unknown')
ICON = I('config.svg') ICON = I('config.svg')
HELP = '' HELP = ''
COMMIT_NAME = None
def __init__(self, parent, name, options): def __init__(self, parent, options):
QWidget.__init__(self, parent) QWidget.__init__(self, parent)
self.setupUi(self) self.setupUi(self)
self._options = options self._options = options
self._name = name self._name = self.commit_name = self.COMMIT_NAME
assert self._name is not None
self._icon = QIcon(self.ICON) self._icon = QIcon(self.ICON)
for name in self._options: for name in self._options:
if not hasattr(self, 'opt_'+name): if not hasattr(self, 'opt_'+name):
@ -58,7 +79,7 @@ class Widget(QWidget):
def commit_options(self, save_defaults=False): def commit_options(self, save_defaults=False):
recs = self.create_recommendations() recs = self.create_recommendations()
if save_defaults: if save_defaults:
save_defaults_(self._name, recs) save_defaults_(self.commit_name, recs)
return recs return recs
def create_recommendations(self): def create_recommendations(self):

View File

@ -14,9 +14,10 @@ class PluginWidget(Widget, Ui_Form):
TITLE = _('Comic Input') TITLE = _('Comic Input')
HELP = _('Options specific to')+' comic '+_('input') HELP = _('Options specific to')+' comic '+_('input')
COMMIT_NAME = 'comic_input'
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'comic_input', Widget.__init__(self, parent,
['colors', 'dont_normalize', 'keep_aspect_ratio', 'right2left', ['colors', 'dont_normalize', 'keep_aspect_ratio', 'right2left',
'despeckle', 'no_sort', 'no_process', 'landscape', 'despeckle', 'no_sort', 'no_process', 'landscape',
'dont_sharpen', 'disable_trim', 'wide', 'output_format', 'dont_sharpen', 'disable_trim', 'wide', 'output_format',

View File

@ -19,9 +19,10 @@ class DebugWidget(Widget, Ui_Form):
TITLE = _('Debug') TITLE = _('Debug')
ICON = I('debug.svg') ICON = I('debug.svg')
HELP = _('Debug the conversion process.') HELP = _('Debug the conversion process.')
COMMIT_NAME = 'debug'
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'debug', Widget.__init__(self, parent,
['debug_pipeline'] ['debug_pipeline']
) )
self.db, self.book_id = db, book_id self.db, self.book_id = db, book_id

View File

@ -14,9 +14,10 @@ class PluginWidget(Widget, Ui_Form):
TITLE = _('EPUB Output') TITLE = _('EPUB Output')
HELP = _('Options specific to')+' EPUB '+_('output') HELP = _('Options specific to')+' EPUB '+_('output')
COMMIT_NAME = 'epub_output'
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'epub_output', Widget.__init__(self, parent,
['dont_split_on_page_breaks', 'flow_size', ['dont_split_on_page_breaks', 'flow_size',
'no_default_epub_cover', 'no_svg_cover', 'no_default_epub_cover', 'no_svg_cover',
'preserve_cover_aspect_ratio',] 'preserve_cover_aspect_ratio',]

View File

@ -11,9 +11,10 @@ class PluginWidget(Widget, Ui_Form):
TITLE = _('FB2 Input') TITLE = _('FB2 Input')
HELP = _('Options specific to')+' FB2 '+_('input') HELP = _('Options specific to')+' FB2 '+_('input')
COMMIT_NAME = 'fb2_input'
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'fb2_input', Widget.__init__(self, parent,
['no_inline_fb2_toc']) ['no_inline_fb2_toc'])
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)

View File

@ -13,8 +13,9 @@ class PluginWidget(Widget, Ui_Form):
TITLE = _('FB2 Output') TITLE = _('FB2 Output')
HELP = _('Options specific to')+' FB2 '+_('output') HELP = _('Options specific to')+' FB2 '+_('output')
COMMIT_NAME = 'fb2_output'
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'fb2_output', ['inline_toc']) Widget.__init__(self, parent, ['inline_toc'])
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)

View File

@ -16,9 +16,10 @@ class LookAndFeelWidget(Widget, Ui_Form):
TITLE = _('Look & Feel') TITLE = _('Look & Feel')
ICON = I('lookfeel.svg') ICON = I('lookfeel.svg')
HELP = _('Control the look and feel of the output') HELP = _('Control the look and feel of the output')
COMMIT_NAME = 'look_and_feel'
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'look_and_feel', Widget.__init__(self, parent,
['change_justification', 'extra_css', 'base_font_size', ['change_justification', 'extra_css', 'base_font_size',
'font_size_mapping', 'line_height', 'font_size_mapping', 'line_height',
'linearize_tables', 'linearize_tables',

View File

@ -18,9 +18,10 @@ class PluginWidget(Widget, Ui_Form):
TITLE = _('LRF Output') TITLE = _('LRF Output')
HELP = _('Options specific to')+' LRF '+_('output') HELP = _('Options specific to')+' LRF '+_('output')
COMMIT_NAME = 'lrf_output'
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'lrf_output', Widget.__init__(self, parent,
['wordspace', 'header', 'header_format', ['wordspace', 'header', 'header_format',
'minimum_indent', 'serif_family', 'minimum_indent', 'serif_family',
'render_tables_as_images', 'sans_family', 'mono_family', 'render_tables_as_images', 'sans_family', 'mono_family',

View File

@ -42,9 +42,10 @@ class MetadataWidget(Widget, Ui_Form):
ICON = I('dialog_information.svg') ICON = I('dialog_information.svg')
HELP = _('Set the metadata. The output file will contain as much of this ' HELP = _('Set the metadata. The output file will contain as much of this '
'metadata as possible.') 'metadata as possible.')
COMMIT_NAME = 'metadata'
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'metadata', ['prefer_metadata_cover']) Widget.__init__(self, parent, ['prefer_metadata_cover'])
self.db, self.book_id = db, book_id self.db, self.book_id = db, book_id
self.cover_changed = False self.cover_changed = False
self.cover_data = None self.cover_data = None

View File

@ -19,10 +19,10 @@ class PluginWidget(Widget, Ui_Form):
TITLE = _('MOBI Output') TITLE = _('MOBI Output')
HELP = _('Options specific to')+' MOBI '+_('output') HELP = _('Options specific to')+' MOBI '+_('output')
COMMIT_NAME = 'mobi_output'
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'mobi_output', Widget.__init__(self, parent,
['prefer_author_sort', 'rescale_images', 'toc_title', ['prefer_author_sort', 'rescale_images', 'toc_title',
'dont_compress', 'no_inline_toc', 'masthead_font','personal_doc'] 'dont_compress', 'no_inline_toc', 'masthead_font','personal_doc']
) )

View File

@ -33,9 +33,10 @@ class ProfileModel(QAbstractListModel):
class PageSetupWidget(Widget, Ui_Form): class PageSetupWidget(Widget, Ui_Form):
TITLE = _('Page Setup') TITLE = _('Page Setup')
COMMIT_NAME = 'page_setup'
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'page_setup', Widget.__init__(self, parent,
['margin_top', 'margin_left', 'margin_right', 'margin_bottom', ['margin_top', 'margin_left', 'margin_right', 'margin_bottom',
'input_profile', 'output_profile'] 'input_profile', 'output_profile']
) )

View File

@ -11,9 +11,10 @@ class PluginWidget(Widget, Ui_Form):
TITLE = _('PDB Input') TITLE = _('PDB Input')
HELP = _('Options specific to')+' PDB '+_('input') HELP = _('Options specific to')+' PDB '+_('input')
COMMIT_NAME = 'pdb_input'
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'pdb_input', Widget.__init__(self, parent,
['single_line_paras', 'print_formatted_paras']) ['single_line_paras', 'print_formatted_paras'])
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)

View File

@ -15,9 +15,10 @@ class PluginWidget(Widget, Ui_Form):
TITLE = _('PDB Output') TITLE = _('PDB Output')
HELP = _('Options specific to')+' PDB '+_('output') HELP = _('Options specific to')+' PDB '+_('output')
COMMIT_NAME = 'pdb_output'
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'pdb_output', ['format', 'inline_toc']) Widget.__init__(self, parent, ['format', 'inline_toc'])
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)

View File

@ -11,9 +11,10 @@ class PluginWidget(Widget, Ui_Form):
TITLE = _('PDF Input') TITLE = _('PDF Input')
HELP = _('Options specific to')+' PDF '+_('input') HELP = _('Options specific to')+' PDF '+_('input')
COMMIT_NAME = 'pdf_input'
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'pdf_input', Widget.__init__(self, parent,
['no_images', 'unwrap_factor']) ['no_images', 'unwrap_factor'])
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)

View File

@ -16,9 +16,10 @@ class PluginWidget(Widget, Ui_Form):
TITLE = _('PDF Output') TITLE = _('PDF Output')
HELP = _('Options specific to')+' PDF '+_('output') HELP = _('Options specific to')+' PDF '+_('output')
COMMIT_NAME = 'pdf_output'
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'pdf_output', ['paper_size', Widget.__init__(self, parent, ['paper_size',
'orientation', 'preserve_cover_aspect_ratio']) 'orientation', 'preserve_cover_aspect_ratio'])
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)

View File

@ -13,8 +13,9 @@ class PluginWidget(Widget, Ui_Form):
TITLE = _('RB Output') TITLE = _('RB Output')
HELP = _('Options specific to')+' RB '+_('output') HELP = _('Options specific to')+' RB '+_('output')
COMMIT_NAME = 'rb_output'
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'rb_output', ['inline_toc']) Widget.__init__(self, parent, ['inline_toc'])
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)

View File

@ -18,9 +18,10 @@ class StructureDetectionWidget(Widget, Ui_Form):
ICON = I('chapters.svg') ICON = I('chapters.svg')
HELP = _('Fine tune the detection of chapter headings and ' HELP = _('Fine tune the detection of chapter headings and '
'other document structure.') 'other document structure.')
COMMIT_NAME = 'structure_detection'
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'structure_detection', Widget.__init__(self, parent,
['chapter', 'chapter_mark', ['chapter', 'chapter_mark',
'remove_first_image', 'remove_first_image',
'insert_metadata', 'page_breaks_before', 'insert_metadata', 'page_breaks_before',

View File

@ -16,9 +16,10 @@ class TOCWidget(Widget, Ui_Form):
TITLE = _('Table of\nContents') TITLE = _('Table of\nContents')
ICON = I('series.svg') ICON = I('series.svg')
HELP = _('Control the creation/conversion of the Table of Contents.') HELP = _('Control the creation/conversion of the Table of Contents.')
COMMIT_NAME = 'toc'
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'toc', Widget.__init__(self, parent,
['level1_toc', 'level2_toc', 'level3_toc', ['level1_toc', 'level2_toc', 'level3_toc',
'toc_threshold', 'max_toc_links', 'no_chapters_in_toc', 'toc_threshold', 'max_toc_links', 'no_chapters_in_toc',
'use_auto_toc', 'toc_filter', 'use_auto_toc', 'toc_filter',

View File

@ -11,9 +11,10 @@ class PluginWidget(Widget, Ui_Form):
TITLE = _('TXT Input') TITLE = _('TXT Input')
HELP = _('Options specific to')+' TXT '+_('input') HELP = _('Options specific to')+' TXT '+_('input')
COMMIT_NAME = 'txt_input'
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'txt_input', Widget.__init__(self, parent,
['single_line_paras', 'print_formatted_paras', 'markdown', ['single_line_paras', 'print_formatted_paras', 'markdown',
'markdown_disable_toc', 'preserve_spaces']) 'markdown_disable_toc', 'preserve_spaces'])
self.db, self.book_id = db, book_id self.db, self.book_id = db, book_id

View File

@ -15,9 +15,10 @@ class PluginWidget(Widget, Ui_Form):
TITLE = _('TXT Output') TITLE = _('TXT Output')
HELP = _('Options specific to')+' TXT '+_('output') HELP = _('Options specific to')+' TXT '+_('output')
COMMIT_NAME = 'txt_output'
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'txt_output', Widget.__init__(self, parent,
['newline', 'max_line_length', 'force_max_line_length', ['newline', 'max_line_length', 'force_max_line_length',
'inline_toc']) 'inline_toc'])
self.db, self.book_id = db, book_id self.db, self.book_id = db, book_id

View File

@ -29,6 +29,7 @@ from calibre.customize.ui import initialized_plugins, is_disabled, enable_plugin
input_format_plugins, \ input_format_plugins, \
output_format_plugins, available_output_formats output_format_plugins, available_output_formats
from calibre.utils.smtp import config as smtp_prefs from calibre.utils.smtp import config as smtp_prefs
from calibre.gui2.convert import config_widget_for_input_plugin
from calibre.gui2.convert.look_and_feel import LookAndFeelWidget from calibre.gui2.convert.look_and_feel import LookAndFeelWidget
from calibre.gui2.convert.page_setup import PageSetupWidget from calibre.gui2.convert.page_setup import PageSetupWidget
from calibre.gui2.convert.structure_detection import StructureDetectionWidget from calibre.gui2.convert.structure_detection import StructureDetectionWidget
@ -36,6 +37,7 @@ from calibre.ebooks.conversion.plumber import Plumber
from calibre.utils.logging import Log from calibre.utils.logging import Log
from calibre.gui2.convert.toc import TOCWidget from calibre.gui2.convert.toc import TOCWidget
class ConfigTabs(QTabWidget): class ConfigTabs(QTabWidget):
def __init__(self, parent): def __init__(self, parent):
@ -58,15 +60,11 @@ class ConfigTabs(QTabWidget):
self.widgets = [lf, ps, sd, toc] self.widgets = [lf, ps, sd, toc]
for plugin in input_format_plugins(): for plugin in input_format_plugins():
name = plugin.name.lower().replace(' ', '_') input_widget = config_widget_for_input_plugin(plugin)
try: if input_widget is not None:
input_widget = __import__('calibre.gui2.convert.'+name,
fromlist=[1])
pw = input_widget.PluginWidget pw = input_widget.PluginWidget
pw.ICON = I('forward.svg') pw.ICON = I('forward.svg')
self.widgets.append(widget_factory(pw)) self.widgets.append(widget_factory(pw))
except ImportError:
continue
for plugin in output_format_plugins(): for plugin in output_format_plugins():
name = plugin.name.lower().replace(' ', '_') name = plugin.name.lower().replace(' ', '_')

View File

@ -22,6 +22,7 @@ from calibre.customize.conversion import OptionRecommendation
from calibre.utils.config import prefs from calibre.utils.config import prefs
from calibre.ebooks.conversion.config import GuiRecommendations, \ from calibre.ebooks.conversion.config import GuiRecommendations, \
load_defaults, load_specifics, save_specifics load_defaults, load_specifics, save_specifics
from calibre.gui2.convert import bulk_defaults_for_input_format
def convert_single_ebook(parent, db, book_ids, auto_conversion=False, out_format=None): def convert_single_ebook(parent, db, book_ids, auto_conversion=False, out_format=None):
changed = False changed = False
@ -148,7 +149,7 @@ class QueueBulk(QProgressDialog):
temp_files = [] temp_files = []
combined_recs = GuiRecommendations() combined_recs = GuiRecommendations()
default_recs = load_defaults('%s_input' % input_format) default_recs = bulk_defaults_for_input_format(input_format)
for key in default_recs: for key in default_recs:
combined_recs[key] = default_recs[key] combined_recs[key] = default_recs[key]
if self.use_saved_single_settings: if self.use_saved_single_settings:
@ -208,7 +209,6 @@ class QueueBulk(QProgressDialog):
self.queue(self.jobs, self.changed, self.bad, *self.args) self.queue(self.jobs, self.changed, self.bad, *self.args)
def fetch_scheduled_recipe(arg): def fetch_scheduled_recipe(arg):
from calibre.ebooks.conversion.config import load_defaults
fmt = prefs['output_format'].lower() fmt = prefs['output_format'].lower()
pt = PersistentTemporaryFile(suffix='_recipe_out.%s'%fmt.lower()) pt = PersistentTemporaryFile(suffix='_recipe_out.%s'%fmt.lower())
pt.close() pt.close()