refactor: move watermark and N-up off the UI thread#35
Merged
Conversation
Both tools loop over every page of the source PDF (watermark merges the overlay onto each, N-up calls show_pdf_page per source page), which freezes the UI on documents with more than a few dozen pages. Migrate both to BasePage._run_background, following the same pattern already used by compress / OCR / convert-images: - All input validation (file exists, watermark file non-empty, password unlock, cell-geometry sanity) stays on the main thread so errors surface as proper QMessageBoxes before any work starts. - The do_work closure is a tight loop with no Qt calls, only emits worker.progress.emit(pct, label) and checks worker.is_cancelled(). - on_done runs on the main thread (via the @slot dispatcher in worker.run_task) and shows the toast / pipeline_success. Add 4 new i18n keys × 8 languages for the progress messages (progress.watermark.applying / .page, progress.nup.placing / .page). Verified end-to-end on Ubuntu 26.04 + Py3.14.4: a smoke test that runs each tool through _run_background asserts on_done fires on the main thread and the output PDF is produced (5,749 bytes for the 8-page watermark sample, 5,266 bytes for the 4-up sheet). Page-numbers and import-pdf tools still run on the UI thread — deferred because page-numbers prompts the user mid-flow about existing numbers (needs main-thread split before/after the prompt) and import-pdf has 8 conversion paths that warrant individual review. 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 watermark and N-up tools from synchronous UI-thread work to
BasePage._run_background, following the same pattern compress / OCR / convert-images already use. Both tools loop over every page of the source PDF, so on large documents the UI freezes during the entire run.Why now
Changes
do_workclosure that loops over pages emitting per-page progress.do_workclosure that builds output sheets callingshow_pdf_pagefor each cell, emitting per-source-page progress.progress.watermark.applying / .pageandprogress.nup.placing / .page.Deferred (separate PRs)
Test plan
_run_background, asserts_on_donefires on the main thread, asserts the output PDF is produced. Both pass.🤖 Generated with Claude Code