Commit 271c7ff2 authored by Tiago Sarmento's avatar Tiago Sarmento

clean up and fixes

parent e2067d7a
Pipeline #1364 failed with stages
{"settings":[
["Respiratory Rate","/min","respiratory_rate","SET_TARGET_","RESPIRATORY_RATE"],
["Inhale Time", "s", "inhale_time", "SET_TARGET_", "INHALE_TIME"],
["IE Ratio", "", "ie_ratio", "SET_TARGET_", "IE_RATIO"],
["Inhale Trigger Sensitivity","","inhale_trigger_threshold","SET_TARGET_","INHALE_TRIGGER_THRESHOLD"],
["Exhale Trigger Sensitivity","","exhale_trigger_threshold","SET_TARGET_","EXHALE_TRIGGER_THRESHOLD"],
["Inhale Pressure","","inspiratory_pressure","SET_TARGET_","INSPIRATORY_PRESSURE"],
["Inhale Volume", "", "volume", "SET_TARGET_", "VOLUME"],
["Percentage O2", "", "fiO2_percent", "SET_TARGET_", "FIO2_PERCENT"]],
["Respiratory Rate","/min","respiratory_rate","SET_TARGET_","RESPIRATORY_RATE", 0, 20, 15, 0.1, 1],
["Inhale Time", "s", "inhale_time", "SET_TARGET_", "INHALE_TIME", 0, 20, 1, 0.1, 1],
["IE Ratio", "", "ie_ratio", "SET_TARGET_", "IE_RATIO", 0, 1, 0.338, 0.001, 3],
["Inhale Trigger Sensitivity","","inhale_trigger_threshold","SET_TARGET_","INHALE_TRIGGER_THRESHOLD", 0, 20, 5, 0.2, 1],
["Exhale Trigger Sensitivity","","exhale_trigger_threshold","SET_TARGET_","EXHALE_TRIGGER_THRESHOLD", 0, 50, 25, 0.2, 1],
["Inhale Pressure","","inspiratory_pressure","SET_TARGET_","INSPIRATORY_PRESSURE", 10, 50, 17, 1, 0],
["Inhale Volume", "", "volume", "SET_TARGET_", "VOLUME", 200, 800, 400, 20, 0],
["Percentage O2", "", "fiO2_percent", "SET_TARGET_", "FIO2_PERCENT", 20, 100, 21, 1, 0]],
"radioSettings": ["Inhale Time", "IE Ratio"],
"enableDict":{"PC/AC":[1, 0, 1, 1, 0, 1, 0, 1], "PC/AC-PRVC":[1, 1, 0, 1, 0, 1, 1, 1], "PC-PSV":[1, 1, 0, 1, 0, 1, 0, 1], "CPAP":[1, 0, 1, 1, 0, 1, 0, 1]}
......
{"settings":[
["Name", "/min", "name", "SET_PERSONAL", "NAME"],
["Patient ID", "s", "patient_id", "SET_PERSONAL", "PATIENT_ID"],
["Age", "", "age", "SET_PERSONAL", "AGE"],
["Sex", "", "sex", "SET_PERSONAL", "SEX"],
["Weight", "", "weight", "SET_PERSONAL", "WEIGHT"],
["Height", "", "height", "SET_PERSONAL", "HEIGHT"]
["Name", "/min", "name", "SET_PERSONAL", "NAME", "Goedkoop Van Tilator"],
["Patient ID", "s", "patient_id", "SET_PERSONAL", "PATIENT_ID", "11235813FIB"],
["Age", "years", "age", "SET_PERSONAL", "AGE", 0, 130, 25, 1, 0],
["Sex", "", "sex", "SET_PERSONAL", "SEX", "X"],
["Weight", "kg", "weight", "SET_PERSONAL", "WEIGHT", 20, 250, 60, 1, 0],
["Height", "cms", "height", "SET_PERSONAL", "HEIGHT",20, 250, 160, 1, 0]
],
"textBoxes": ["Name", "Patient ID", "Sex"]
......
......@@ -86,7 +86,13 @@ class labelledSpin(QtWidgets.QWidget):
self.NativeUI = NativeUI
self.cmd_type, self.cmd_code = "", ""
self.min, self.max, self.step = 0, 10000, 0.3
self.initVal = 1
self.decPlaces = 2
self.label = 'default'
if len(infoArray) == 10:
self.label, self.units, self.tag, self.cmd_type, self.cmd_code, self.min, self.max, self.initVal, self.step, self.decPlaces = (
infoArray
)
if len(infoArray) == 9:
self.label, self.units, self.tag, self.cmd_type, self.cmd_code, self.min, self.max, self.step, self.decPlaces = (
infoArray
......@@ -106,6 +112,7 @@ class labelledSpin(QtWidgets.QWidget):
self.nameLabel.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
self.simpleSpin = signallingSpinBox(NativeUI)
self.simpleSpin.setValue(self.initVal)
self.simpleSpin.setRange(self.min, self.max)
self.simpleSpin.setSingleStep(self.step)
self.simpleSpin.setDecimals(self.decPlaces)
......@@ -124,7 +131,7 @@ class labelledSpin(QtWidgets.QWidget):
" color:" + NativeUI.colors["page_background"].name() + ";"
"}"
"QDoubleSpinBox[textColour='0']{"
" color:" + NativeUI.colors["page_foreground"].name() + ";"pri
" color:" + NativeUI.colors["page_foreground"].name() + ";"
"}"
"QDoubleSpinBox[textColour='2']{"
" color:" + NativeUI.colors["red"].name() + ";"
......
......@@ -507,9 +507,14 @@ class Layout:
personalDict = json.load(json_file)
textBoxes = personalDict["textBoxes"]
personalList = [self.NativeUI.widgets.get_widget(attrName) for attrName in dir(self.NativeUI.widgets) if
'startup_personal_edit' in attrName]
# consider subclassing labelledspinbox to have modespinbox with attribute mode
personalList = []
for setting in personalDict["settings"]:
attrName = 'startup_personal_edit_' + setting[2]
if setting[0] in textBoxes:
personalList.append(self.NativeUI.widgets.get_widget('text_' + attrName))
else:
personalList.append(self.NativeUI.widgets.get_widget('spin_' + attrName))
vLayout = QtWidgets.QVBoxLayout()
for widget in personalList:
......@@ -527,8 +532,15 @@ class Layout:
personalDict = json.load(json_file)
textBoxes = personalDict["textBoxes"]
personalList = [self.NativeUI.widgets.get_widget(attrName) for attrName in dir(self.NativeUI.widgets) if 'personal_edit' in attrName]
# consider subclassing labelledspinbox to have modespinbox with attribute mode
personalList = []
for setting in personalDict["settings"]:
attrName = 'personal_edit_' + setting[2]
if setting[0] in textBoxes:
personalList.append(self.NativeUI.widgets.get_widget('text_' + attrName))
else:
personalList.append(self.NativeUI.widgets.get_widget('spin_' + attrName))
vLayout = QtWidgets.QVBoxLayout()
for widget in personalList:
......
......@@ -76,25 +76,17 @@ class Widgets:
self.startup_confirm_popup = SetConfirmPopup(NativeUI)
self.startup_handler = StartupHandler(NativeUI, self.startup_confirm_popup)
#self.startup_mode
with open('NativeUI/configs/startup_config.json') as json_file:
startupDict = json.load(json_file)
for key, procedureDict in startupDict.items():
self.add_handled_widget(calibrationWidget(NativeUI, key, procedureDict),key, self.startup_handler )
#self.calibration = calibrationWidget(NativeUI, 'calibration')
#self.leakTest = calibrationWidget(NativeUI, 'leak test')
#self.maintenance = calibrationWidget(NativeUI, 'maintenance')
#self.nextButton = OkButtonWidget(NativeUI)
self.add_handled_widget(OkButtonWidget(NativeUI), 'nextButton', self.startup_handler)
self.nextButton.setColour(1)
#self.skipButton = OkSendButtonWidget(NativeUI)
self.add_handled_widget(OkSendButtonWidget(NativeUI), 'skipButton', self.startup_handler)
self.skipButton.setColour(1)
#self.backButton = CancelButtonWidget(NativeUI)
self.add_handled_widget(CancelButtonWidget(NativeUI), 'backButton', self.startup_handler)
#self.backButton.setColour(1)
# Top bar widgets
self.tab_modeswitch = TabModeswitchButton(NativeUI)
......@@ -144,7 +136,7 @@ class Widgets:
self.groupDict[mode] = QButtonGroup()
for setting in modeDict["settings"]:
attrName = mode + '_' + setting[2]
targettedSetting =[ target.replace("SET_TARGET_", "SET_TARGET_" + mode.replace("/", "_").replace("-", "_")) for target in setting]
targettedSetting =[ target.replace("SET_TARGET_", "SET_TARGET_" + mode.replace("/", "_").replace("-", "_")) if isinstance(target,str) else target for target in setting ]
if mode == 'startup':
self.add_handled_widget(labelledSpin(NativeUI, targettedSetting), 'spin_' + attrName,
self.startup_handler)
......
......@@ -44,8 +44,8 @@ class LabelledLineEditWidget(QtWidgets.QWidget):
self.label, self.units, self.tag, self.cmd_type, self.cmd_code, self.min, self.max, self.step, self.decPlaces = (
infoArray
)
elif len(infoArray) == 5:
self.label, self.units, self.tag, self.cmd_type, self.cmd_code = infoArray
elif len(infoArray) == 6:
self.label, self.units, self.tag, self.cmd_type, self.cmd_code, self.initText = infoArray
elif len(infoArray) == 3:
self.label, self.units, self.tag = infoArray
self.manuallyUpdated = False
......@@ -60,7 +60,7 @@ class LabelledLineEditWidget(QtWidgets.QWidget):
widgetList.append(self.nameLabel)
self.simpleSpin = SignallingLineEditWidget(NativeUI)
self.simpleSpin.setText("")
self.simpleSpin.setText(self.initText)
self.simpleSpin.setStyleSheet(
"""QDoubleSpinBox{ width:100px; font:16pt}
QDoubleSpinBox[bgColour="0"]{background-color:white; }
......
......@@ -15,18 +15,14 @@ __status__ = "Prototype"
from PySide2 import QtWidgets, QtGui, QtCore
import os
class OkButtonWidget(
QtWidgets.QPushButton
):
def __init__(self, NativeUI, *args, **kwargs):
class styledButton(QtWidgets.QPushButton):
def __init__(self, NativeUI, colour, iconpath_play, *args, **kwargs):
super().__init__(*args, **kwargs)
iconpath_check = os.path.join(NativeUI.iconpath, "check-solid.png")
# set icon color
pixmap = QtGui.QPixmap(iconpath_check)
pixmap = QtGui.QPixmap(iconpath_play)
mask = pixmap.mask()
pixmap.fill(NativeUI.colors["page_background"])
pixmap.fill(NativeUI.colors["button_background_enabled"])
pixmap.setMask(mask)
self.setIcon(QtGui.QIcon(pixmap))
......@@ -35,7 +31,7 @@ class OkButtonWidget(
+ NativeUI.colors["page_foreground"].name()
+ ";}"
"QPushButton[bgColour='1']{background-color: "
+ NativeUI.colors["green"].name()
+ NativeUI.colors[colour].name()
+ ";}"
"QPushButton{color: " + NativeUI.colors["page_background"].name() + ";"
"border-color: " + NativeUI.colors["page_foreground"].name() + ";"
......@@ -56,85 +52,25 @@ class OkButtonWidget(
self.style().polish(self)
class CancelButtonWidget(
QtWidgets.QPushButton
class OkButtonWidget(
styledButton
):
def __init__(self, NativeUI, *args, **kwargs):
super().__init__(*args, **kwargs)
iconpath_cross = os.path.join(NativeUI.iconpath, "times-solid.png")
# set icon color
pixmap = QtGui.QPixmap(iconpath_cross)
mask = pixmap.mask()
pixmap.fill(NativeUI.colors["page_background"])
pixmap.setMask(mask)
self.setIcon(QtGui.QIcon(pixmap))
self.setStyleSheet(
"QPushButton[bgColour='0']{"
" background-color:"
+ NativeUI.colors["button_foreground_enabled"].name()
+ ";"
"}"
"QPushButton[bgColour='1']{"
"background-color:" + NativeUI.colors["red"].name() + ";"
"}"
"QPushButton{"
" color: " + NativeUI.colors["button_background_enabled"].name() + ";"
" font-size: " + NativeUI.text_size + ";"
" border:none;"
"}"
)
self.setProperty("bgColour", "0")
self.setEnabled(False)
iconpath_check = os.path.join(NativeUI.iconpath, "check-solid.png")
super().__init__(NativeUI, 'green', iconpath_check, *args, **kwargs)
self.setFixedHeight(50)
# self.setFixedSize(QtCore.QSize(150, 50))
def setColour(self, option):
self.setEnabled(bool(float(option)))
self.setProperty("bgColour", str(option))
self.style().polish(self)
class CancelButtonWidget(
styledButton
):
def __init__(self, NativeUI, *args, **kwargs):
iconpath_cross = os.path.join(NativeUI.iconpath, "times-solid.png")
super().__init__(NativeUI, 'red', iconpath_cross, *args, **kwargs)
class OkSendButtonWidget(
QtWidgets.QPushButton
styledButton
): # chose QWidget over QDialog family because easier to modify
def __init__(self, NativeUI, *args, **kwargs):
super().__init__(*args, **kwargs)
iconpath_play = os.path.join(NativeUI.iconpath, "play-solid.png")
# set icon color
pixmap = QtGui.QPixmap(iconpath_play)
mask = pixmap.mask()
pixmap.fill(NativeUI.colors["button_background_enabled"])
pixmap.setMask(mask)
self.setIcon(QtGui.QIcon(pixmap))
self.setStyleSheet(
"QPushButton[bgColour='0']{"
" background-color: "
+ NativeUI.colors["button_foreground_enabled"].name()
+ ";"
"}"
"QPushButton[bgColour='1']{"
" background-color:" + NativeUI.colors["green"].name() + ";"
"}"
"QPushButton{"
" color: " + NativeUI.colors["button_background_enabled"].name() + ";"
" font-size: " + NativeUI.text_size + ";"
" border:none"
"}"
"font-size: " + NativeUI.text_size + ";"
"border:none;"
)
self.setProperty("bgColour", "0")
self.setEnabled(False)
self.setFixedHeight(50)
# self.setFixedSize(QtCore.QSize(150, 50))
def setColour(self, option):
self.setEnabled(bool(float(option)))
self.setProperty("bgColour", str(option))
self.style().polish(self)
super().__init__(NativeUI, 'green', iconpath_play, *args, **kwargs)
......@@ -30,7 +30,7 @@ class SpinButton(QtWidgets.QFrame):
def __init__(self, NativeUI, settings):
super().__init__()
self.liveUpdating = True
self.manuallyUpdated = False
# self.setStyleSheet("background-color:blue;")
self.currentVal = 0
self.cmd_type = settings[3]
......@@ -112,17 +112,18 @@ class SpinButton(QtWidgets.QFrame):
if (newVal == {}) or (self.val_code == ""):
a = 1 # do nothing
else:
if self.liveUpdating:
if not self.manuallyUpdated:
self.simpleSpin.setValue(newVal[self.val_code])
self.setTextColour(1)
else:
if self.simpleSpin.value() == newVal[self.val_code]:
self.liveUpdating = True
if int(self.simpleSpin.value()) == int(newVal[self.val_code]):
self.manuallyUpdated = False
self.setTextColour(1)
def manualChanged(self):
"""Called when user manually makes a change. Stops value from updating and changes colour"""
self.liveUpdating = False
self.manuallyUpdated = True
self.setTextColour(2)
return 0
......@@ -162,14 +163,19 @@ class SpinButtonsWidget(QtWidgets.QWidget):
["IE Ratio", "", "ie_ratio", "SET_TARGET_CURRENT", "IE_RATIO"],
["Percentage O2", "", "fiO2_percent", "SET_TARGET_CURRENT", "FIO2_PERCENT"],
]
self.okButton = OkButtonWidget(self.NativeUI)
self.okButton.pressed.connect(self.ok_button_pressed)
self.cancelButton = CancelButtonWidget(self.NativeUI)
self.cancelButton.pressed.connect(self.cancel_button_pressed)
self.spinDict = {}
self.spinStack = QtWidgets.QStackedWidget()
stackedNames = ["Inhale Time", "IE Ratio"]
for settings in self.settingsList:
self.spinDict[settings[0]] = SpinButton(NativeUI, settings)
self.spinDict[settings[0]].simpleSpin.manualChanged.connect(
lambda i=1: self.colourButtons(i)
)
self.spinDict[settings[0]].simpleSpin.manualChanged.connect(lambda: self.refresh_button_colour())
if settings[0] in stackedNames:
self.spinStack.addWidget(self.spinDict[settings[0]])
else:
......@@ -179,12 +185,7 @@ class SpinButtonsWidget(QtWidgets.QWidget):
self.buttonLayout = QtWidgets.QVBoxLayout()
self.buttonLayout.setSpacing(5)
self.okButton = OkButtonWidget(self.NativeUI)
self.okButton.pressed.connect(self.ok_button_pressed)
self.buttonLayout.addWidget(self.okButton)
self.cancelButton = CancelButtonWidget(self.NativeUI)
self.cancelButton.pressed.connect(self.cancel_button_pressed)
self.buttonLayout.addWidget(self.cancelButton)
self.layout.addLayout(self.buttonLayout)
......@@ -206,6 +207,15 @@ class SpinButtonsWidget(QtWidgets.QWidget):
def update_targets(self):
for widget in self.spinDict:
self.spinDict[widget].update_targets_value() # pass database
self.refresh_button_colour()
def refresh_button_colour(self):
self.manuallyUpdated = False
for spin in self.spinDict:
self.manuallyUpdated = self.manuallyUpdated or self.spinDict[spin].manuallyUpdated
self.okButton.setColour(str(int(self.manuallyUpdated)))
self.cancelButton.setColour((str(int(self.manuallyUpdated))))
# targets = self.NativeUI.get_db("targets")
# if targets == {}:
......@@ -225,7 +235,7 @@ class SpinButtonsWidget(QtWidgets.QWidget):
"""Respond to ok button pressed by changing text colour and liveUpdating to True"""
message, command = [], []
for widget in self.spinDict:
if not self.spinDict[widget].liveUpdating:
if self.spinDict[widget].manuallyUpdated:
setVal = self.spinDict[widget].simpleSpin.value()
message.append("set" + widget + " to " + str(setVal))
command.append(
......@@ -243,16 +253,17 @@ class SpinButtonsWidget(QtWidgets.QWidget):
def commandSent(self):
for spin in self.spinDict:
self.spinDict[spin].liveUpdating = True
self.spinDict[spin].manuallyUpdated = False
self.spinDict[spin].setTextColour("1")
self.colourButtons(0)
self.refresh_button_colour()
#self.colourButtons(0)
def cancel_button_pressed(self):
"""Respond to cancel button pressed by changing text colour and liveUpdating to True"""
for spin in self.spinDict:
self.spinDict[spin].liveUpdating = True
self.spinDict[spin].manuallyUpdated = False
self.spinDict[spin].setTextColour("1")
self.colourButtons(0)
self.refresh_button_colour()
# targets = self.NativeUI.get_targets_db()
# if targets == {}:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment