pyopticon._system._automation_widget module
- class pyopticon._system._automation_widget.AutomationWidget(parent_dashboard)
Bases:
MinimalWidgetThis widget contains buttons to show/hide the console (on PC’s), show/hide all the other widgets’ serial controls, print automation help to the console, and open help/tutorials.
- Parameters:
parent (pyopticon.dashboard.Dashboard) – The dashboard to which this widget will be added.
- _on_log_toggle()
- get_frame()
Get the tkinter frame on which this object is drawn.
- Returns:
The widget’s tkinter frame
- Return type:
tkinter.Frame
- get_parent_dashboard()
Get the automation widget’s parent Dashboard object.
- Returns:
The Dashboard to which this widget was added
- Return type:
pyopticon.dashboard.Dashboard
- log_data()
The automation widget will optionally log whatever step of the automation it’s currently on, in order to make splitting up time series data easier in post-experiment analysis.
- Returns:
A dict of the widget’s loggable fields and their current values
- Return type:
dict
- schedule_delay(delay)
This function is meant to be called in automation scripts. It causes a delay before a subsequent call to schedule_function or schedule_action is executed. It fills a role in an automation script similar to time.sleep() in a Python program.
In the automation script, you can just say ‘schedule_delay(…)’; you don’t need to say ‘dashboard.automation_widget.schedule_delay(…)’ or similar.
- Parameters:
delay (str) – The delay in hh:mm:ss format
- schedule_function(function)
This function is meant to be called in automation scripts. It executes whatever function is passed after any delay that has been caused by preceding calls to schedule_delay. If you are trying to change a widget field and then confirm the change, it’s better to use schedule_action – this method is meant to let you execute arbitrary functions at a scheduled time within an automation script, e.g. printing a widget’s instance variable to the console.
In the automation script, you can just say ‘schedule_function(…)’; you don’t need to say ‘dashboard.automation_widget.schedule_function(…)’ or similar.
- Parameters:
function (function) – The function to be executed at the scheduled time
- schedule_action(target_widget_nickname, target_field_name, new_target_value, confirm=True)
This function is meant to be called in automation scripts. It changes the target field in the target widget to a certain value, then optionally executes that widget’s confirm function. It’s useful for scheduling most simple automation tasks, e.g., flipping a valve at a certain time.
If you want to change multiple fields on a widget, make several consecutive calls to schedule_action, with confirm=False on all but the last and confirm=True on the last. That way, the widget’s confirm function is only executed once all its fields have been set properly.
In the automation script, you can just say ‘schedule_action(…)’; you don’t need to say ‘dashboard.automation_widget.schedule_action(…)’ or similar.
- Parameters:
target_widget_nickname (str) – The nickname of the widget whose field you want to change.
target_field_name (str) – The name of the widget field that you want to change.
new_target_value (str) – The new value to which the target field should be set. Numbers should be typecast to str first.
confirm (bool, optional) – True if the target widget’s confirm method should be called after updating the field; False if not.
- _schedule_helper(target_widget, field_name, new_target_value, confirm_function)
This is used to generate function objects that will be executed at a future time as a result of the schedule_action method
- Parameters:
target_widget (pyopticon.generic_widget.GenericWidget) – The widget whose field you want to change.
field_name (str) – The name of the widget field that you want to change.
new_target_value (str) – The new value to which the target field should be set. Numbers should be typecast to str first.
confirm_function (function) – The widget’s confirm function, or None if no confirm function should be executed.
- schedule_await_condition(condition, console_message='(No summary provided)')
This function schedules the script to ‘await’ a certain condition, such as a thermocouple temperature dropping below a certain value, before allowing the automation script to proceed. Data logging and GUI functions proceed in the meantime. While the script is awaiting the condition, a ‘Skip’ button also becomes available in the automation control widget.
- Parameters:
condition – A function that takes a Dashboard object as its only argument and returns True if the condition to proceed is met and False if not. See tutorials for an example.
console_message – A message that’s printed to the console as user-legible shorthand for the condition being awaited, e.g. ‘Temperature < 100C’
- _schedule_await_condition_helper(condition, console_message)
This is a function whose execution is scheduled by schedule_await_condition. It checks whether the awaited condition is met. If so, it lets the automation script proceed. If not, or if an error is raised, it causes the automation panel to check again during the next automation update cycle (usually 1 second later). It does various cosmetic things to manage the ‘time to next step’ and ‘time remaining’ readouts, as well as showing and hiding the ‘skip’ button.
- Parameters:
condition – A function that takes a Dashboard object as its only argument and returns True if the condition to proceed is met and False if not.
console_message – A message that’s printed to the console as user-legible shorthand for the condition being awaited, e.g. ‘Temperature < 100C’
- _skip_await()
This function gets called when the ‘skip await’ button gets pressed. It just sets a flag that _schedule_await_condition_helper reads.
- _update_tasks()
This function gets called every polling interval and checks whether it’s time to execute the next task(s) in the automation queue. There’s some other machinery to handle pausing the script and update GUI components like the ‘n out of m steps done’ and ‘xx:xx:xx to go’ readouts.
- _start_automated_tasks()
Start an automation script. Generates a list of absolute times at which each action in the automation queue will be executed, and starts calling _update_tasks every second.
- _load_automation_file()
Load an automation script from a file. Generates a list of functions and a list of the delays before each one will be executed after starting the script. Sets GUI elements like ‘0/n steps done’ and ‘xx:xx:xx remaining’.
Note that this method loads the contents of the automation file and calls exec() on it. This is obviously not secure; only use automation scripts whose authors you trues. exec() is called in a namespace with schedule_delay, schedule_action, schedule_function, and schedule_await_condition already defined as local variables for you to use.
- _pause_automated_tasks()
Pause the automation script
- _stop_automated_tasks()
Stop the automation script and go back to the beginning
- _buttons_running_mode()
Disable ‘start’ and ‘load’ buttons, turn frame green, add ‘running’ label.
- _buttons_paused_mode()
Disable ‘pause’ and ‘load’ buttons, turn frame yellow, add ‘paused’ label.
- _buttons_stopped_mode()
Disable ‘pause’ and ‘stop’ buttons, turn frame red, add ‘inactive’ label.