Skip to content

Commit

Permalink
Merged dark/light qss stylesheets with CSS selector
Browse files Browse the repository at this point in the history
  • Loading branch information
jooste committed Sep 28, 2023
1 parent 24731c4 commit 2da757c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 50 deletions.
45 changes: 45 additions & 0 deletions bluesky/resources/graphics/bluesky.qss
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,49 @@ QToolButton#panup {
}
QToolButton#pandown {
qproperty-icon: url(bluesky/resources/graphics/icons/pandown.svg)
}

/* Palette settings for Dark mode */
QMainWindow[style="dark"], QMainWindow[style="dark"] QToolBox, QMainWindow[style="dark"] QWidget {
background-color: rgb(40, 40, 40);
}

QMainWindow[style="dark"] QToolButton, QMainWindow[style="dark"] QTreeWidget, QMainWindow[style="dark"] QTreeWidget QLabel {
background-color:rgb(60, 60, 60);
}

QMainWindow[style="dark"] Stackwin, QMainWindow[style="dark"] Cmdline {
color: lightgreen;
background-color: rgb(90, 90, 90)
}

QMainWindow[style="dark"] QToolButton {
border: 0.5px solid rgb(75, 75, 75);
}

QMainWindow[style="dark"] QToolButton:hover {
background-color: rgb(75, 75, 75);
}

/* Palette settings for Light mode */
QMainWindow[style="light"], QMainWindow[style="light"] QToolBox, QMainWindow[style="light"] QWidget {
background-color: rgb(245, 245, 245);
}

QMainWindow[style="light"] QToolButton, QMainWindow[style="light"] QTreeWidget, QMainWindow[style="light"] QTreeWidget QLabel {
background-color:white;
}

QMainWindow[style="light"] Stackwin, QMainWindow[style="light"] Cmdline {
color: rgb(0, 81, 255);
background-color: white;
border: 0.5px solid rgb(205,205,205);
}

QMainWindow[style="light"] QToolButton {
border: 0.5px solid rgb(205,205,205);
}

QMainWindow[style="light"] QToolButton:hover {
background-color: rgb(235, 235, 235);
}
20 changes: 0 additions & 20 deletions bluesky/resources/graphics/dark.qss

This file was deleted.

21 changes: 0 additions & 21 deletions bluesky/resources/graphics/light.qss

This file was deleted.

21 changes: 12 additions & 9 deletions bluesky/ui/qtgl/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

try:
from PyQt5.QtWidgets import QApplication as app
from PyQt5.QtCore import Qt, pyqtSlot, QTimer, QItemSelectionModel, QSize, QEvent
from PyQt5.QtCore import Qt, pyqtSlot, QTimer, QItemSelectionModel, QSize, QEvent, pyqtProperty
from PyQt5.QtGui import QPixmap, QIcon
from PyQt5.QtWidgets import QMainWindow, QSplashScreen, QTreeWidgetItem, \
QPushButton, QFileDialog, QDialog, QTreeWidget, QVBoxLayout, \
QDialogButtonBox, QMenu, QLabel, QWidget
from PyQt5 import uic
except ImportError:
from PyQt6.QtWidgets import QApplication as app
from PyQt6.QtCore import Qt, pyqtSlot, QTimer, QItemSelectionModel, QSize, QEvent
from PyQt6.QtCore import Qt, pyqtSlot, QTimer, QItemSelectionModel, QSize, QEvent, pyqtProperty
from PyQt6.QtGui import QPixmap, QIcon
from PyQt6.QtWidgets import QMainWindow, QSplashScreen, QTreeWidgetItem, \
QPushButton, QFileDialog, QDialog, QTreeWidget, QVBoxLayout, \
Expand Down Expand Up @@ -49,8 +49,9 @@


def isdark():
p = app.instance().style().standardPalette()
return (p.color(p.ColorRole.Window).value() < p.color(p.ColorRole.WindowText).value())
''' Returns true if app is in dark mode, false otherwise. '''
p = app.instance().style().standardPalette()
return (p.color(p.ColorRole.Window).value() < p.color(p.ColorRole.WindowText).value())


class Splash(QSplashScreen):
Expand Down Expand Up @@ -123,6 +124,11 @@ class MainWindow(Base, QMainWindow):
nlos_cur = rs.ActData(0, group='acdata')
nlos_tot = rs.ActData(0, group='acdata')

@pyqtProperty(str)
def style(self):
''' Returns "dark"" if app is in dark mode, "light" otherwise. '''
return "dark" if self.darkmode else "light"

def __init__(self, mode):
super().__init__()
# Running mode of this gui. Options:
Expand Down Expand Up @@ -208,11 +214,8 @@ def recursiveNoFocus(w):

def setStyleSheet(self, contents=''):
if not contents:
gfxpath = bs.resource(bs.settings.gfx_path)
colfname = gfxpath / f"{'dark' if self.darkmode else 'light'}.qss"
with open(gfxpath / 'bluesky.qss') as style, open(colfname) as col:
contents = col.read() + style.read()
super().setStyleSheet(contents)
with open(bs.resource(bs.settings.gfx_path) / 'bluesky.qss') as style:
super().setStyleSheet(style.read())

def keyPressEvent(self, event):
if event.modifiers() & Qt.KeyboardModifier.ShiftModifier \
Expand Down

0 comments on commit 2da757c

Please sign in to comment.