Add dark theme from QDarkStyle. Part 1: Force the theme

This commit is contained in:
Raoul Snyman 2017-09-28 10:31:28 -07:00
parent 2cfb03a606
commit 93fd4053b2
3 changed files with 47 additions and 8 deletions

View File

@ -45,11 +45,13 @@ from openlp.core.common.versionchecker import VersionThread, get_application_ver
from openlp.core.lib import ScreenList from openlp.core.lib import ScreenList
from openlp.core.resources import qInitResources from openlp.core.resources import qInitResources
from openlp.core.ui import SplashScreen 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.exceptionform import ExceptionForm
from openlp.core.ui.firsttimeform import FirstTimeForm from openlp.core.ui.firsttimeform import FirstTimeForm
from openlp.core.ui.firsttimelanguageform import FirstTimeLanguageForm from openlp.core.ui.firsttimelanguageform import FirstTimeLanguageForm
from openlp.core.ui.mainwindow import MainWindow from openlp.core.ui.mainwindow import MainWindow
__all__ = ['OpenLP', 'main'] __all__ = ['OpenLP', 'main']
@ -122,13 +124,16 @@ class OpenLP(OpenLPMixin, QtWidgets.QApplication):
sys.exit() sys.exit()
# Correct stylesheet bugs # Correct stylesheet bugs
application_stylesheet = '' application_stylesheet = ''
if not Settings().value('advanced/alternate rows'): if HAS_DARK_STYLE:
base_color = self.palette().color(QtGui.QPalette.Active, QtGui.QPalette.Base) application_stylesheet = DARK_STYLESHEET
alternate_rows_repair_stylesheet = \ else:
'QTableWidget, QListWidget, QTreeWidget {alternate-background-color: ' + base_color.name() + ';}\n' if not Settings().value('advanced/alternate rows'):
application_stylesheet += alternate_rows_repair_stylesheet base_color = self.palette().color(QtGui.QPalette.Active, QtGui.QPalette.Base)
if is_win(): alternate_rows_repair_stylesheet = \
application_stylesheet += WIN_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: if application_stylesheet:
self.setStyleSheet(application_stylesheet) self.setStyleSheet(application_stylesheet)
can_show_splash = Settings().value('core/show splash') can_show_splash = Settings().value('core/show splash')

32
openlp/core/ui/dark.py Normal file
View File

@ -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 = ''

View File

@ -45,6 +45,7 @@ from openlp.core.lib import Renderer, PluginManager, ImageManager, PluginStatus,
from openlp.core.lib.ui import create_action from openlp.core.lib.ui import create_action
from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, ThemeManager, LiveController, PluginForm, \ from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, ThemeManager, LiveController, PluginForm, \
ShortcutListForm, FormattingTagForm, PreviewController ShortcutListForm, FormattingTagForm, PreviewController
from openlp.core.ui.dark import HAS_DARK_STYLE
from openlp.core.ui.firsttimeform import FirstTimeForm from openlp.core.ui.firsttimeform import FirstTimeForm
from openlp.core.ui.media import MediaController from openlp.core.ui.media import MediaController
from openlp.core.ui.printserviceform import PrintServiceForm from openlp.core.ui.printserviceform import PrintServiceForm
@ -155,7 +156,8 @@ class Ui_MainWindow(object):
# Create the MediaManager # Create the MediaManager
self.media_manager_dock = OpenLPDockWidget(main_window, 'media_manager_dock', self.media_manager_dock = OpenLPDockWidget(main_window, 'media_manager_dock',
':/system/system_mediamanager.png') ':/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 # Create the media toolbox
self.media_tool_box = QtWidgets.QToolBox(self.media_manager_dock) self.media_tool_box = QtWidgets.QToolBox(self.media_manager_dock)
self.media_tool_box.setObjectName('media_tool_box') self.media_tool_box.setObjectName('media_tool_box')