Skip to content
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

Merged
merged 28 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b41f01e
Change button colors on arm and disarm
ShannonGriswold Oct 5, 2024
4e84807
Now uses IndicatorMixin instead of arm
ShannonGriswold Oct 29, 2024
2a84948
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 29, 2024
6957880
Fixed linter issues
ShannonGriswold Oct 29, 2024
2a35088
Fixed linter issues
ShannonGriswold Oct 29, 2024
47c98b5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 29, 2024
f6fb632
Fixed more linter issues
ShannonGriswold Oct 30, 2024
73c7570
Merge branch 'color-arm-disarm' of github.com:CWRUbotix/rov-25 into c…
ShannonGriswold Oct 30, 2024
6b5d9b0
Deleted old qss files
ShannonGriswold Nov 2, 2024
6903537
Removed Circle class
ShannonGriswold Nov 5, 2024
6496580
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 5, 2024
aeb3d5c
Changed docstring to imperative mood
ShannonGriswold Nov 5, 2024
41168c2
Merge branch 'main' into color-arm-disarm
ShannonGriswold Nov 5, 2024
9cae118
Styles now stored in dictionary
ShannonGriswold Nov 9, 2024
bc305c6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 9, 2024
e211b06
Styles are now a TypedDict
ShannonGriswold Nov 9, 2024
042e5a2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 9, 2024
c110140
Styles are now Final
ShannonGriswold Nov 9, 2024
0b37703
Merge branch 'color-arm-disarm' of github.com:CWRUbotix/rov-25 into c…
ShannonGriswold Nov 9, 2024
1da1203
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 9, 2024
5cbc6b6
imported Final
ShannonGriswold Nov 9, 2024
9ab125b
Merge branch 'color-arm-disarm' of github.com:CWRUbotix/rov-25 into c…
ShannonGriswold Nov 9, 2024
1a846a4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 9, 2024
b135ae2
Added type parameters for dict
ShannonGriswold Nov 12, 2024
4d615d8
Deleted commented out TypedDict
ShannonGriswold Nov 12, 2024
c436153
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 12, 2024
77292ec
Now uses IntEnum
ShannonGriswold Nov 12, 2024
5c63ff5
Merge branch 'color-arm-disarm' of github.com:CWRUbotix/rov-25 into c…
ShannonGriswold Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 18 additions & 26 deletions src/surface/gui/gui/styles/custom_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Contributor

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

self._ORIGINAL_STYLESHEET = self.styleSheet()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SCREAMING_SNAKE is for constants, make this self._original_stylesheet


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()
3 changes: 0 additions & 3 deletions src/surface/gui/gui/styles/dark.qss

This file was deleted.

3 changes: 0 additions & 3 deletions src/surface/gui/gui/styles/light.qss

This file was deleted.

4 changes: 0 additions & 4 deletions src/surface/gui/gui/styles/watermelon.qss

This file was deleted.

24 changes: 21 additions & 3 deletions src/surface/gui/gui/widgets/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
BUTTON_STYLESHEET = 'QPushButton { font-size: 20px;}'
BUTTON_STYLESHEET = 'QPushButton { font-size: 20px; }'


command_response_signal = pyqtSignal(CommandBool.Response)
vehicle_state_signal = pyqtSignal(VehicleState)
Expand All @@ -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)
Expand Down Expand Up @@ -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}'
)
5 changes: 3 additions & 2 deletions src/surface/gui/gui/widgets/circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ def __init__(
super().__init__(parent)
self.setFixedSize(QSize(2 * radius, 2 * radius))
stylesheet = self.styleSheet()
self.setStyleSheet(f'{stylesheet}border-radius: {radius}px;')
self.setStyleSheet(f'{stylesheet} QLabel {{border-radius: {radius}px;}}')

if color:
self.set_color(color)

def set_color(self, color: QColor | Qt.GlobalColor) -> None:
if isinstance(color, Qt.GlobalColor):
color = QColor(color)
style = f'background-color: rgb({color.red()}, {color.green()}, {color.blue()});'
style = f'QLabel {{background-color: rgb({color.red()}, {color.green()}, {color.blue()});}}'
self.setStyleSheet(f'{self.styleSheet()}{style}')


class CircleIndicator(Circle, IndicatorMixin):
def __init__(self, parent: QWidget | None = None, radius: int = 50) -> None:
super().__init__(parent, radius)
self.set_initial_stylesheet()
self.set_inactive()