From f415c6ad809aca279b807301316b6faa627e5bde Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 27 Sep 2014 10:06:25 +0530 Subject: [PATCH] Bulk metadata edit: Fix getting cover from EPUB files that have no cover image by rendering the first page as the cover not working. Fixes #1374243 [Bulk Metadata "Set from ebook file(s)" when no cover image doesn't work](https://bugs.launchpad.net/calibre/+bug/1374243) --- src/calibre/ebooks/__init__.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/__init__.py b/src/calibre/ebooks/__init__.py index 024d48c886..76c988582c 100644 --- a/src/calibre/ebooks/__init__.py +++ b/src/calibre/ebooks/__init__.py @@ -8,7 +8,7 @@ from various formats. ''' import traceback, os, re -from calibre import CurrentDir +from calibre import CurrentDir, prints class ConversionError(Exception): @@ -123,10 +123,26 @@ def render_html_svg_workaround(path_to_html, log, width=590, height=750): pass if data is None: - renderer = render_html(path_to_html, width, height) - data = getattr(renderer, 'data', None) + from calibre.gui2 import is_ok_to_use_qt + if is_ok_to_use_qt(): + data = render_html_data(path_to_html, width, height) + else: + from calibre.utils.ipc.simple_worker import fork_job, WorkerError + try: + result = fork_job('calibre.ebooks', + 'render_html_data', + (path_to_html, width, height), + no_output=True) + data = result['result'] + except WorkerError as err: + prints(err.orig_tb) + except: + traceback.print_exc() return data +def render_html_data(path_to_html, width, height): + renderer = render_html(path_to_html, width, height) + return getattr(renderer, 'data', None) def render_html(path_to_html, width=590, height=750, as_xhtml=True): from PyQt5.QtWebKitWidgets import QWebPage