diff --git a/src/calibre/gui2/convert/bulk.py b/src/calibre/gui2/convert/bulk.py index d6d03c9aec..8a8c796403 100644 --- a/src/calibre/gui2/convert/bulk.py +++ b/src/calibre/gui2/convert/bulk.py @@ -14,6 +14,8 @@ from calibre.customize.ui import available_output_formats from calibre.gui2 import ResizableDialog from calibre.gui2.convert.look_and_feel import LookAndFeelWidget from calibre.gui2.convert.page_setup import PageSetupWidget +from calibre.gui2.convert.structure_detection import StructureDetectionWidget +from calibre.gui2.convert.toc import TOCWidget from calibre.gui2.convert import GuiRecommendations from calibre.ebooks.conversion.plumber import Plumber, OUTPUT_FORMAT_PREFERENCES from calibre.utils.logging import Log @@ -58,6 +60,8 @@ class BulkConfig(Config): self.setWindowTitle(_('Bulk Convert')) lf = widget_factory(LookAndFeelWidget) ps = widget_factory(PageSetupWidget) + sd = widget_factory(StructureDetectionWidget) + toc = widget_factory(TOCWidget) output_widget = None name = 'calibre.gui2.convert.%s' % self.plumber.output_plugin.name.lower().replace(' ', '_') @@ -76,7 +80,7 @@ class BulkConfig(Config): if not c: break self.stack.removeWidget(c) - widgets = [lf, ps] + widgets = [lf, ps, sd, toc] if output_widget is not None: widgets.append(output_widget) for w in widgets: @@ -89,7 +93,7 @@ class BulkConfig(Config): idx = oidx if -1 < oidx < self._groups_model.rowCount() else 0 self.groups.setCurrentIndex(self._groups_model.index(idx)) - + self.stack.setCurrentIndex(idx) def setup_output_formats(self, db, preferred_output_format): available_formats = '' diff --git a/src/calibre/gui2/convert/single.py b/src/calibre/gui2/convert/single.py index 2b0cfd52d0..eea4b6e11a 100644 --- a/src/calibre/gui2/convert/single.py +++ b/src/calibre/gui2/convert/single.py @@ -18,6 +18,7 @@ from calibre.gui2.convert.metadata import MetadataWidget from calibre.gui2.convert.look_and_feel import LookAndFeelWidget from calibre.gui2.convert.page_setup import PageSetupWidget from calibre.gui2.convert.structure_detection import StructureDetectionWidget +from calibre.gui2.convert.toc import TOCWidget from calibre.ebooks.conversion.plumber import Plumber, supported_input_formats, \ @@ -138,6 +139,7 @@ class Config(ResizableDialog, Ui_Dialog): lf = widget_factory(LookAndFeelWidget) ps = widget_factory(PageSetupWidget) sd = widget_factory(StructureDetectionWidget) + toc = widget_factory(TOCWidget) output_widget = None name = 'calibre.gui2.convert.%s' % self.plumber.output_plugin.name.lower().replace(' ', '_') @@ -166,7 +168,7 @@ class Config(ResizableDialog, Ui_Dialog): if not c: break self.stack.removeWidget(c) - widgets = [self.mw, lf, ps, sd] + widgets = [self.mw, lf, ps, sd, toc] if input_widget is not None: widgets.append(input_widget) if output_widget is not None: @@ -181,6 +183,7 @@ class Config(ResizableDialog, Ui_Dialog): idx = oidx if -1 < oidx < self._groups_model.rowCount() else 0 self.groups.setCurrentIndex(self._groups_model.index(idx)) + self.stack.setCurrentIndex(idx) def setup_input_output_formats(self, db, book_id, preferred_input_format, diff --git a/src/calibre/gui2/convert/structure_detection.py b/src/calibre/gui2/convert/structure_detection.py index a757ccb8b3..66dff86aca 100644 --- a/src/calibre/gui2/convert/structure_detection.py +++ b/src/calibre/gui2/convert/structure_detection.py @@ -37,6 +37,6 @@ class StructureDetectionWidget(Widget, Ui_Form): x = getattr(self, 'opt_'+x) if not x.check(): error_dialog(self, _('Invalid XPath'), - _('The XPath expression %s is invalid.')%x.xpath).exec_() + _('The XPath expression %s is invalid.')%x.text).exec_() return False return True diff --git a/src/calibre/gui2/convert/toc.py b/src/calibre/gui2/convert/toc.py new file mode 100644 index 0000000000..0343e164ea --- /dev/null +++ b/src/calibre/gui2/convert/toc.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import with_statement + +__license__ = 'GPL v3' +__copyright__ = '2009, Kovid Goyal ' +__docformat__ = 'restructuredtext en' + + +from calibre.gui2.convert.toc_ui import Ui_Form +from calibre.gui2.convert import Widget +from calibre.gui2 import error_dialog + +class TOCWidget(Widget, Ui_Form): + + TITLE = _('Table of\nContents') + ICON = ':/images/series.svg' + HELP = _('Control the creation/conversion of the Table of Contents.') + + def __init__(self, parent, get_option, get_help, db=None, book_id=None): + Widget.__init__(self, parent, 'structure_detection', + ['level1_toc', 'level2_toc', 'level3_toc', + 'toc_threshold', 'max_toc_links', 'no_chapters_in_toc', + 'use_auto_toc', 'toc_filter', + ] + ) + self.db, self.book_id = db, book_id + self.initialize_options(get_option, get_help, db, book_id) + self.opt_level1_toc.set_msg(_('Level &1 TOC (XPath expression):')) + self.opt_level2_toc.set_msg(_('Level &2 TOC (XPath expression):')) + self.opt_level3_toc.set_msg(_('Level &3 TOC (XPath expression):')) + + + def pre_commit_check(self): + for x in ('level1', 'level2', 'level3'): + x = getattr(self, 'opt_'+x) + if not x.check(): + error_dialog(self, _('Invalid XPath'), + _('The XPath expression %s is invalid.')%x.text).exec_() + return False + return True diff --git a/src/calibre/gui2/convert/toc.ui b/src/calibre/gui2/convert/toc.ui new file mode 100644 index 0000000000..e4ebc7fee9 --- /dev/null +++ b/src/calibre/gui2/convert/toc.ui @@ -0,0 +1,104 @@ + + + Form + + + + 0 + 0 + 436 + 382 + + + + Form + + + + + + Do not add &detected chapters to the Table of Contents + + + + + + + Number of &links to add to Table of Contents + + + opt_max_toc_links + + + + + + + + + + Chapter &threshold + + + opt_toc_threshold + + + + + + + + + + &Force use of auto-generated Table of Contents + + + + + + + TOC &Filter: + + + opt_toc_filter + + + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + XPathEdit + QWidget +
convert/xpath_wizard.h
+ 1 +
+
+ + +
diff --git a/src/calibre/gui2/convert/xpath_edit.ui b/src/calibre/gui2/convert/xpath_edit.ui index c1e8946635..00f0782c47 100644 --- a/src/calibre/gui2/convert/xpath_edit.ui +++ b/src/calibre/gui2/convert/xpath_edit.ui @@ -1,7 +1,8 @@ - + + Form - - + + 0 0 @@ -9,40 +10,43 @@ 64 - + Form - - - + + + - - + + TextLabel - + true + + edit + - + - - - + + + Use a wizard to help construct the XPath expression - + ... - - + + :/images/wizard.svg:/images/wizard.svg - + 40 40 @@ -53,7 +57,7 @@ - + diff --git a/src/calibre/gui2/convert/xpath_wizard.py b/src/calibre/gui2/convert/xpath_wizard.py index a98db16c09..63914b0b94 100644 --- a/src/calibre/gui2/convert/xpath_wizard.py +++ b/src/calibre/gui2/convert/xpath_wizard.py @@ -76,12 +76,18 @@ class XPathEdit(QWidget, Ui_Edit): def text(self): return unicode(self.edit.text()) + @property + def xpath(self): + return self.text + def check(self): from calibre.ebooks.oeb.base import XPNSMAP from lxml.etree import XPath try: - XPath(self.text, namespace=XPNSMAP) + XPath(self.text, namespaces=XPNSMAP) except: + import traceback + traceback.print_exc() return False return True