organoid_tracker.gui.worker_job module

A worker job is a job that is applied once to each experiment that is currently open in the GUI. It allows you to collect some measurement, or make some change to each experiment. It is run on a worker thread, which avoids freezing the GUI while images are being loaded. The job is applied to each experiment, and the results are passed back to the GUI.

To get started, make a subclass of WorkerJob, and then call the submit_job function with an instance of your class.

class organoid_tracker.gui.worker_job.WorkerJob

Bases: ABC

A task that makes changes to the experiment. Will be applied to all open tabs.

copy_experiment(experiment: Experiment) Experiment

As gather_data is called on a worker thread, this method is called on the GUI thread to make a copy of the experiment. This copy will be passed to gather_data.

You would normally write something like return experiment.copy_selected(positions=True), to copy whatever data you will need on the worker thread. You should copy as few things as possible, as copying may be slow.

gather_data(experiment_copy: Experiment) Any

Gather data from the experiment. Will be called on the worker thread.

Note: the experiment will be closed (Experiment.close()) after this method is called. This is to avoid memory leaks. The original experiment (of the GUI thread) will stay open.

on_error(e: BaseException)

Called when an error occurs.

on_finished(data: Iterable[Any])

Called when the task is finished for all experiments. use_data will already have been called once for every experiment.

use_data(tab: SingleGuiTab, data: Any)

Uses the data. Called on the GUI thread, once for every experiment.

organoid_tracker.gui.worker_job.submit_job(window: Window, job: WorkerJob)

Submit a job to the worker thread.