Skip to content

Commit a595f80

Browse files
committed
Handle Qsci import for PyQt 4-6 bindings
1 parent 61cb7f7 commit a595f80

File tree

11 files changed

+44
-23
lines changed

11 files changed

+44
-23
lines changed

preditor/scintilla/__init__.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
from __future__ import absolute_import
22

3+
__all__ = ["delayables", "FindState", "Qsci", "QsciScintilla"]
4+
5+
import Qt
6+
7+
if Qt.IsPyQt6:
8+
from PyQt6 import Qsci
9+
from PyQt6.Qsci import QsciScintilla
10+
elif Qt.IsPyQt5:
11+
from PyQt5 import Qsci
12+
from PyQt5.Qsci import QsciScintilla
13+
elif Qt.IsPyQt4:
14+
from PyQt4 import Qsci
15+
from PyQt4.Qsci import QsciScintilla
16+
else:
17+
raise ImportError(
18+
"QScintilla library is not supported by {}".format(Qt.__binding__)
19+
)
20+
321

422
class FindState(object):
523
"""
@@ -19,4 +37,4 @@ def __init__(self):
1937
self.end_pos = None
2038

2139

22-
from . import delayables # noqa: F401, E402
40+
from . import delayables # noqa: E402

preditor/scintilla/delayables/smart_highlight.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from __future__ import absolute_import, print_function
22

33
import Qt
4-
from PyQt5.Qsci import QsciScintilla
54
from Qt.QtCore import QSignalMapper
65
from Qt.QtWidgets import QWidget
76

87
from ...delayable_engine.delayables import SearchDelayable
9-
from .. import FindState
8+
from .. import FindState, QsciScintilla
109

1110

1211
class SmartHighlight(SearchDelayable):

preditor/scintilla/delayables/spell_check.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
import re
55
import string
66

7-
from PyQt5.Qsci import QsciScintilla
87
from Qt.QtCore import Qt
98
from Qt.QtGui import QColor
109

1110
from ...delayable_engine.delayables import RangeDelayable
12-
from .. import lang
11+
from .. import QsciScintilla, lang
1312

1413
logger = logging.getLogger(__name__)
1514

preditor/scintilla/documenteditor.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from functools import partial
2121

2222
import six
23-
from PyQt5.Qsci import QsciScintilla
2423
from PyQt5.QtCore import QTextCodec
2524
from Qt import QtCompat
2625
from Qt.QtCore import Property, QFile, QPoint, Qt, Signal
@@ -38,7 +37,7 @@
3837
from ..delayable_engine import DelayableEngine
3938
from ..enum import Enum, EnumGroup
4039
from ..gui import QtPropertyInit
41-
from . import lang
40+
from . import QsciScintilla, lang
4241

4342
logger = logging.getLogger(__name__)
4443

preditor/scintilla/lang/language.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
except ImportError:
99
from ConfigParser import ConfigParser
1010

11-
from PyQt5 import Qsci
11+
from .. import Qsci
1212

1313

1414
class MethodDescriptor(object):

preditor/scintilla/lexers/cpplexer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from __future__ import absolute_import
22

3-
from PyQt5.Qsci import QsciLexerCPP
43
from Qt.QtGui import QColor
54

5+
from .. import Qsci
66

7-
class CppLexer(QsciLexerCPP):
7+
8+
class CppLexer(Qsci.QsciLexerCPP):
89
# Items in this list will be highlighted using the color for self.KeywordSet2
910
highlightedKeywords = ''
1011

preditor/scintilla/lexers/javascriptlexer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from __future__ import absolute_import
22

3-
from PyQt5.Qsci import QsciLexerJavaScript
43
from Qt.QtGui import QColor
54

5+
from .. import Qsci
66

7-
class JavaScriptLexer(QsciLexerJavaScript):
7+
8+
class JavaScriptLexer(Qsci.QsciLexerJavaScript):
89
# Items in this list will be highlighted using the color for self.KeywordSet2
910
highlightedKeywords = ''
1011

preditor/scintilla/lexers/maxscriptlexer.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from builtins import str as text
55

66
from future.utils import iteritems
7-
from PyQt5.Qsci import QsciLexerCustom, QsciScintilla
7+
8+
from .. import Qsci, QsciScintilla
89

910
MS_KEYWORDS = """
1011
if then else not and or key collect
@@ -17,12 +18,12 @@
1718
"""
1819

1920

20-
class MaxscriptLexer(QsciLexerCustom):
21+
class MaxscriptLexer(Qsci.QsciLexerCustom):
2122
# Items in this list will be highligheded using the color for self.SmartHighlight
2223
highlightedKeywords = ''
2324

2425
def __init__(self, parent=None):
25-
QsciLexerCustom.__init__(self, parent)
26+
super(MaxscriptLexer, self).__init__(parent)
2627
self._styles = {
2728
0: 'Default',
2829
1: 'Comment',
@@ -56,7 +57,7 @@ def defaultColor(self, style):
5657
elif style == self.String:
5758
return QColor(180, 140, 30)
5859

59-
return QsciLexerCustom.defaultColor(self, style)
60+
return super(MaxscriptLexer, self).defaultColor(style)
6061

6162
def defaultPaper(self, style):
6263
if style == self.SmartHighlight:
@@ -77,7 +78,7 @@ def keywords(self, style):
7778
return MS_KEYWORDS
7879
if style == self.SmartHighlight:
7980
return self.highlightedKeywords
80-
return QsciLexerCustom.keywords(self, style)
81+
return super(MaxscriptLexer, self).keywords(style)
8182

8283
def processChunk(self, chunk, lastState, keywords):
8384
# process the length of the chunk

preditor/scintilla/lexers/mellexer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import re
44

5-
from PyQt5.Qsci import QsciLexerCPP
65
from Qt.QtGui import QColor
76

7+
from .. import Qsci
8+
89
MEL_SYNTAX = """and array as case catch continue do else exit float for from global if
910
in int local not of off on or proc random return select string then throw to try vector
1011
when where while with true false
@@ -310,7 +311,7 @@
310311
"""
311312

312313

313-
class MelLexer(QsciLexerCPP):
314+
class MelLexer(Qsci.QsciLexerCPP):
314315
# Items in this list will be highlighted using the color for self.GlobalClass
315316
_highlightedKeywords = ''
316317
# Mel uses $varName for variables, so we have to allow them in words

preditor/scintilla/lexers/mulexer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from __future__ import absolute_import
22

3-
from PyQt5.Qsci import QsciLexerCPP
43
from Qt.QtGui import QColor
54

5+
from .. import Qsci
6+
67
MU_KEYWORDS = """
78
method string Color use require module for_each let global function nil void
89
"""
910

1011

11-
class MuLexer(QsciLexerCPP):
12+
class MuLexer(Qsci.QsciLexerCPP):
1213
# Items in this list will be highlighted using the color for self.KeywordSet2
1314
highlightedKeywords = ''
1415

0 commit comments

Comments
 (0)