pyopticon.built_in_widgets package
Submodules
pyopticon.built_in_widgets.spiciness_widget module
- class pyopticon.built_in_widgets.spiciness_widget.SpicinessWidget(parent_dashboard, name, nickname)
Bases:
GenericWidgetThis is a silly demonstration of extending the GenericWidget class to make a widget that has no serial connection and only updates every few seconds. The superclass constructor is called with no_serial=True and update_every_n_cycles=3. The widget simply reports how spicy it’s feeling with a value randomly selected from a list.
The use_serial=False option is intended to allow the creation of widgets that do something besides poll a serial connection to update their information, but still have access to the data-logging and other machinery of the GenericWidget class. You might use this to:
Make a widget that communicates with a physical device through some means other than a Pyserial serial connection, e.g. a Python package provided by the instrument vendor.
Make a widget that reads the latest values from some instrument’s logfile on the computer. This can simplify post-experiment data fusion even if the entire instrument (e.g., a gas chromatograph) is far too complex to configure and run with a PyOpticon interface alone.
Make a standalone widget, e.g. a handy calculator, that has GUI elements but doesn’t interface with any physical devices.
The update_every_n_cycles option is meant to help interface with instruments that update less than once per second or take a long time to query. For example, a gas chromatograph will only log new concentration data every few minutes, while reading its logfile may be a slow operation, so polling it every 10 or 20 seconds is plenty and avoids gumming up the program with unnecessary reads. Similarly, if a device for some reason required serial queries to be spaced 200ms apart, and one needed to make 6 queries to extract all the data one wanted from it, beginning a sequence of 6 queries every second would overwhelm the instrument. Using update_every_n_cycles to start a sequence of 6 queries every other or every third second would avoid that issue.
- Parameters:
parent_dashboard (pyopticon.dashboard.PyOpticonDashboard) – The dashboard object to which this device will be added
name (str) – The name that the widget will be labeled with, and under which its data will be logged, e.g. “Methane Mass Flow Controller”
nickname (str) – A shortened nickname that can be used to identify the widget in automation scripts, e.g. “CH4 MFC”
- on_failed_serial_open(success)
Set readout to ‘no reading’ if initialization failed.
- on_update()
Update the device by polling the serial connection.
- on_serial_query()
“Nothing is done on a serial query for this device.
- on_serial_read()
Updates the readout with a randomly selected level of spiciness. Returns True if this process was successful and False otherwise.
- Returns:
True if the device updated itself successfully, False otherwise.
- Return type:
bool
- on_serial_close()
When serial is closed, set all readouts to ‘None’.
pyopticon.built_in_widgets.title_widget module
- class pyopticon.built_in_widgets.title_widget.TitleWidget(parent_dashboard, title, font_size)
Bases:
MinimalWidgetA simple widget containing only text, intended for making a big-text title for a dashboard. Uses the MinimalWidget superclass, since all of the GenericWidget machinery is unnecessary.
- Parameters:
parent_dashboard (pyopticon.dashboard.PyOpticonDashboard) – The dashboard object to which this device will be added
title (str) – The text to be displayed within this widget, called ‘title’ because it’s likely to be the title of the entire dashboard.
font_size (int) – The size of font to be used in the text, as an integer.