refactor(import): move 8 import-to-PDF paths off the UI thread#38
Merged
Conversation
import_pdf.py was the last tool still doing heavy work synchronously on the main thread, polling QApplication.processEvents() between sources / slides / chapters. UI froze on multi-file imports and on content-rich sources (DOCX with images, PPTX with many slides, EPUB chapters). Migrate all 8 paths (TXT / images / Markdown / DOCX / PPTX / XLSX / HTML / EPUB) to BasePage._run_background, mirroring the pattern from the rest of the converters: - Optional-dep ImportError checks happen on the main thread BEFORE launching the worker, with localized "library required" dialogs via QMessageBox.critical (reusing the existing tool.convert.dep_docx / dep_pptx / dep_xlsx / dep_epub keys, plus a new tool.import.dep_bs4 for the HTML/EPUB BeautifulSoup parsers). - do_work re-imports the libs and runs the build loop with worker.is_cancelled() checks at every source / slide / chapter boundary, emitting per-source progress (PPTX nests slide granularity inside the file index for finer feedback). - on_done runs on the main thread via the @slot dispatcher and calls the existing self._done(out_path) helper. Add 1 new i18n key × 8 languages (tool.import.dep_bs4) — before this PR HTML/EPUB silently used a generic str(e) on missing BS4. Verified end-to-end on Ubuntu 26.04 + Py3.14.4: a smoke test feeds each converter a minimal source file (PIL-generated PNG, doc-/pptx-/ xlsx-built fixtures, ebooklib-built EPUB, etc.) and asserts on_done fires on the main thread with a non-empty output PDF. All 8 pass: txt 1077B / images 63KB / md 1508B / docx 1086B / pptx 794B / xlsx 1197B / html 1060B / epub 1530B. This completes the long-running-tools background-task migration — no remaining tool calls QApplication.processEvents(). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrate the last remaining synchronous tool —
import_pdf.py— toBasePage._run_background. With this PR the long-running-tools background-task migration is complete: no tool callsQApplication.processEvents()anymore.Per-converter pattern
ImportErrorcheck on the main thread BEFORE launching the worker, with localized "library required" dialog viaQMessageBox.critical. Reuses the existingtool.convert.dep_docx / dep_pptx / dep_xlsx / dep_epubkeys; adds newtool.import.dep_bs4for the HTML/EPUB BeautifulSoup parsers.do_workre-imports the libs and runs the build loop withworker.is_cancelled()checks at every source / slide / chapter boundary, emitting per-source progress. PPTX nests slide-granular progress inside the file index (f"{file}/{n}: {slide}/{total_slides}…") so multi-slide presentations show movement rather than appearing stuck on the file marker.on_doneruns on the main thread via the@Slotdispatcher and calls the existingself._done(out_path)helper.Changes
_convert_txt / images / md / docx / pptx / xlsx / html / epub). DropQApplicationimport (no longer used).tool.import.dep_bs4).Test plan
on_donefires on the main thread with a non-empty PDF. All 8 pass:txt 1077B / images 63KB / md 1508B / docx 1086B / pptx 794B / xlsx 1197B / html 1060B / epub 1530BBackground-task migration: complete
After this lands, every tool with a long-running action goes through
TaskRunner/_run_background:🤖 Generated with Claude Code