Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
HEV - High Energy Ventilator
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
5
Issues
5
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
HEV - High Energy Ventilator
Commits
3d9f4bbc
Commit
3d9f4bbc
authored
May 26, 2021
by
Benjamin Mummery
💻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
alarm popups scale with ui resolution
parent
32d22a41
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
33 deletions
+41
-33
NativeUI.py
NativeUI/NativeUI.py
+7
-3
alarm_popup.py
NativeUI/alarm_widgets/alarm_popup.py
+34
-30
No files found.
NativeUI/NativeUI.py
View file @
3d9f4bbc
...
...
@@ -15,7 +15,7 @@ Command-line arguments:
__author__
=
[
"Benjamin Mummery"
,
"Dónal Murray"
,
"Tiago Sarmento"
]
__credits__
=
[
"Benjamin Mummery"
,
"Dónal Murray"
,
"Tim Powell"
,
"Tiago Sarmento"
]
__license__
=
"GPL"
__version__
=
"0.1.
1
"
__version__
=
"0.1.
2
"
__maintainer__
=
"Benjamin Mummery"
__email__
=
"benjamin.mummery@stfc.ac.uk"
__status__
=
"Prototype"
...
...
@@ -151,8 +151,12 @@ class NativeUI(HEVClient, QMainWindow):
# Set up fonts based on the screen resolution. text_font and value_font are 20
# and 40px respectively for 1920*1080.
self
.
text_font
=
QFont
(
"Sans Serif"
,
resolution
[
0
]
/
96
)
self
.
value_font
=
QFont
(
"Sans Serif"
,
2
*
resolution
[
0
]
/
96
)
self
.
text_font
=
QFont
(
"Sans Serif"
,
int
(
resolution
[
0
]
/
96
))
self
.
value_font
=
QFont
(
"Sans Serif"
,
int
(
2
*
resolution
[
0
]
/
96
))
# Set the popup size based on the screen resolution. alarm_popup_width is 400
# for 1920*1080
self
.
alarm_popup_width
=
int
(
resolution
[
0
]
/
4.8
)
# Import icons
self
.
icons
=
{
...
...
NativeUI/alarm_widgets/alarm_popup.py
View file @
3d9f4bbc
...
...
@@ -24,6 +24,7 @@ class AlarmWidget(QtWidgets.QWidget):
def
__init__
(
self
,
NativeUI
,
abstractAlarm
,
alarmCarrier
,
*
args
,
**
kwargs
):
super
(
AlarmWidget
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
popup_height
=
int
(
NativeUI
.
alarm_popup_width
/
10.0
)
self
.
NativeUI
=
NativeUI
self
.
alarmCarrier
=
alarmCarrier
# Needs to refer to its containing object
...
...
@@ -37,27 +38,26 @@ class AlarmWidget(QtWidgets.QWidget):
iconpath_check
=
os
.
path
.
join
(
self
.
NativeUI
.
iconpath
,
"exclamation-triangle-solid.png"
)
pixmap
=
QtGui
.
QPixmap
(
iconpath_check
)
.
scaledToHeight
(
40
)
pixmap
=
QtGui
.
QPixmap
(
iconpath_check
)
.
scaledToHeight
(
popup_height
)
iconLabel
.
setPixmap
(
pixmap
)
self
.
layout
.
addWidget
(
iconLabel
)
self
.
textLabel
=
QtWidgets
.
QLabel
()
alarmLevel
=
self
.
alarmPayload
[
"alarm_type"
]
.
replace
(
'PRIORITY_'
,
''
)
self
.
textLabel
.
setText
(
alarmLevel
+
" - "
+
self
.
alarmPayload
[
"alarm_code"
]
)
self
.
textLabel
.
setFixedWidth
(
400
)
alarmLevel
=
self
.
alarmPayload
[
"alarm_type"
]
.
replace
(
"PRIORITY_"
,
""
)
self
.
textLabel
.
setText
(
alarmLevel
+
" - "
+
self
.
alarmPayload
[
"alarm_code"
])
self
.
textLabel
.
setFixedWidth
(
NativeUI
.
alarm_popup_width
)
self
.
textLabel
.
setAlignment
(
QtCore
.
Qt
.
AlignCenter
)
self
.
textLabel
.
setFont
(
NativeUI
.
text_font
)
#self.textLabel.setStyleSheet("font-size: " + NativeUI.text_size + ";")
#
self.textLabel.setStyleSheet("font-size: " + NativeUI.text_size + ";")
self
.
layout
.
addWidget
(
self
.
textLabel
)
self
.
setFixedHeight
(
40
)
self
.
setFixedHeight
(
popup_height
)
self
.
setLayout
(
self
.
layout
)
if
self
.
alarmPayload
[
"alarm_type"
]
==
"PRIORITY_HIGH"
:
self
.
setStyleSheet
(
"background-color:red;"
)
elif
self
.
alarmPayload
[
"alarm_type"
]
==
"PRIORITY_MEDIUM"
:
self
.
setStyleSheet
(
"background-color:orange;"
)
self
.
setFixedSize
(
NativeUI
.
alarm_popup_width
+
popup_height
,
popup_height
)
# self.timer = QtCore.QTimer()
# self.timer.setInterval(500) # just faster than 60Hz
...
...
@@ -66,14 +66,13 @@ class AlarmWidget(QtWidgets.QWidget):
self
.
installEventFilter
(
self
)
def
eventFilter
(
self
,
source
,
event
):
if
(
event
.
type
()
==
QtCore
.
QEvent
.
MouseButtonPress
)
:
if
event
.
type
()
==
QtCore
.
QEvent
.
MouseButtonPress
:
self
.
NativeUI
.
widgets
.
page_buttons
.
alarms_button
.
click
()
return
False
def
get_priority
(
self
):
return
self
.
alarmPayload
[
"alarm_type"
]
def
setFont
(
self
,
font
)
->
int
:
"""
Set the font for textLabel.
...
...
@@ -95,12 +94,13 @@ class AlarmWidget(QtWidgets.QWidget):
class
AlarmPopup
(
QtWidgets
.
QDialog
):
"""Container class for alarm widgets. Handles ordering and positioning of alarms.
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
.
alarmDict
=
{}
self
.
NativeUI
=
NativeUI
self
.
extraAlarms
=
AlarmExtrasWidget
(
NativeUI
,
self
)
self
.
extraAlarms
=
AlarmExtrasWidget
(
NativeUI
,
self
)
self
.
layout
=
QtWidgets
.
QVBoxLayout
()
self
.
layout
.
setSpacing
(
0
)
...
...
@@ -141,7 +141,7 @@ class AlarmPopup(QtWidgets.QDialog):
self
.
NativeUI
,
abstractAlarm
,
self
)
self
.
refresh_alarm_ordering
()
#self.layout.addWidget(self.alarmDict[abstractAlarm.alarmPayload["alarm_code"]])
#
self.layout.addWidget(self.alarmDict[abstractAlarm.alarmPayload["alarm_code"]])
return
0
def
removeAlarm
(
self
,
abstractAlarm
):
...
...
@@ -157,25 +157,26 @@ class AlarmPopup(QtWidgets.QDialog):
self
.
layout
.
removeWidget
(
self
.
alarmDict
[
key
])
for
key
in
self
.
alarmDict
:
if
self
.
alarmDict
[
key
]
.
get_priority
()
==
'PRIORITY_HIGH'
:
if
self
.
alarmDict
[
key
]
.
get_priority
()
==
"PRIORITY_HIGH"
:
if
self
.
layout
.
count
()
==
4
:
self
.
extraAlarms
.
update_text
(
1
+
len
(
self
.
alarmDict
)
-
self
.
layout
.
count
())
self
.
extraAlarms
.
update_text
(
1
+
len
(
self
.
alarmDict
)
-
self
.
layout
.
count
()
)
self
.
layout
.
addWidget
(
self
.
extraAlarms
)
break
self
.
layout
.
addWidget
(
self
.
alarmDict
[
key
])
if
self
.
layout
.
count
()
<
5
:
for
key
in
self
.
alarmDict
:
if
self
.
layout
.
count
()
==
3
:
self
.
extraAlarms
.
update_text
(
len
(
self
.
alarmDict
)
-
self
.
layout
.
count
())
self
.
extraAlarms
.
update_text
(
len
(
self
.
alarmDict
)
-
self
.
layout
.
count
()
)
self
.
layout
.
addWidget
(
self
.
extraAlarms
)
break
if
self
.
alarmDict
[
key
]
.
get_priority
()
==
'PRIORITY_LOW'
:
if
self
.
alarmDict
[
key
]
.
get_priority
()
==
"PRIORITY_LOW"
:
self
.
layout
.
addWidget
(
self
.
alarmDict
[
key
])
# def resetTimer(self, alarmPayload):
# self.alarmDict[alarmPayload["alarm_code"]].timer.start()
...
...
@@ -188,49 +189,52 @@ class AlarmPopup(QtWidgets.QDialog):
return
0
class
AlarmExtrasWidget
(
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
,
alarmCarrier
,
*
args
,
**
kwargs
):
super
(
AlarmExtrasWidget
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
popup_height
=
int
(
NativeUI
.
alarm_popup_width
/
10.0
)
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
)
self
.
layout
.
setMargin
(
0
)
#self.alarmPayload = abstractAlarm.alarmPayload
#
self.alarmPayload = abstractAlarm.alarmPayload
iconLabel
=
QtWidgets
.
QLabel
()
iconpath_check
=
os
.
path
.
join
(
self
.
NativeUI
.
iconpath
,
"exclamation-triangle-solid.png"
)
pixmap
=
QtGui
.
QPixmap
(
iconpath_check
)
.
scaledToHeight
(
40
)
pixmap
=
QtGui
.
QPixmap
(
iconpath_check
)
.
scaledToHeight
(
popup_height
)
iconLabel
.
setPixmap
(
pixmap
)
self
.
layout
.
addWidget
(
iconLabel
)
self
.
textLabel
=
QtWidgets
.
QLabel
()
self
.
textLabel
.
setText
(
'1 More Alarms'
)
self
.
textLabel
.
setFixedWidth
(
400
)
self
.
textLabel
.
setText
(
"1 More Alarms"
)
self
.
textLabel
.
setFixedWidth
(
NativeUI
.
alarm_popup_width
)
self
.
textLabel
.
setAlignment
(
QtCore
.
Qt
.
AlignCenter
)
self
.
textLabel
.
setFont
(
NativeUI
.
text_font
)
#self.textLabel.setStyleSheet("font-size: " + NativeUI.text_size + ";")
#
self.textLabel.setStyleSheet("font-size: " + NativeUI.text_size + ";")
self
.
layout
.
addWidget
(
self
.
textLabel
)
self
.
setFixedHeight
(
40
)
self
.
setFixedHeight
(
popup_height
)
self
.
setLayout
(
self
.
layout
)
self
.
setStyleSheet
(
"background-color:red;"
)
#
self.priority = "PRIORITY_LOW"
#
self.priority = "PRIORITY_LOW"
self
.
installEventFilter
(
self
)
self
.
setFixedSize
(
NativeUI
.
alarm_popup_width
+
popup_height
,
popup_height
)
def
update_text
(
self
,
num
):
self
.
textLabel
.
setText
(
str
(
num
)
+
' More Alarms'
)
self
.
textLabel
.
setText
(
str
(
num
)
+
" More Alarms"
)
def
eventFilter
(
self
,
source
,
event
):
if
(
event
.
type
()
==
QtCore
.
QEvent
.
MouseButtonPress
)
:
if
event
.
type
()
==
QtCore
.
QEvent
.
MouseButtonPress
:
self
.
NativeUI
.
widgets
.
page_buttons
.
alarms_button
.
click
()
return
False
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment