Writing a task script

When you write a Python script that runs with ‘srsgui`, you make a subclass of Task class, and implement setup, test and cleanup.

Following is the simplest form of a task. Even though it does not do much, srsgui is happy to run the task, if it is included in a .taskconfig file.

from srsgui import Task

class ZerothTask(Task):
    def setup(self):
        print('Setup done.')

    def test(self):
        print('Test finished.')

    def cleanup(self):
        print('Cleanup done.')

When a task runs, the setup() method runs first. if the setup finished with an exception, the task is aborted without running test() or cleanup(). If the setup() method completes without exception, the test() method runs next. Regardless of exception happened while the test() is finished, running the cleanup() method completes the task.

You write a task based on the template any way you want, utilizing the resources and APIs provided in Task class for Graphic User Interface (GUI) inputs and outputs. As long as your tasks use the limited GUI resources available from Task class, your task will run along with srsgui application.

A task is a Python thread (if it is run by an application with a Qt backend, it will be QThread.), running as concurrently with the main application.

The Task is designed with much consideration on protection of the main application from crashing caused by unhandled Exception, while a buggy task running. srsgui provides information as much as Python interpreter does. After modifying a task, reopen the .taskconfig file will reload the modified task before you run it again.

The main application provides resources that a task can use, and responds to the callbacks from the task. The resources are set using the APIs provided by the task.

  • set_inst_dict is to set the instrument dictionary that contains the instrument instances.

  • set_data_dict is to set the data dictionary that contains the data instances.

  • set_figure_dict is to set the figure dictionary that contains the figure instances.

  • set_session_handler is

    to set the session handler that saves the data to a file.

  • set_callback_handler is to set the callback handler that handles the callbacks from the task.

The main application and the running task are separate threads, and the main application responds only to the callbacks from the task.

For text output,
For python logging,
  • get_logger is to get the logger instance for the task.

  • logger.debug is to use the logger instance to log debug messages.

  • logger.info is to use the logger instance to log info messages.

  • logger.error is to use the logger instance to log error messages.

  • logger.warning is to use the logger instance to log warning messages.

  • logger.critical is to use the logger instance to log critical messages.

For the input panel in the srsgui main window,

input_parameters is a dictionary that contains the input parameters that will be displayed in the input panel.

  • get_all_input_parameters is to get all the input parameters that are displayed in the input panel.

  • set_input_parameter is to set the value of an input parameter.

  • get_input_parameter is to get the value of an input parameter.

  • notify_parameter_changed is a wrapper method for callbacks.parameter_changed <srsgui.task.callbacks.parameter_changed(), which is to notify the main application that the value of an input parameter has changed. The main application will update the value of the input parameter in the input panel.

For Matplotlib Figures,

callbacks.request_figure_update - draw callbacks.notify_data_available - update clear_figure get_figure

For a question dialog box during running a task,
For the session_handler that save information from a task to a file,

add_details create_table add_data_to_table create_table_in_file add_to_table_in_file

For inst_dict
  • get_instrument is to retrieve the Instrument subclass instance named in the .taskconfig file. Once getting the instrument instance, you can use it in the task in the same way with the instance created from a Python interpreter.

Once you get used to the APIs of Task class, you can write scripts that runs as a part of srsgui.