Skip to content

Commit

Permalink
Detect dark_mode in sidepanel
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-el committed Oct 29, 2024
1 parent e397968 commit 0aa55b4
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/ert/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,25 @@
padding-top: 5px;
padding-bottom: 10px;
}
QToolButton:hover {
background-color: rgba(50, 50, 50, 90);
}
QToolButton::menu-indicator {
right: 10px; bottom: 5px;
}
"""

BUTTON_STYLE_SHEET_LIGHT: str = (
BUTTON_STYLE_SHEET
+ """
QToolButton:hover {background-color: rgba(50, 50, 50, 90);}
"""
)

BUTTON_STYLE_SHEET_DARK: str = (
BUTTON_STYLE_SHEET
+ """
QToolButton:hover {background-color: rgba(30, 30, 30, 150);}
"""
)


class ErtMainWindow(QMainWindow):
close_signal = Signal()
Expand Down Expand Up @@ -76,7 +87,12 @@ def __init__(
self.central_widget.setLayout(self.central_layout)
self.facade = LibresFacade(self.ert_config)
self.side_frame = QFrame(self)
self.side_frame.setStyleSheet("background-color: lightgray;")

if self.is_dark_mode():
self.side_frame.setStyleSheet("background-color: rgb(64, 64, 64);")
else:
self.side_frame.setStyleSheet("background-color: lightgray;")

self.vbox_layout = QVBoxLayout(self.side_frame)
self.side_frame.setLayout(self.vbox_layout)

Expand All @@ -103,6 +119,9 @@ def __init__(
self.__add_tools_menu()
self.__add_help_menu()

def is_dark_mode(self) -> bool:
return self.palette().base().color().value() < 70

def select_central_widget(self) -> None:
actor = self.sender()
if actor:
Expand Down Expand Up @@ -216,7 +235,11 @@ def _add_sidebar_button(self, name: str, icon: QIcon) -> QToolButton:
button = QToolButton(self.side_frame)
button.setFixedSize(85, 95)
button.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
button.setStyleSheet(BUTTON_STYLE_SHEET)

button.setStyleSheet(
BUTTON_STYLE_SHEET_DARK
) if self.is_dark_mode() else button.setStyleSheet(BUTTON_STYLE_SHEET_LIGHT)

pad = 45
icon_size = QSize(button.size().width() - pad, button.size().height() - pad)
button.setIconSize(icon_size)
Expand Down

0 comments on commit 0aa55b4

Please sign in to comment.