photons.app module
Main application entry point and GUI.
- class photons.app.App(config=None)[source]
Bases:
QObjectMain application entry point.
- Parameters:
config (
str) – The path to a configuration file. If not specified then uses~/photons.xml.
-
added_connection:
SignalInstance
-
removed_connection:
SignalInstance
- add_lab_logging_metadata(writer)[source]
Add the current temperature and humidity of an OMEGA iServer to the writer.
All parameters are read from the configuration file.
- Return type:
- connect_equipment(*args)[source]
Connect to equipment.
The connection to each equipment is attempted in the following order:
If a Link can be established then that gets precedence
If a BaseEquipment exists then use it
Use EquipmentRecord.connect()
- Parameters:
*args (
str) – The alias(es) of the EquipmentRecord(s) or the name(s) of Services to Link with to establish the connection.- Return type:
Link|BaseEquipment|Connection|tuple[Link|BaseEquipment|Connection,...]- Returns:
The connection(s).
- connect_manager(**kwargs)[source]
Connect to a
Manager.All keyword arguments are passed to
connect().- Return type:
- property connections
The connections to equipment.
- create_writer(prefix, *, root=None, suffix=None, use_timestamp=True, zero_padding=3)[source]
Create a new PhotonWriter to save data to.
The file path has the following structure:
<root>/<year>/<month>/<day>/<prefix>_<suffix | timestamp | run_number>.json
- Parameters:
prefix (
str) – The prefix of the filename.root (
str) – The root directory where the data is saved. If not specified then the value is determined from the <data_root> element in the configuration file.suffix (
str) – If specified, use this value as the suffix. The use_timestamp and zero_padding parameters are ignored.use_timestamp (
bool) – If True and suffix is not specified then use the current time as the suffix.zero_padding (
int) – If use_timestamp is False and suffix is not specified then use an auto-incremented run number as the suffix. The zero_padding value specifies how many leading zeros should be padded to the run number.
- Return type:
- Returns:
The writer object.
- disconnect_equipment(*args)[source]
Disconnect from equipment.
Also handles if the connection to the equipment was established via a Link.
- property equipment: dict[str, EquipmentRecord]
The equipment record`s that were specified in the configuration file.
- link(*names, timeout=10, strict=True)[source]
Create links with
Services.You must have first connected to a
Manager(seeconnect_manager()).A Link is established with the first Service that was found with the appropriate name.
- property logger
The application logger.
- static plot(data=None, block=True, **kwargs)[source]
Show the
Plotwidget.- Parameters:
data (
str|Root|Dataset|ndarray|list|tuple) – The data to initially plot. If a string then a file path. If not specified then an emtpyPlotis returned.block (
bool) – Whether to block until all plots are closed.**kwargs – If data is a filename then all keyword arguments are passed to
read(). Otherwise, ignored.
- Return type:
- Returns:
The application instance.
- property prompt
Prompt the user (see
msl.qt.prompt).
- records(*aliases, **kwargs)[source]
Returns the equipment records.
- Parameters:
*aliases (
str) – The alias(es) of the equipment records that are specified in the configuration file.**kwargs – Find all equipment records that match the specified search criteria (e.g., manufacturer, model, description). See
msl.equipment.database.Database.records()for more details.
- Return type:
Examples
>>> app.records('dmm-3458a', 'shutter', manufacturer='Keithley')
- run(show=True)[source]
Run the main application.
To override the default style, font and palette theme that is used for the QApplication you can create an <app> XML element in the configuration file with the following (optional) attributes:
<app style=”windows” font_family=”arial” font_size=”12” theme=”dark”/>
For possible themes, see
MainWindow.create_palette().- Parameters:
show (
bool) – After the application is created, either return immediately or instantiate and show the GUI (which blocks until the GUI is closed).- Return type:
- Returns:
The application instance.
- send_email(*to, subject=None, body=None)[source]
Send an email.
Requires a <smtp> element in the XML configuration file with a <settings> sub-element which is the path to an SMTP configuration file, a <from> sub-element which is the email address of the person who is sending the email and can contain multiple <to> sub-elements for the email addresses that should be emailed. For example,
<smtp> <settings>path/to/SMTP/setting.txt</settings> <from>max.planck</from> <!-- The following are optional --> <to>neils.bohr</to> <to>marie.curie</to> </smtp>
- Parameters:
to (
str) – Who to send the email to. If not specified then uses the <to> elements in the configuration file.subject (
str) – The text to include in the subject field.body (
str) – The text to include in the body of the email. The text can be enclosed in<html></html>tags to use HTML elements to format the message.
- Return type:
- static sleep(duration)[source]
Suspend execution of the calling thread for the given number of seconds.
- start_equipment_service(alias, **kwargs)[source]
Start a
Servicethat interfaces with equipment.This is a blocking call. It is meant to be invoked by the console script.
- class photons.app.MainWindow(app, **kwargs)[source]
Bases:
QMainWindowMain application window.
- Parameters:
app (
App) – The application instance.**kwargs – All keyword argument are passed to super().
-
hide_progress_bar:
SignalInstance Hide the progress bar.
-
show_indeterminate_progress_bar:
SignalInstance Show an indeterminate progress bar.
-
status_bar_message:
SignalInstance The message (text) to display in the status bar.
-
update_progress_bar:
SignalInstance Update the progress bar with a value in the range [0, 100].
- closeEvent(event)[source]
Overrides
QtWidgets.QWidget.closeEvent().- Return type:
- dragEnterEvent(event)[source]
Overrides
QtWidgets.QWidget.dragEnterEvent().- Return type:
- dropEvent(event)[source]
Overrides
QtWidgets.QWidget.dropEvent().- Return type:
- static find_widget(connection, *, parent=None, **kwargs)[source]
Returns the widget that is used for the equipment.
- Parameters:
connection (
Link|BaseEquipment|Connection) – The connection to the equipment.parent (
QWidget) – The parent widget to use for the BaseEquipmentWidget.**kwargs – All additional keyword arguments are passed to super() for the BaseEquipmentWidget.
- Raises:
RuntimeError – If a widget does not exist for the connection.
- Return type:
- on_added_connection(alias)[source]
Add a checkmark to a QAction in the Connections QMenu.
- Return type:
- on_connections_triggered(action)[source]
A QAction in the Connections QMenu was triggered.
- Return type:
- on_dock_top_level_changed(widget, is_floating)[source]
Show the Minimum, Maximum and Close buttons when a docked widget becomes floating.
- Return type:
- on_removed_connection(alias)[source]
Remove a checkmark from a QAction in the Connections QMenu.
- Return type:
- on_show_indeterminate_progress_bar()[source]
Show an indeterminate progress bar.
Call this method if a process completion rate is unknown or if it is not necessary to indicate how long the process will take.
- Return type: