From 2834d6d258e7265c61cb8f146f4ed587dc5141f8 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 6 Feb 2013 17:08:58 +0530 Subject: [PATCH] Work on Polish Books GUI --- src/calibre/gui2/actions/polish.py | 117 ++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/actions/polish.py b/src/calibre/gui2/actions/polish.py index 0edd6538b6..6e488371fe 100644 --- a/src/calibre/gui2/actions/polish.py +++ b/src/calibre/gui2/actions/polish.py @@ -7,7 +7,9 @@ __license__ = 'GPL v3' __copyright__ = '2013, Kovid Goyal ' __docformat__ = 'restructuredtext en' -from PyQt4.Qt import (QDialog) +from PyQt4.Qt import (QDialog, QGridLayout, QIcon, QCheckBox, QLabel, QFrame, + QApplication, QDialogButtonBox, Qt, QSize, QSpacerItem, + QSizePolicy) from calibre.gui2 import error_dialog from calibre.gui2.actions import InterfaceAction @@ -18,6 +20,112 @@ class Polish(QDialog): def __init__(self, db, book_id_map, parent=None): QDialog.__init__(self, parent) + self.setWindowIcon(QIcon(I('polish.png'))) + self.setWindowTitle(ngettext( + 'Polish book', _('Polish %d books')%len(book_id_map), len(book_id_map))) + + # Help {{{ + self.help_text = { + 'polish':_( + ''' +

About Polishing books

+ +

Polishing books is all about putting the shine of + perfection onto your carefully crafted ebooks.

+ +

Polishing tries to minimize the changes to the internal code + of your ebook. Unlike conversion, it does not flatten CSS, + rename files, change font sizes, adjust margins, etc. Every + action to the left performs only the minimum set of changes + needed for the desired effect.

+ +

You should use this tool as the last step in your ebook + creation process.

+ +

Note that polishing only works on files in the + %s formats.

+ ''')%_(' or ').join(SUPPORTED), + + 'subset':_( + ''' +

Subsetting fonts

+ +

Subsetting fonts means reducing an embedded font to contain + only the characters used from that font in the book. This + greatly reduces the size of the font files (halving the font + file sizes is common).

+ +

For example, if the book uses a specific font for headers, + then subsetting will reduce that font to contain only the + characters present in the actual headers in the book. Or if the + book embeds the bold and italic versions of a font, but bold + and italic text is relatively rare, or absent altogether, then + the bold and italic fonts can either be reduced to only a few + characters or completely removed.

+ +

The only downside to subsetting fonts is that if, at a later + date you decide to add more text to your books, the newly added + text might not be covered by the subset font.

+ '''), + } # }}} + + self.l = l = QGridLayout() + self.setLayout(l) + + self.la = la = QLabel(''+_('Select actions to perform:')) + l.addWidget(la, 0, 0, 1, 2) + + count = 0 + + for name, text in ( + ('subset', _('Subset all embedded fonts')), + ): + count += 1 + x = QCheckBox(text, self) + l.addWidget(x, count, 0, 1, 1) + setattr(self, 'opt_'+name, x) + la = QLabel(' %s'%(name, _('About'))) + setattr(self, 'label_'+name, x) + la.linkActivated.connect(self.help_link_activated) + l.addWidget(la, count, 1, 1, 1) + + count += 1 + l.addItem(QSpacerItem(10, 10, vPolicy=QSizePolicy.Expanding), count, 1, 1, 2) + + la = self.help_label = QLabel('') + self.help_link_activated('#polish') + la.setWordWrap(True) + la.setTextFormat(Qt.RichText) + la.setFrameShape(QFrame.StyledPanel) + la.setAlignment(Qt.AlignLeft|Qt.AlignTop) + la.setLineWidth(2) + la.setStyleSheet('QLabel { margin-left: 75px }') + l.addWidget(la, 0, 2, count+1, 1) + l.setColumnStretch(2, 1) + + self.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) + bb.accepted.connect(self.accept) + bb.rejected.connect(self.reject) + l.addWidget(bb, count+1, 0, 1, -1) + + self.resize(QSize(800, 600)) + + def help_link_activated(self, link): + link = unicode(link)[1:] + self.help_label.setText(self.help_text[link]) + + def accept(self): + self.actions = ac = {} + something = False + for action in ('subset',): + ac[action] = bool(getattr(self, 'opt_'+action).isChecked()) + if ac[action]: + something = True + if not something: + return error_dialog(self, _('No actions selected'), + _('You must select at least one action, or click Cancel.'), + show=True) + return super(Polish, self).accept() class PolishAction(InterfaceAction): @@ -68,3 +176,10 @@ class PolishAction(InterfaceAction): if d.exec_() == d.Accepted: pass +if __name__ == '__main__': + app = QApplication([]) + app + from calibre.library import db + d = Polish(db(), {1:{'EPUB'}, 2:{'AZW3'}}) + d.exec_() +