-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change button colors on arm and disarm #99
Changes from 9 commits
b41f01e
4e84807
2a84948
6957880
2a35088
47c98b5
f6fb632
73c7570
6b5d9b0
6903537
6496580
aeb3d5c
41168c2
9cae118
bc305c6
e211b06
042e5a2
c110140
0b37703
1da1203
5cbc6b6
9ab125b
1a846a4
b135ae2
4d615d8
c436153
77292ec
5c63ff5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,43 +2,35 @@ | |
|
||
|
||
class IndicatorMixin(QWidget): | ||
_PROPERTY_NAME = 'widgetState' | ||
# Stylesheet for when a component is running, enabled, or armed | ||
_ON_STYLESHEET = 'QWidget { background-color: limegreen; }' | ||
|
||
# A component is running, enabled, or armed | ||
_ON = 'on' | ||
# Stylesheet for when a component is disabled, not running, or disarmed, but could be enabled | ||
# through this widget | ||
_OFF_STYLESHEET = 'QWidget { background-color: red; }' | ||
|
||
# A component is disabled, not running, or disarmed, but could be enabled through this widget | ||
_OFF = 'off' | ||
# Stylesheet for when a component is disabled, not expected to have any effect or perform its | ||
# function because of some external factor, either another widget or something external | ||
# to the gui. For example, a the arm button when the pi is not connected | ||
_INACTIVE_STYLESHEET = 'QWidget { background-color: silver; }' | ||
|
||
# A component is disabled, not expected to have any effect or perform its function because of | ||
# some external factor, either another widget or something external to the gui | ||
# For example, a the arm button when the pi is not connected | ||
_INACTIVE = 'inactive' | ||
|
||
# Removes any state | ||
_NO_STATE = '' | ||
def set_initial_stylesheet(self) -> None: | ||
self._ORIGINAL_STYLESHEET = self.styleSheet() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SCREAMING_SNAKE is for constants, make this |
||
|
||
def set_on(self) -> None: | ||
self.setProperty(IndicatorMixin._PROPERTY_NAME, IndicatorMixin._ON) | ||
self._update_style() | ||
self.setStyleSheet(self._ORIGINAL_STYLESHEET + self._ON_STYLESHEET) | ||
|
||
def set_off(self) -> None: | ||
self.setProperty(IndicatorMixin._PROPERTY_NAME, IndicatorMixin._OFF) | ||
self._update_style() | ||
self.setStyleSheet(self._ORIGINAL_STYLESHEET + self._OFF_STYLESHEET) | ||
|
||
def set_inactive(self) -> None: | ||
self.setProperty(IndicatorMixin._PROPERTY_NAME, IndicatorMixin._INACTIVE) | ||
self._update_style() | ||
self.setStyleSheet(self._ORIGINAL_STYLESHEET + self._INACTIVE_STYLESHEET) | ||
|
||
def remove_state(self) -> None: | ||
self.setProperty(IndicatorMixin._PROPERTY_NAME, IndicatorMixin._NO_STATE) | ||
self._update_style() | ||
|
||
def _update_style(self) -> None: | ||
style = self.style() | ||
if style is not None: | ||
style.polish(self) | ||
self.setStyleSheet(self._ORIGINAL_STYLESHEET) | ||
|
||
|
||
class ButtonIndicator(QPushButton, IndicatorMixin): | ||
pass | ||
def __init__(self, text: str = '') -> None: | ||
super().__init__(text) | ||
self.set_initial_stylesheet() |
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,7 +14,7 @@ class Arm(QWidget): | |||||
DISARM_REQUEST = CommandBool.Request(value=False) | ||||||
BUTTON_WIDTH = 120 | ||||||
BUTTON_HEIGHT = 60 | ||||||
BUTTON_STYLESHEET = 'QPushButton { font-size: 20px; }' | ||||||
BUTTON_STYLESHEET = 'QPushButton { font-size: 20px;}' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
command_response_signal = pyqtSignal(CommandBool.Response) | ||||||
vehicle_state_signal = pyqtSignal(VehicleState) | ||||||
|
@@ -37,10 +37,12 @@ def __init__(self) -> None: | |||||
self.arm_button.setMinimumHeight(self.BUTTON_HEIGHT) | ||||||
self.disarm_button.setMinimumHeight(self.BUTTON_HEIGHT) | ||||||
|
||||||
self.arm_button.setStyleSheet(self.BUTTON_STYLESHEET) | ||||||
self.disarm_button.setStyleSheet(self.BUTTON_STYLESHEET) | ||||||
self.arm_button.set_inactive() | ||||||
self.disarm_button.set_inactive() | ||||||
self.arm_button.setStyleSheet(f'{self.arm_button.styleSheet()}{self.BUTTON_STYLESHEET}') | ||||||
self.disarm_button.setStyleSheet( | ||||||
f'{self.disarm_button.styleSheet()}{self.BUTTON_STYLESHEET}' | ||||||
) | ||||||
|
||||||
self.arm_button.clicked.connect(self.arm_clicked) | ||||||
self.disarm_button.clicked.connect(self.disarm_clicked) | ||||||
|
@@ -81,9 +83,25 @@ def vehicle_state_callback(self, msg: VehicleState) -> None: | |||||
if msg.armed: | ||||||
self.arm_button.set_on() | ||||||
self.disarm_button.remove_state() | ||||||
self.arm_button.setStyleSheet( | ||||||
f'{self.arm_button.styleSheet()}{self.BUTTON_STYLESHEET}' | ||||||
) | ||||||
self.disarm_button.setStyleSheet( | ||||||
f'{self.disarm_button.styleSheet()}{self.BUTTON_STYLESHEET}' | ||||||
) | ||||||
else: | ||||||
self.arm_button.remove_state() | ||||||
self.disarm_button.set_off() | ||||||
self.arm_button.setStyleSheet( | ||||||
f'{self.arm_button.styleSheet()}{self.BUTTON_STYLESHEET}' | ||||||
) | ||||||
self.disarm_button.setStyleSheet( | ||||||
f'{self.disarm_button.styleSheet()}{self.BUTTON_STYLESHEET}' | ||||||
) | ||||||
else: | ||||||
self.arm_button.set_inactive() | ||||||
self.disarm_button.set_inactive() | ||||||
self.arm_button.setStyleSheet(f'{self.arm_button.styleSheet()}{self.BUTTON_STYLESHEET}') | ||||||
self.disarm_button.setStyleSheet( | ||||||
f'{self.disarm_button.styleSheet()}{self.BUTTON_STYLESHEET}' | ||||||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write docstrings for all the methods here
Use the VSCode autodocstring extension with the
numpy
preset