From d88d34728e84da398de481675c2fb2a4b159499b Mon Sep 17 00:00:00 2001 From: YourBoyRory Date: Sun, 15 Dec 2024 21:59:48 -0500 Subject: [PATCH] Darkmode is now forced --- FrameDialog.py | 2 +- FrameWidgets.py | 5 ++- PaintingStudio.py | 34 ++++++++++---------- build-windows.cmd | 2 +- styles/Adwaita-Dark.qss | 70 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 20 deletions(-) create mode 100644 styles/Adwaita-Dark.qss diff --git a/FrameDialog.py b/FrameDialog.py index d931b86..1b735af 100644 --- a/FrameDialog.py +++ b/FrameDialog.py @@ -1,7 +1,7 @@ from PyQt5.QtCore import Qt, QUrl, QSize, QTimer, QStringListModel, pyqtSignal from PyQt5.QtGui import QPixmap, QImage, QIcon, QColor, QFont from PyQt5.QtWidgets import QScrollArea, QSlider, QMainWindow, QMessageBox, QMenuBar, QDialog, QColorDialog, QFormLayout, QLineEdit, QMenu, QAction, QListWidgetItem, QListWidget, QTabWidget, QApplication, QWidget, QVBoxLayout, QComboBox, QLabel, QFrame, QHBoxLayout, QFileDialog, QSizePolicy, QSpinBox, QPushButton -from PyQt5.QtWidgets import QApplication, QStyleFactory, QProgressBar +from PyQt5.QtWidgets import QApplication, QStyleFactory, QProgressBar, QSpacerItem class HelpDialog(QDialog): def __init__(self, parent): diff --git a/FrameWidgets.py b/FrameWidgets.py index d528271..76eedf5 100644 --- a/FrameWidgets.py +++ b/FrameWidgets.py @@ -66,13 +66,14 @@ def displayText(self, text): text_item = QGraphicsTextItem(text) font = QFont("Sans", 16) text_item.setFont(font) - #text_item.setDefaultTextColor(Qt.black) + text_item.setDefaultTextColor(Qt.white) # Center the text in the scene text_item.setPos(200, 250) # Adjust the position to suit your needs # Add the text item to the scene scene = QGraphicsScene(self) + scene.setObjectName("IgnoreMin") scene.addItem(text_item) self.setScene(scene) @@ -117,6 +118,7 @@ def __init__(self, parent): combine_OptionsViewport = QHBoxLayout() """Options Pane""" PaintingOptions = QWidget() + PaintingOptions.setObjectName("Frame") PaintingOptions_layout = QVBoxLayout() lable_width = 120 @@ -196,6 +198,7 @@ def __init__(self, parent): """Tool Bar""" ToolBar = QWidget() + ToolBar.setObjectName("Frame") ToolBar_layout = QVBoxLayout() # View Port Tools tools_layout = QHBoxLayout() diff --git a/PaintingStudio.py b/PaintingStudio.py index fe0d3a7..8cc3430 100644 --- a/PaintingStudio.py +++ b/PaintingStudio.py @@ -18,7 +18,9 @@ class PaintingStudio(QMainWindow): def __init__(self): super().__init__() + self.setObjectName("Frame") self.central_widget = QWidget() + self.central_widget.setObjectName("Frame") self.setCentralWidget(self.central_widget) layout = QHBoxLayout(self) self.central_widget.setLayout(layout) @@ -135,6 +137,12 @@ def addToComboBox(self, item): else: print(item, "Exists") +def resource_path(file): + if getattr(sys, 'frozen', False): + base_path = sys._MEIPASS + else: + base_path = os.path.dirname(__file__) + return os.path.join(base_path, 'styles', file) def set_theme(app): desktop = "" @@ -145,26 +153,18 @@ def set_theme(app): ] desktop = os.environ.get('DESKTOP_SESSION') if any(sub in desktop for sub in gtk_based): - try: - import subprocess - result = subprocess.run( - ['gsettings', 'get', 'org.gnome.desktop.interface', 'color-scheme'], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - text=True - ) - theme = result.stdout.strip().lower() - print(theme) - if 'dark' in theme: - app.setStyle("Adwaita-Dark") - else: - app.setStyle("Adwaita") - except: - print("Failed to get theme satus") - app.setStyle("Adwaita") + app.setStyle("Adwaita-Dark") except: pass current_style = app.style().objectName() + if desktop == "" or current_style == "windowsvista": + desktop = "windows" + try: + with open(resource_path("Adwaita-Dark.qss"), "r") as f: + app.setStyleSheet(f.read()) + except: + print("Failed to load darkmode") + pass print(f"Loaded Theme: {current_style} on {desktop}") if __name__ == "__main__": diff --git a/build-windows.cmd b/build-windows.cmd index e2b40ff..79ac3de 100644 --- a/build-windows.cmd +++ b/build-windows.cmd @@ -2,7 +2,7 @@ python -m venv ./venv-windows source ./venv-windows/Scripts/activate.bat pip install -r requirements.txt -pyinstaller --onefile --windowed --name "MCPaintingStudio" --add-data "assets:assets/" ./PaintingStudio.py +pyinstaller --onefile --windowed --name "MCPaintingStudio" --add-data "assets:assets/" --add-data "styles:styles/" ./PaintingStudio.py echo. echo Build Done echo. diff --git a/styles/Adwaita-Dark.qss b/styles/Adwaita-Dark.qss new file mode 100644 index 0000000..8e96775 --- /dev/null +++ b/styles/Adwaita-Dark.qss @@ -0,0 +1,70 @@ +/* General QWidget styling */ + +QWidget { + border: 1px solid #393939; + background-color: #393939; + color: #f9fafa; +} + +QWidget#IgnoreMin { + min-height: 1px; +} + +QWidget:disabled { + border: 1px solid #2d2d2d; + background-color: #2d2d2d; + color: #999999; +} +QWidget:focus { + border: 2px solid #587392; +} + +QWidget#Frame { + background-color: #242424; + border: none; +} + +QLabel { + background-color: #242424; + border: none; +} + +QCheckBox { + background-color: #242424; + border: none; +} + +QSlider { + background-color: #242424; + border: none; +} + +QSlider:disabled { + background-color: #242424; + border: none; +} + +QLineEdit { + min-height: 25px; +} + +QSpinBox { + min-height: 25px; +} + +QComboBox { + min-height: 25px; +} + +QPushButton { + min-height: 25px; + min-width: 100px; +} + +QPushButton:hover { + background-color: #454545; +} + +QPushButton:pressed { + background-color: #707070; +}