trspectrometer.busydialog module¶
- class trspectrometer.busydialog.BusyDialog(parent=None, modal=False, title=None, label='Please wait...', progress=(0, 0), task=None, args=(), kwargs={}, callback=None)[source]¶
Bases:
QDialogRuns a task in a background thread, and makes callback when complete. A dialog is displayed, with a progress bar and label. These may be updated by the background task to communicate progress to the user.
- Parameters:
parent – QWidget parent (for example, a QMainWindow instance) to which this dialog box belongs.
modal – Set the modal window flag on the dialog.
title – String to display in the dialog title bar.
label – String to display in the dialog label.
progress – Tuple of initial current and maximum progress values.
task – Reference to function which performs the desired task. See
BusyThreadfor more information.args – Tuple of positional arguments to pass to the task function.
kwargs – Dictionary of keyword arguments to pass to the task function.
callback – Reference to function to call once task is complete. It will be passed whatever is returned from the task function.
- closeEvent(event)[source]¶
Handler for window close event. If the background task is still running, the window close event will be ignored.
- setLabel(label)[source]¶
Update the text of the dialog label. This method is thread safe and may be called by the running background task. Do not attempt to manipulate the label directly from outside the main Qt application thread!
- Parameters:
label – String to display in the dialog label.
- setProgress(progress_current, progress_maximum=-1)[source]¶
Update the progress bar of the dialog. This method is thread safe and may be called by the running background task. Do not attempt to manipulate the progress bar directly from outside the main Qt application thread!
- Parameters:
progress_current – Number representing current progress.
progress_maximum – Number representing maximum (complete) progress.
- staticMetaObject = PySide6.QtCore.QMetaObject("BusyDialog" inherits "QDialog": Methods: #41 type=Signal, signature=_task_finished_signal(PyObject), parameters=PyObject #42 type=Signal, signature=_update_label_signal(QString), parameters=QString #43 type=Signal, signature=_update_progress_signal(int,int), parameters=int, int #44 type=Signal, signature=_increment_progress_signal(int), parameters=int )¶
- class trspectrometer.busydialog.BusyThread(task=None, args=(), kwargs={}, callback=None)[source]¶
Bases:
QObjectRuns a task in a background thread, and makes callback when complete.
- Parameters:
task – Reference to function which performs the desired task. In addition to the given args and kwargs, the task will be passed a reference to the instance of this BusyThread instance. Care should be taken if manipulating the BusyThread from the separate (new task) thread, but it is provided in case it is useful (e.g. to update the GUI of the
BusyDialogsubclass). If the specified task function does not expect being passed this additional reference, then it can be ignored by wrapping with a lambda expression, e.g.task=lambda _: time.sleep(5).args – Tuple of positional arguments to pass to the task function.
kwargs – Dictionary of keyword arguments to pass to the task function.
callback – Reference to function to call once task is complete. It will be passed whatever is returned from the task function.
- staticMetaObject = PySide6.QtCore.QMetaObject("BusyThread" inherits "QObject": Methods: #4 type=Signal, signature=_task_finished_signal(PyObject), parameters=PyObject )¶