photons.app module

Main application entry point and GUI.

class photons.app.App(config=None)[source]

Bases: QObject

Main 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:

None

property config: Config

The configuration object.

connect_equipment(*args)[source]

Connect to equipment.

The connection to each equipment is attempted in the following order:

  1. If a Link can be established then that gets precedence

  2. If a BaseEquipment exists then use it

  3. 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:

None

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:

PhotonWriter

Returns:

The writer object.

property database: Database

The database object.

disconnect_equipment(*args)[source]

Disconnect from equipment.

Also handles if the connection to the equipment was established via a Link.

Parameters:

*args (str) – The alias(es) of the EquipmentRecord(s) or the name(s) of Services to disconnect from. If not specified then disconnect from all connections.

Return type:

None

disconnect_managers()[source]

Disconnect from all Managers.

Return type:

None

property equipment: dict[str, EquipmentRecord]

The equipment record`s that were specified in the configuration file.

Create links with Services.

You must have first connected to a Manager (see connect_manager()).

A Link is established with the first Service that was found with the appropriate name.

Parameters:
  • names (str) – The name(s) of the Service(s) to link with.

  • timeout (float) – The maximum number of seconds to wait when sending a request to a Manager.

  • strict (bool) – Whether to raise an error if the Service does not exist.

Return type:

Link | tuple[Link, ...]

Returns:

The link(s).

The Links that have been made to Services.

property logger

The application logger.

static play_sound(wav=None, wait=True)[source]

Play a WAV file or theme.

Parameters:
  • wav (str | Theme) – The file or Theme to play. If not specified then play a random Theme.

  • wait (bool) – Whether to wait for the WAV file to finish playing before returning. Only used if wav is a file. Specifying a Theme will always wait, since the audio data is stored in memory.

Return type:

None

static plot(data=None, block=True, **kwargs)[source]

Show the Plot widget.

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 emtpy Plot is 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:

QApplication

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:

list[EquipmentRecord]

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:

QApplication

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:

None

set_logging_level(level, *names)[source]

Set the logging level for the specified loggers.

Parameters:
  • level (int | str) – The logging level.

  • names (str) – The names of the loggers to set to level. If none are specified then defaults to the logger for this package.

Return type:

None

static sleep(duration)[source]

Suspend execution of the calling thread for the given number of seconds.

Parameters:

duration (float) – The number of seconds to sleep.

Return type:

None

start_equipment_service(alias, **kwargs)[source]

Start a Service that interfaces with equipment.

This is a blocking call. It is meant to be invoked by the console script.

Parameters:
  • alias (str) – The alias of an EquipmentRecord.

  • **kwargs – Keyword arguments.

Return type:

None

static start_service(name, **kwargs)[source]

Start a registered Service.

This is a blocking call. It is meant to be invoked by the console script.

Parameters:
  • name (str) – The name of the Service to start.

  • **kwargs – Keyword arguments.

Return type:

None

Unlink from Services.

Parameters:

names (str) – The name(s) of the Services to unlink with. If not specified then unlink from all Services.

Return type:

None

class photons.app.MainWindow(app, **kwargs)[source]

Bases: QMainWindow

Main 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:

None

static create_palette(name)[source]

Create and return a QPalette based on a colour theme.

Parameters:

name (str) – The name of the theme. Currently only supports “dark”.

Return type:

QPalette

dragEnterEvent(event)[source]

Overrides QtWidgets.QWidget.dragEnterEvent().

Return type:

None

dropEvent(event)[source]

Overrides QtWidgets.QWidget.dropEvent().

Return type:

None

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:

BaseEquipmentWidget

on_added_connection(alias)[source]

Add a checkmark to a QAction in the Connections QMenu.

Return type:

None

on_connections_triggered(action)[source]

A QAction in the Connections QMenu was triggered.

Return type:

None

on_dock_top_level_changed(widget, is_floating)[source]

Show the Minimum, Maximum and Close buttons when a docked widget becomes floating.

Return type:

None

on_hide_progress_bar()[source]

Hide the progress bar.

Return type:

None

on_plugin_closed(action, plugin)[source]

Called when a Plugin closes.

Return type:

None

on_plugins_triggered(action)[source]

A QAction in the Plugins QMenu was triggered.

Return type:

None

on_removed_connection(alias)[source]

Remove a checkmark from a QAction in the Connections QMenu.

Return type:

None

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:

None

on_status_bar_message(message)[source]

Display a message in the QStatusBar.

Return type:

None

on_update_progress_bar(percentage)[source]

Update the value of the progress bar.

Call this method if a process completion rate can be determined. Automatically shows the progress bar if it is hidden.

Parameters:

percentage (int | float) – A value in the range [0, 100]. The value gets rounded to the nearest integer.

Return type:

None

on_widget_closed(action, widget)[source]

Called when a docked widget closes.

Return type:

None

on_widgets_triggered(action)[source]

A QAction in the Widgets QMenu was triggered.

Return type:

None