ibl_alignment_gui.app.load_worker
Generic background worker for running slow tasks off the GUI thread.
Classes
A modal progress dialog for a background task. |
|
Run a single callable on a background thread and report the outcome via Qt signals. |
Exceptions
Raised inside a background task, at its next progress report, after Cancel is pressed. |
- exception ibl_alignment_gui.app.load_worker.TaskCancelledError[source]
Bases:
ExceptionRaised inside a background task, at its next progress report, after Cancel is pressed.
- class ibl_alignment_gui.app.load_worker.TaskProgressDialog(title, message, cancellable, parent)[source]
Bases:
QProgressDialogA modal progress dialog for a background task.
Cancel (the button, Escape or closing the window) does not close it: it emits
cancel_requestedand the dialog stays until the task has stopped, as the task can only stop at its next progress report. Without a Cancel button, Escape and closing are ignored.- Parameters:
title (str) – The window title.
message (str) – The initial message.
cancellable (bool) – Whether the dialog has a Cancel button.
parent (QtWidgets.QWidget or None) – The parent window.
- class ibl_alignment_gui.app.load_worker.Worker(func, *args, report_progress=False, **kwargs)[source]
Bases:
QObjectRun a single callable on a background thread and report the outcome via Qt signals.
The worker runs
func(*args, **kwargs)when itsrun()slot is invoked (typically by aQThread.startedsignal). It must not touch any Qt widgets; results are delivered back to the main thread through thefinishedanderrorsignals (Qt marshals cross-thread signal emissions onto the receiving thread’s event loop).When
report_progressis True the worker injects its own progress emitter as aprogress_callbackkeyword argument, sofunccan report progress by callingprogress_callback(message, current, total). Aftercancel(), the next call raisesTaskCancelledError, which stops the task; a task can also call it only to check for Cancel.- Parameters:
func (Callable) – The callable to run on the background thread.
*args (Any) – Positional arguments forwarded to
func.report_progress (bool) – If True, pass a
progress_callbackkeyword tofuncthat re-emits as theprogresssignal.**kwargs (Any) – Keyword arguments forwarded to
func.
- Variables:
progress (QtCore.Signal) – Emitted as
(message, current, total)whilefuncruns (only if it reports progress).finished (QtCore.Signal) – Emitted with the return value of
funconce it completes successfully.error (QtCore.Signal) – Emitted with a formatted traceback string if
funcraises.cancelled (QtCore.Signal) – Emitted if
funcstopped because Cancel was pressed.
- cancel()[source]
Ask the task to stop: its next progress report raises
TaskCancelledError.Called from the main thread; the task stops at its next progress report, not part-way through a step that does not report (e.g. a download).
- Return type:
None