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
- 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()
The task-specific preparation before running test() comes in here. When a task starts, it runs setup() first. If setup() finished without error, it runs test(), the main routine of the task. If setup() finished with an error, test() will not even start.
- test()
Test() is the main part of a Task subclass. And a lot of times, test() takes long time to finish. Check frequently if is_running() is true. If not, test() should finish voluntarily as soon as possible.
- cleanup()
After test() is finished, cleanup() will run subsequently. Any cleanup and closing routine can be added here.
- 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-specific 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 is_running() 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 return the first figure in figure_dict as the default.
- 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_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')
Add msg to
TaskResult
with key. Also display it on the Result panel.
- create_table(name: str, *args)
Create a table with name in
TaskResult
- Parameters:
name (str) – name of the table
args – horizontal header for the table. The length of args defines the number of table columns
- add_data_to_table(name: str, *args)
Add args into the table with name
- Parameters:
name (str) – the name of the table into which data are added
args – A row of data The length of args should match with the number of columns in the table
- create_table_in_file(name, *args)
Create a table only saved outside
TaskResult
class.When a table will get big, use this instead of
create_table
.- Parameters:
name (str) – name of the table
args – horizontal header for the table. The length of args defines the number of table columns
- add_to_table_in_file(name, *args, format_list=None)
Add args into the table with name
- Parameters:
name (str) – the name of the table into which data are added
args – A row of data The length of args should match with the number of columns in the table
format_list (tuple) – optional format for args
- add_dict_to_file(name, data_dict)
Add a dictionary to the file.
- save_result(msg)
Deprecated. Use add_details instead
- round_float(number)
Round a float number with a resolution
Set the resolution of the number with self.round_float_resolution
- 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 the Device Info panel
- display_result(message, clear=False)
output to the Result panel
- write_text(text)
Base method to send output text to UI
- get_input_parameter(name)
Get the parameter value in input_parameters
- Parameters:
name (str) – the key to retrieve a value from input_parameter dictionary
- Return type:
The value from the dictionary
- get_all_input_parameters()
Get all the parameter values in input_parameters
- Returns:
All the value with key in the dictionary format
- Return type:
dict
- classmethod set_input_parameter(name, value)
Set manually a value in input_parameters
- Parameters:
name (str) – name of the key in the dictionary, input_parameters
value – value associated with name in the dictionary
- notify_parameter_changed()
Notify UI that there are changes in input_parameters for display update
- request_figure_update(figure=None)
It requests the parent of the task to update the figure, if the callback is set up properly.
- update_figure(figure: Figure)
Deprecated. Use request_figure_update instead.
- notify_data_available(data={})
It needs a matching update() defined in the task class that will be run by the parent. It is used to run both data processing and figure_update from the parent thread to prevent a race condition between them.
- 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
- Parameters:
name (str) – name of an instrument in inst_dict
- Returns:
an instance of Instrument in Inst_dict
- Return type:
- 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
- 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
- class srsgui.task.callbacks.DummyFigure
Bases:
object
- class srsgui.task.callbacks.Callbacks
Bases:
object
Base callbacks used by
Task
class. The parent of Task should subclass Callbacks class, override callback methods that it will use and call set_callback_handler() to make it available to the Task subclass.- started()
- finished()
- text_available(text: str)
- parameter_changed()
Override to do something when a parameter in input_parameters is changed
- figure_update_requested(fig: Figure)
- data_available(data: dict)
- new_question(question: str, return_type: object)
srsgui.task.inputs module
Interface for input parameters in Task
instance
and InputPanel
instance 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=None)
Bases:
IntegerInput
It provides the interface to
InputPanel
to query the value of a command and to change the set value of the command. Currently, InputPanel does not update self.value. Do not use get_value(). Query the command directly in a task.- set_inst_name(inst_name)
- get_value()
Do not use. The command handler used in the InputPanel that performs command query does not set the self.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
- FileExtension = 'sgdata'
- 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)