From 5b106d2231b268b5fce149a0aecac54ce62d5247 Mon Sep 17 00:00:00 2001 From: Cathy Wright Date: Thu, 26 Apr 2018 12:03:33 -0400 Subject: [PATCH] Fixed remaining issues with PyQt5 compatibility. --- .gitignore | 1 + Libs/pyqode/core/api/code_edit.py | 18 +++++++++++++++--- Libs/pyqode/core/api/panel.py | 14 ++++++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 44dbcd6..a15a5be 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.pyc .idea/ +.DS_Store diff --git a/Libs/pyqode/core/api/code_edit.py b/Libs/pyqode/core/api/code_edit.py index 36a2e5d..b0cc213 100644 --- a/Libs/pyqode/core/api/code_edit.py +++ b/Libs/pyqode/core/api/code_edit.py @@ -1232,8 +1232,14 @@ class CodeEdit(QtWidgets.QPlainTextEdit): self._foreground = QtGui.QColor('black') self._whitespaces_foreground = QtGui.QColor('light gray') app = QtWidgets.QApplication.instance() - self._sel_background = app.palette().highlight().color() - self._sel_foreground = app.palette().highlightedText().color() + # Qt5 compatibility + try: + self._sel_background = app.palette().highlight().color() + self._sel_foreground = app.palette().highlightedText().color() + except: + palette = QtGui.QGuiApplication.palette() + self._sel_background = palette.highlight().color() + self._sel_foreground = palette.highlightedText().color() self._font_size = 10 self.font_name = "" @@ -1269,7 +1275,13 @@ class CodeEdit(QtWidgets.QPlainTextEdit): self.setFont(QtGui.QFont(self._font_family, self._font_size + self._zoom_level)) flg_stylesheet = hasattr(self, '_flg_stylesheet') - if QtWidgets.QApplication.instance().styleSheet() or flg_stylesheet: + # Qt5 compatibility + try: + curStylesheet = QtWidgets.QApplication.instance().styleSheet() + except: + curStylesheet = None + + if curStylesheet or flg_stylesheet: self._flg_stylesheet = True # On Window, if the application once had a stylesheet, we must # keep on using a stylesheet otherwise strange colors appear diff --git a/Libs/pyqode/core/api/panel.py b/Libs/pyqode/core/api/panel.py index 1a3bc18..d638d86 100644 --- a/Libs/pyqode/core/api/panel.py +++ b/Libs/pyqode/core/api/panel.py @@ -84,8 +84,18 @@ class Panel(QtWidgets.QWidget, Mode): """ Mode.on_install(self, editor) self.setParent(editor) - self.setPalette(QtWidgets.QApplication.instance().palette()) - self.setFont(QtWidgets.QApplication.instance().font()) + # Qt5 compatibility + try: + self.setPalette(QtWidgets.QApplication.instance().palette()) + except: + self.setPalette(QtGui.QGuiApplication.palette()) + + # Qt5 compatibility + try: + self.setFont(QtWidgets.QApplication.instance().font()) + except: + self.setFont(QtGui.QGuiApplication.font()) + self.editor.panels.refresh() self._background_brush = QtGui.QBrush(QtGui.QColor( self.palette().window().color()))