1
0
Fork 0
mirror of synced 2024-05-19 12:02:54 +12:00

Resources: Add static stylesheet for widgets that need special handling irregardless of theme

The static stylesheet properties are always applied. If there is a theme
stylesheet to be applied, they are appended in the end of the theme
stylesheet.

This removes stylesheet properties from the library widgets, some special
buttons and the queue worker labels.

To update the static stylesheet first edit `rare/resources/static_css/stylesheet.py`
and then execute it as a script.
This commit is contained in:
loathingKernel 2023-03-02 15:36:45 +02:00
parent 46664f3577
commit 1dd8856a29
14 changed files with 306 additions and 153 deletions

View file

@ -2,7 +2,7 @@ import os
from logging import getLogger
from PyQt5.QtCore import Qt, QSettings, QTimer, QSize, pyqtSignal, pyqtSlot
from PyQt5.QtGui import QCloseEvent, QCursor, QColor
from PyQt5.QtGui import QCloseEvent, QCursor
from PyQt5.QtWidgets import (
QMainWindow,
QApplication,
@ -173,27 +173,13 @@ class MainWindow(QMainWindow):
for label in self.queued_container.findChildren(QLabel, options=Qt.FindDirectChildrenOnly):
self.queued_container.layout().removeWidget(label)
label.deleteLater()
stylesheet = """
QLabel#QueueWorkerLabel {{
border-radius: 3px;
border: 1px solid {br_color};
background-color: {bg_color};
}}
"""
color = {
"Verify": QColor("#d6af57"),
"Move": QColor("#41cad9"),
}
for info in self.rcore.queue_info():
label = ElideLabel(info.app_title)
label.setObjectName("QueueWorkerLabel")
label.setToolTip(f"<b>{info.worker_type}</b>: {info.app_title}")
label.setProperty("workerType", info.worker_type)
label.setFixedWidth(150)
label.setContentsMargins(3, 0, 3, 0)
label.setStyleSheet(stylesheet.format(
br_color=color[info.worker_type].darker(200).name(),
bg_color=color[info.worker_type].darker(400).name(),
))
if info.state == QueueWorkerState.ACTIVE:
self.active_container.layout().addWidget(label)
self.active_label.setVisible(True)

View file

@ -32,35 +32,12 @@ class IconWidget(object):
self.status_label = ElideLabel(parent=widget)
self.status_label.setObjectName(f"{type(self).__name__}StatusLabel")
self.status_label.setFixedHeight(False)
self.status_label.setStyleSheet(
f"""
QLabel#{self.status_label.objectName()} {{
font-weight: bold;
color: white;
background-color: rgba(0, 0, 0, 65%);
border-radius: 5%;
border-top-left-radius: 11%;
border-top-right-radius: 11%;
}}
"""
)
self.status_label.setContentsMargins(6, 6, 6, 6)
self.status_label.setAutoFillBackground(False)
# on-hover popup
self.mini_widget = QWidget(parent=widget)
self.mini_widget.setObjectName(f"{type(self).__name__}MiniWidget")
self.mini_widget.setStyleSheet(
f"""
QWidget#{self.mini_widget.objectName()} {{
color: rgb(238, 238, 238);
background-color: rgba(0, 0, 0, 65%);
border-radius: 5%;
border-bottom-left-radius: 9%;
border-bottom-right-radius: 9%;
}}
"""
)
self.mini_widget.setFixedHeight(widget.height() // 3)
self.mini_effect = QGraphicsOpacityEffect(self.mini_widget)
@ -69,14 +46,6 @@ class IconWidget(object):
# game title
self.title_label = QLabel(parent=self.mini_widget)
self.title_label.setObjectName(f"{type(self).__name__}TitleLabel")
self.title_label.setStyleSheet(
f"""
QLabel#{self.title_label.objectName()} {{
font-weight: bold;
background-color: rgba(0, 0, 0, 0%); color: white;
}}
"""
)
self.title_label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.title_label.setAlignment(Qt.AlignVCenter)
self.title_label.setAutoFillBackground(False)
@ -85,48 +54,17 @@ class IconWidget(object):
# information below title
self.tooltip_label = ElideLabel(parent=self.mini_widget)
self.tooltip_label.setObjectName(f"{type(self).__name__}TooltipLabel")
self.tooltip_label.setStyleSheet(
f"""
QLabel#{self.tooltip_label.objectName()} {{
background-color: rgba(0, 0, 0, 0%); color: white;
}}
"""
)
self.tooltip_label.setAutoFillBackground(False)
# play button
self.launch_btn = QPushButton(parent=self.mini_widget)
self.launch_btn.setObjectName(f"{type(self).__name__}LaunchButton")
self.launch_btn.setStyleSheet(
f"""
QPushButton#{self.launch_btn.objectName()} {{
border-radius: 10%;
background-color: rgba(0, 0, 0, 65%);
border-color: black; border-width: 1px;
}}
QPushButton#{self.launch_btn.objectName()}::hover {{
border-color: gray;
}}
"""
)
self.launch_btn.setIcon(icon("ei.play-alt", color="white"))
self.launch_btn.setIconSize(QSize(20, 20))
self.launch_btn.setFixedSize(QSize(widget.width() // 4, widget.width() // 4))
self.install_btn = QPushButton(parent=self.mini_widget)
self.install_btn.setObjectName(f"{type(self).__name__}InstallButton")
self.install_btn.setStyleSheet(
f"""
QPushButton#{self.install_btn.objectName()} {{
border-radius: 10%;
background-color: rgba(0, 0, 0, 65%);
border-color: black; border-width: 1px;
}}
QPushButton#{self.install_btn.objectName()}::hover {{
border-color: gray;
}}
"""
)
self.install_btn.setIcon(icon("ri.install-fill", color="white"))
self.install_btn.setIconSize(QSize(20, 20))
self.install_btn.setFixedSize(QSize(widget.width() // 4, widget.width() // 4))

View file

@ -29,36 +29,14 @@ class ListWidget(object):
self.title_label = QLabel(parent=widget)
self.title_label.setObjectName(f"{type(self).__name__}TitleLabel")
self.title_label.setWordWrap(False)
self.title_label.setStyleSheet(
f"QLabel#{self.title_label.objectName()} {{font-weight: bold;}}"
)
self.status_label = QLabel(parent=widget)
self.status_label.setObjectName(f"{type(self).__name__}StatusLabel")
self.status_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
self.status_label.setStyleSheet(
f"""
QLabel#{self.status_label.objectName()} {{
font-weight: bold;
background-color: rgba(0,0,0,75%);
border: 1px solid black;
border-radius: 5px;
}}
"""
)
self.tooltip_label = QLabel(parent=widget)
self.tooltip_label.setObjectName(f"{type(self).__name__}TooltipLabel")
self.tooltip_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
self.tooltip_label.setStyleSheet(
f"""
QLabel#{self.tooltip_label.objectName()} {{
background-color: rgba(0,0,0,75%);
border: 1px solid black;
border-radius: 5px;
}}
"""
)
self.install_btn = QPushButton(parent=widget)
self.install_btn.setIcon(icon("ri.install-fill"))
@ -75,24 +53,15 @@ class ListWidget(object):
self.developer_label = ElideLabel(parent=widget)
self.developer_label.setObjectName(f"{type(self).__name__}DeveloperLabel")
self.developer_label.setFixedWidth(120)
self.developer_label.setStyleSheet(
f"QLabel#{self.developer_label.objectName()} {{color: #999;}}"
)
self.version_label = ElideLabel(parent=widget)
self.version_label.setObjectName(f"{type(self).__name__}VersionLabel")
self.version_label.setFixedWidth(120)
self.version_label.setStyleSheet(
f"QLabel#{self.version_label.objectName()} {{color: #999;}}"
)
self.size_label = ElideLabel(parent=widget)
self.size_label.setObjectName(f"{type(self).__name__}SizeLabel")
self.size_label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
self.size_label.setFixedWidth(60)
self.size_label.setStyleSheet(
f"QLabel#{self.size_label.objectName()} {{color: #999;}}"
)
# Create layouts
top_layout = QHBoxLayout()

View file

@ -1,2 +1,4 @@
import rare.resources.resources
# Static QSS independent of application style/colorsheme
import rare.resources.static_css
import rare.resources.stylesheets

Binary file not shown.

View file

@ -0,0 +1,180 @@
import os
import sys
import qstylizer.style
from PyQt5.QtCore import QDir
from PyQt5.QtGui import QColor
from PyQt5.pyrcc import RCCResourceLibrary, CONSTANT_COMPRESSLEVEL_DEFAULT, CONSTANT_COMPRESSTHRESHOLD_DEFAULT
verbose = True
compressLevel = 6
compressThreshold = CONSTANT_COMPRESSTHRESHOLD_DEFAULT
resourceRoot = ''
def processResourceFile(filenamesIn, filenameOut, listFiles):
if verbose:
sys.stderr.write("PyQt5 resource compiler\n")
# Setup.
library = RCCResourceLibrary()
library.setInputFiles(filenamesIn)
library.setVerbose(verbose)
library.setCompressLevel(compressLevel)
library.setCompressThreshold(compressThreshold)
library.setResourceRoot(resourceRoot)
if not library.readFiles():
return False
if filenameOut == '-':
filenameOut = ''
if listFiles:
# Open the output file or use stdout if not specified.
if filenameOut:
try:
out_fd = open(filenameOut, 'w')
except Exception:
sys.stderr.write(
"Unable to open %s for writing\n" % filenameOut)
return False
else:
out_fd = sys.stdout
for df in library.dataFiles():
out_fd.write("%s\n" % QDir.cleanPath(df))
if out_fd is not sys.stdout:
out_fd.close()
return True
return library.output(filenameOut)
css = qstylizer.style.StyleSheet()
# [Un]InstallButton
css.QPushButton["#InstallButton"].setValues(
borderColor=QColor(0, 180, 0).name(),
backgroundColor=QColor(0, 120, 0).name()
)
css.QPushButton["#InstallButton"].hover.setValues(
borderColor=QColor(0, 135, 0).name(),
backgroundColor=QColor(0, 90, 0).name()
)
css.QPushButton["#InstallButton"].disabled.setValues(
borderColor=QColor(0, 60, 0).name(),
backgroundColor=QColor(0, 40, 0).name()
)
css.QPushButton["#UninstallButton"].setValues(
borderColor=QColor(180, 0, 0).name(),
backgroundColor=QColor(120, 0, 0).name()
)
css.QPushButton["#UninstallButton"].hover.setValues(
borderColor=QColor(135, 0, 0).name(),
backgroundColor=QColor(90, 0, 0).name()
)
css.QPushButton["#UninstallButton"].disabled.setValues(
borderColor=QColor(60, 0, 0).name(),
backgroundColor=QColor(40, 0, 0).name()
)
# QueueWorkerLabel
css.QLabel["#QueueWorkerLabel"].setValues(
borderWidth="1px",
borderStyle="solid",
borderRadius="3px",
)
verify_color = QColor("#d6af57")
css.QLabel["#QueueWorkerLabel"]['[workerType="Verify"]'].setValues(
borderColor=verify_color.darker(200).name(),
backgroundColor=verify_color.darker(400).name()
)
move_color = QColor("#41cad9")
css.QLabel["#QueueWorkerLabel"]['[workerType="Move"]'].setValues(
borderColor=move_color.darker(200).name(),
backgroundColor=move_color.darker(400).name()
)
# IconGameWidget
icon_name = lambda x: f"#IconWidget{x}"
icon_background_props = {
"backgroundColor":"rgba(0, 0, 0, 65%)",
}
css.QLabel[icon_name("StatusLabel")].setValues(
fontWeight="bold",
color="white",
**icon_background_props,
borderRadius="5%",
borderTopLeftRadius="11%",
borderTopRightRadius="11%",
)
css.QWidget[icon_name("MiniWidget")].setValues(
color="rgb(238, 238, 238)",
**icon_background_props,
borderRadius="5%",
borderBottomLeftRadius="9%",
borderBottomRightRadius="9%",
)
icon_bottom_label_props = {
"color": "white",
"backgroundColor": "rgba(0, 0, 0, 0%)",
}
css.QLabel[icon_name("TitleLabel")].setValues(
fontWeight="bold",
**icon_bottom_label_props,
)
css.QLabel[icon_name("TooltipLabel")].setValues(
**icon_bottom_label_props,
)
icon_square_button_props = {
"border": "1px solid black",
"borderRadius": "10%",
}
icon_square_button_props.update(icon_background_props)
css.QPushButton[icon_name("LaunchButton")].setValues(
**icon_square_button_props
)
css.QPushButton[icon_name("LaunchButton")].hover.borderColor.setValue("gray")
css.QPushButton[icon_name("InstallButton")].setValues(
**icon_square_button_props
)
css.QPushButton[icon_name("InstallButton")].hover.borderColor.setValue("gray")
# ListGameWidget
list_name = lambda x: f"#ListWidget{x}"
css.QLabel[list_name("TitleLabel")].fontWeight.setValue("bold")
list_status_label_props = {
"backgroundColor": "rgba(0, 0, 0, 75%)",
"border": "1px solid black",
"borderRadius": "5px",
}
css.QLabel[list_name("StatusLabel")].setValues(
fontWeight="bold",
**list_status_label_props,
)
css.QLabel[list_name("TooltipLabel")].setValues(
**list_status_label_props,
)
list_info_label_color = "#999"
css.QLabel[list_name("DeveloperLabel")].color.setValue(list_info_label_color)
css.QLabel[list_name("VersionLabel")].color.setValue(list_info_label_color)
css.QLabel[list_name("SizeLabel")].color.setValue(list_info_label_color)
if __name__ == "__main__":
with open("stylesheet.qss", "w") as qss:
qss.write(f'\n/* This file is auto-generated from "{os.path.basename(__file__)}". DO NOT EDIT!!! */\n\n')
qss.write(css.toString())
if not processResourceFile(["stylesheet.qrc"], "__init__.py", False):
print("Error while creating compiled resources")
sys.exit(1)
sys.exit(0)

View file

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="static_css">
<file>stylesheet.qss</file>
</qresource>
</RCC>

View file

@ -0,0 +1,103 @@
/* This file is auto-generated from "stylesheet.py". DO NOT EDIT!!! */
QPushButton#InstallButton {
border-color: #00b400;
background-color: #007800;
}
QPushButton#InstallButton:hover {
border-color: #008700;
background-color: #005a00;
}
QPushButton#InstallButton:disabled {
border-color: #003c00;
background-color: #002800;
}
QPushButton#UninstallButton {
border-color: #b40000;
background-color: #780000;
}
QPushButton#UninstallButton:hover {
border-color: #870000;
background-color: #5a0000;
}
QPushButton#UninstallButton:disabled {
border-color: #3c0000;
background-color: #280000;
}
QLabel#QueueWorkerLabel {
border-width: 1px;
border-style: solid;
border-radius: 3px;
}
QLabel#QueueWorkerLabel[workerType="Verify"] {
border-color: #6b572c;
background-color: #352c16;
}
QLabel#QueueWorkerLabel[workerType="Move"] {
border-color: #20656c;
background-color: #103236;
}
QLabel#IconWidgetStatusLabel {
font-weight: bold;
color: white;
background-color: rgba(0, 0, 0, 65%);
border-radius: 5%;
border-top-left-radius: 11%;
border-top-right-radius: 11%;
}
QWidget#IconWidgetMiniWidget {
color: rgb(238, 238, 238);
background-color: rgba(0, 0, 0, 65%);
border-radius: 5%;
border-bottom-left-radius: 9%;
border-bottom-right-radius: 9%;
}
QLabel#IconWidgetTitleLabel {
font-weight: bold;
color: white;
background-color: rgba(0, 0, 0, 0%);
}
QLabel#IconWidgetTooltipLabel {
color: white;
background-color: rgba(0, 0, 0, 0%);
}
QPushButton#IconWidgetLaunchButton {
border: 1px solid black;
border-radius: 10%;
background-color: rgba(0, 0, 0, 65%);
}
QPushButton#IconWidgetLaunchButton:hover {
border-color: gray;
}
QPushButton#IconWidgetInstallButton {
border: 1px solid black;
border-radius: 10%;
background-color: rgba(0, 0, 0, 65%);
}
QPushButton#IconWidgetInstallButton:hover {
border-color: gray;
}
QLabel#ListWidgetTitleLabel {
font-weight: bold;
}
QLabel#ListWidgetStatusLabel {
font-weight: bold;
background-color: rgba(0, 0, 0, 75%);
border: 1px solid black;
border-radius: 5px;
}
QLabel#ListWidgetTooltipLabel {
background-color: rgba(0, 0, 0, 75%);
border: 1px solid black;
border-radius: 5px;
}
QLabel#ListWidgetDeveloperLabel {
color: #999;
}
QLabel#ListWidgetVersionLabel {
color: #999;
}
QLabel#ListWidgetSizeLabel {
color: #999;
}

