Main GUI Module

Classes:

Alarm(alarm_type, severity, start_time, …)

Representation of alarm status and parameters

AlarmSeverity(value)

An enumeration.

AlarmType(value)

An enumeration.

Alarm_Manager()

The Alarm Manager

ControlSetting(name, value, min_value, …)

Message containing ventilation control parameters.

CoordinatorBase([sim_mode])

PVP_Gui(coordinator, set_defaults, update_period)

The Main GUI window.

SensorValues([timestamp, loop_counter, …])

Structured class for communicating sensor readings throughout PVP.

ValueName(value)

Canonical names of all values used in PVP.

Functions:

get_gui_instance()

Retreive the currently running instance of the GUI

init_logger(module_name[, log_level, …])

Initialize a logger for logging events.

launch_gui(coordinator[, set_defaults, …])

Launch the GUI with its appropriate arguments and doing its special opening routine

mono_font()

module function to return a PySide2.QtGui.QFont to use as the mono font.

set_gui_instance(instance)

Store the current instance of the GUI

class pvp.gui.main.PVP_Gui(coordinator: pvp.coordinator.coordinator.CoordinatorBase, set_defaults: bool = False, update_period: float = 0.05, screenshot=False)[source]

The Main GUI window.

Creates 5 sets of widgets:

  • A Control_Panel in the top left corner that controls basic system operation and settings

  • A Alarm_Bar along the top that displays active alarms and allows them to be dismissed or muted

  • A column of Display widgets (according to values.DISPLAY_MONITOR ) on the left that display sensor values and control their alarm limits

  • A column of Plot widgets (according to values.PLOTS ) in the center that display waveforms of sensor readings

  • A column of Display widgets (according to values.DISPLAY_CONTROL ) that control ventilation settings

Continually polls the coordinator with update_gui() to receive new SensorValues and dispatch them to display widgets, plot widgets, and the alarm manager

Note

Only one instance can be created at a time. Uses set_gui_instance() to store a reference to itself. after initialization, use get_gui_instance to retrieve a reference.

Parameters
  • coordinator (CoordinatorBase) – Used to communicate with the ControlModuleBase .

  • set_defaults (bool) – Whether default Value s should be set on initialization (default False) – used for testing and development, values should be set manually for each patient.

  • update_period (float) – The global delay between redraws of the GUI (seconds), used by timer .

  • screenshot (bool) – Whether alarms should be manually raised to show the different alarm severities, only used for testing and development and should never be used in a live system.

monitor

Dictionary mapping values.DISPLAY_MONITOR keys to widgets.Display objects

Type

dict

controls

Dictionary mapping values.DISPLAY_CONTROL keys to widgets.Display objects

Type

dict

plot_box

Container for plots

Type

Plot_Box

coordinator

Some coordinator object that we use to communicate with the controller

Type

pvp.coordinator.coordinator.CoordinatorBase

alarm_manager

Alarm manager instance

Type

Alarm_Manager

timer

Timer that calls PVP_Gui.update_gui()

Type

PySide2.QtCore.QTimer

running

whether ventilation is currently running

Type

bool

locked

whether controls have been locked

Type

bool

start_time

Start time as returned by time.time()

Type

float

update_period

The global delay between redraws of the GUI (seconds)

Type

float

logger

Logger generated by loggers.init_logger()

Attributes:

CONTROL

MONITOR

PLOTS

control_width

controls_set

Check if all controls are set

gui_closing(*args, **kwargs)

monitor_width

plot_width

state_changed(*args, **kwargs)

staticMetaObject

total_width

update_period

The global delay between redraws of the GUI (seconds)

Methods:

_screenshot()

Raise each of the alarm severities to check if they work and to take a screenshot

_set_cycle_control(value_name, new_value)

Compute the computed breath cycle control.

closeEvent(event)

Emit gui_closing and close!

get_breath_detection()

Get the current state of breath detection from the controller

handle_alarm(alarm)

Receive an Alarm from the Alarm_Manager

init_controls()

on startup, set controls in coordinator to ensure init state is synchronized

init_ui()

  1. Create the UI components for the ventilator screen

init_ui_controls()

  1. Create the “controls” column of widgets.Display widgets

init_ui_monitor()

  1. Create the left “sensor monitor” column of widgets.Display widgets

init_ui_plots()

  1. Create the Plot_Container

init_ui_signals()

  1. Connect Qt signals and slots between widgets

init_ui_status_bar()

  1. Create the widgets.Control_Panel and widgets.Alarm_Bar

limits_updated(control)

Receive updated alarm limits from the Alarm_Manager

load_state(state)

Load GUI state and reconstitute

save_state()

