Commit e06401f0 authored by Tiago Sarmento's avatar Tiago Sarmento

implement hold buttons

parent 39c9c9f5
Pipeline #997 failed
......@@ -3,10 +3,11 @@ from PySide2 import QtCore, QtGui, QtWidgets
class alarmWidget(QtWidgets.QWidget):
def __init__(self, NativeUI, alarmPayload, *args, **kwargs):
def __init__(self, NativeUI, alarmPayload, alarmCarrier, *args, **kwargs):
super(alarmWidget, self).__init__(*args, **kwargs)
self.NativeUI = NativeUI
self.alarmCarrier = alarmCarrier
self.layout = QtWidgets.QHBoxLayout()
self.layout.setSpacing(0)
......@@ -35,12 +36,16 @@ class alarmWidget(QtWidgets.QWidget):
self.setStyleSheet("background-color:orange;")
self.timer = QtCore.QTimer()
self.timer.setInterval(5000) # just faster than 60Hz
self.timer.setInterval(500) # just faster than 60Hz
self.timer.timeout.connect(self.checkAlarm)
self.timer.start()
def checkAlarm(self):
self.parent().alarmDict.pop(self.alarmPayload["alarm_code"])
self.ongoingAlarms = self.NativeUI.ongoingAlarms
for alarm in self.ongoingAlarms:
if self.alarmPayload["alarm_code"] == alarm["alarm_code"]:
return
self.alarmCarrier.alarmDict.pop(self.alarmPayload["alarm_code"])
self.setParent(None)
......@@ -81,7 +86,7 @@ class alarmPopup(QtWidgets.QDialog):
def addAlarm(self, alarmPayload):
self.alarmDict[alarmPayload["alarm_code"]] = alarmWidget(
self.NativeUI, alarmPayload
self.NativeUI, alarmPayload, self
)
self.layout.addWidget(self.alarmDict[alarmPayload["alarm_code"]])
......
......@@ -12,14 +12,15 @@ class okButton(
# set icon color
pixmap = QtGui.QPixmap(iconpath_check)
mask = pixmap.mask()
pixmap.fill(NativeUI.colors["foreground"])
pixmap.fill(NativeUI.colors["background"])
pixmap.setMask(mask)
self.setIcon(QtGui.QIcon(pixmap))
self.setStyleSheet(
"background-color: " + NativeUI.colors["background-enabled"].name() + ";"
"color: " + NativeUI.colors["foreground"].name() + ";"
"background-color: " + NativeUI.colors["foreground"].name() + ";"
"color: " + NativeUI.colors["background"].name() + ";"
"border-color: " + NativeUI.colors["foreground"].name() + ";"
"border-radius: 8px;"
"border:none"
)
......@@ -37,14 +38,15 @@ class cancelButton(
# set icon color
pixmap = QtGui.QPixmap(iconpath_cross)
mask = pixmap.mask()
pixmap.fill(NativeUI.colors["foreground"])
pixmap.fill(NativeUI.colors["background"])
pixmap.setMask(mask)
self.setIcon(QtGui.QIcon(pixmap))
self.setStyleSheet(
"background-color: " + NativeUI.colors["background-enabled"].name() + ";"
"color: " + NativeUI.colors["foreground"].name() + ";"
"background-color: " + NativeUI.colors["foreground"].name() + ";"
"color: " + NativeUI.colors["background"].name() + ";"
"border-color: " + NativeUI.colors["foreground"].name() + ";"
"border-radius: 8px;"
"border:none"
)
......
......@@ -11,11 +11,6 @@ class SetConfirmPopup(
super().__init__(*args, **kwargs)
# self.setStyleSheet("background-color:rgba(255,0,255,50%);color:rgb(0,255,0)")
# if NativeUI is None:
# iconpath = "hev-display/svg/check-solid.svg"
# else:
# iconpath_check = os.path.join(NativeUI.iconpath, "check-solid.png")
# iconpath_cross = os.path.join(NativeUI.iconpath, "times-solid.png")
self.NativeUI = NativeUI
if setList == []:
setList = ["no values were set"]
......
......@@ -25,6 +25,7 @@ class signallingSpinBox(QtWidgets.QDoubleSpinBox):
def stepBy(self, step):
value = self.value()
self.prevValue = value
super(signallingSpinBox, self).stepBy(step)
if self.value() != value:
self.manualChanged.emit()
......@@ -47,10 +48,12 @@ class labelledSpin(QtWidgets.QWidget):
self.NativeUI = NativeUI
self.template = template
self.cmd_type, self.cmd_code = "", ""
self.min, self.max, self.step = 0,10000,0.3
self.min, self.max, self.step = 0, 10000, 0.3
self.decPlaces = 2
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
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) == 3:
......@@ -105,9 +108,15 @@ class labelledSpin(QtWidgets.QWidget):
# self.simpleSpin.valueChanged.connect(self.valChange)
def manualStep(self):
if self.manuallyUpdated != True:
self.oldValue = self.simpleSpin.prevValue
self.template.liveUpdating = False
self.manuallyUpdated = True
self.simpleSpin.setProperty("textColour", "1")
if self.simpleSpin.value() != self.oldValue:
self.simpleSpin.setProperty("textColour", "1")
else:
self.simpleSpin.setProperty("textColour", "0")
self.manuallyUpdated = False
self.simpleSpin.style().polish(self.simpleSpin)
def update_readback_value(self):
......
from PySide2 import QtCore, QtGui, QtWidgets
from global_widgets.global_ok_cancel_buttons import okButton, cancelButton
import time
class timerConfirmPopup(QtWidgets.QWidget):
def __init__(self, NativeUI, *args, **kwargs):
super(timerConfirmPopup, self).__init__(*args, **kwargs)
self.setAttribute(QtCore.Qt.WA_ShowWithoutActivating)
self.setWindowFlags(
QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.FramelessWindowHint
) # ensures focus is not stolen by alarm or confirmation
self.setStyleSheet(
"background-color: " + NativeUI.colors["background-enabled"].name() + ";"
"color: " + NativeUI.colors["foreground"].name() + ";"
"border-color: " + NativeUI.colors["foreground"].name() + ";"
"border:none"
)
self.stack = QtWidgets.QStackedWidget()
vlayout = QtWidgets.QVBoxLayout()
self.label = QtWidgets.QLabel("progressing")
vlayout.addWidget(self.label)
self.progressBar = QtWidgets.QProgressBar()
self.progressBar.setMaximum(3000)
self.progressBar.setFormat("")
# self.progressBar
vlayout.addWidget(self.progressBar)
self.progressWidg = QtWidgets.QWidget()
self.progressWidg.setLayout(vlayout)
self.stack.addWidget(self.progressWidg)
# self.setLayout(vlayout)
self.completeLayout = QtWidgets.QVBoxLayout()
self.completeLabel = QtWidgets.QLabel("confirm it")
buttonLayout = QtWidgets.QHBoxLayout()
self.okButton = okButton(NativeUI)
buttonLayout.addWidget(self.okButton)
self.cancelButton = cancelButton(NativeUI)
buttonLayout.addWidget(self.cancelButton)
self.completeLayout.addWidget(self.completeLabel)
self.completeLayout.addLayout(buttonLayout)
self.completeWidg = QtWidgets.QWidget()
self.completeWidg.setLayout(self.completeLayout)
self.stack.addWidget(self.completeWidg)
stackLayout = QtWidgets.QVBoxLayout()
stackLayout.addWidget(self.stack)
self.setLayout(stackLayout)
class holdButton(QtWidgets.QPushButton):
def __init__(self, NativeUI, *args, **kwargs):
super(holdButton, self).__init__(*args, **kwargs)
self.NativeUI = NativeUI
self.timeOut = 3000
self.timeStep = 60
self.setAutoRepeat(True)
self.setAutoRepeatDelay(self.timeStep)
self.setAutoRepeatInterval(self.timeStep)
self.pressTime = 0
self.state = 0
self.complete = False
self.clicked.connect(self.handleClick)
self.popUp = timerConfirmPopup(NativeUI)
self.popUp.okButton.pressed.connect(self.okButtonPressed)
self.popUp.cancelButton.pressed.connect(self.closePopup)
def handleClick(self):
self.now = time.time()
if self.state == 0:
# print('pressed')
self.popUp.show()
self.initial = time.time()
if self.isDown():
if self.pressTime == self.timeOut:
self.complete = True
print(self.now - self.initial)
self.popUp.stack.setCurrentWidget(self.popUp.completeWidg)
self.pressTime = self.pressTime + self.timeStep
self.state = 1
self.popUp.progressBar.setValue(self.pressTime)
self.popUp.progressBar.update()
else:
self.pressTime = 0
print("aa")
print(self.complete)
print(self.state)
if self.state == 1:
print("released")
if not self.complete:
self.popUp.close()
self.state = 0
def okButtonPressed(self):
self.NativeUI.q_send_cmd("GENERAL", self.text())
self.closePopup()
def closePopup(self):
self.popUp.progressBar.setValue(0)
self.popUp.stack.setCurrentWidget(self.popUp.progressWidg)
self.popUp.close()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
widg = holdButton("Standby")
widg.show()
sys.exit(app.exec_())
......@@ -60,7 +60,10 @@ class TabPageButtons(QtWidgets.QWidget):
"background-color: "
+ NativeUI.colors["background-enabled"].name()
+ ";"
"border-color: " + NativeUI.colors["background"].name() + ";"
+ "border-color: "
+ NativeUI.colors["background"].name()
+ ";"
+ "border:none;"
"}"
"QPushButton:disabled{"
"background-color: "
......
......@@ -4,6 +4,7 @@ TODO
import logging
from PySide2 import QtGui, QtWidgets
from PySide2.QtCore import QSize
from global_widgets.tab_hold_buttons import holdButton
class TabStartStopStandbyButtons(QtWidgets.QWidget):
......@@ -23,15 +24,17 @@ class TabStartStopStandbyButtons(QtWidgets.QWidget):
layout = QtWidgets.QVBoxLayout()
self.button_start = QtWidgets.QPushButton()
self.button_stop = QtWidgets.QPushButton()
self.button_standby = QtWidgets.QPushButton()
self.button_start = holdButton(NativeUI) # QtWidgets.QPushButton()
self.button_stop = holdButton(NativeUI) # QtWidgets.QPushButton()
self.button_standby = holdButton(NativeUI) # QtWidgets.QPushButton()
self.__buttons = [self.button_start, self.button_stop, self.button_standby]
self.__buttontext = ["START", "STOP", "STANDBY"]
self.__buttoncommand = [""]
for button, text in zip(self.__buttons, self.__buttontext):
button.setText(text)
button.popUp.completeLabel.setText("Ventilation " + text)
layout.addWidget(button)
button.setStyleSheet(
"background-color: "
......@@ -39,8 +42,7 @@ class TabStartStopStandbyButtons(QtWidgets.QWidget):
+ ";"
"border-color: " + NativeUI.colors["foreground"].name() + ";"
"font-size: 20pt;"
"color: " + NativeUI.colors["foreground"].name() + ";" +
"border:none"
"color: " + NativeUI.colors["foreground"].name() + ";" + "border:none"
)
button.setFixedSize(self.__button_size)
......
......@@ -6,6 +6,7 @@ from global_widgets.global_typeval_popup import TypeValuePopup
from global_widgets.global_ok_cancel_buttons import okButton, cancelButton
from global_widgets.global_spinbox import signallingSpinBox
class SpinButton(QtWidgets.QFrame):
def __init__(self, NativeUI):
super().__init__()
......@@ -91,7 +92,6 @@ class SpinButton(QtWidgets.QFrame):
def manualChanged(self):
self.liveUpdating = False
def eventFilter(self, source, event):
if (
source is self.doubleSpin.lineEdit()
......@@ -133,12 +133,12 @@ class TabSpinButtons(QtWidgets.QWidget):
self.__spins = [self.spinInsp, self.spinRR, self.spinFIo2, self.spinInhaleT]
self.__labels = [
"inhalation_pressure",
"inspiratory_pressure",
"respiratory_rate",
"fiO2_percent",
"lung_compliance",
"inhale_time",
]
for spin,label in zip(self.__spins,self.__labels):
for spin, label in zip(self.__spins, self.__labels):
spin.label.setText(label)
self.layout.addWidget(spin)
......@@ -159,22 +159,23 @@ class TabSpinButtons(QtWidgets.QWidget):
self.timer = QtCore.QTimer()
self.timer.setInterval(160)
self.timer.timeout.connect(self.updateCycle)
self.timer.timeout.connect(self.updatetargets)
self.timer.start()
def updateCycle(self):
cycle = self.NativeUI.get_cycle_db()
if cycle == {}:
def updatetargets(self):
targets = self.NativeUI.get_targets_db()
if targets == {}:
return
for spin, label in zip(self.__spins, self.__labels):
if spin.doubleSpin.value() != float(cycle[label]):
if spin.liveUpdating:
spin.doubleSpin.setValue(float(cycle[label]))
spin.setTextColour("2")
if targets["mode"] == "CURRENT":
for spin, label in zip(self.__spins, self.__labels):
if spin.doubleSpin.value() != float(targets[label]):
if spin.liveUpdating:
spin.doubleSpin.setValue(float(targets[label]))
spin.setTextColour("2")
else:
spin.setTextColour("0")
else:
spin.setTextColour("0")
else:
spin.setTextColour("2")
spin.setTextColour("2")
def ok_button_pressed(self):
for spin in self.__spins:
......
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