From ef7fc86a643d6b0be68b2d70fe08f2d91e7c64a5 Mon Sep 17 00:00:00 2001 From: Matt Reynolds Date: Sat, 20 Apr 2019 09:27:28 -0700 Subject: [PATCH 1/2] Add pyqt5 support to load_stylesheet() --- qdarkstyle/__init__.py | 63 +++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/qdarkstyle/__init__.py b/qdarkstyle/__init__.py index 37b834c7..46f63569 100644 --- a/qdarkstyle/__init__.py +++ b/qdarkstyle/__init__.py @@ -213,36 +213,50 @@ def load_stylesheet(pyside=True): "Set QtPy environment variable to specify the Qt binding insteady.", PendingDeprecationWarning ) - # Smart import of the rc file - pyside_ver = None + qt_binding_ver = None + # Smart import of the rc file if pyside: # Detect the PySide version available try: import PySide + qt_binding_ver = 1 except ImportError: # Compatible with py27 import PySide2 - pyside_ver = 2 - else: - pyside_ver = 1 + qt_binding_ver = 2 - if pyside_ver == 1: + if qt_binding_ver == 1: import qdarkstyle.pyside_style_rc else: import qdarkstyle.pyside2_style_rc else: - import qdarkstyle.pyqt_style_rc + + # Detect PyQt version available + try: + import PyQt4 + qt_binding_ver = 4 + except ImportError: + import PyQt5 + qt_binding_ver = 5 + + if qt_binding_ver == 4: + import qdarkstyle.pyqt_style_rc + else: + import qdarkstyle.pyqt5_style_rc # Load the stylesheet content from resources - if not pyside: - from PyQt4.QtCore import QFile, QTextStream - else: - if pyside_ver == 1: + if pyside: + if qt_binding_ver == 1: from PySide.QtCore import QFile, QTextStream else: from PySide2.QtCore import QFile, QTextStream + else: + if qt_binding_ver == 4: + from PyQt4.QtCore import QFile, QTextStream + else: + from PyQt5.QtCore import QFile, QTextStream f = QFile(":qdarkstyle/style.qss") if not f.exists(): @@ -325,32 +339,7 @@ def load_stylesheet_pyqt5(): "use load_stylesheet()", PendingDeprecationWarning ) - # 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 - { - background-color: #32414B; - text-align: center; - height: 12px; - } - ''' - stylesheet += mac_fix - return stylesheet + return load_stylesheet(pyside=False) def information(): From 644e533aaa5b4126db3cf24a925562c724fcb61b Mon Sep 17 00:00:00 2001 From: Matt Reynolds Date: Sat, 20 Apr 2019 09:44:58 -0700 Subject: [PATCH 2/2] Update Authors --- AUTHORS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS.md b/AUTHORS.md index 7723525b..c9c5d767 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -19,8 +19,9 @@ These people contribute to bug fixes, improvements and so on. Please, insert your information after the last one. - Year - Name - `` - contribution. -- 2018 - [mowoolli](https://github.com/mowoolli) - bug fixes. - 2018 - Xingyun Wu - `xingyun.wu@foxmail.com` - bug fixes. - 2018 - [KcHNST](https://github.com/KcHNST) - bug fixes. +- 2018 - [mowoolli](https://github.com/mowoolli) - bug fixes. +- 2019 - [Matthew-Reynolds](https://github.com/Matthew-Reynolds) - bug fixes. Thank you all!