srsgui.task package
srsgui.task.task module
- class srsgui.task.task.Task(parent=None)
Bases:
QThread
Base class for derived Task subclasses.
The parent process starts a task instance as a separate thread. Before starting the task thread, the parent process injects resources the task thread dependent on (instruments, figures, session handler), and connects callback functions to handle the requests from the task. The task uses the resources and send requests without knowing much about how they are handled by the parent process. It makes easy to write a derived task as a simple Python script starting from the base class.
- exception TaskException
Bases:
Exception
- exception TaskSetupFailed
Bases:
TaskException
- exception TaskRunFailed
Bases:
TaskException
- EscapeForResult = '@RESULT@'
- EscapeForDevice = '@DEVICE@'
- EscapeForStatus = '@STATUS@'
- EscapeForStart = '@START@'
- EscapeForStop = '@STOP@'
Escape strings used in stdout redirection to GUI
- input_parameters = {'Define parameters': <srsgui.task.inputs.FloatInput object>, 'before use!! ': <srsgui.task.inputs.StringInput object>}
Class variable to define parameters used in the task. values in input_parameters can be changed interactively from GUI before the task runs IntegerInput, FloatInput, StringInput, ListInput and InstrumentInput can be used as dictionary values.
- additional_figure_names = []
Names for extra Matplotlib figures added to use in the task If empty, only one figure named ‘plot’ is available as a default.
- InitialImage = None
Image file for parent to display instead of the default logo image when the task is selected.
- setup()
Subclass needs to override this method. Put all preparation for a task in the overridden method.
- test()
Subclass must override this method. Check if is_running() is true to continue. Add data using in add_details, create_table, and add_data_to_table.
- cleanup()
Subclass need to override this method Put any cleanup after task in the overridden method
- get_logger(name)
Get a logger with its handler available from the parent
- basic_setup() runs before task-specific setup()
- basic_cleanup()
basic_cleanup runs after task-specific cleanup()
- run()
Overrides Thread run() method. task-speciic test() runs inside this method.
- start()
Overrides Thread start() method.
- stop()
Make is_running() returns False. A task should check is_running() frequently. Stop if it returns False.
- delay(seconds)
Check if the task is stopped and wait for the given seconds.
- set_session_handler(session_handler)
Parent should set a session handler for Task to use file output.
- set_callback_handler(callback_handler: Callbacks)
Parent should set a callback handler to handle events from Task.
- set_inst_dict(inst_dict)
Parent should set inst_dict for Task to use instruments available from the parent.
- set_data_dict(data_dict)
A dictionary injected when the task run. It is a way to share data among different tasks Do not reset the whole dictionary unless you know what you are doing.
- set_figure_dict(figure_dict)
Parent should set figure_dict for Task to use Matplotlib figures available from the parent.
- get_figure(name=None) Figure
Get a Matplotlib figure from figure_dict. if name is None, it will reutrn the first figure in figure_dict as the defualt
- clear_figures()
Clear all the figures in figure_dict
- is_running()
Task should check is_running() is True. If it returns False, Task should stop ASAP.
- is_task_passed()
- set_task_passed(status)
- is_error_raised()
Check if Task stopped with an error
- set_error_raised()
Mark Task is stopped with an error
- add_details(msg: str, key='summary')
- create_table(name: str, *args)
- add_data_to_table(name: str, *args)
- create_table_in_file(name, *args)
- add_to_table_in_file(*args, format_list=None)
- add_dict_to_file(name, data_dict)
Add a dictionary to the file.
- save_result(msg)
- round_float(number)
- update_status(message)
Output to the status bar at the bottom of srsgui application
- display_device_info(message='', device_name=None, update=False, clear=False)
output to device info windows
- display_result(message, clear=False)
output to the result window
- write_text(text)
- get_input_parameter(name)
- get_all_input_parameters()
- classmethod set_input_parameter(name, value)
- notify_parameter_changed()
- request_figure_update(figure=None)
- update_figure(figure: Figure)
- notify_data_available(data={})
- update(data: dict)
when notify_data_available is called, this method handles data processing and display update. By default, it does no data handling, but figure update request. GUI related data processing needs to be done here to be handled in proper order by the GUI event loop handler.
- get_instrument(name)
Get an instrument from parent’s inst_dict and check its validity
- ask_question(question, return_type=<class 'bool'>, timeout=300.0)
This method display message with an OK button with return_type set to None, it asks a yes/no question when with return_type set to bool, and it asks for a string when with return_type set to str. This method returns True/False for a yes/no question, and it returns a string for the return type of str. it returns None if the question is aborted
- staticMetaObject = <PySide2.QtCore.QMetaObject object>
- question_background_update()
Repeat this method, while a dialog box is open with ask_question method. A Task subclass can re-implement this method as it needs
- set_log_error_detail(state=False)
Set True To log exception traceback for debugging
- log_exception(err)
With set_log_error_detail(True), an error is logged with traceback information
srsgui.task.callbacks module
srsgui.task.inputs module
Interface for input variables between Task and InputPanel in GUI
- class srsgui.task.inputs.IntegerInput(default_value, suffix='', minimum=0, maximum=65535, single_step=1)
Bases:
BaseInput
- class srsgui.task.inputs.FloatInput(default_value, suffix='', minimum=0.0, maximum=100.0, single_step=1)
Bases:
BaseInput
- class srsgui.task.inputs.ListInput(item_list, default_index=0)
Bases:
BaseInput
- get_value()
- set_value(text)
- get_index()
- set_index(index)
- class srsgui.task.inputs.BoolInput(item_list=('False', 'True'), default_index=0)
Bases:
ListInput
- get_value()
- set_value(value)
- class srsgui.task.inputs.IntegerListInput(item_list, default_index=0)
Bases:
ListInput
- get_value()
- set_value(int_value)
- class srsgui.task.inputs.FloatListInput(item_list, fmt='{:.2e}', default_index=0)
Bases:
ListInput
- get_value()
- set_value(float_number)
- class srsgui.task.inputs.InstrumentInput(default_index=0)
Bases:
ListInput
InputPanel will setup a QComboBox widget with inst_dict
- class srsgui.task.inputs.FindListInput(default_index=0)
Bases:
ListInput
Hold a list of available resources from a communication interface find() method
- class srsgui.task.inputs.CommandInput(cmd_name, cmd_instance, default_value=None)
Bases:
IntegerInput
- set_inst_name(inst_name)
- get_value()
srsgui.task.config module
srsgui.task.sessionhandler module
- class srsgui.task.sessionhandler.SessionHandler(use_file=False, use_db=False, use_api=False)
Bases:
object
- is_open()
- set_data_directory(base_dir, task_dict_name)
- open_session(sn, reuse_last_session=True)
- close_session(is_passed=False)
- create_new_task_result(result: TaskResult)
- create_file(task_name)
- add_dict_to_file(name, data_dict)
- create_table_in_file(name, *args)
args: list of header string
- add_to_table_in_file(name, *args, format_list=None)
- close_file()
- close_data_dir()
- is_data_dir_closed(directory)
- get_data_dir(serial_number, reuse_last_run_number=True)
- static get_last_run_number(unit_data_dir)
srsgui.task.taskresult module
- srsgui.task.taskresult.timestamp_now()
- srsgui.task.taskresult.strip_tags(message)
Removes HTML tags
- class srsgui.task.taskresult.ResultLogHandler(task_result)
Bases:
Handler
- emit(record)
Do whatever it takes to actually log the specified logging record.
This version is intended to be implemented by subclasses and so raises a NotImplementedError.
- class srsgui.task.taskresult.TaskResult(task_class_name, task_id=None)
Bases:
object
An object that stores relevant test result data
Any data stored in attributes of this object will end up saved in the database
Be sure to store only json-serializable objects in the attributes of this class (i.e. only python primitives like dict, list, str, int) or it will throw an error when it tries to store it in a database
- reserved = {}
- clear()
- set_start_time_now()
- set_stop_time_now()
- set_aborted(state=True)
- set_passed(state=True)
- append_error(msg)
- add_details(msg: str, key='summary')
- create_table(name: str, *args)
- add_data_to_table(name: str, *args)