From fea4edf432c1f6a967c983e8508d87eac9130822 Mon Sep 17 00:00:00 2001 From: bookfere Date: Fri, 3 May 2024 11:25:57 +0800 Subject: [PATCH] feat: Separated translation from conversion progress. resolved #298 --- lib/conversion.py | 11 +++++++++-- lib/translation.py | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/conversion.py b/lib/conversion.py index 8af68e1..7de6106 100644 --- a/lib/conversion.py +++ b/lib/conversion.py @@ -7,7 +7,8 @@ from calibre.gui2 import Dispatcher from calibre.utils.logging import Log, Stream from calibre.constants import DEBUG, __version__ -from calibre.ebooks.conversion.plumber import Plumber +from calibre.ebooks.conversion.plumber import ( + Plumber, CompositeProgressReporter) from calibre.ptempfile import PersistentTemporaryFile from calibre.ebooks.metadata.meta import get_metadata, set_metadata @@ -55,6 +56,8 @@ def convert_book( elements = [] def convert(self, oeb, output_path, input_plugin, opts, log): + backup_progress = self.report_progress.global_min + self.report_progress = CompositeProgressReporter(0, 1, notification) log.info('Translating ebook content... (this will take a while)') log.info(debug_info) translation.set_progress(self.report_progress) @@ -73,6 +76,10 @@ def convert(self, oeb, output_path, input_plugin, opts, log): log(sep()) log(_('Start to convert ebook format...')) log(sep()) + + self.report_progress = CompositeProgressReporter( + backup_progress, 1, notification) + self.report_progress(0., _('Outputting ebook file...')) _convert(oeb, output_path, input_plugin, opts, log) plumber.output_plugin.convert = MethodType(convert, plumber.output_plugin) @@ -339,4 +346,4 @@ def callback(payload): _('Ebook Translation Log'), _('Translation Completed'), _('The translation of "{}" was completed. Do you want to ' 'open the book?').format(ebook_title), - log_is_file=True, icon=self.icon, auto_hide_after=5) + log_is_file=True, icon=self.icon, auto_hide_after=10) diff --git a/lib/translation.py b/lib/translation.py index 9f2601b..b60c66d 100644 --- a/lib/translation.py +++ b/lib/translation.py @@ -264,7 +264,7 @@ def handle(self, paragraphs=[]): consuming = round((time.time() - start_time) / 60, 2) self.log(_('Time consuming: {} minutes').format(consuming)) self.log(_('Translation completed.')) - self.progress(1, _('Outputting ebook file...')) + self.progress(1, _('Translation completed.')) def get_engine_class(engine_name=None):