mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Show report after polishing
This commit is contained in:
parent
c37e2b4be8
commit
45dff60eaf
@ -92,7 +92,7 @@ def polish(file_map, opts, log, report):
|
|||||||
rt = lambda x: report('\n### ' + x)
|
rt = lambda x: report('\n### ' + x)
|
||||||
st = time.time()
|
st = time.time()
|
||||||
for inbook, outbook in file_map.iteritems():
|
for inbook, outbook in file_map.iteritems():
|
||||||
report('Polishing: %s'%(inbook.rpartition('.')[-1].upper()))
|
report('## Polishing: %s'%(inbook.rpartition('.')[-1].upper()))
|
||||||
ebook = get_container(inbook, log)
|
ebook = get_container(inbook, log)
|
||||||
|
|
||||||
if opts.subset:
|
if opts.subset:
|
||||||
@ -135,6 +135,7 @@ def gui_polish(data):
|
|||||||
log(REPORT)
|
log(REPORT)
|
||||||
for msg in report:
|
for msg in report:
|
||||||
log(msg)
|
log(msg)
|
||||||
|
return '\n\n'.join(report)
|
||||||
|
|
||||||
def option_parser():
|
def option_parser():
|
||||||
from calibre.utils.config import OptionParser
|
from calibre.utils.config import OptionParser
|
||||||
|
@ -12,7 +12,7 @@ from collections import OrderedDict
|
|||||||
|
|
||||||
from PyQt4.Qt import (QDialog, QGridLayout, QIcon, QCheckBox, QLabel, QFrame,
|
from PyQt4.Qt import (QDialog, QGridLayout, QIcon, QCheckBox, QLabel, QFrame,
|
||||||
QApplication, QDialogButtonBox, Qt, QSize, QSpacerItem,
|
QApplication, QDialogButtonBox, Qt, QSize, QSpacerItem,
|
||||||
QSizePolicy, QTimer, QModelIndex)
|
QSizePolicy, QTimer, QModelIndex, QTextEdit)
|
||||||
|
|
||||||
from calibre.gui2 import error_dialog, Dispatcher
|
from calibre.gui2 import error_dialog, Dispatcher
|
||||||
from calibre.gui2.actions import InterfaceAction
|
from calibre.gui2.actions import InterfaceAction
|
||||||
@ -21,8 +21,7 @@ from calibre.gui2.dialogs.progress import ProgressDialog
|
|||||||
from calibre.ptempfile import PersistentTemporaryDirectory
|
from calibre.ptempfile import PersistentTemporaryDirectory
|
||||||
from calibre.utils.config_base import tweaks
|
from calibre.utils.config_base import tweaks
|
||||||
|
|
||||||
|
class Polish(QDialog): # {{{
|
||||||
class Polish(QDialog):
|
|
||||||
|
|
||||||
def __init__(self, db, book_id_map, parent=None):
|
def __init__(self, db, book_id_map, parent=None):
|
||||||
from calibre.ebooks.oeb.polish.main import HELP
|
from calibre.ebooks.oeb.polish.main import HELP
|
||||||
@ -165,6 +164,77 @@ class Polish(QDialog):
|
|||||||
num=num, tot=len(self.book_id_map), title=mi.title))
|
num=num, tot=len(self.book_id_map), title=mi.title))
|
||||||
|
|
||||||
self.jobs.append((desc, data, book_id, base))
|
self.jobs.append((desc, data, book_id, base))
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
class Report(QDialog): # {{{
|
||||||
|
|
||||||
|
def __init__(self, parent):
|
||||||
|
QDialog.__init__(self, parent)
|
||||||
|
self.gui = parent
|
||||||
|
self.setAttribute(Qt.WA_DeleteOnClose, False)
|
||||||
|
self.setWindowIcon(QIcon(I('polish.png')))
|
||||||
|
self.reports = []
|
||||||
|
|
||||||
|
self.l = l = QGridLayout()
|
||||||
|
self.setLayout(l)
|
||||||
|
self.view = v = QTextEdit(self)
|
||||||
|
v.setReadOnly(True)
|
||||||
|
l.addWidget(self.view, 0, 0, 1, 2)
|
||||||
|
|
||||||
|
self.ign_msg = _('Ignore remaining %d reports')
|
||||||
|
self.ign = QCheckBox(self.ign_msg, self)
|
||||||
|
l.addWidget(self.ign, 1, 0)
|
||||||
|
|
||||||
|
bb = self.bb = QDialogButtonBox(QDialogButtonBox.Close)
|
||||||
|
bb.accepted.connect(self.accept)
|
||||||
|
bb.rejected.connect(self.reject)
|
||||||
|
l.addWidget(bb, 1, 1)
|
||||||
|
|
||||||
|
self.finished.connect(self.show_next, type=Qt.QueuedConnection)
|
||||||
|
|
||||||
|
self.resize(QSize(800, 600))
|
||||||
|
|
||||||
|
def setup_ign(self):
|
||||||
|
self.ign.setText(self.ign_msg%len(self.reports))
|
||||||
|
self.ign.setVisible(bool(self.reports))
|
||||||
|
self.ign.setChecked(False)
|
||||||
|
|
||||||
|
def __call__(self, *args):
|
||||||
|
self.reports.append(args)
|
||||||
|
self.setup_ign()
|
||||||
|
if not self.isVisible():
|
||||||
|
self.show_next()
|
||||||
|
|
||||||
|
def show_report(self, book_title, book_id, fmts, report):
|
||||||
|
from calibre.ebooks.markdown.markdown import markdown
|
||||||
|
self.setWindowTitle(_('Polishing of %s')%book_title)
|
||||||
|
self.view.setText(markdown('# %s\n\n'%book_title + report,
|
||||||
|
output_format='html4'))
|
||||||
|
|
||||||
|
def show_next(self, *args):
|
||||||
|
if not self.reports:
|
||||||
|
return
|
||||||
|
if not self.isVisible():
|
||||||
|
self.show()
|
||||||
|
self.show_report(*self.reports.pop(0))
|
||||||
|
self.setup_ign()
|
||||||
|
|
||||||
|
def accept(self):
|
||||||
|
if self.ign.isChecked():
|
||||||
|
self.reports = []
|
||||||
|
if self.reports:
|
||||||
|
self.show_next()
|
||||||
|
return
|
||||||
|
super(Report, self).accept()
|
||||||
|
|
||||||
|
def reject(self):
|
||||||
|
if self.ign.isChecked():
|
||||||
|
self.reports = []
|
||||||
|
if self.reports:
|
||||||
|
self.show_next()
|
||||||
|
return
|
||||||
|
super(Report, self).reject()
|
||||||
|
# }}}
|
||||||
|
|
||||||
class PolishAction(InterfaceAction):
|
class PolishAction(InterfaceAction):
|
||||||
|
|
||||||
@ -175,6 +245,7 @@ class PolishAction(InterfaceAction):
|
|||||||
|
|
||||||
def genesis(self):
|
def genesis(self):
|
||||||
self.qaction.triggered.connect(self.polish_books)
|
self.qaction.triggered.connect(self.polish_books)
|
||||||
|
self.report = Report(self.gui)
|
||||||
|
|
||||||
def location_selected(self, loc):
|
def location_selected(self, loc):
|
||||||
enabled = loc == 'library'
|
enabled = loc == 'library'
|
||||||
@ -227,9 +298,11 @@ class PolishAction(InterfaceAction):
|
|||||||
return
|
return
|
||||||
db = self.gui.current_db
|
db = self.gui.current_db
|
||||||
book_id, base, files = job.polish_args
|
book_id, base, files = job.polish_args
|
||||||
|
fmts = set()
|
||||||
for path in files:
|
for path in files:
|
||||||
fmt = path.rpartition('.')[-1].upper()
|
fmt = path.rpartition('.')[-1].upper()
|
||||||
if tweaks['save_original_format']:
|
if tweaks['save_original_format']:
|
||||||
|
fmts.add(fmt)
|
||||||
db.save_original_format(book_id, fmt, notify=False)
|
db.save_original_format(book_id, fmt, notify=False)
|
||||||
with open(path, 'rb') as f:
|
with open(path, 'rb') as f:
|
||||||
db.add_format(book_id, fmt, f, index_is_id=True)
|
db.add_format(book_id, fmt, f, index_is_id=True)
|
||||||
@ -246,7 +319,7 @@ class PolishAction(InterfaceAction):
|
|||||||
current = self.gui.library_view.currentIndex()
|
current = self.gui.library_view.currentIndex()
|
||||||
if current.isValid():
|
if current.isValid():
|
||||||
self.gui.library_view.model().current_changed(current, QModelIndex())
|
self.gui.library_view.model().current_changed(current, QModelIndex())
|
||||||
|
self.report(db.title(book_id, index_is_id=True), book_id, fmts, job.result)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app = QApplication([])
|
app = QApplication([])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user