View file

@ -320,24 +320,6 @@ QPushButton::menu-indicator {
left: -2px;
border-style: none;
}
QPushButton#InstallButton {
background-color: #F9A7FF;
}
QPushButton#InstallButton:hover {
background-color: #BB7DBF;
}
QPushButton#InstallButton:disabled {
background-color: #7D5380;
}
QPushButton#UninstallButton {
background-color: #FFB085;
}
QPushButton#UninstallButton:hover {
background-color: #BF8464;
}
QPushButton#UninstallButton:disabled {
background-color: #805843;
}
QGroupBox,
QCheckBox,

View file

@ -320,30 +320,6 @@ QPushButton::menu-indicator {
left: -2px;
border-style: none;
}
QPushButton#InstallButton {
border-color: rgb( 0, 180, 0);
background-color: rgb( 0, 120, 0);
}
QPushButton#InstallButton:hover {
border-color: rgb( 0, 135, 0);
background-color: rgb( 0, 90, 0);
}
QPushButton#InstallButton:disabled {
border-color: rgb( 0, 60, 0);
background-color: rgb( 0, 40, 0);
}
QPushButton#UninstallButton {
border-color: rgb(180, 0, 0);
background-color: rgb(120, 0, 0);
}
QPushButton#UninstallButton:hover {
border-color: rgb( 135, 0, 0);
background-color: rgb( 90, 0, 0);
}
QPushButton#UninstallButton:disabled {
border-color: rgb( 60, 0, 0);
background-color: rgb( 40, 0, 0);
}
QGroupBox,
QCheckBox,