Try to save GUI state to prefs['VENT_DIR"] + prefs['GUI_STATE_FN']

set_breath_detection(breath_detection)

Connected to breath_detection_button - toggles autonomous breath detection in the controller

set_control(control_object)

Set a control in the alarm manager, coordinator, and gui

set_pressure_units(units)

Select whether pressure units are displayed as “cmH2O” or “hPa”

set_value(new_value[, value_name])

Set a control value using a value and its name.

start()

Click the start_button

toggle_cycle_widget(button)

Set which breath cycle control is automatically calculated

toggle_lock(state)

Toggle the lock state of the controls

toggle_start(state)

Start or stop ventilation.

update_gui([vals])

param vals

Default None, but SensorValues can be passed manually – usually for debugging

update_state(state_type, key, val)

Update the GUI state and save it to disk with Vent_Gui.save_state()

gui_closing(*args, **kwargs) = <PySide2.QtCore.Signal object>

PySide2.QtCore.Signal emitted when the GUI is closing.

state_changed(*args, **kwargs) = <PySide2.QtCore.Signal object>

PySide2.QtCore.Signal emitted when the gui is started (True) or stopped (False)

MONITOR = OrderedDict([(<ValueName.PIP: 1>, <pvp.common.values.Value object>), (<ValueName.PEEP: 3>, <pvp.common.values.Value object>), (<ValueName.BREATHS_PER_MINUTE: 5>, <pvp.common.values.Value object>), (<ValueName.INSPIRATION_TIME_SEC: 6>, <pvp.common.values.Value object>), (<ValueName.PRESSURE: 10>, <pvp.common.values.Value object>), (<ValueName.VTE: 9>, <pvp.common.values.Value object>), (<ValueName.FLOWOUT: 11>, <pvp.common.values.Value object>), (<ValueName.FIO2: 8>, <pvp.common.values.Value object>)])

Values to create Display widgets for in the Sensor Monitor column. See values.DISPLAY_MONITOR

CONTROL = OrderedDict([(<ValueName.PIP: 1>, <pvp.common.values.Value object>), (<ValueName.PEEP: 3>, <pvp.common.values.Value object>), (<ValueName.BREATHS_PER_MINUTE: 5>, <pvp.common.values.Value object>), (<ValueName.INSPIRATION_TIME_SEC: 6>, <pvp.common.values.Value object>), (<ValueName.IE_RATIO: 7>, <pvp.common.values.Value object>), (<ValueName.PIP_TIME: 2>, <pvp.common.values.Value object>)])

Values to create Display widgets for in the Control column. See values.CONTROL

PLOTS = OrderedDict([(<ValueName.PRESSURE: 10>, <pvp.common.values.Value object>), (<ValueName.FLOWOUT: 11>, <pvp.common.values.Value object>), (<ValueName.FIO2: 8>, <pvp.common.values.Value object>)])

Values to create Plot widgets for. See values.PLOTS

monitor_width = 3

Relative width of the sensor monitor column

plot_width = 4

Relative width of the plot column

control_width = 3

Relative width of the control column

total_width = 10

computed from monitor_width+plot_width+control_width

update_gui(vals: pvp.common.message.SensorValues = None)[source]
Parameters

vals (SensorValue) – Default None, but SensorValues can be passed manually – usually for debugging

init_ui()[source]
  1. Create the UI components for the ventilator screen

Call, in order:

Create and set sizes of major layouts

init_ui_status_bar()[source]
  1. Create the widgets.Control_Panel and widgets.Alarm_Bar

and add them to the main layout

init_ui_monitor()[source]
  1. Create the left “sensor monitor” column of widgets.Display widgets

And add the logo to the bottom left corner if there’s room

init_ui_plots()[source]
  1. Create the Plot_Container

init_ui_controls()[source]
  1. Create the “controls” column of widgets.Display widgets

init_ui_signals()[source]
  1. Connect Qt signals and slots between widgets

  • Connect controls and sensor monitors to PVP_Gui.set_value()

  • Connect control panel buttons to their respective methods

set_value(new_value, value_name=None)[source]

Set a control value using a value and its name.

Constructs a message.ControlSetting object to give to PVP_Gui.set_control()

Note

This method is primarily intended as a means of responding to signals from other widgets, Other cases should use set_control()

Parameters
  • new_value (float) – A new value for some control setting

  • value_name (values.ValueName) – THe ValueName for the control setting. If None, assumed to be coming from a Display widget that can identify itself with its objectName

set_control(control_object: pvp.common.message.ControlSetting)[source]

Set a control in the alarm manager, coordinator, and gui

Also update our state with update_state()

Parameters

control_object (message.ControlSetting) – A control setting to give to CoordinatorBase.set_control

handle_alarm(alarm: pvp.alarm.alarm.Alarm)[source]

Receive an Alarm from the Alarm_Manager

Alarms are both raised and cleared with this method – there is no separate “clear_alarm” method because an alarm of AlarmSeverity of OFF is cleared.

Give the alarm to the Alarm_Bar and update the alarm Display.alarm_state of all widgets listed as Alarm.cause

Parameters

alarm (Alarm) – The alarm to raise (or clear)

limits_updated(control: pvp.common.message.ControlSetting)[source]

Receive updated alarm limits from the Alarm_Manager

When a value is set that has an Alarm_Rule that Alarm_Rule.depends on it, the alarm thresholds will be updated and handled here.

Eg. the high-pressure alarm is set to be 15% above PIP. When PIP is changed, this method will receive a message.ControlSetting that tells us that alarm threshold has changed.

Update the Display and Plot widgets.

If we are setting a new HAPA limit, that is also sent to the controller as it needs to respond as quickly as possible to high-pressure events.

Parameters

control (message.ControlSetting) – A ControlSetting with its max_value or

:param min_value set:

start()[source]

Click the start_button

toggle_start(state: bool)[source]

Start or stop ventilation.

Typically called by the PVP_Gui.control_panel.start_button.

Raises a dialogue to confirm ventilation start or stop

Starts or stops the controller via the coordinator

If starting, locks controls.

Parameters

state (bool) – If True, start ventilation. If False, stop ventilation.

closeEvent(event)[source]

Emit gui_closing and close!

Kill the coordinator with CoordinatorBase.kill()

toggle_lock(state)[source]

Toggle the lock state of the controls

Typically called by PVP_Gui.control_panel.lock_button

Parameters

state

Returns:

update_state(state_type: str, key: str, val: Union[str, float, int])[source]

Update the GUI state and save it to disk with Vent_Gui.save_state()

Currently, just saves the state of control settings.

Parameters
  • state_type (str) – What type of state to save, one of ('controls')

  • key (str) – Which of that type is being saved (eg. if ‘control’, ‘PIP’)

  • val (str, float, int) – What is that item being set to?

Returns:

save_state()[source]

Try to save GUI state to prefs['VENT_DIR"] + prefs['GUI_STATE_FN']

load_state(state: Union[str, dict])[source]

Load GUI state and reconstitute

currently, just PVP_Gui.set_value() for all previously saved values

Parameters

state (str, dict) – either a pathname to a state file or an already-loaded state dictionary

staticMetaObject = <PySide2.QtCore.QMetaObject object>
toggle_cycle_widget(button)[source]

Set which breath cycle control is automatically calculated

The timing of a breath cycle can be parameterized with Respiration Rate, Inspiration Time, and Inspiratory/Expiratory ratio, but if two of these parameters are set the third is already known.

This method changes which value has its Display widget hidden and is automatically calculated

Parameters

button (PySide2.QtWidgets.QAbstractButton, values.ValueName) – The Qt Button that invoked the method or else a ValueName

set_pressure_units(units)[source]

Select whether pressure units are displayed as “cmH2O” or “hPa”

calls Display.set_units() on controls and plots that display pressure

Parameters

units (str) – one of “cmH2O” or “hPa”

set_breath_detection(breath_detection: bool)[source]

Connected to breath_detection_button - toggles autonomous breath detection in the controller

Parameters

breath_detection (bool) – Whether the controller detects autonomous breaths and resets the breath cycle accordingly

get_breath_detection()bool[source]

Get the current state of breath detection from the controller

Returns

if True, automatic breath detection is enabled

Return type

bool

_set_cycle_control(value_name: str, new_value: float)[source]

Compute the computed breath cycle control.

We only actually have BPM and INSPt as controls, so if we’re using I:E ratio we have to compute one or the other.

Computes the value and calls set_control() with the appropriate values:

# ie = inspt/expt
# inspt = ie*expt
# expt = inspt/ie
#
# cycle_time = inspt + expt
# cycle_time = inspt + inspt/ie
# cycle_time = inspt * (1+1/ie)
# inspt = cycle_time / (1+1/ie)
property controls_set

Check if all controls are set

Note

Note that even when RR or INSPt are autocalculated, they are still set in their control objects, so this check is the same regardless of what is set to autocalculate

property update_period

The global delay between redraws of the GUI (seconds)

init_controls()[source]

on startup, set controls in coordinator to ensure init state is synchronized

_screenshot()[source]

Raise each of the alarm severities to check if they work and to take a screenshot

Warning

should never be used except for testing and development!

pvp.gui.main.launch_gui(coordinator, set_defaults=False, screenshot=False) → Tuple[PySide2.QtWidgets.QApplication, pvp.gui.main.PVP_Gui][source]

Launch the GUI with its appropriate arguments and doing its special opening routine

To launch the gui, one must:

  • Create a PySide2.QtWidgets.QApplication

  • Set the app style using gui.styles.DARK_THEME

  • Set the app palette with gui.styles.set_dark_palette()

  • Call the gui’s show method

Parameters
  • coordinator (coordinator.CoordinatorBase) – Coordinator used to communicate between GUI and controller

  • set_defaults (bool) – whether default control parameters should be set on startup – only to be used for development or testing

  • screenshot (bool) – whether alarms should be raised to take a screenshot, should never be used on a live system.

Returns

The PySide2.QtWidgets.QApplication and PVP_Gui

Return type

(tuple)