Commit 2b80f055 authored by Tiago Sarmento's avatar Tiago Sarmento

merged with brain braun

parents 4fee0439 8e8f0423
Pipeline #1498 failed with stages
......@@ -61,9 +61,12 @@ logging.basicConfig(
class NativeUI(HEVClient, QMainWindow):
"""Main application with client logic"""
def __init__(self, *args, **kwargs):
def __init__(self, resolution: list, *args, **kwargs):
super().__init__(*args, **kwargs)
self.screen_width = resolution[0]
self.screen_height = resolution[1]
config_path = self.__find_configs()
# self.setFixedSize(1920, 1080)
......@@ -87,9 +90,11 @@ class NativeUI(HEVClient, QMainWindow):
for key in self.colors:
self.colors[key] = QColor.fromRgb(*self.colors[key])
self.text_font = QFont("Sans Serif", 20)
self.value_font = QFont("Sans Serif", 40)
self.text_size = "20pt" # TODO: remove in favour of self.text_font
self.text_font = QFont("Sans Serif", resolution[0] / 96) # 20px for 1920*1080
#self.text_size = 16 # temporary, used by Tiago
self.value_font = QFont(
"Sans Serif", 2 * resolution[0] / 96
) # 40px for 1920*1080
self.icons = {
"button_main_page": "user-md-solid",
"button_alarms_page": "exclamation-triangle-solid",
......@@ -103,6 +108,27 @@ class NativeUI(HEVClient, QMainWindow):
self.iconpath, self.icons[key] + "." + self.iconext
)
# initialise databases TODO: remove these and use handlers instead.
self.db_lock = Lock()
# self.__data = {}
self.__readback = {}
# self.__cycle = {}
self.__alarms = {}
self.__targets = {}
self.__personal = {}
self.ongoingAlarms = {}
self.__database_list = [
"__data",
"__readback",
"__cycle",
"__battery",
"__plots",
"__alarms",
"__targets",
"__personal",
]
# Set up the handlers
self.battery_handler = BatteryHandler()
self.data_handler = DataHandler(plot_history_length=1000)
......@@ -125,25 +151,6 @@ class NativeUI(HEVClient, QMainWindow):
]
self.messageCommandPopup = SetConfirmPopup(self)
# initialise databases TODO: remove these and use handlers instead.
self.db_lock = Lock()
# self.__data = {}
self.__readback = {}
# self.__cycle = {}
self.__alarms = {}
self.__targets = {}
self.__personal = {}
self.ongoingAlarms = {}
self.__database_list = [
"__data",
"__readback",
"__cycle",
"__battery",
"__plots",
"__alarms",
"__targets",
"__personal",
]
self.widgets = Widgets(self) # Create all the widgets we'll need
self.layouts = Layout(self, self.widgets) #
......@@ -355,10 +362,7 @@ class NativeUI(HEVClient, QMainWindow):
self.mode_handler.commandSent
)
print('main button connections')
for key, button_widget in self.mode_handler.mainButtonDict.items():
print(key)
print(button_widget)
if isinstance(button_widget, (OkButtonWidget)):
button_widget.clicked.connect(
self.mode_handler.handle_mainokbutton_click
......@@ -369,21 +373,21 @@ class NativeUI(HEVClient, QMainWindow):
button_widget.clicked.connect(
self.mode_handler.commandSent
)
for key, spin_widget in self.clinical_handler.spinDict.items():
spin_widget.simpleSpin.manualChanged.connect(
lambda i=key: self.clinical_handler.handle_manual_change(i)
)
for key, button_widget in self.clinical_handler.buttonDict.items():
if isinstance(button_widget, (OkButtonWidget)):
button_widget.clicked.connect(
self.clinical_handler.handle_okbutton_click
)
elif isinstance(button_widget, CancelButtonWidget):
button_widget.clicked.connect(
self.clinical_handler.commandSent
)
#
# for key, spin_widget in self.clinical_handler.spinDict.items():
# spin_widget.simpleSpin.manualChanged.connect(
# lambda i=key: self.clinical_handler.handle_manual_change(i)
# )
#
# for key, button_widget in self.clinical_handler.buttonDict.items():
# if isinstance(button_widget, (OkButtonWidget)):
# button_widget.clicked.connect(
# self.clinical_handler.handle_okbutton_click
# )
# elif isinstance(button_widget, CancelButtonWidget):
# button_widget.clicked.connect(
# self.clinical_handler.commandSent
# )
self.mode_handler.OpenPopup.connect(self.messageCommandPopup.populatePopup)
self.messageCommandPopup.ModeSend.connect(self.mode_handler.sendCommands)
......@@ -392,8 +396,8 @@ class NativeUI(HEVClient, QMainWindow):
self.expert_handler.OpenPopup.connect(self.messageCommandPopup.populatePopup)
self.messageCommandPopup.ExpertSend.connect(self.expert_handler.sendCommands)
self.clinical_handler.OpenPopup.connect(self.messageCommandPopup.populatePopup)
self.messageCommandPopup.ClinicalSend.connect(self.expert_handler.sendCommands)
#self.clinical_handler.OpenPopup.connect(self.messageCommandPopup.populatePopup)
#self.messageCommandPopup.ClinicalSend.connect(self.expert_handler.sendCommands)
#self.messageCommandPopup.okButton.pressed.connect(self.expert_handler.sendCommands)
self.messageCommandPopup.cancelButton.pressed.connect(self.messageCommandPopup.close)
......@@ -477,6 +481,10 @@ class NativeUI(HEVClient, QMainWindow):
return database_name
def set_current_mode(self, mode):
"""
Set the current mode
TODO: move to mode handler
"""
print("setting native ui mode")
print(mode)
self.currentMode = mode
......@@ -713,7 +721,7 @@ if __name__ == "__main__":
# setup pyqtplot widget
app = QApplication(sys.argv)
dep = NativeUI()
dep = NativeUI(interpret_resolution(command_line_args.resolution))
set_window_size(
dep,
resolution=command_line_args.resolution,
......
......@@ -26,9 +26,8 @@ class AlarmList(QtWidgets.QListWidget):
self.setSizePolicy(
QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding
)
self.setStyleSheet(
"background-color:white;" "font-size: " + NativeUI.text_size + ";"
)
self.setStyleSheet("background-color:white;")
self.setFont(NativeUI.text_font)
iconpath_bell = os.path.join(NativeUI.iconpath, "bell-solid.png")
iconpath_bellReg = os.path.join(NativeUI.iconpath, "bell-regular.png")
......@@ -36,10 +35,9 @@ class AlarmList(QtWidgets.QListWidget):
self.solidBell = QtGui.QIcon(iconpath_bell)
self.regularBell = QtGui.QIcon(iconpath_bellReg)
newItem = QtWidgets.QListWidgetItem(' ')
newItem = QtWidgets.QListWidgetItem(" ")
self.addItem(newItem)
def acknowledge_all(self):
for x in range(self.count() - 1):
self.item(x).setText("acknowledgedAlarm")
......@@ -47,9 +45,16 @@ class AlarmList(QtWidgets.QListWidget):
def addAlarm(self, abstractAlarm):
timestamp = str(abstractAlarm.startTime)[:-3]
newItem = QtWidgets.QListWidgetItem(self.solidBell, timestamp + ': ' + abstractAlarm.alarmPayload['alarm_type'] + ' - ' + abstractAlarm.alarmPayload["alarm_code"])
newItem = QtWidgets.QListWidgetItem(
self.solidBell,
timestamp
+ ": "
+ abstractAlarm.alarmPayload["alarm_type"]
+ " - "
+ abstractAlarm.alarmPayload["alarm_code"],
)
self.insertItem(0, newItem) # add to the top
#self.labelList
# self.labelList
def removeAlarm(self, abstractAlarm):
for x in range(self.count() - 1):
......@@ -57,7 +62,6 @@ class AlarmList(QtWidgets.QListWidget):
self.takeItem(x)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
widg = alarmList()
......
......@@ -21,11 +21,12 @@ class AlarmWidget(QtWidgets.QWidget):
"""Object containing information particular to one alarm.
Created when alarm received from microcontroller, timeout after alarm signal stops.
Is contained within alarmPopup"""
def __init__(self, NativeUI, abstractAlarm, alarmCarrier, *args, **kwargs):
super(AlarmWidget, self).__init__(*args, **kwargs)
self.NativeUI = NativeUI
self.alarmCarrier = alarmCarrier # Needs to refer to its containing object
self.alarmCarrier = alarmCarrier # Needs to refer to its containing object
self.layout = QtWidgets.QHBoxLayout()
self.layout.setSpacing(0)
......@@ -41,22 +42,21 @@ class AlarmWidget(QtWidgets.QWidget):
self.layout.addWidget(iconLabel)
self.textLabel = QtWidgets.QLabel()
self.textLabel.setText(self.alarmPayload['alarm_type']+ ' - ' + self.alarmPayload["alarm_code"])
self.textLabel.setText(
self.alarmPayload["alarm_type"] + " - " + self.alarmPayload["alarm_code"]
) #remove priority_
self.textLabel.setFixedWidth(400)
self.textLabel.setAlignment(QtCore.Qt.AlignCenter)
self.textLabel.setStyleSheet("font-size: " + NativeUI.text_size + ";")
self.textLabel.setFont(NativeUI.text_font)
#self.textLabel.setStyleSheet("font-size: " + NativeUI.text_size + ";")
self.layout.addWidget(self.textLabel)
self.setFixedHeight(40)
self.setLayout(self.layout)
if self.alarmPayload["alarm_type"] == "PRIORITY_HIGH":
self.setStyleSheet("background-color:red;")
#self.priority = "PRIORITY_HIGH"
elif self.alarmPayload["alarm_type"] == "PRIORITY_MEDIUM":
self.setStyleSheet("background-color:orange;")
#self.priority = "PRIORITY_LOW"
#self.code =
# self.timer = QtCore.QTimer()
# self.timer.setInterval(500) # just faster than 60Hz
......@@ -74,6 +74,13 @@ class AlarmWidget(QtWidgets.QWidget):
return self.alarmPayload["alarm_type"]
def setFont(self, font) -> int:
"""
Set the font for textLabel.
"""
self.textLabel.setFont(font)
return 0
# def checkAlarm(self):
# """Check alarm still exists in ongoingAlarms object. If present do nothing, otherwise delete."""
# self.ongoingAlarms = self.NativeUI.ongoingAlarms
......@@ -90,7 +97,7 @@ class AlarmPopup(QtWidgets.QDialog):
Needs to adjust its size whenever a widget is deleted"""
def __init__(self, NativeUI, *args, **kwargs):
super(AlarmPopup, self).__init__(*args, **kwargs)
self.setParent(NativeUI) # ensures popup closes when main UI does
self.setParent(NativeUI) # ensures popup closes when main UI does
self.alarmDict = {}
self.NativeUI = NativeUI
self.extraAlarms = AlarmExtrasWidget(NativeUI,self)
......@@ -102,7 +109,9 @@ class AlarmPopup(QtWidgets.QDialog):
self.location_on_window()
self.setWindowFlags(
QtCore.Qt.FramelessWindowHint | QtCore.Qt.Dialog | QtCore.Qt.WindowStaysOnTopHint
QtCore.Qt.FramelessWindowHint
| QtCore.Qt.Dialog
| QtCore.Qt.WindowStaysOnTopHint
) # no window title
self.shadow = QtWidgets.QGraphicsDropShadowEffect()
......@@ -113,7 +122,6 @@ class AlarmPopup(QtWidgets.QDialog):
self.timer = QtCore.QTimer()
self.timer.setInterval(100) # just faster than 60Hz
self.timer.timeout.connect(self.adjustSize)
#self.timer.timeout.connect(self.refresh_alarm_ordering)
self.timer.start()
self.show()
......@@ -208,7 +216,8 @@ class AlarmExtrasWidget(QtWidgets.QWidget):
self.textLabel.setText('1 More Alarms')
self.textLabel.setFixedWidth(400)
self.textLabel.setAlignment(QtCore.Qt.AlignCenter)
self.textLabel.setStyleSheet("font-size: " + NativeUI.text_size + ";")
self.textLabel.setFont(NativeUI.text_font)
#self.textLabel.setStyleSheet("font-size: " + NativeUI.text_size + ";")
self.layout.addWidget(self.textLabel)
self.setFixedHeight(40)
......
......@@ -26,34 +26,41 @@ class AlarmTable(QtWidgets.QTableWidget):
self.setSizePolicy(
QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding
)
self.setStyleSheet(
"background-color:white;" "font-size: " + NativeUI.text_size + ";"
)
self.setStyleSheet("background-color:white;")
self.setFont(NativeUI.text_font)
self.nrows = 0
self.setColumnCount(4)
self.setSortingEnabled(True)
if self.nrows == 0:
self.setHorizontalHeaderLabels(['Timestamp', 'Priority Level', 'Alarm Code', 'Duration'])
self.setHorizontalHeaderLabels(
["Timestamp", "Priority Level", "Alarm Code", "Duration"]
)
self.payloadKeys = ['alarm_type', 'alarm_code']
self.payloadKeys = ["alarm_type", "alarm_code"]
self.resizeColumnsToContents()
self.alarmDict = {}
self.timer = QtCore.QTimer()
self.timer.setInterval(100)
#self.timer.timeout.connect(self.updateDuration)
# self.timer.timeout.connect(self.updateDuration)
self.timer.start()
def addAlarm(self, abstractAlarm):
timestamp = str(datetime.now())[:-3]
newItem = QtWidgets.QListWidgetItem(self.solidBell, timestamp + ': ' + abstractAlarm.alarmPayload['alarm_type'] + ' - ' + abstractAlarm.alarmPayload["alarm_code"])
newItem = QtWidgets.QListWidgetItem(
self.solidBell,
timestamp
+ ": "
+ abstractAlarm.alarmPayload["alarm_type"]
+ " - "
+ abstractAlarm.alarmPayload["alarm_code"],
)
self.insertItem(0, newItem) # add to the top
#self.labelList
# self.labelList
#widg = self.cellWidget(rowNumber, 4)
#cellItem.setText(str(abstractAlarm.duration))
# widg = self.cellWidget(rowNumber, 4)
# cellItem.setText(str(abstractAlarm.duration))
# abstractAlarm.alarmExpired.connect(lambda i =newItem, j = abstractAlarm: self.update_duration(i,j))
# self.setItem(self.nrows, colnum, newItem)
# tableItem.setText(str(abstractAlarm.duration))
......@@ -65,24 +72,28 @@ class AlarmTable(QtWidgets.QTableWidget):
def addAlarmRow(self, abstractAlarm):
self.setSortingEnabled(False)
self.setRowCount(self.nrows+1)
self.setRowCount(self.nrows + 1)
colnum = 0
newItem = QtWidgets.QTableWidgetItem(str(abstractAlarm.startTime)[:-3])
self.setItem(self.nrows, 0, newItem)
newItem = QtWidgets.QTableWidgetItem(abstractAlarm.alarmPayload['alarm_type'])
newItem = QtWidgets.QTableWidgetItem(abstractAlarm.alarmPayload["alarm_type"])
self.setItem(self.nrows, 1, newItem)
newItem = QtWidgets.QTableWidgetItem(abstractAlarm.alarmPayload['alarm_code'])
newItem = QtWidgets.QTableWidgetItem(abstractAlarm.alarmPayload["alarm_code"])
self.setItem(self.nrows, 2, newItem)
newItem = QtWidgets.QTableWidgetItem(' ')
newItem = QtWidgets.QTableWidgetItem(" ")
self.alarmDict[self.nrows] = newItem
self.setItem(self.nrows, 3, self.alarmDict[self.nrows])
#abstractAlarm.alarmExpired.connect(lambda i = self.alarmDict[self.nrows], j = abstractAlarm: self.update_duration(i,j))
self.timer.timeout.connect(lambda i = self.alarmDict[self.nrows], j = abstractAlarm: self.update_duration(i,j))
# abstractAlarm.alarmExpired.connect(lambda i = self.alarmDict[self.nrows], j = abstractAlarm: self.update_duration(i,j))
self.timer.timeout.connect(
lambda i=self.alarmDict[self.nrows], j=abstractAlarm: self.update_duration(
i, j
)
)
if self.nrows == 1:
self.resizeColumnsToContents()
self.nrows = self.nrows + 1
......@@ -90,8 +101,6 @@ class AlarmTable(QtWidgets.QTableWidget):
def update_duration(self, cellItem, abstractAlarm):
cellItem.setText(str(abstractAlarm.duration))
if __name__ == "__main__":
......
......@@ -9,6 +9,8 @@
"label_foreground":[200, 200, 200],
"display_background":[200, 200, 200],
"display_foreground":[0, 0, 0],
"display_foreground_changed":[0, 200, 0],
"display_foreground_red":[200, 0, 0],
"baby_blue":[144, 231, 211],
"red":[200, 0, 0],
"green":[0, 200, 0],
......
......@@ -20,13 +20,9 @@ class selectorButton(QtWidgets.QPushButton):
def __init__(self, NativeUI, *args, **kwargs):
super(selectorButton, self).__init__(*args, **kwargs)
self.setFont(NativeUI.text_font)
style = (
"QPushButton{"
" font-size: " + NativeUI.text_size + ";"
"}"
"QPushButton[selected='0']{"
" font-size: " + NativeUI.text_size + ";"
" color: " + NativeUI.colors["page_foreground"].name() + ";"
" background-color: "
+ NativeUI.colors["button_background_enabled"].name()
......@@ -34,7 +30,6 @@ class selectorButton(QtWidgets.QPushButton):
" border:none"
"}"
"QPushButton[selected='1']{"
" font-size: " + NativeUI.text_size + ";"
" color: " + NativeUI.colors["page_background"].name() + ";"
" background-color:"
+ NativeUI.colors["button_foreground_disabled"].name()
......
......@@ -104,11 +104,12 @@ class labelledSpin(QtWidgets.QWidget):
self.manuallyUpdated = False
self.layout = QtWidgets.QHBoxLayout()
textStyle = "color:white;" "font-size: " + NativeUI.text_size + ";"
textStyle = "color:white;"
# if self.label != "":
self.nameLabel = QtWidgets.QLabel(self.label)
self.nameLabel.setStyleSheet(textStyle)
self.nameLabel.setFont(NativeUI.text_font)
self.nameLabel.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
self.simpleSpin = signallingSpinBox(NativeUI)
......@@ -119,7 +120,6 @@ class labelledSpin(QtWidgets.QWidget):
self.simpleSpin.setStyleSheet(
"QDoubleSpinBox{"
" width:100px;" # TODO: unhardcode
" font:" + NativeUI.text_size + ";"
"}"
"QDoubleSpinBox[bgColour='1']{"
" background-color:" + NativeUI.colors["page_foreground"].name() + ";"
......@@ -138,15 +138,13 @@ class labelledSpin(QtWidgets.QWidget):
"}"
"QDoubleSpinBox::up-button{"
"width:20; "
"background-color:white;"
"color:black;"
"}"
"QDoubleSpinBox::down-button{"
"width:20px;"
"height:20px; "
"border:none;"
"}"
)
self.simpleSpin.setFont(NativeUI.text_font)
self.simpleSpin.setProperty("textColour", "1")
self.simpleSpin.setProperty("bgColour", "1")
self.simpleSpin.setButtonSymbols(
......
......@@ -33,7 +33,6 @@ class TypeValuePopup(QtWidgets.QDialog):
self.lineEdit.setText("4")
self.lineEdit.setStyleSheet(
"QLineEdit{"
" font-size: " + NativeUI.text_size + ";"
" background-color: white;"
" border-radius: 4px;"
"}"
......@@ -47,6 +46,7 @@ class TypeValuePopup(QtWidgets.QDialog):
" 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()
......
......@@ -64,6 +64,10 @@ class TabModeswitchButton(QtWidgets.QWidget):
self.switchButton.setText(self.mode_popup.mode)
self.modeSwitched.emit(self.mode_popup.mode)
def set_size(self, x: int, y: int, spacing=10) -> int:
self.setFixedSize(x, y)
return 0
class modeswitchPopup(QtWidgets.QWidget):
def __init__(self, NativeUI, *args, **kwargs):
......
......@@ -50,10 +50,10 @@ class TabStartStopStandbyButtons(QtWidgets.QWidget):
button.setStyleSheet(
"background-color:" + NativeUI.colors["background_enabled"].name() + ";"
"border-color:" + NativeUI.colors["page_foreground"].name() + ";"
"font-size:" + NativeUI.text_size + ";"
"color:" + NativeUI.colors["page_foreground"].name() + ";"
"border:none"
)
button.setFont(NativeUI.text_font)
button.setFixedSize(self.__button_size)
self.setLayout(layout)
......@@ -16,7 +16,7 @@ class ClinicalHandler(PayloadHandler):
#settingToggle = QtCore.Signal(str)
def __init__(self, NativeUI, *args, **kwargs):
super().__init__(['TARGET'],*args, **kwargs)
super().__init__([''],*args, **kwargs)
#super(TabModes, self).__init__(NativeUI, *args, **kwargs)
self.NativeUI = NativeUI
self.spinDict = {}
......@@ -27,7 +27,7 @@ class ClinicalHandler(PayloadHandler):
with open("NativeUI/configs/clinical_config.json") as json_file:
clinicalDict = json.load(json_file)
#self.relevantKeys = [print(setting) for setting in clinicalDict['settings']]
#self.relevantKeys = [setting for setting in clinicalDict['settings']]
def add_widget(self, widget, key: str):
if isinstance(widget, labelledSpin):
......
......@@ -25,7 +25,7 @@ class ModeHandler(PayloadHandler):
self.commandList = []
self.mainSpinDict = {}
self.mainButtonDict = {}
self.modeList = self.NativeUI.modeList + ['CURRENT']
self.modeList = ["PC/AC", "PC/AC-PRVC", "PC-PSV", "CPAP", 'CURRENT']
self.manuallyUpdatedBoolDict = { mode: False for mode in self.modeList }
self.mainManuallyUpdated = False
self.activeMode = self.modeList[0]
......
......@@ -34,19 +34,35 @@ class Layout:
def __init__(self, NativeUI, widgets, *args, **kwargs):
self.NativeUI = NativeUI
self.widgets = widgets
self.text_font = NativeUI.text_font
self.screen_width = NativeUI.screen_width
self.screen_height = NativeUI.screen_height
# Define sizes
self.top_bar_height = 75
self.left_bar_width = 150
self.main_page_bottom_bar_height = 150
self.main_page_normal_measurements_width = 250
# Global
self.widget_spacing = max(
[int(self.screen_height / 192), 5]
) # 10 for 1920x1080
self.measurement_widget_size_ratio = 1 / 0.46
self.top_bar_height = int(self.screen_height / 14.4) # 75 for 1920x1080
self.left_bar_width = int(self.screen_width / 12.8) # 150 for 1920x1080
# main page
self.main_page_bottom_bar_height = int(
self.screen_height / 7.2
) # 150 for 1920x1080
self.main_page_normal_measurements_width = int(
self.screen_width / 7.68
) # 250 for 1920x1080
self.main_page_detailed_measurement_width = (
self.main_page_normal_measurements_width * 2
)
self.measurement_widget_size_ratio = 1 / 0.46
self.construct_page_widgets()
# Popups
NativeUI.widgets.alarm_popup.setFont(self.NativeUI.text_font)
def construct_page_widgets(self) -> int:
"""
Build all of the main pages
......@@ -95,11 +111,21 @@ class Layout:
widg.setLayout(vlayout)
return widg
def global_layout(self):
hlayout = QtWidgets.QHBoxLayout()
vlayout = QtWidgets.QVBoxLayout()
# Define Sizes
f_mode = 0.25
f_battery = 0.2
f_localisation = 0.1
f_personal = 1 - (f_mode + f_battery + f_localisation)
mode_display_width = int(self.screen_width * f_mode)
personal_display_width = int(self.screen_width * f_personal)
localisation_display_width = int(self.screen_width * f_localisation)
battery_display_width = int(self.screen_width * f_battery)
# Define the stack of pages (used by the page buttons to set the current page)
self.widgets.add_widget(
self.__make_stack(
......@@ -123,9 +149,11 @@ class Layout:
]
)
)
self.widgets.page_buttons.set_size(self.left_bar_width, None)
self.widgets.page_buttons.set_size(
self.left_bar_width, None, spacing=self.widget_spacing
)
self.widgets.ventilator_start_stop_buttons_widget.set_size(
self.left_bar_width, None
self.left_bar_width, None, spacing=self.widget_spacing
)
self.widgets.ventilator_start_stop_buttons_widget.setFont(
self.NativeUI.text_font
......@@ -145,11 +173,23 @@ class Layout:
]
)
)
self.widgets.battery_display.set_size(400, self.top_bar_height)
self.widgets.personal_display.set_size(None, self.top_bar_height)
self.widgets.battery_display.setFont(self.NativeUI.text_font)
self.widgets.tab_modeswitch.set_size(
mode_display_width, self.top_bar_height, spacing=self.widget_spacing
)
# self.widgets.tab_modeswitch.setFont()
self.widgets.personal_display.set_size(
personal_display_width, self.top_bar_height, spacing=self.widget_spacing
)
self.widgets.personal_display.setFont(self.NativeUI.text_font)
self.widgets.localisation_button.set_size(
localisation_display_width, self.top_bar_height, spacing=self.widget_spacing
)
self.widgets.localisation_button.setFont(self.NativeUI.text_font)
self.widgets.battery_display.set_size(
battery_display_width, self.top_bar_height, spacing=self.widget_spacing
)
self.widgets.battery_display.setFont(self.NativeUI.text_font)
vlayout.addLayout(hlayout)
return vlayout
......@@ -171,6 +211,7 @@ class Layout:
self.main_page_normal_measurements_width, # but allow plots to expand to
None, # fill the available space.
widget_size_ratio=self.measurement_widget_size_ratio,
spacing=self.widget_spacing,
)
self.widgets.normal_measurements.set_label_font(self.NativeUI.text_font)
self.widgets.normal_measurements.set_value_font(self.NativeUI.value_font)
......@@ -212,9 +253,17 @@ class Layout:
center_widgets = [self.widgets.plot_stack]
bottom_widgets = [self.widgets.history_buttons, self.layout_main_spin_buttons()]
self.widgets.history_buttons.set_size(None, self.main_page_bottom_bar_height)
self.widgets.history_buttons.set_size(
None, self.main_page_bottom_bar_height, spacing=self.widget_spacing
)
self.widgets.history_buttons.setFont(self.NativeUI.text_font)
# TODO spin_buttons sizes
self.widgets.spin_buttons.set_size(
self.screen_width - self.left_bar_width - self.main_page_bottom_bar_height,
self.main_page_bottom_bar_height,
spacing=self.widget_spacing,
)
self.widgets.spin_buttons.set_label_font(self.NativeUI.text_font)
self.widgets.spin_buttons.set_value_font(self.NativeUI.value_font)
for widget in center_widgets:
page_main_center_layout.addWidget(widget)
......@@ -240,9 +289,9 @@ class Layout:
[
self.layout_tab_alarm_list(alarm_tab_widgets),
self.layout_tab_alarm_table(alarm_table_tab_widgets),
#self.layout_tab_clinical_limits(),
self.layout_tab_clinical_limits(),
],
["List of Alarms", "Alarm Table"],#, "Clinical Limits"],
["List of Alarms", "Alarm Table", "Clinical Limits"],
)
page_alarms.setFont(self.NativeUI.text_font)
return page_alarms
......@@ -256,7 +305,9 @@ class Layout:
[self.widgets.charts_widget, self.widgets.chart_buttons_widget]
)
self.widgets.chart_buttons_widget.setFont(self.NativeUI.text_font)
self.widgets.chart_buttons_widget.set_size(self.left_bar_width, None)
self.widgets.chart_buttons_widget.set_size(
self.left_bar_width, None, spacing=self.widget_spacing
)
# Create the stack
page_settings = SwitchableStackWidget(
......@@ -550,8 +601,8 @@ class Layout:
+ self.NativeUI.colors["page_background"].name()
+ ";"
"color:" + self.NativeUI.colors["page_foreground"].name() + ";"
"font-size: " + self.NativeUI.text_size + ";"
)
titleLabel.setFont(self.text_font)
titleLabel.setAlignment(QtCore.Qt.AlignCenter)
vlayout.addWidget(titleLabel)
......
......@@ -114,7 +114,9 @@ class Widgets:
self.tab_modeswitch = TabModeswitchButton(NativeUI)
self.battery_display = BatteryDisplayWidget(NativeUI)
self.personal_display = PersonalDisplayWidget(NativeUI)
self.localisation_button = LocalisationButtonWidget(NativeUI.localisation_files)
self.localisation_button = LocalisationButtonWidget(
NativeUI.localisation_files, NativeUI.colors
)
# Left Bar widgets
self.page_buttons = PageButtonsWidget(NativeUI)
......@@ -142,31 +144,32 @@ class Widgets:
self.alarm_table = AlarmTable(NativeUI)
self.clinical_tab = QWidget() # TabClinical(NativeUI)
# ### Alarm limits
# with open("NativeUI/configs/clinical_config.json") as json_file:
# clinicalDict = json.load(json_file)
#
# #radioSettings = modeDict["radioSettings"]
# #modes = NativeUI.modeList
#
# #self.add_handled_widget(QStackedWidget(), 'main_mode_stack', NativeUI.mode_handler)
# for setting in clinicalDict['settings']:
# attrName = 'clinical_spin_' + setting[0][1][2]
# setting[3] = setting[3] + 'MIN'
# self.add_handled_widget(labelledSpin(NativeUI, setting), attrName + '_min', NativeUI.clinical_handler)
# setting[3] = setting[3] + 'MAX'
# self.add_handled_widget(labelledSpin(NativeUI, setting), attrName + '_max', NativeUI.clinical_handler)
# #setting[3] = 'SET_TARGET'
#
# #if setting[0] in clinicalDict['HighLowLimits']:
# # self.add_handled_widget(labelledSpin(NativeUI, [setting[0], "", setting[2]]), attrName, NativeUI.clinical_handler)
# # self.add_handled_widget(labelledSpin(NativeUI, ["", setting[1], setting[2]]), attrName + '_2', NativeUI.clinical_handler)
# #else:
# # self.add_handled_widget(labelledSpin(NativeUI, setting), attrName, NativeUI.clinical_handler)
#
# self.add_handled_widget(OkButtonWidget(NativeUI), 'clinical_ok_button', NativeUI.clinical_handler)
# self.add_handled_widget(CancelButtonWidget(NativeUI), 'clinical_cancel_button', NativeUI.clinical_handler)
#
### Alarm limits
with open("NativeUI/configs/clinical_config.json") as json_file:
clinicalDict = json.load(json_file)
#radioSettings = modeDict["radioSettings"]
#modes = NativeUI.modeList
#self.add_handled_widget(QStackedWidget(), 'main_mode_stack', NativeUI.mode_handler)
for setting in clinicalDict['settings']:
#print(setting)
attrName = 'clinical_spin_' + setting[0][2]
#setting[0][3] = setting[0][3] + 'MIN'
self.add_handled_widget(labelledSpin(NativeUI, setting[0]), attrName + '_min', NativeUI.clinical_handler)
#setting[0][3] = setting[0][3] + 'MAX'
self.add_handled_widget(labelledSpin(NativeUI, setting[1]), attrName + '_max', NativeUI.clinical_handler)
#setting[3] = 'SET_TARGET'
#if setting[0] in clinicalDict['HighLowLimits']:
# self.add_handled_widget(labelledSpin(NativeUI, [setting[0], "", setting[2]]), attrName, NativeUI.clinical_handler)
# self.add_handled_widget(labelledSpin(NativeUI, ["", setting[1], setting[2]]), attrName + '_2', NativeUI.clinical_handler)
#else:
# self.add_handled_widget(labelledSpin(NativeUI, setting), attrName, NativeUI.clinical_handler)
self.add_handled_widget(OkButtonWidget(NativeUI), 'clinical_ok_button', NativeUI.clinical_handler)
self.add_handled_widget(CancelButtonWidget(NativeUI), 'clinical_cancel_button', NativeUI.clinical_handler)
#### Mode settings tab: Mode (x4), Personal
......
......@@ -72,7 +72,7 @@ class BatteryDisplayWidget(QtWidgets.QWidget):
widget.update_value(self.status)
return 0
def set_size(self, x: int, y: int) -> int:
def set_size(self, x: int, y: int, spacing=None) -> int:
"""
Set the size of the battery display widget. Due to the way that the text_display
needs to resize itself, both the x and y sizes must be specified.
......
......@@ -15,28 +15,50 @@ __maintainer__ = "Benjamin Mummery"
__email__ = "benjamin.mummery@stfc.ac.uk"
__status__ = "Development"
from PySide2 import QtWidgets
from PySide2 import QtWidgets, QtGui
import json
import os
from PySide2.QtCore import Signal
class LocalisationButtonWidget(QtWidgets.QPushButton):
class LocalisationButtonWidget(QtWidgets.QWidget):
"""
TODO BM: add set_size and setFont
"""
SetLocalisation = Signal(dict)
def __init__(self, localisation_config_file_paths: list, *args, **kwargs):
def __init__(
self, localisation_config_file_paths: list, colors: dict, *args, **kwargs
):
super().__init__(*args, **kwargs)
self.__localisation_dict: dict = {}
self.__localisation_files_list: list = localisation_config_file_paths
self.__current_localisation_index: int = -1
self.localisation_button = QtWidgets.QPushButton()
hlayout = QtWidgets.QHBoxLayout()
hlayout.addWidget(self.localisation_button)
self.setLayout(hlayout)
self.localisation_button.setStyleSheet(
"background-color:" + colors["button_background_enabled"].name() + ";"
"border-color:" + colors["page_foreground"].name() + ";"
"color:" + colors["page_foreground"].name() + ";"
"border: none"
)
self.set_localisation(0)
self.localisation_button.pressed.connect(self.on_press)
self.pressed.connect(self.on_press)
def set_size(self, x: int, y: int, spacing: int = 10) -> int:
self.setFixedSize(x, y)
self.localisation_button.setFixedSize(x - spacing, y - spacing)
return 0
def setFont(self, font: QtGui.QFont) -> int:
self.localisation_button.setFont(font)
return 0
def on_press(self) -> int:
"""
......@@ -60,7 +82,7 @@ class LocalisationButtonWidget(QtWidgets.QPushButton):
self.__current_localisation_index = index
self.__import_localisation_config()
self.setText(self.__localisation_dict["language_name"])
self.localisation_button.setText(self.__localisation_dict["language_name"])
self.SetLocalisation.emit(self.__localisation_dict)
return 0
......
......@@ -39,7 +39,6 @@ class MeasurementsBlockWidget(QtWidgets.QWidget):
# Create "Measurements" Title
self.title_label = QtWidgets.QLabel()
self.title_label.setStyleSheet(
# "font-size:" + NativeUI.text_size + ";"
"color:" + NativeUI.colors["page_foreground"].name() + ";"
"background-color:" + NativeUI.colors["page_background"].name() + ";"
)
......@@ -62,9 +61,7 @@ class MeasurementsBlockWidget(QtWidgets.QWidget):
)
else:
self.widget_list.append(
MeasurementWidget(
NativeUI, measurement[0], measurement[1] # Label key # Key
)
MeasurementWidget(NativeUI, measurement[0], measurement[1])
)
# Compute max number of items per column
......@@ -221,7 +218,6 @@ class MeasurementWidget(QtWidgets.QWidget):
"color: " + self.NativeUI.colors["label_foreground"].name() + ";"
"background-color:" + self.NativeUI.colors["label_background"].name() + ";"
"border: none;"
# "font-size: " + NativeUI.text_size + ";"
)
self.value_display.setAlignment(QtCore.Qt.AlignCenter)
......@@ -230,7 +226,6 @@ class MeasurementWidget(QtWidgets.QWidget):
"background-color: " + self.NativeUI.colors["label_foreground"].name() + ";"
"border: none;"
)
# self.value_display.setFont(QtGui.QFont("SansSerif", 40))
# Layout
layout.setSpacing(0)
......
......@@ -15,6 +15,7 @@ __status__ = "Prototype"
from PySide2 import QtWidgets, QtGui, QtCore
import os
class styledButton(QtWidgets.QPushButton):
def __init__(self, NativeUI, colour, iconpath_play, *args, **kwargs):
super().__init__(*args, **kwargs)
......@@ -35,10 +36,10 @@ class styledButton(QtWidgets.QPushButton):
+ ";}"
"QPushButton{color: " + NativeUI.colors["page_background"].name() + ";"
"border-color: " + NativeUI.colors["page_foreground"].name() + ";"
"font-size: " + NativeUI.text_size + ";"
"border-radius: 8px;"
"border:none}"
)
self.setFont(NativeUI.text_font)
self.setProperty("bgColour", "0")
self.setEnabled(False)
......@@ -46,25 +47,22 @@ class styledButton(QtWidgets.QPushButton):
# self.setFixedSize(QtCore.QSize(150, 50))
def setColour(self, option):
# print('setting colour again again')
self.setEnabled(bool(float(option)))
self.setProperty("bgColour", str(option))
self.style().polish(self)
class OkButtonWidget(
styledButton
):
class OkButtonWidget(styledButton):
def __init__(self, NativeUI, *args, **kwargs):
iconpath_check = os.path.join(NativeUI.iconpath, "check-solid.png")
super().__init__(NativeUI, 'green', iconpath_check, *args, **kwargs)
super().__init__(NativeUI, "green", iconpath_check, *args, **kwargs)
class CancelButtonWidget(
styledButton
):
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)
super().__init__(NativeUI, "red", iconpath_cross, *args, **kwargs)
class OkSendButtonWidget(
......@@ -72,4 +70,4 @@ class OkSendButtonWidget(
): # chose QWidget over QDialog family because easier to modify
def __init__(self, NativeUI, *args, **kwargs):
iconpath_play = os.path.join(NativeUI.iconpath, "play-solid.png")
super().__init__(NativeUI, 'green', iconpath_play, *args, **kwargs)
super().__init__(NativeUI, "green", iconpath_play, *args, **kwargs)
......@@ -32,7 +32,7 @@ class PersonalDisplayWidget(QtWidgets.QWidget):
hlayout.addWidget(self.info_label)
self.setLayout(hlayout)
def set_size(self, x: int, y: int) -> int:
def set_size(self, x: int, y: int, spacing=None) -> int:
"""
Set the size of the personal display widget.
......
......@@ -68,17 +68,14 @@ class TimePlotsWidget(QtWidgets.QWidget):
self.graph_widget.setBackground(self.NativeUI.colors["page_background"])
# Add grid, hide the autoscale button, and add the legend
font = QtGui.QFont() # TODO: change to an imported font from NativeuI
font.setPixelSize(24)
for plot in self.plots:
plot.showGrid(x=True, y=True)
plot.hideButtons()
l = plot.addLegend(offset=(-1, 1))
l.setLabelTextSize(self.NativeUI.text_size)
l.setFont(NativeUI.text_font)
plot.setMouseEnabled(x=False, y=False)
plot.getAxis("bottom").setStyle(tickFont=font)
plot.getAxis("left").setStyle(tickFont=font)
plot.getAxis("bottom").setStyle(tickFont=NativeUI.text_font)
plot.getAxis("left").setStyle(tickFont=NativeUI.text_font)
plot.getAxis("left").setTextPen(NativeUI.colors["page_foreground"])
plot.getAxis("bottom").setTextPen(NativeUI.colors["page_foreground"])
......@@ -189,17 +186,14 @@ class CirclePlotsWidget(QtWidgets.QWidget):
self.graph_widget.setBackground(self.NativeUI.colors["page_background"])
# Add grid, hide the autoscale button, and add the legend
font = QtGui.QFont() # TODO: change to an imported font from NativeuI
font.setPixelSize(25)
for plot in self.plots:
plot.showGrid(x=True, y=True)
plot.hideButtons()
l = plot.addLegend(offset=(-1, 1))
l.setLabelTextSize(self.NativeUI.text_size)
l.setFont(NativeUI.text_font)
plot.setMouseEnabled(x=False, y=False)
plot.getAxis("bottom").setStyle(tickFont=font)
plot.getAxis("left").setStyle(tickFont=font)
plot.getAxis("bottom").setStyle(tickFont=NativeUI.text_font)
plot.getAxis("left").setStyle(tickFont=NativeUI.text_font)
plot.getAxis("left").setTextPen(NativeUI.colors["page_foreground"])
plot.getAxis("bottom").setTextPen(NativeUI.colors["page_foreground"])
......
......@@ -47,7 +47,6 @@ class SpinButton(QtWidgets.QFrame):
labelBgColour = "rgb(60,58,60)"
self.label.setStyleSheet(
"font-size: " + NativeUI.text_size + ";"
"color:white;"
"background-color:" + labelBgColour + ";"
""#border-radius:4px;"
......@@ -55,17 +54,19 @@ class SpinButton(QtWidgets.QFrame):
)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setFixedHeight(45)
self.label.setFont(NativeUI.text_font)
self.layout.addWidget(self.label)
#self.setFont(NativeUI.text_font)
self.simpleSpin = signallingSpinBox(NativeUI)
self.simpleSpin.lineEdit().setStyleSheet("border:blue;")
self.simpleSpin.setFixedHeight(100)
self.simpleSpin.setFont(NativeUI.text_font)
boxStyleString = (
"QDoubleSpinBox{"
" border:none;"
" background-color: black;"
" font: " + NativeUI.text_size + " large 'Times New Roman';"
"}"
"QDoubleSpinBox[colour='0'] {"
" color:green;"
......@@ -77,7 +78,7 @@ class SpinButton(QtWidgets.QFrame):
" color:red;"
"}"
)
self.setFont(NativeUI.text_font)
upButtonStyleString = "QDoubleSpinBox::up-button{" "height:50;" "width:50;" "}"
# upButtonPressedStyleString = (
......@@ -87,17 +88,15 @@ class SpinButton(QtWidgets.QFrame):
"up", "down"
) # "QDoubleSpinBox::down-button{image: url('" + downImage + "');}"
# downButtonPressedStyleString = "" # "QDoubleSpinBox::down-button:pressed{background-color:white;image: url('" + upImage + "');}"
upButtonStyleString = "QDoubleSpinBox::up-button{" "height:30;" "width:40;" "}"
downButtonStyleString = upButtonStyleString.replace("up", "down")
self.simpleSpin.setStyleSheet(
boxStyleString + upButtonStyleString + downButtonStyleString
)
# + upButtonPressedStyleString
# + downButtonPressedStyleString
# )
self.simpleSpin.setProperty("colour", "1")
self.simpleSpin.setButtonSymbols(
QtWidgets.QAbstractSpinBox.ButtonSymbols.PlusMinus
)
# self.doubleSpin.setStyleSheet("QDoubleSpinBox::up-button{ height:30; width:100;")
self.simpleSpin.setAlignment(QtCore.Qt.AlignCenter)
self.simpleSpin.manualChanged.connect(self.manualChanged)
self.simpleSpin.setSizePolicy(
......@@ -137,6 +136,20 @@ class SpinButton(QtWidgets.QFrame):
self.simpleSpin.style().polish(self.simpleSpin)
return 0
def set_label_font(self, font) -> int:
"""
Set the font for the spinbox label.
"""
self.label.setFont(font)
return 0
def set_value_font(self, font) -> int:
"""
Set the font for the spinbox value display.
"""
self.simpleSpin.setFont(font)
return 0
class SpinButtonsWidget(QtWidgets.QWidget):
def __init__(self, NativeUI, *args, **kwargs):
......@@ -170,20 +183,23 @@ class SpinButtonsWidget(QtWidgets.QWidget):
self.okButton = OkButtonWidget(self.NativeUI)
self.okButton.pressed.connect(self.ok_button_pressed)
self.okButton.setSizePolicy(
QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Fixed)
QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed
)
self.cancelButton = CancelButtonWidget(self.NativeUI)
self.cancelButton.pressed.connect(self.cancel_button_pressed)
self.cancelButton.setSizePolicy(
QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Fixed)
QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed
)
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: self.refresh_button_colour())
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:
......@@ -191,7 +207,6 @@ class SpinButtonsWidget(QtWidgets.QWidget):
self.spinStack.setCurrentIndex(1)
self.layout.addWidget(self.spinStack)
self.buttonLayout = QtWidgets.QVBoxLayout()
self.buttonLayout.setSpacing(5)
......@@ -222,7 +237,9 @@ class SpinButtonsWidget(QtWidgets.QWidget):
def refresh_button_colour(self):
self.manuallyUpdated = False
for spin in self.spinDict:
self.manuallyUpdated = self.manuallyUpdated or self.spinDict[spin].manuallyUpdated
self.manuallyUpdated = (
self.manuallyUpdated or self.spinDict[spin].manuallyUpdated
)
self.okButton.setColour(str(int(self.manuallyUpdated)))
self.cancelButton.setColour((str(int(self.manuallyUpdated))))
......@@ -252,7 +269,7 @@ class SpinButtonsWidget(QtWidgets.QWidget):
self.spinDict[spin].manuallyUpdated = False
self.spinDict[spin].setTextColour("1")
self.refresh_button_colour()
#self.colourButtons(0)
# self.colourButtons(0)
def cancel_button_pressed(self):
"""Respond to cancel button pressed by changing text colour and liveUpdating to True"""
......@@ -262,3 +279,41 @@ class SpinButtonsWidget(QtWidgets.QWidget):
self.refresh_button_colour()
def set_size(self, x: int, y: int, spacing: int = 10) -> int:
"""
Set the size of the spinwidgets block and all widgets contained within.
The SpinButtonsWidget is set to x by y pixels. Each spinbox within is set to
x_spin by y pixels (minus spacing) where x_spin is the x value divided by 1 plus
the number of shown spinboxes (at present this is one less than the total number
of spinboxes since two of them are combined in a stack). The additional 1 is
used to provide space for the ok and cancel buttons, which are set to x_spin by
y_spin/2 pixels such that the two buttonstogether take up the space of a single
spinbox.
"""
self.setFixedSize(x, y)
x_spin = int(x / len(self.spinDict)) - spacing
y_spin = y - spacing
for key in self.spinDict:
self.spinDict[key].setFixedSize(x_spin, y_spin)
self.spinStack.setFixedSize(x_spin, y_spin)
self.cancelButton.setFixedSize(x_spin, int(y_spin / 2) - spacing)
self.okButton.setFixedSize(x_spin, int(y_spin / 2) - spacing)
return 0
def set_label_font(self, font) -> int:
"""
Set the font for all labels in spinboxes.
"""
for key in self.spinDict:
self.spinDict[key].set_label_font(font)
return 0
def set_value_font(self, font) -> int:
"""
set the font for all value displays in spinboxes.
"""
for key in self.spinDict:
self.spinDict[key].set_value_font(font)
return 0
cmake_minimum_required (VERSION 3.1.0)
project (hev-display)
configure_file (
${PROJECT_SOURCE_DIR}/extras/cmake/cmake_uninstall.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake @ONLY)
add_custom_target (uninstall
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
# Configure packaging
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "HEV native display")
set (CPACK_PACKAGE_VENDOR "CERN, Riga Technical University and University of Liverpool")
set (CPACK_PACKAGE_CONTACT "The High Energy Ventilator Project <https://hev.web.cern.ch/>")
set (CPACK_STRIP_FILES "hev-display")
set (CPACK_PACKAGE_EXECUTABLES "hev-display")
# Calculate version identifiers from git tags
include (${PROJECT_SOURCE_DIR}/extras/cmake/CPackGit.cmake)
add_definitions (-DVERSION="${CPACK_PACKAGE_VERSION}")
# Configure Qt
set (CMAKE_AUTOMOC ON)
set (CMAKE_AUTORCC ON)
set (CMAKE_AUTOUIC ON)
if (CMAKE_VERSION VERSION_LESS "3.7.0")
set (CMAKE_INCLUDE_CURRENT_DIR ON)
endif ()
find_package (Qt5 5.12 COMPONENTS Core Quick QuickControls2 Svg Charts Network Concurrent LinguistTools REQUIRED)
set (SOURCES sources/main.cpp sources/datasource.cpp sources/localization.cpp)
set (RESOURCES assets/resources.qrc languages/translations.qrc)
set (TS_FILES
languages/translation-qml_en.ts
languages/translation-qml_es.ts
languages/translation-qml_fr.ts
languages/translation-qml_de.ts
languages/translation-qml_lv.ts
languages/translation-qml_it.ts
languages/translation-qml_sk.ts
)
set_source_files_properties (${TS_FILES} PROPERTIES OUTPUT_LOCATION ${CMAKE_SOURCE_DIR}/languages)
qt5_add_translation (QM_FILES ${TS_FILES})
# Main executable
add_executable (hev-display
${SOURCES}
${RESOURCES}
${QM_FILES}
)
target_link_libraries (hev-display Qt5::Core Qt5::Quick Qt5::QuickControls2 Qt5::Svg Qt5::Charts Qt5::Network Qt5::Concurrent)
install (TARGETS hev-display RUNTIME DESTINATION bin)
# Raspbian-specific packaging
if (CPACK_SYSTEM_NAME MATCHES "raspbian.*")
# QT5_BASEDIR must match the path Qt was compiled to use, RPATH adjustments do not help as
# Qt will still look for plugins and qml modules in the location configured initially
set (QT5_BASEDIR "/usr/local/qt5pi")
get_target_property (qt5_core_location Qt5::Core LOCATION)
get_filename_component (qt5_lib_dir ${qt5_core_location} DIRECTORY)
file (GLOB qt5_sos "${qt5_lib_dir}/lib*.so*")
foreach (qt5_so ${qt5_sos})
install (FILES "${qt5_so}" DESTINATION "${QT5_BASEDIR}/lib")
endforeach ()
install (DIRECTORY "${qt5_lib_dir}/../plugins" DESTINATION "${QT5_BASEDIR}/")
install (DIRECTORY "${qt5_lib_dir}/../qml" DESTINATION "${QT5_BASEDIR}/")
# Not all libraries autodetect the host rpath, RPATH still required for libQt5Core and a few others
set_target_properties (hev-display PROPERTIES INSTALL_RPATH "${QT5_BASEDIR}/lib:/opt/vc/lib:")
endif ()
set (CPACK_PROJECT_CONFIG_FILE "${PROJECT_SOURCE_DIR}/extras/cmake/CPackConfig.cmake")
# CPackConfig.cmake is stored in the source dir so that upstream tarballs automatically have a copy of it
# (it contains variables computed from git tags, and git history is not available in an upstream tarball)
if (NOT EXISTS "${CPACK_PROJECT_CONFIG_FILE}")
find_package (Git REQUIRED)
execute_process (
COMMAND ${GIT_EXECUTABLE} --git-dir "${PROJECT_SOURCE_DIR}/.git" describe --always
OUTPUT_VARIABLE GIT_HASH)
execute_process (
COMMAND ${GIT_EXECUTABLE} --git-dir "${PROJECT_SOURCE_DIR}/.git" rev-list --count ${GIT_HASH}
OUTPUT_VARIABLE COMMIT_COUNT)
execute_process (
COMMAND ${GIT_EXECUTABLE} --git-dir "${PROJECT_SOURCE_DIR}/.git" tag
OUTPUT_VARIABLE LATEST_TAG)
set (GIT_DESCRIBE "v0.0.0-284-g${GIT_HASH}")
message ("Git describe: ${GIT_DESCRIBE}")
string (REGEX MATCH "v([0-9]+).([0-9]+).([0-9]+)-([0-9]+)-g([0-9a-f]+)" match ${GIT_DESCRIBE})
if (NOT match)
string (REGEX MATCH "v([0-9]+).([0-9]+).([0-9]+)" match ${GIT_DESCRIBE})
endif ()
if (NOT match)
message (WARNING "Version '${GIT_DESCRIBE}' from git cannot be recognized as a valid version string")
endif ()
set (CMAKE_PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1})
set (CMAKE_PROJECT_VERSION_MINOR ${CMAKE_MATCH_2})
set (CMAKE_PROJECT_VERSION_PATCH ${CMAKE_MATCH_3})
set (CMAKE_PROJECT_VERSION_TWEAK ${CMAKE_MATCH_4})
set (GIT_SHA_SHORT ${CMAKE_MATCH_5})
configure_file ("${CPACK_PROJECT_CONFIG_FILE}.in" "${CPACK_PROJECT_CONFIG_FILE}" @ONLY)
endif ()
include (${CPACK_PROJECT_CONFIG_FILE})
# include CPack module once all variables are set
include (CPack)
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