From f6a0c0cc6d604f152b6a3ddfdbcb8218fa7b95b5 Mon Sep 17 00:00:00 2001 From: Andrew Senetar Date: Mon, 24 Jan 2022 19:14:30 -0600 Subject: [PATCH] Add initial dark style for use in Windows - Other platforms can achieve this with the OS theme so not enabled for them at this time. - Adds preference in display options to use dark style, default is false. --- qt/app.py | 41 +++++++++++++++++++++++++++++++++++++--- qt/preferences.py | 3 +++ qt/preferences_dialog.py | 6 ++++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/qt/app.py b/qt/app.py index 06d7eeef..225544fd 100644 --- a/qt/app.py +++ b/qt/app.py @@ -8,11 +8,11 @@ import sys import os.path as op from PyQt5.QtCore import QTimer, QObject, QUrl, pyqtSignal, Qt -from PyQt5.QtGui import QDesktopServices -from PyQt5.QtWidgets import QApplication, QFileDialog, QDialog, QMessageBox +from PyQt5.QtGui import QColor, QDesktopServices, QPalette +from PyQt5.QtWidgets import QApplication, QFileDialog, QDialog, QMessageBox, QStyleFactory, QToolTip from hscommon.trans import trget -from hscommon import desktop +from hscommon import desktop, plat from qtlib.about_box import AboutBox from qtlib.recent import Recent @@ -197,6 +197,8 @@ class DupeGuru(QObject): if self.details_dialog: self.details_dialog.update_options() + self._set_style("dark" if self.prefs.use_dark_style else "light") + # --- Private def _get_details_dialog_class(self): if self.model.app_mode == AppMode.PICTURE: @@ -214,6 +216,39 @@ class DupeGuru(QObject): else: return PreferencesDialogStandard + def _set_style(self, style="light"): + # Only support this feature on windows for now + if not plat.ISWINDOWS: + return + if style == "dark": + QApplication.setStyle(QStyleFactory.create("Fusion")) + palette = QApplication.style().standardPalette() + palette.setColor(QPalette.ColorRole.Window, QColor(53, 53, 53)) + palette.setColor(QPalette.ColorRole.WindowText, Qt.white) + palette.setColor(QPalette.ColorRole.Base, QColor(25, 25, 25)) + palette.setColor(QPalette.ColorRole.AlternateBase, QColor(53, 53, 53)) + palette.setColor(QPalette.ColorRole.ToolTipBase, QColor(53, 53, 53)) + palette.setColor(QPalette.ColorRole.ToolTipText, Qt.white) + palette.setColor(QPalette.ColorRole.Text, Qt.white) + palette.setColor(QPalette.ColorRole.Button, QColor(53, 53, 53)) + palette.setColor(QPalette.ColorRole.ButtonText, Qt.white) + palette.setColor(QPalette.ColorRole.BrightText, Qt.red) + palette.setColor(QPalette.ColorRole.Link, QColor(42, 130, 218)) + palette.setColor(QPalette.ColorRole.Highlight, QColor(42, 130, 218)) + palette.setColor(QPalette.ColorRole.HighlightedText, Qt.black) + palette.setColor(QPalette.ColorGroup.Disabled, QPalette.ColorRole.Text, QColor(164, 166, 168)) + palette.setColor(QPalette.ColorGroup.Disabled, QPalette.ColorRole.WindowText, QColor(164, 166, 168)) + palette.setColor(QPalette.ColorGroup.Disabled, QPalette.ColorRole.ButtonText, QColor(164, 166, 168)) + palette.setColor(QPalette.ColorGroup.Disabled, QPalette.ColorRole.HighlightedText, QColor(164, 166, 168)) + palette.setColor(QPalette.ColorGroup.Disabled, QPalette.ColorRole.Base, QColor(68, 68, 68)) + palette.setColor(QPalette.ColorGroup.Disabled, QPalette.ColorRole.Window, QColor(68, 68, 68)) + palette.setColor(QPalette.ColorGroup.Disabled, QPalette.ColorRole.Highlight, QColor(68, 68, 68)) + else: + QApplication.setStyle(QStyleFactory.create("windowsvista" if plat.ISWINDOWS else "Fusion")) + palette = QApplication.style().standardPalette() + QToolTip.setPalette(palette) + QApplication.setPalette(palette) + # --- Public def add_selected_to_ignore_list(self): self.model.add_selected_to_ignore_list() diff --git a/qt/preferences.py b/qt/preferences.py index 9c8875dc..7e25daef 100644 --- a/qt/preferences.py +++ b/qt/preferences.py @@ -30,6 +30,7 @@ class Preferences(PreferencesBase): if not self.language and trans.installed_lang: self.language = trans.installed_lang self.portable = get("Portable", False) + self.use_dark_style = get("UseDarkStyle", False) self.use_native_dialogs = get("UseNativeDialogs", True) self.tableFontSize = get("TableFontSize", self.tableFontSize) @@ -95,6 +96,7 @@ class Preferences(PreferencesBase): self.destination_type = 1 self.custom_command = "" self.language = trans.installed_lang if trans.installed_lang else "" + self.use_dark_style = False self.use_native_dialogs = True self.tableFontSize = QApplication.font().pointSize() @@ -146,6 +148,7 @@ class Preferences(PreferencesBase): set_("CustomCommand", self.custom_command) set_("Language", self.language) set_("Portable", self.portable) + set_("UseDarkStyle", self.use_dark_style) set_("UseNativeDialogs", self.use_native_dialogs) set_("TableFontSize", self.tableFontSize) diff --git a/qt/preferences_dialog.py b/qt/preferences_dialog.py index 9f010bd9..f83abdf3 100644 --- a/qt/preferences_dialog.py +++ b/qt/preferences_dialog.py @@ -29,6 +29,7 @@ from PyQt5.QtWidgets import ( QFormLayout, ) from PyQt5.QtGui import QPixmap, QIcon +from hscommon import plat from hscommon.trans import trget from hscommon.plat import ISLINUX @@ -168,6 +169,9 @@ On MacOS, the tab bar will fill up the window's width instead." ) ) layout.addWidget(self.use_native_dialogs) + if plat.ISWINDOWS: + self._setupAddCheckbox("use_dark_style", tr("Use dark style")) + layout.addWidget(self.use_dark_style) self.ui_groupbox.setLayout(layout) self.displayVLayout.addWidget(self.ui_groupbox) @@ -297,6 +301,7 @@ use the modifier key to drag the floating window around" setchecked(self.reference_bold_font, prefs.reference_bold_font) setchecked(self.tabs_default_pos, prefs.tabs_default_pos) setchecked(self.use_native_dialogs, prefs.use_native_dialogs) + setchecked(self.use_dark_style, prefs.use_dark_style) setchecked( self.details_dialog_titlebar_enabled, prefs.details_dialog_titlebar_enabled, @@ -341,6 +346,7 @@ use the modifier key to drag the floating window around" prefs.tableFontSize = self.fontSizeSpinBox.value() prefs.tabs_default_pos = ischecked(self.tabs_default_pos) prefs.use_native_dialogs = ischecked(self.use_native_dialogs) + prefs.use_dark_style = ischecked(self.use_dark_style) lang = self.supportedLanguages[self.languageComboBox.currentIndex()] oldlang = self.app.prefs.language if oldlang not in self.supportedLanguages: