ibl_alignment_gui.app.load_worker

Generic background worker for running slow tasks off the GUI thread.

Classes

TaskProgressDialog

A modal progress dialog for a background task.

Worker

Run a single callable on a background thread and report the outcome via Qt signals.

Exceptions

TaskCancelledError

Raised inside a background task, at its next progress report, after Cancel is pressed.

exception ibl_alignment_gui.app.load_worker.TaskCancelledError[source]

Bases: Exception

Raised 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: QProgressDialog

A modal progress dialog for a background task.

Cancel (the button, Escape or closing the window) does not close it: it emits cancel_requested and 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.

closeEvent(event)[source]

Treat closing the window as Cancel; the dialog closes when the task stops.

Return type:

None

finish()[source]

Close the dialog, once the task has stopped.

Return type:

None

reject()[source]

Treat Escape (and closing the window) as Cancel until the task has stopped.

Return type:

None

class ibl_alignment_gui.app.load_worker.Worker(func, *args, report_progress=False, **kwargs)[source]

Bases: QObject

Run a single callable on a background thread and report the outcome via Qt signals.

The worker runs func(*args, **kwargs) when its run() slot is invoked (typically by a QThread.started signal). It must not touch any Qt widgets; results are delivered back to the main thread through the finished and error signals (Qt marshals cross-thread signal emissions onto the receiving thread’s event loop).

When report_progress is True the worker injects its own progress emitter as a progress_callback keyword argument, so func can report progress by calling progress_callback(message, current, total). After cancel(), the next call raises TaskCancelledError, 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_callback keyword to func that re-emits as the progress signal.

  • **kwargs (Any) – Keyword arguments forwarded to func.

Variables:
  • progress (QtCore.Signal) – Emitted as (message, current, total) while func runs (only if it reports progress).

  • finished (QtCore.Signal) – Emitted with the return value of func once it completes successfully.

  • error (QtCore.Signal) – Emitted with a formatted traceback string if func raises.

  • cancelled (QtCore.Signal) – Emitted if func stopped 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

run()[source]

Run the callable, emitting finished with its result or error on failure.

Return type:

None