Add various polish actions to Tweak Book

This commit is contained in:
Kovid Goyal 2013-11-08 15:35:38 +05:30
parent 45edfa442c
commit 862bc734f2
5 changed files with 51 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 776 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -11,12 +11,12 @@ from functools import partial
from PyQt4.Qt import ( from PyQt4.Qt import (
QObject, QApplication, QDialog, QGridLayout, QLabel, QSize, Qt, QObject, QApplication, QDialog, QGridLayout, QLabel, QSize, Qt,
QDialogButtonBox, QIcon, QTimer, QPixmap) QDialogButtonBox, QIcon, QTimer, QPixmap, QTextBrowser, QVBoxLayout)
from calibre import prints from calibre import prints
from calibre.ptempfile import PersistentTemporaryDirectory from calibre.ptempfile import PersistentTemporaryDirectory
from calibre.ebooks.oeb.base import urlnormalize from calibre.ebooks.oeb.base import urlnormalize
from calibre.ebooks.oeb.polish.main import SUPPORTED from calibre.ebooks.oeb.polish.main import SUPPORTED, tweak_polish
from calibre.ebooks.oeb.polish.container import get_container as _gc, clone_container, guess_type from calibre.ebooks.oeb.polish.container import get_container as _gc, clone_container, guess_type
from calibre.ebooks.oeb.polish.replace import rename_files from calibre.ebooks.oeb.polish.replace import rename_files
from calibre.gui2 import error_dialog, choose_files, question_dialog, info_dialog from calibre.gui2 import error_dialog, choose_files, question_dialog, info_dialog
@ -156,12 +156,37 @@ class Boss(QObject):
if not self.check_dirtied(): if not self.check_dirtied():
return return
self.add_savepoint(_('Edit Table of Contents')) self.add_savepoint(_('Edit Table of Contents'))
d = TOCEditor(parent=self.gui) d = TOCEditor(title=self.current_metadata.title, parent=self.gui)
if d.exec_() != d.Accepted: if d.exec_() != d.Accepted:
self.rewind_savepoint() self.rewind_savepoint()
return return
self.update_editors_from_container() self.update_editors_from_container()
def polish(self, action, name):
if not self.check_dirtied():
return
self.add_savepoint(name)
try:
report = tweak_polish(current_container(), {action:True})
except:
self.rewind_savepoint()
raise
self.apply_container_update_to_gui()
from calibre.ebooks.markdown import markdown
report = markdown('# %s\n\n'%self.current_metadata.title + '\n\n'.join(report), output_format='html4')
d = QDialog(self.gui)
d.l = QVBoxLayout()
d.setLayout(d.l)
d.e = QTextBrowser(d)
d.l.addWidget(d.e)
d.e.setHtml(report)
d.bb = QDialogButtonBox(QDialogButtonBox.Close)
d.l.addWidget(d.bb)
d.bb.rejected.connect(d.reject)
d.bb.accepted.connect(d.accept)
d.resize(600, 400)
d.exec_()
# Renaming {{{ # Renaming {{{
def rename_requested(self, oldname, newname): def rename_requested(self, oldname, newname):
if not self.check_dirtied(): if not self.check_dirtied():

View File

@ -6,6 +6,8 @@ from __future__ import (unicode_literals, division, absolute_import,
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
from functools import partial
from PyQt4.Qt import ( from PyQt4.Qt import (
QDockWidget, Qt, QLabel, QIcon, QAction, QApplication, QWidget, QDockWidget, Qt, QLabel, QIcon, QAction, QApplication, QWidget,
QVBoxLayout, QStackedWidget, QTabWidget, QImage, QPixmap, pyqtSignal) QVBoxLayout, QStackedWidget, QTabWidget, QImage, QPixmap, pyqtSignal)
@ -179,6 +181,18 @@ class Main(MainWindow):
group = _('Tools') group = _('Tools')
self.action_toc = reg('toc.png', _('&Edit Table of Contents'), self.boss.edit_toc, 'edit-toc', (), _('Edit Table of Contents')) self.action_toc = reg('toc.png', _('&Edit Table of Contents'), self.boss.edit_toc, 'edit-toc', (), _('Edit Table of Contents'))
# Polish actions
group = _('Polish')
self.action_subset_fonts = reg(
'subset-fonts.png', _('&Subset embedded fonts'), partial(
self.boss.polish, 'subset', _('Subset fonts')), 'subset-fonts', (), _('Subset embedded fonts'))
self.action_embed_fonts = reg(
'embed-fonts.png', _('&Embed referenced fonts'), partial(
self.boss.polish, 'embed', _('Embed fonts')), 'embed-fonts', (), _('Embed referenced fonts'))
self.action_smarten_punctuation = reg(
'smarten-punctuation.png', _('&Smarten punctuation'), partial(
self.boss.polish, 'smarten_punctuation', _('Smarten punstuation')), 'smarten-punctuation', (), _('Smarten punctuation'))
def create_menubar(self): def create_menubar(self):
b = self.menuBar() b = self.menuBar()
@ -200,6 +214,9 @@ class Main(MainWindow):
e = b.addMenu(_('&Tools')) e = b.addMenu(_('&Tools'))
e.addAction(self.action_toc) e.addAction(self.action_toc)
e.addAction(self.action_embed_fonts)
e.addAction(self.action_subset_fonts)
e.addAction(self.action_smarten_punctuation)
def create_toolbar(self): def create_toolbar(self):
self.global_bar = b = self.addToolBar(_('Book tool bar')) self.global_bar = b = self.addToolBar(_('Book tool bar'))
@ -210,6 +227,12 @@ class Main(MainWindow):
b.addAction(self.action_save) b.addAction(self.action_save)
b.addAction(self.action_toc) b.addAction(self.action_toc)
self.polish_bar = b = self.addToolBar(_('Polish book tool bar'))
b.setObjectName('polish_bar') # Needed for saveState
b.addAction(self.action_embed_fonts)
b.addAction(self.action_subset_fonts)
b.addAction(self.action_smarten_punctuation)
def create_docks(self): def create_docks(self):
self.file_list_dock = d = QDockWidget(_('&Files Browser'), self) self.file_list_dock = d = QDockWidget(_('&Files Browser'), self)
d.setObjectName('file_list_dock') # Needed for saveState d.setObjectName('file_list_dock') # Needed for saveState