From 93fd4053b2e81184bead35035feebfb085fa3731 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 28 Sep 2017 10:31:28 -0700 Subject: [PATCH] Add dark theme from QDarkStyle. Part 1: Force the theme --- openlp/core/__init__.py | 19 ++++++++++++------- openlp/core/ui/dark.py | 32 ++++++++++++++++++++++++++++++++ openlp/core/ui/mainwindow.py | 4 +++- 3 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 openlp/core/ui/dark.py diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 88b3dbfb7..c49ccff95 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -45,11 +45,13 @@ from openlp.core.common.versionchecker import VersionThread, get_application_ver from openlp.core.lib import ScreenList from openlp.core.resources import qInitResources from openlp.core.ui import SplashScreen +from openlp.core.ui.dark import HAS_DARK_STYLE, DARK_STYLESHEET from openlp.core.ui.exceptionform import ExceptionForm from openlp.core.ui.firsttimeform import FirstTimeForm from openlp.core.ui.firsttimelanguageform import FirstTimeLanguageForm from openlp.core.ui.mainwindow import MainWindow + __all__ = ['OpenLP', 'main'] @@ -122,13 +124,16 @@ class OpenLP(OpenLPMixin, QtWidgets.QApplication): sys.exit() # Correct stylesheet bugs application_stylesheet = '' - if not Settings().value('advanced/alternate rows'): - base_color = self.palette().color(QtGui.QPalette.Active, QtGui.QPalette.Base) - alternate_rows_repair_stylesheet = \ - 'QTableWidget, QListWidget, QTreeWidget {alternate-background-color: ' + base_color.name() + ';}\n' - application_stylesheet += alternate_rows_repair_stylesheet - if is_win(): - application_stylesheet += WIN_REPAIR_STYLESHEET + if HAS_DARK_STYLE: + application_stylesheet = DARK_STYLESHEET + else: + if not Settings().value('advanced/alternate rows'): + base_color = self.palette().color(QtGui.QPalette.Active, QtGui.QPalette.Base) + alternate_rows_repair_stylesheet = \ + 'QTableWidget, QListWidget, QTreeWidget {alternate-background-color: ' + base_color.name() + ';}\n' + application_stylesheet += alternate_rows_repair_stylesheet + if is_win(): + application_stylesheet += WIN_REPAIR_STYLESHEET if application_stylesheet: self.setStyleSheet(application_stylesheet) can_show_splash = Settings().value('core/show splash') diff --git a/openlp/core/ui/dark.py b/openlp/core/ui/dark.py new file mode 100644 index 000000000..762c1ee4a --- /dev/null +++ b/openlp/core/ui/dark.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2017 OpenLP Developers # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +""" +The :mod:`~openlp.core.ui.dark` module looks for and loads a dark theme +""" + +try: + import qdarkstyle + HAS_DARK_STYLE = True + DARK_STYLESHEET = qdarkstyle.load_stylesheet_pyqt5() +except: + HAS_DARK_STYLE = False + DARK_STYLESHEET = '' diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 413e97a17..33a9ec2ca 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -45,6 +45,7 @@ from openlp.core.lib import Renderer, PluginManager, ImageManager, PluginStatus, from openlp.core.lib.ui import create_action from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, ThemeManager, LiveController, PluginForm, \ ShortcutListForm, FormattingTagForm, PreviewController +from openlp.core.ui.dark import HAS_DARK_STYLE from openlp.core.ui.firsttimeform import FirstTimeForm from openlp.core.ui.media import MediaController from openlp.core.ui.printserviceform import PrintServiceForm @@ -155,7 +156,8 @@ class Ui_MainWindow(object): # Create the MediaManager self.media_manager_dock = OpenLPDockWidget(main_window, 'media_manager_dock', ':/system/system_mediamanager.png') - self.media_manager_dock.setStyleSheet(MEDIA_MANAGER_STYLE) + if not HAS_DARK_STYLE: + self.media_manager_dock.setStyleSheet(MEDIA_MANAGER_STYLE) # Create the media toolbox self.media_tool_box = QtWidgets.QToolBox(self.media_manager_dock) self.media_tool_box.setObjectName('media_tool_box')