mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-05 08:40:13 -04:00
GUI for Tale of Contents options
This commit is contained in:
parent
8b0fc486b5
commit
9cd8856738
@ -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 = ''
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
41
src/calibre/gui2/convert/toc.py
Normal file
41
src/calibre/gui2/convert/toc.py
Normal file
@ -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 <kovid@kovidgoyal.net>'
|
||||
__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
|
104
src/calibre/gui2/convert/toc.ui
Normal file
104
src/calibre/gui2/convert/toc.ui
Normal file
@ -0,0 +1,104 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Form</class>
|
||||
<widget class="QWidget" name="Form">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>436</width>
|
||||
<height>382</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="opt_no_chapters_in_toc">
|
||||
<property name="text">
|
||||
<string>Do not add &detected chapters to the Table of Contents</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="text">
|
||||
<string>Number of &links to add to Table of Contents</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>opt_max_toc_links</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="opt_max_toc_links"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_16">
|
||||
<property name="text">
|
||||
<string>Chapter &threshold</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>opt_toc_threshold</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QSpinBox" name="opt_toc_threshold"/>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="opt_use_auto_toc">
|
||||
<property name="text">
|
||||
<string>&Force use of auto-generated Table of Contents</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>TOC &Filter:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>opt_toc_filter</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLineEdit" name="opt_toc_filter"/>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="XPathEdit" name="opt_level1_toc" native="true"/>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="2">
|
||||
<widget class="XPathEdit" name="opt_level2_toc" native="true"/>
|
||||
</item>
|
||||
<item row="7" column="0" colspan="2">
|
||||
<widget class="XPathEdit" name="opt_level3_toc" native="true"/>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>XPathEdit</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>convert/xpath_wizard.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -1,7 +1,8 @@
|
||||
<ui version="4.0" >
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Form</class>
|
||||
<widget class="QWidget" name="Form" >
|
||||
<property name="geometry" >
|
||||
<widget class="QWidget" name="Form">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
@ -9,40 +10,43 @@
|
||||
<height>64</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" >
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" >
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="msg" >
|
||||
<property name="text" >
|
||||
<widget class="QLabel" name="msg">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
<property name="wordWrap" >
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>edit</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="edit" />
|
||||
<widget class="QLineEdit" name="edit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="button" >
|
||||
<property name="toolTip" >
|
||||
<item row="0" column="1">
|
||||
<widget class="QToolButton" name="button">
|
||||
<property name="toolTip">
|
||||
<string>Use a wizard to help construct the XPath expression</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon" >
|
||||
<iconset resource="../images.qrc" >
|
||||
<property name="icon">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/wizard.svg</normaloff>:/images/wizard.svg</iconset>
|
||||
</property>
|
||||
<property name="iconSize" >
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>40</height>
|
||||
@ -53,7 +57,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../images.qrc" />
|
||||
<include location="../images.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user