Skip to content

refactor(import): move 8 import-to-PDF paths off the UI thread#38

Merged
nelsonduarte merged 1 commit into
mainfrom
refactor/import-pdf-background
May 6, 2026
Merged

refactor(import): move 8 import-to-PDF paths off the UI thread#38
nelsonduarte merged 1 commit into
mainfrom
refactor/import-pdf-background

Conversation

@nelsonduarte
Copy link
Copy Markdown
Owner

Summary

Migrate the last remaining synchronous tool — import_pdf.py — to BasePage._run_background. With this PR the long-running-tools background-task migration is complete: no tool calls QApplication.processEvents() anymore.

Per-converter pattern

  • Optional-dep ImportError check on the main thread BEFORE launching the worker, with localized "library required" dialog via QMessageBox.critical. Reuses the existing tool.convert.dep_docx / dep_pptx / dep_xlsx / dep_epub keys; adds 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-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_done runs on the main thread via the @Slot dispatcher and calls the existing self._done(out_path) helper.

Changes

  • app/tools/import_pdf.py — 8 methods migrated (_convert_txt / images / md / docx / pptx / xlsx / html / epub). Drop QApplication import (no longer used).
  • app/translations.json — 1 new key × 8 languages (tool.import.dep_bs4).

Test plan

  • Smoke test on Ubuntu 26.04 + Py3.14.4 (offscreen): drives all 8 converters with minimal fixtures (PIL PNG / docx / pptx / xlsx / ebooklib EPUB) and asserts on_done fires 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 1530B
  • Live GUI on Windows + Py3.14: large multi-file import (10+ DOCX or 50-slide PPTX) no longer freezes the UI; Cancel button aborts at next iteration boundary.
  • Spot-check optional-dep error path: rename a wheel temporarily and confirm the localized "library required" dialog appears for HTML/EPUB.

Background-task migration: complete

After this lands, every tool with a long-running action goes through TaskRunner / _run_background:

  • compress, OCR, convert (8 paths), watermark, N-up, page_numbers, import (8 paths)

🤖 Generated with Claude Code

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>
@nelsonduarte nelsonduarte merged commit 3803d90 into main May 6, 2026
3 checks passed
@nelsonduarte nelsonduarte deleted the refactor/import-pdf-background branch May 6, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant