2014-01-02 09:57:14 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# The MIT License (MIT)
|
|
|
|
#
|
2014-01-02 10:15:54 -05:00
|
|
|
# Copyright (c) <2013-2014> <Colin Duquesnoy>
|
2014-01-02 09:57:14 -05:00
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
# all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
# THE SOFTWARE.
|
|
|
|
#
|
2013-03-10 11:21:37 -04:00
|
|
|
"""
|
|
|
|
Initialise the QDarkStyleSheet module when used with python.
|
|
|
|
|
|
|
|
This modules provides a function to transparently load the stylesheets
|
|
|
|
with the correct rc file.
|
|
|
|
"""
|
2014-05-16 17:34:59 -04:00
|
|
|
import logging
|
2014-05-16 17:29:53 -04:00
|
|
|
import platform
|
2013-03-10 11:21:37 -04:00
|
|
|
|
|
|
|
|
2016-06-19 08:53:30 -04:00
|
|
|
__version__ = "2.2"
|
2014-02-20 07:31:58 -05:00
|
|
|
|
|
|
|
|
2014-05-16 17:34:59 -04:00
|
|
|
def _logger():
|
|
|
|
return logging.getLogger('qdarkstyle')
|
|
|
|
|
|
|
|
|
2013-03-10 11:21:37 -04:00
|
|
|
def load_stylesheet(pyside=True):
|
|
|
|
"""
|
|
|
|
Loads the stylesheet. Takes care of importing the rc module.
|
|
|
|
|
|
|
|
:param pyside: True to load the pyside rc file, False to load the PyQt rc file
|
|
|
|
|
|
|
|
:return the stylesheet string
|
|
|
|
"""
|
|
|
|
# Smart import of the rc file
|
|
|
|
if pyside:
|
2014-01-02 10:06:01 -05:00
|
|
|
import qdarkstyle.pyside_style_rc
|
2013-03-10 11:21:37 -04:00
|
|
|
else:
|
2014-01-02 10:06:01 -05:00
|
|
|
import qdarkstyle.pyqt_style_rc
|
2013-03-10 11:21:37 -04:00
|
|
|
|
2014-02-17 09:56:46 -05:00
|
|
|
# Load the stylesheet content from resources
|
|
|
|
if not pyside:
|
|
|
|
from PyQt4.QtCore import QFile, QTextStream
|
|
|
|
else:
|
|
|
|
from PySide.QtCore import QFile, QTextStream
|
|
|
|
|
|
|
|
f = QFile(":qdarkstyle/style.qss")
|
|
|
|
if not f.exists():
|
2014-05-16 17:34:59 -04:00
|
|
|
_logger().error("Unable to load stylesheet, file not found in "
|
|
|
|
"resources")
|
2014-02-17 09:56:46 -05:00
|
|
|
return ""
|
|
|
|
else:
|
|
|
|
f.open(QFile.ReadOnly | QFile.Text)
|
|
|
|
ts = QTextStream(f)
|
2014-05-16 17:29:53 -04:00
|
|
|
stylesheet = ts.readAll()
|
|
|
|
if platform.system().lower() == 'darwin': # see issue #12 on github
|
|
|
|
mac_fix = '''
|
|
|
|
QDockWidget::title
|
|
|
|
{
|
2016-06-19 09:12:13 -04:00
|
|
|
background-color: #31363b;
|
2014-05-29 17:57:21 -04:00
|
|
|
text-align: center;
|
2015-04-25 15:42:10 -04:00
|
|
|
height: 12px;
|
2014-05-16 17:29:53 -04:00
|
|
|
}
|
|
|
|
'''
|
|
|
|
stylesheet += mac_fix
|
|
|
|
return stylesheet
|
2014-05-17 14:35:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
def load_stylesheet_pyqt5():
|
|
|
|
"""
|
|
|
|
Loads the stylesheet for use in a pyqt5 application.
|
|
|
|
|
|
|
|
:param pyside: True to load the pyside rc file, False to load the PyQt rc file
|
|
|
|
|
|
|
|
:return the stylesheet string
|
|
|
|
"""
|
|
|
|
# Smart import of the rc file
|
|
|
|
import qdarkstyle.pyqt5_style_rc
|
|
|
|
|
|
|
|
# Load the stylesheet content from resources
|
|
|
|
from PyQt5.QtCore import QFile, QTextStream
|
|
|
|
|
|
|
|
f = QFile(":qdarkstyle/style.qss")
|
|
|
|
if not f.exists():
|
|
|
|
_logger().error("Unable to load stylesheet, file not found in "
|
|
|
|
"resources")
|
|
|
|
return ""
|
|
|
|
else:
|
|
|
|
f.open(QFile.ReadOnly | QFile.Text)
|
|
|
|
ts = QTextStream(f)
|
|
|
|
stylesheet = ts.readAll()
|
|
|
|
if platform.system().lower() == 'darwin': # see issue #12 on github
|
|
|
|
mac_fix = '''
|
|
|
|
QDockWidget::title
|
|
|
|
{
|
2016-06-19 09:12:13 -04:00
|
|
|
background-color: #31363b;
|
2014-05-29 18:02:55 -04:00
|
|
|
text-align: center;
|
2015-04-25 15:42:10 -04:00
|
|
|
height: 12px;
|
2014-05-17 14:35:22 -04:00
|
|
|
}
|
|
|
|
'''
|
|
|
|
stylesheet += mac_fix
|
2015-04-06 05:37:11 -04:00
|
|
|
return stylesheet
|