Commit 9d495a4c authored by Benjamin Mummery's avatar Benjamin Mummery 💻

Merge branch 'ui_dev' of https://ohwr.org/project/hev into ui_dev

parents 8e4aa580 b26d2ba0
Pipeline #1575 failed with stages
......@@ -58,8 +58,8 @@ from mode_widgets.clinical_handler import ClinicalHandler
from alarm_widgets.alarm_handler import AlarmHandler
# from handler_library.readback_handler import ReadbackHandler
from global_widgets.global_typeval_popup import TypeValuePopup
from global_widgets.global_typeval_popup import TypeValuePopup, AbstractTypeValPopup
from widget_library.numpad_widget import NumberpadWidget, AlphapadWidget
logging.basicConfig(
level=logging.INFO,
......@@ -189,7 +189,12 @@ class NativeUI(HEVClient, QMainWindow):
self.alarm_handler,
]
self.messageCommandPopup = SetConfirmPopup(self)
self.typeValPopup = TypeValuePopup(self)
self.typeValPopupNum = AbstractTypeValPopup(
self, "numeric"
) # TypeValuePopup(self, NumberpadWidget(self))
self.typeValPopupAlpha = AbstractTypeValPopup(
self, "alpha"
) # TypeValuePopup(self, AlphapadWidget(self))
# Create all of the widgets and place them in the layout.
self.widgets = Widgets(self)
......@@ -199,6 +204,7 @@ class NativeUI(HEVClient, QMainWindow):
# a time.
self.messageCommandPopup = SetConfirmPopup(self)
self.confirmPopup = confirmPopup(self, self)
self.confirmPopup.show()
self.main_display = QWidget(self)
self.main_display.setLayout(self.layouts.global_layout())
self.startupWidget = QDialog(self)
......@@ -208,8 +214,10 @@ class NativeUI(HEVClient, QMainWindow):
self.display_stack = QStackedWidget(self)
for widget in [
self.typeValPopupNum,
self.typeValPopupAlpha,
self.messageCommandPopup,
self.confirmPopup,
# self.confirmPopup,
self.main_display,
self.startupWidget,
]:
......@@ -648,9 +656,13 @@ class NativeUI(HEVClient, QMainWindow):
logging.debug("to MCU: cmd: %s", cmd)
check = self.send_cmd(cmdtype=cmdtype, cmd=cmd, param=param)
if check:
print("confirmed this command " + cmdtype + " " + cmd)
self.confirmPopup.addConfirmation(cmdtype + " " + cmd)
print("added popup")
return 0
return 1
else:
print("failed this command " + cmdtype + " " + cmd)
return 1
@Slot(str)
def q_ack_alarm(self, alarm: str) -> int:
......
......@@ -63,12 +63,11 @@ class AlarmWidget(QtWidgets.QWidget):
# self.timer.setInterval(500) # just faster than 60Hz
# self.timer.timeout.connect(self.checkAlarm)
# self.timer.start()
# self.installEventFilter(self)
self.installEventFilter(self)
def eventFilter(self, source, event):
if (event.type() == QtCore.QEvent.MouseButtonPress):
self.NativeUI.leftBar.tab_page_buttons.button_alarms.click()
self.NativeUI.alarms_view.alarmButton.click()
self.NativeUI.widgets.page_buttons.alarms_button.click()
return False
def get_priority(self):
......@@ -225,21 +224,14 @@ class AlarmExtrasWidget(QtWidgets.QWidget):
self.setLayout(self.layout)
self.setStyleSheet("background-color:red;")
#self.priority = "PRIORITY_LOW"
self.installEventFilter(self)
def update_text(self, num):
self.textLabel.setText(str(num)+ ' More Alarms')
#self.code =
# self.timer = QtCore.QTimer()
# self.timer.setInterval(500) # just faster than 60Hz
# self.timer.timeout.connect(self.checkAlarm)
# self.timer.start()
# self.installEventFilter(self)
def eventFilter(self, source, event):
if (event.type() == QtCore.QEvent.MouseButtonPress):
self.NativeUI.leftBar.tab_page_buttons.button_alarms.click()
self.NativeUI.alarms_view.alarmButton.click()
self.NativeUI.widgets.page_buttons.alarms_button.click()
return False
def get_priority(self):
......
{"calibration": {"label": "calibration", "last_performed": 1621526657, "cmd_code": "calib_rate"}, "leak_test": {"label": "Leak Test", "last_performed": 1621526657, "cmd_code": "leak_test"}, "maintenance": {"label": "maintenance", "last_performed": 1621526658, "cmd_code": "main_tenance"}}
......@@ -149,7 +149,7 @@ class confirmWidget(QtWidgets.QWidget):
self.setParent(None)
class confirmPopup(QtWidgets.QWidget):
class confirmPopup(QtWidgets.QDialog):
"""Popup when a command is confirmed by microcontroller.
This popup is a frame containing a confirmWidget object for
each successful command."""
......@@ -159,15 +159,26 @@ class confirmPopup(QtWidgets.QWidget):
self.NativeUI = NativeUI
self.confirmDict = {}
self.vlayout = QtWidgets.QVBoxLayout()
self.vlayout.setSpacing(0)
self.vlayout.setMargin(0)
self.setLayout(self.vlayout)
self.setStyleSheet("background-color:green;")
self.location_on_window()
self.setWindowFlags(
QtCore.Qt.FramelessWindowHint
| QtCore.Qt.Dialog
| QtCore.Qt.WindowStaysOnTopHint
) # no window title
self.timer = QtCore.QTimer()
self.timer.setInterval(500) # just faster than 60Hz
self.timer.timeout.connect(self.adjustSize)
self.timer.start()
def addConfirmation(self, confirmMessage):
print('adding confirmation')
"""Add a confirmation to the popup. Triggered when UI receives a confirmation from the microcontroller"""
self.confirmDict[confirmMessage] = confirmWidget(
self.NativeUI, confirmMessage
......@@ -175,9 +186,9 @@ class confirmPopup(QtWidgets.QWidget):
self.vlayout.addWidget(self.confirmDict[confirmMessage])
return 0
# def location_on_window(self):
# screen = QtWidgets.QDesktopWidget().screenGeometry()
# # widget = self.geometry()
# x = screen.width() - screen.width() / 2
# y = 0 # screen.height() - widget.height()
# self.move(x, y)
def location_on_window(self):
screen = QtWidgets.QDesktopWidget().screenGeometry()
# widget = self.geometry()
x = screen.width() - screen.width() / 2
y = 0 # screen.height() - widget.height()
self.move(x, y)
......@@ -27,7 +27,7 @@ class signallingSpinBox(QtWidgets.QDoubleSpinBox):
manualChanged = QtCore.Signal()
programmaticallyChanged = QtCore.Signal()
def __init__(self, NativeUI, label_text, min, max, initVal, step, decPlaces):
def __init__(self, NativeUI, popup, label_text, min, max, initVal, step, decPlaces):
super().__init__()
self.lineEdit().installEventFilter(self)
self.editable = True
......@@ -36,8 +36,9 @@ class signallingSpinBox(QtWidgets.QDoubleSpinBox):
self.setSingleStep(step)
self.setDecimals(decPlaces)
self.setValue(initVal)
self.NativeUI = NativeUI
#self.populateVals = [label_text, min, max, initVal, step, decPlaces]
self.popUp = NativeUI.typeValPopup# TypeValuePopup(NativeUI, label_text, min, max, initVal, step, decPlaces)
self.popUp = popup# TypeValuePopup(NativeUI, label_text, min, max, initVal, step, decPlaces)
#self.popUp.okButton.clicked.connect(self.okButtonPressed)
#self.popUp.cancelButton.clicked.connect(self.cancelButtonPressed)
......@@ -78,8 +79,10 @@ class signallingSpinBox(QtWidgets.QDoubleSpinBox):
return
#self.popUp.lineEdit.setText(str(self.value()))
#self.popUp.lineEdit.setFocus()
self.popUp.populatePopup(self)
self.popUp.show()
self.popUp.populatePopup(self,self.NativeUI.display_stack.currentWidget())
self.NativeUI.display_stack.setCurrentWidget(self.popUp)
#self.popUp.show()
return True
return False
......@@ -89,7 +92,7 @@ class labelledSpin(QtWidgets.QWidget):
It is created by an information array which indicates labels, units, command type and code for value setting,
and the range of permitted values"""
def __init__(self, NativeUI, infoArray, *args, **kwargs):
def __init__(self, NativeUI, popup, infoArray, *args, **kwargs):
super(labelledSpin, self).__init__(*args, **kwargs)
self.NativeUI = NativeUI
......@@ -122,7 +125,7 @@ class labelledSpin(QtWidgets.QWidget):
self.nameLabel.setFont(NativeUI.text_font)
self.nameLabel.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
self.simpleSpin = signallingSpinBox(NativeUI, self.label, self.min, self.max, self.initVal, self.step, self.decPlaces)
self.simpleSpin = signallingSpinBox(NativeUI, popup, self.label, self.min, self.max, self.initVal, self.step, self.decPlaces)
# self.simpleSpin.setRange(self.min, self.max)
# self.simpleSpin.setSingleStep(self.step)
# self.simpleSpin.setDecimals(self.decPlaces)
......
......@@ -17,14 +17,179 @@ import os
os.environ["QT_IM_MODULE"] = "qtvirtualkeyboard"
from widget_library.ok_cancel_buttons_widget import OkButtonWidget, CancelButtonWidget
from widget_library.numpad_widget import NumberpadWidget
from widget_library.numpad_widget import NumberpadWidget, AlphapadWidget
class TypeValuePopup(QtWidgets.QDialog):
class AbstractTypeValPopup(QtWidgets.QDialog):
"""Popup takes user input to put in spin box. """
okPressed = QtCore.Signal(str)
cancelPressed = QtCore.Signal()
def __init__(self, NativeUI, *args, **kwargs):
def __init__(self, NativeUI, characterType, *args, **kwargs):
super().__init__(*args, **kwargs)
self.NativeUI = NativeUI
# self.label_text = label_text
# self.min, self.max, self.initVal, self.step, self.decPlaces = min, max, initVal, step, decPlaces
grid = QtWidgets.QGridLayout()
grid.setSpacing(1)
self.setStyleSheet("border-radius:4px; background-color:black")
self.characterType = characterType
self.label = QtWidgets.QLabel() # self.label_text)
self.label.setFont(NativeUI.text_font)
self.label.setStyleSheet('color: ' + NativeUI.colors["page_foreground"].name())
self.lineEdit = QtWidgets.QLineEdit()
self.lineEdit.setText("4")
self.lineEdit.setStyleSheet(
"QLineEdit{"
" background-color: white;"
" border-radius: 4px;"
"}"
"QLineEdit[colour = '0']{"
" color: green;"
"}"
"QLineEdit[colour = '1']{"
" color: rgb(144, 231, 211);"
"}"
"QLineEdit[colour = '2']{"
" color: red;"
"}"
)
self.lineEdit.setFont(NativeUI.text_font)
self.lineEdit.setProperty("colour", "1")
self.lineEdit.setAlignment(QtCore.Qt.AlignCenter)
self.lineEdit.saveVal = '' # self.lineEdit.text()
hlayout = QtWidgets.QHBoxLayout()
if characterType == 'numeric':
self.lineEdit.setValidator(
QtGui.QDoubleValidator(0.0, 100.0, 5)
) # ensures only doubles can be typed, do
#self.lineEdit.textEdited.connect(self.setTextColour(1))
self.numberpad = NumberpadWidget(NativeUI)
self.numberpad.numberPressed.connect(self.handle_numberpress)
self.increaseButton = OkButtonWidget(NativeUI)
self.increaseButton.clicked.connect(self.increase_button_clicked)
self.increaseButton.setEnabled(True)
self.decreaseButton = CancelButtonWidget(NativeUI)
self.decreaseButton.clicked.connect(self.decrease_button_clicked)
self.decreaseButton.setEnabled(True)
hlayout.addWidget(self.decreaseButton)
hlayout.addWidget(self.lineEdit)
hlayout.addWidget(self.increaseButton)
if characterType == 'alpha':
self.numberpad = AlphapadWidget(NativeUI)
self.numberpad.numberPressed.connect(self.handle_alphapress)
hlayout.addWidget(self.lineEdit)
# grid.addWidget(self.lineEdit, 0, 0, 1, 2)
self.hlayout2 = QtWidgets.QHBoxLayout()
self.okButton = OkButtonWidget(NativeUI)
self.okButton.setEnabled(True)
self.okButton.pressed.connect(self.handle_ok_press)
self.hlayout2.addWidget(self.okButton)
# grid.addWidget(self.okButton, 1, 0)
self.cancelButton = CancelButtonWidget(NativeUI)
self.cancelButton.setEnabled(True)
self.hlayout2.addWidget(self.cancelButton)
# grid.addWidget(self.cancelButton, 1, 1)
vlayout = QtWidgets.QVBoxLayout()
vlayout.addWidget(self.label)
vlayout.addLayout(hlayout)
vlayout.addWidget(self.numberpad)
vlayout.addLayout((self.hlayout2))
self.setLayout(vlayout)
self.setWindowFlags(
QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint
) # no window title
def handle_ok_press(self):
val = self.lineEdit.text()
if self.characterType == 'numeric':
val = float(val)
self.NativeUI.display_stack.setCurrentWidget(self.return_stack_widget)
if val != self.currentWidg.value():
self.currentWidg.setValue(val)
self.currentWidg.manualChanged.emit()
def populatePopup(self, currentWidg, return_widget):
self.currentWidg = currentWidg
self.return_stack_widget = return_widget
if self.characterType == 'numeric':
self.label_text, self.min, self.max, self.initVal, self.step, self.decPlaces = currentWidg.label_text, currentWidg.min, currentWidg.max, currentWidg.initVal, currentWidg.step, currentWidg.decPlaces
else:
self.label_text = currentWidg.label_text
self.label.setText(self.label_text)
self.lineEdit.setText(str(currentWidg.value()))
def handle_numberpress(self, symbol):
"""Handle number pad button press. Put button value in line edit text, and handle inputs
outside accepted range or number of decimal places. Handle backspace"""
oldText = self.lineEdit.text()
if symbol.isnumeric() or (symbol == '.'):
newText = oldText + symbol
if float(newText) > self.max:
newText = str(self.max)
elif float(newText) < self.min:
newText = str(self.min)
elif '.' in newText:
if len(newText.split('.')[1]) > self.decPlaces:
newText = oldText
self.lineEdit.setText(newText)
elif symbol == '<':
self.lineEdit.setText(oldText[0:-1])
def handle_alphapress(self, symbol):
"""Handle number pad button press. Put button value in line edit text, and handle inputs
outside accepted range or number of decimal places. Handle backspace"""
oldText = self.lineEdit.text()
if symbol.isalpha():
newText = oldText + symbol
self.lineEdit.setText(newText)
elif symbol == '<':
self.lineEdit.setText(oldText[0:-1])
def increase_button_clicked(self):
"""Handle increase step button click"""
currentVal = self.get_value()
newVal = round(float(currentVal) + self.step, self.decPlaces)
if newVal >= self.max:
newVal = self.max
self.lineEdit.setText(str(newVal))
return 0
def decrease_button_clicked(self):
"""Handle decrease step button click"""
currentVal = self.get_value()
newVal = round(float(currentVal) - self.step, self.decPlaces)
if newVal <= self.min:
newVal = self.min
self.lineEdit.setText(str(newVal))
return 0
def get_value(self):
return self.lineEdit.text()
class TypeValuePopup():
"""Popup takes user input to put in spin box. """
okPressed = QtCore.Signal(str)
cancelPressed = QtCore.Signal()
def __init__(self, NativeUI, keyboard, *args, **kwargs):
super().__init__(*args, **kwargs)
#self.label_text = label_text
......@@ -64,7 +229,7 @@ class TypeValuePopup(QtWidgets.QDialog):
) # ensures only doubles can be typed, do
# self.lineEdit.textEdited.connect(self.setTextColour(1))
self.numberpad = NumberpadWidget(NativeUI)
self.numberpad = keyboard#NumberpadWidget(NativeUI)
self.numberpad.numberPressed.connect(self.handle_numberpress)
self.increaseButton = OkButtonWidget(NativeUI)
......@@ -137,6 +302,17 @@ class TypeValuePopup(QtWidgets.QDialog):
elif symbol == '<':
self.lineEdit.setText(oldText[0:-1])
def handle_alphapress(self, symbol):
"""Handle number pad button press. Put button value in line edit text, and handle inputs
outside accepted range or number of decimal places. Handle backspace"""
oldText = self.lineEdit.text()
if symbol.isalpha():
newText = oldText + symbol
self.lineEdit.setText(newText)
elif symbol == '<':
self.lineEdit.setText(oldText[0:-1])
def increase_button_clicked(self):
"""Handle increase step button click"""
currentVal = self.get_value()
......
......@@ -57,7 +57,6 @@ class ModeHandler(PayloadHandler):
outdict[key] = target_data[key]
except KeyError:
logging.debug("Invalid key %s in measurement database", key)
self.UpdateModes.emit(outdict)
return 0
......@@ -68,7 +67,7 @@ class ModeHandler(PayloadHandler):
for widget in self.spinDict:
if (mode in widget) and self.spinDict[widget].manuallyUpdated:
setVal = self.spinDict[widget].get_value()
setVal = round(setVal, widget.decPlaces)
setVal = round(setVal, self.spinDict[widget].decPlaces)
message.append("set" + widget + " to " + str(setVal))
command.append(
[
......@@ -87,7 +86,7 @@ class ModeHandler(PayloadHandler):
for widget in self.mainSpinDict:
if self.mainSpinDict[widget].manuallyUpdated:
setVal = self.mainSpinDict[widget].get_value()
setVal = round(setVal, widget.decPlaces)
setVal = round(setVal, self.mainSpinDict[widget].decPlaces)
message.append("set" + widget + " to " + str(setVal))
command.append(
[
......@@ -100,13 +99,15 @@ class ModeHandler(PayloadHandler):
# command sending should occur in handler
self.commandList = command
self.OpenPopup.emit(message)
self.OpenPopup.emit(self,message)
def sendCommands(self):
if self.commandList == []:
a=1
else:
for command in self.commandList:
print('sending commands')
print(command)
self.NativeUI.q_send_cmd(*command)
self.modeSwitched.emit(self.activeMode)
self.commandSent()
......@@ -167,10 +168,8 @@ class ModeHandler(PayloadHandler):
spin.simpleSpin.set_value(widget.get_value())
def refresh_main_button_colour(self):
print('refreshing main buttons')
self.manuallyUpdatedBoolDict['CURRENT'] = False
for spin in self.mainSpinDict:
print(spin + 'is ' + str(self.mainSpinDict[spin].manuallyUpdated))
self.manuallyUpdatedBoolDict['CURRENT'] = self.manuallyUpdatedBoolDict['CURRENT'] or self.mainSpinDict[spin].manuallyUpdated
for button in self.mainButtonDict:
self.mainButtonDict[button].setColour(str(int(self.manuallyUpdatedBoolDict['CURRENT'])))
......
......@@ -697,7 +697,11 @@ class Layout:
vlayout.addLayout(hButtonLayout)
return expert_tab
passlock_stack = QtWidgets.QStackedWidget()
passlock_stack.addWidget(self.NativeUI.widgets.expert_password_widget)
passlock_stack.addWidget(expert_tab)
# break this here
return passlock_stack # expert_tab
def layout_main_spin_buttons(self) -> QtWidgets.QWidget:
hlayout = QtWidgets.QHBoxLayout()
......
......@@ -61,7 +61,7 @@ from widget_library.ventilator_start_stop_buttons_widget import (
VentilatorStartStopButtonsWidget,
)
from widget_library.line_edit_widget import LabelledLineEditWidget
from global_widgets.global_typeval_popup import TypeValuePopup, AbstractTypeValPopup
# from widget_library.NativeUI.expert_handler import ExpertHandler
# from mode_widgets.NativeUI.personal_handler import PersonalHandler
......@@ -163,24 +163,24 @@ class Widgets:
attrName = "clinical_spin_" + setting[0][2]
if len(setting) == 1:
self.add_handled_widget(
labelledSpin(NativeUI, setting[0]),
labelledSpin(NativeUI, NativeUI.typeValPopupNum,setting[0]),
attrName + "_lim",
NativeUI.clinical_handler,
)
if len(setting) >= 2:
self.add_handled_widget(
labelledSpin(NativeUI, setting[0]),
labelledSpin(NativeUI, NativeUI.typeValPopupNum,setting[0]),
attrName + "_min",
NativeUI.clinical_handler,
)
self.add_handled_widget(
labelledSpin(NativeUI, setting[-1]),
labelledSpin(NativeUI, NativeUI.typeValPopupNum,setting[-1]),
attrName + "_max",
NativeUI.clinical_handler,
)
if len(setting) == 3:
self.add_handled_widget(
labelledSpin(NativeUI, setting[1]),
labelledSpin(NativeUI, NativeUI.typeValPopupNum,setting[1]),
attrName + "_set",
NativeUI.clinical_handler,
)
......@@ -209,8 +209,9 @@ class Widgets:
for setting in modeDict["settings"]:
if setting[0] in modeDict["mainPageSettings"]:
attrName = "CURRENT_" + setting[2]
#setting[3] = setting[3].replace('SET_TARGET_', 'SET_TARGET_CURRENT')
self.add_handled_widget(
SpinButton(NativeUI, setting), attrName, NativeUI.mode_handler
SpinButton(NativeUI, NativeUI.typeValPopupNum,setting), attrName, NativeUI.mode_handler
)
self.add_handled_widget(
......@@ -237,13 +238,13 @@ class Widgets:
]
if startup == "_startup":
self.add_handled_widget(
labelledSpin(NativeUI, targettedSetting),
labelledSpin(NativeUI, NativeUI.typeValPopupNum,targettedSetting),
"spin_" + attrName,
self.startup_handler,
)
else:
self.add_handled_widget(
labelledSpin(NativeUI, targettedSetting),
labelledSpin(NativeUI, NativeUI.typeValPopupNum,targettedSetting),
"spin_" + attrName,
NativeUI.mode_handler,
)
......@@ -290,26 +291,26 @@ class Widgets:
if setting[0] in textBoxes:
if startup == "startup_":
self.add_handled_widget(
LabelledLineEditWidget(NativeUI, setting),
LabelledLineEditWidget(NativeUI, NativeUI.typeValPopupAlpha, setting),
"text_" + startup + attrName,
self.startup_handler,
)
else:
self.add_handled_widget(
LabelledLineEditWidget(NativeUI, setting),
LabelledLineEditWidget(NativeUI, NativeUI.typeValPopupAlpha, setting),
"text_" + startup + attrName,
NativeUI.personal_handler,
)
else:
if startup == "startup_":
self.add_handled_widget(
labelledSpin(NativeUI, setting),
labelledSpin(NativeUI, NativeUI.typeValPopupNum,setting),
"spin_" + startup + attrName,
self.startup_handler,
)
else:
self.add_handled_widget(
labelledSpin(NativeUI, setting),
labelledSpin(NativeUI, NativeUI.typeValPopupNum,setting),
"spin_" + startup + attrName,
NativeUI.personal_handler,
)
......@@ -329,6 +330,7 @@ class Widgets:
)
##### Settings Tab: Expert and Charts tabs
self.add_widget(AbstractTypeValPopup(NativeUI,'numeric'), 'expert_password_widget')
# Expert Tab
# self.expert_confirm_popup = SetConfirmPopup(NativeUI)
......@@ -343,7 +345,7 @@ class Widgets:
for setting in controlDict[key]:
attrName = "expert_spin_" + setting[2]
self.add_handled_widget(
labelledSpin(NativeUI, setting), attrName, NativeUI.expert_handler
labelledSpin(NativeUI, NativeUI.typeValPopupNum,setting), attrName, NativeUI.expert_handler
)
self.add_handled_widget(
......
......@@ -47,7 +47,7 @@ class ExpertHandler(PayloadHandler): # chose QWidget over QDialog family becaus
for widget in self.spinDict:
if self.spinDict[widget].manuallyUpdated:
setVal = self.spinDict[widget].get_value()
setVal = round(setVal, widget.decPlaces)
setVal = round(setVal, self.spindict[widget].decPlaces)
message.append("set" + widget + " to " + str(setVal))
command.append(
[
......
......@@ -5,10 +5,12 @@ from global_widgets.global_typeval_popup import TypeValuePopup
class SignallingLineEditWidget(QtWidgets.QLineEdit):
manualChanged = QtCore.Signal()
def __init__(self, NativeUI):
def __init__(self, NativeUI, popup, label):
super().__init__()
self.installEventFilter(self)
self.label_text = label
self.NativeUI = NativeUI
self.popUp = popup#NativeUI.typeValPopupAlpha
#self.popUp = TypeValuePopup(NativeUI)#,'text edit',0,1,2,3,4)
#self.popUp.lineEdit.setValidator(None) # nsure it accepts text
#self.popUp.okButton.clicked.connect(self.okButtonPressed)
......@@ -26,14 +28,20 @@ class SignallingLineEditWidget(QtWidgets.QLineEdit):
def eventFilter(self, source, event):
if source is self and event.type() == QtCore.QEvent.MouseButtonDblClick:
self.popUp.lineEdit.setText(str(self.text()))
self.popUp.show()
self.popUp.populatePopup(self, self.NativeUI.display_stack.currentWidget())
self.NativeUI.display_stack.setCurrentWidget(self.popUp)
return True
return False
def value(self):
return self.text()
def setValue(self, value):
self.setText(str(value))
class LabelledLineEditWidget(QtWidgets.QWidget):
def __init__(self, NativeUI, infoArray, *args, **kwargs):
def __init__(self, NativeUI, popup, infoArray, *args, **kwargs):
super().__init__(*args, **kwargs)
# print(infoArray)
self.NativeUI = NativeUI
......@@ -59,7 +67,7 @@ class LabelledLineEditWidget(QtWidgets.QWidget):
self.nameLabel.setAlignment(QtCore.Qt.AlignRight)
widgetList.append(self.nameLabel)
self.simpleSpin = SignallingLineEditWidget(NativeUI)
self.simpleSpin = SignallingLineEditWidget(NativeUI, popup, self.label)
self.simpleSpin.setText(self.initText)
self.simpleSpin.setStyleSheet(
"""QDoubleSpinBox{ width:100px; font:16pt}
......
......@@ -45,6 +45,37 @@ class NumberpadWidget(QtWidgets.QWidget):
self.setLayout(grid)
def buttonPressed(self,symbol: str):
"""Emit a signal with the button's character"""
self.numberPressed.emit(symbol)
class AlphapadWidget(QtWidgets.QWidget):
"""A widget with digits 0-9, a decimal point '.', and a backspace '<'.
Has one signal for any button pressed, the corresponding character is emitted with the signal.
"""
numberPressed = QtCore.Signal(str)
def __init__(self, NativeUI, *args, **kwargs):
super().__init__(*args, **kwargs)
symbol_list = ['Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M','<']
newLineCharacters = ['P','L']
button_dict = {}
grid = QtWidgets.QGridLayout()
ncolumns = 3
i = 0
j=0
for symbol in symbol_list:
button_dict[symbol] = NumberpadButton(NativeUI, symbol)
button_dict[symbol].pressed.connect(lambda j=symbol: self.buttonPressed(j))
grid.addWidget(button_dict[symbol], j, i)
i = i+1
if symbol in newLineCharacters:
i = 0
j = j + 1
self.setLayout(grid)
def buttonPressed(self,symbol: str):
"""Emit a signal with the button's character"""
self.numberPressed.emit(symbol)
\ No newline at end of file
......@@ -28,7 +28,7 @@ from global_widgets.global_spinbox import signallingSpinBox
class SpinButton(QtWidgets.QFrame):
"""TO DO: Implement command sending"""
def __init__(self, NativeUI, infoArray):
def __init__(self, NativeUI, popup, infoArray):
super().__init__()
self.manuallyUpdated = False
......@@ -38,9 +38,12 @@ class SpinButton(QtWidgets.QFrame):
self.label_text, self.units, self.tag, self.cmd_type, self.cmd_code, self.min, self.max, self.initVal, self.step, self.decPlaces = (
infoArray
)
# self.cmd_type = settings[3]
# self.cmd_code = settings[4]
# self.tag = settings[2]
#print('before')
#print(self.cmd_type)
self.cmd_type = self.cmd_type.replace('SET_TARGET_','SET_TARGET_CURRENT')
#self.cmd_type = settings[3]
#self.cmd_code = settings[4]
#self.tag = settings[2]
self.NativeUI = NativeUI
self.layout = QtWidgets.QVBoxLayout()
......@@ -64,15 +67,7 @@ class SpinButton(QtWidgets.QFrame):
self.layout.addWidget(self.label)
# self.setFont(NativeUI.text_font)
self.simpleSpin = signallingSpinBox(
NativeUI,
self.label_text,
self.min,
self.max,
self.initVal,
self.step,
self.decPlaces,
)
self.simpleSpin = signallingSpinBox(NativeUI, popup, self.label_text, self.min, self.max, self.initVal, self.step, self.decPlaces)
self.simpleSpin.lineEdit().setStyleSheet("border:blue;")
# self.simpleSpin.setFixedHeight(100)
# self.simpleSpin.setFont(NativeUI.text_font)
......@@ -131,7 +126,7 @@ class SpinButton(QtWidgets.QFrame):
self.simpleSpin.setValue(newVal[self.tag])
self.setTextColour(1)
else:
if int(self.simpleSpin.value()) == int(newVal[self.tag]):
if round(self.simpleSpin.value(),self.decPlaces) == round(newVal[self.tag],self.decPlaces):
self.manuallyUpdated = False
self.setTextColour(1)
......@@ -143,6 +138,7 @@ class SpinButton(QtWidgets.QFrame):
self.manuallyUpdated = True
self.simpleSpin.programmaticallyChanged.emit()
def manualChanged(self):
print("manually changed" + self.label.text())
"""Called when user manually makes a change. Stops value from updating and changes colour"""
......@@ -171,26 +167,3 @@ class SpinButton(QtWidgets.QFrame):
self.simpleSpin.setFont(font)
return 0
# targets = self.NativeUI.get_targets_db()
# if targets == {}:
# return
# for spin, label in zip(self.__spins, self.__labels):
# if spin.doubleSpin.value() != float(targets[label]):
# spin.setTextColour("0")
# else:
# spin.setTextColour("2")
@QtCore.Slot(dict)
def localise_text(self, text: dict) -> int:
self.spinDict["Inhale Pressure"].label.setText(
text["spin_box_label_Inhale_Pressure"]
)
self.spinDict["Respiratory Rate"].label.setText(
text["spin_box_label_Respiratory_Rate"]
)
self.spinDict["Inhale Time"].label.setText(text["spin_box_label_Inhale_Time"])
self.spinDict["IE Ratio"].label.setText(text["spin_box_label_IE_Ratio"])
self.spinDict["Percentage O2"].label.setText(
text["spin_box_label_Percentage_O2"]
)
return 0
......@@ -102,7 +102,7 @@ class StartupHandler(
message, command = [], []
for widget in self.spinDict:
setVal = self.spinDict[widget].get_value()
setVal = round(setVal, widget.decPlaces)
setVal = round(setVal, self.spinDict[widget].decPlaces)
message.append("set" + widget + " to " + str(setVal))
command.append(
[self.spinDict[widget].cmd_type, self.spinDict[widget].cmd_code, setVal]
......
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