8dae91c2ca
Protect pending edits on window close, keep save-as paths and drafts consistent, copy relative image resources, reject oversized table imports without truncation, and preserve independent preview scrolling during refresh. Archive rendered MHTML resources with portable references and embedded local fonts. Preserve existing outputs on export cancellation or failure. Convert editor match positions and filter directory results in linear passes. Include the previously completed editor image/table/history improvements, undoable replacement, export snapshots, shared page settings, and cancellable PDF/Word export workflow. Update documentation and version to 0.3.1. Validation: 142 pytest cases passed; GUI smoke, improvements integration, and offline MHTML/scroll reliability smoke checks passed.
37 lines
953 B
Python
37 lines
953 B
Python
from __future__ import annotations
|
|
|
|
import threading
|
|
from pathlib import Path
|
|
from PySide6.QtCore import QObject, QRunnable, Signal
|
|
|
|
|
|
class ExportCancelled(Exception):
|
|
pass
|
|
|
|
|
|
def check_cancelled(cancel: object) -> None:
|
|
if cancel is not None and cancel.is_set():
|
|
raise ExportCancelled()
|
|
|
|
|
|
class ExportSignals(QObject):
|
|
finished = Signal(object, str)
|
|
progress = Signal(str)
|
|
|
|
|
|
class ExportJob(QRunnable):
|
|
def __init__(self, callback: object) -> None:
|
|
super().__init__()
|
|
self.signals = ExportSignals()
|
|
self.cancel = threading.Event()
|
|
self.callback = callback
|
|
|
|
def run(self) -> None:
|
|
try:
|
|
result = self.callback(self.cancel, self.signals.progress.emit)
|
|
self.signals.finished.emit(result, "")
|
|
except ExportCancelled:
|
|
self.signals.finished.emit(None, "")
|
|
except Exception as exc:
|
|
self.signals.finished.emit(None, str(exc))
|