Commit 14a93e9f authored by Benjamin Mummery's avatar Benjamin Mummery 💻

error handling in lock button to allow for unused widgets

parent b4698554
Pipeline #1797 failed with stages
......@@ -754,8 +754,12 @@ class NativeUI(HEVClient, QMainWindow):
return 0
def toggle_editability(self):
"""Set all widgets disabled to lock screen"""
print("toggling")
"""
Set all widgets disabled to lock screen.
Handles RuntimeErrors to deal with widgets that are created but are not used in
the final layout.
"""
self.q_send_cmd("DO_CALIBRATION", "DO_CALIBRATIONING")
self.q_send_cmd("MUTE_ALARM", "TRUE")
# self.q_send_cmd("GENERAL", "START")
......@@ -765,7 +769,12 @@ class NativeUI(HEVClient, QMainWindow):
for attribute in dir(self.widgets):
widg = self.widgets.get_widget(attribute)
if isinstance(widg, QWidget):
self.saveStateDict[attribute] = widg.isEnabled()
try:
self.saveStateDict[attribute] = widg.isEnabled()
except KeyError as e:
logging.warning(e)
except RuntimeError as e:
logging.warning(e)
if self.enableState:
self.alt_palette.setColor(QPalette.Window, self.colors["page_background"])
......@@ -776,9 +785,15 @@ class NativeUI(HEVClient, QMainWindow):
widg = self.widgets.get_widget(attribute)
if isinstance(widg, QWidget):
if self.enableState:
widg.setEnabled(self.saveStateDict[attribute])
try:
widg.setEnabled(self.saveStateDict[attribute])
except KeyError as e:
logging.warning(e)
else:
widg.setEnabled(self.enableState)
try:
widg.setEnabled(self.enableState)
except RuntimeError as e:
logging.warning(e)
self.widgets.lock_button.setEnabled(True)
@Slot(str)
......
......@@ -39,7 +39,7 @@ class AbstractTypeValPopup(QtWidgets.QDialog):
# self.label_text, self.min, self.max, self.initVal, self.step, self.decPlaces = 'Enter Password', 0, 10000, 0, 0, 0
self.setStyleSheet("border-radius:4px; background-color:black")
self.setStyleSheet("background-color:black")
self.characterType = characterType
self.label = QtWidgets.QLabel() # self.label_text)
self.label.setFont(NativeUI.value_font)
......@@ -51,7 +51,7 @@ class AbstractTypeValPopup(QtWidgets.QDialog):
self.lineEdit.setStyleSheet(
"QLineEdit{"
" background-color: white;"
" border-radius: 4px;"
# " border-radius: 4px;"
"}"
"QLineEdit[colour = '0']{"
" color: green;"
......
......@@ -210,32 +210,37 @@ class Layout:
hlayout.addWidget(self.widgets.page_stack)
# Populate the Top Bar
vlayout.addWidget(
self.layout_top_bar(
[
self.widgets.tab_modeswitch,
self.widgets.personal_display,
self.widgets.localisation_button,
self.widgets.battery_display,
self.widgets.alarm_control,
self.widgets.lock_button,
]
)
)
topbar_widgets = [
self.widgets.tab_modeswitch,
self.widgets.localisation_button,
self.widgets.personal_display,
self.widgets.alarm_control,
self.widgets.lock_button,
self.widgets.battery_display,
]
vlayout.addWidget(self.layout_top_bar(topbar_widgets))
self.widgets.tab_modeswitch.set_size(
mode_display_width, self.top_bar_height, spacing=self.widget_spacing
)
self.widgets.tab_modeswitch.setFont(self.NativeUI.text_font)
self.widgets.tab_modeswitch.setButtonSize(None, self.min_button_height)
self.widgets.personal_display.set_size(
personal_display_width, self.top_bar_height, spacing=self.widget_spacing
self.widgets.tab_modeswitch.setButtonSize(
mode_display_width - self.widget_spacing, self.min_button_height
)
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.localisation_button.setButtonSize(
localisation_display_width - self.widget_spacing, self.min_button_height
)
self.widgets.personal_display.set_size(
personal_display_width, self.top_bar_height
)
self.widgets.personal_display.setFont(self.NativeUI.text_font)
self.widgets.battery_display.set_size(
battery_display_width, self.top_bar_height, spacing=self.widget_spacing
)
......@@ -246,7 +251,15 @@ class Layout:
self.widgets.lock_button.setFixedWidth(lock_display_width)
self.widgets.lock_button.setFixedHeight(self.top_bar_height)
self.widgets.lock_button.setStyleSheet(
"background-color: " + self.NativeUI.colors["display_foreground"].name()
"QPushButton{"
" background-color:"
+ self.NativeUI.colors["page_background"].name()
+ ";"
" border:none;"
"}"
"QPushButton::pressed{"
" background-color:" + self.NativeUI.colors["highlight"].name() + ";"
"}"
)
vlayout.addLayout(hlayout)
return vlayout
......
......@@ -58,7 +58,6 @@ class LocalisationButtonWidget(QtWidgets.QWidget):
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:
......@@ -91,6 +90,13 @@ class LocalisationButtonWidget(QtWidgets.QWidget):
self.SetLocalisation.emit(self.__localisation_dict)
return 0
def setButtonSize(self, x: int, y: int) -> int:
if x is not None:
self.localisation_button.setFixedWidth(x)
if y is not None:
self.localisation_button.setFixedHeight(y)
return 0
def __import_localisation_config(self) -> int:
"""
Read in the current configuration
......
......@@ -36,6 +36,8 @@ class calibrationWidget(QtWidgets.QWidget):
" background-color:"
+ NativeUI.colors["button_background_enabled"].name()
+ ";"
" color:" + NativeUI.colors["page_foreground"].name() + ";"
" text-align: center;"
"}"
"QProgressBar::chunk{"
" background-color:" + NativeUI.colors["highlight"].name() + ";"
......
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