View file

@ -103,16 +103,23 @@ def get_color_schemes() -> List[str]:
def set_style_sheet(style_sheet: str):
file = QFile(":/static_css/stylesheet.qss")
file.open(QFile.ReadOnly)
static = file.readAll().data().decode("utf-8")
file.close()
if not style_sheet:
qApp.setStyle(QStyleFactory.create(qApp.property("rareDefaultQtStyle")))
qApp.setStyleSheet("")
qApp.setStyleSheet(static)
return
qApp.setStyle(QStyleFactory.create("Fusion"))
file = QFile(f":/stylesheets/{style_sheet}/stylesheet.qss")
file.open(QFile.ReadOnly)
stylesheet = file.readAll().data().decode("utf-8")
file.close()
qApp.setStyleSheet(stylesheet + static)
qApp.setStyleSheet(stylesheet)
icon_color = qApp.palette().color(QPalette.Text).name()
qtawesome.set_defaults(color="#eeeeee")

View file

@ -91,9 +91,14 @@ class RareApp(QApplication):
if color_scheme := self.settings.value("color_scheme", False):
self.settings.setValue("style_sheet", "")
set_color_pallete(color_scheme)
# lk: set the static stylesheet
set_style_sheet("")
elif style_sheet := self.settings.value("style_sheet", False):
self.settings.setValue("color_scheme", "")
set_style_sheet(style_sheet)
else:
# lk: set the static stylesheet
set_style_sheet("")
self.setWindowIcon(QIcon(":/images/Rare.png"))
def load_translator(self, lang: str):