1
+ import sys , os
1
2
from PyQt5 .QtGui import *
2
3
from PyQt5 .Qsci import *
3
4
4
5
5
6
class SimplePythonEditor (QsciScintilla ):
6
7
ARROW_MARKER_NUM = 8
7
8
8
- def __init__ (self , lexer_type , parent = None ):
9
+ def __init__ (self , lexer_type , parent = None , style_data : dict = None ):
9
10
super (SimplePythonEditor , self ).__init__ (parent )
10
11
11
12
# Set the default font
12
- font = QFont ()
13
- font .setFamily ('Courier' )
13
+ font = None
14
+ font_family = 'Courier'
15
+ font_id = None
16
+ if style_data is not None :
17
+ try :
18
+ font_id = QFontDatabase .addApplicationFont (style_data ['EditorQsciFont' ].replace ('/' , os .sep ))
19
+ font_family = QFontDatabase .applicationFontFamilies (font_id )[0 ]
20
+ except Exception :
21
+ ""
22
+ font = QFont (font_family )
14
23
font .setFixedPitch (True )
15
24
font .setPointSize (10 )
16
25
self .setFont (font )
@@ -21,17 +30,11 @@ def __init__(self, lexer_type, parent=None):
21
30
self .setMarginsFont (font )
22
31
self .setMarginWidth (0 , fontmetrics .width ("00000" ) + 6 )
23
32
self .setMarginLineNumbers (0 , True )
24
- self .setMarginsBackgroundColor (QColor ("#cccccc" ))
25
33
26
34
# Clickable margin 1 for showing markers
27
35
self .setMarginSensitivity (1 , True )
28
- # self.connect(self,
29
- # SIGNAL('marginClicked(int, int, Qt::KeyboardModifiers)'),
30
- # self.on_margin_clicked)
31
36
self .markerDefine (QsciScintilla .RightArrow , self .ARROW_MARKER_NUM )
32
- self .setMarkerBackgroundColor (QColor ("#ee1111" ), self .ARROW_MARKER_NUM )
33
37
self .setFolding (QsciScintilla .BoxedTreeFoldStyle )
34
- self .setFoldMarginColors (QColor ("#cccccc" ), QColor ("#333333" ))
35
38
36
39
# Brace matching: enable for a brace immediately before or after
37
40
# the current position
@@ -40,21 +43,64 @@ def __init__(self, lexer_type, parent=None):
40
43
41
44
# Current line visible with special background color
42
45
self .setCaretLineVisible (True )
43
- self .setCaretLineBackgroundColor (QColor ("#ffe4e4" ))
44
-
45
- # Set Python lexer
46
- # Set style for Python comments (style number 1) to a fixed-width
47
- # courier.
48
- #
49
46
50
47
if lexer_type is not None :
51
48
self .elexer = lexer_type
49
+ self .elexer .setFont (font )
52
50
self .elexer .setDefaultFont (font )
53
51
self .setLexer (self .elexer )
54
52
else :
55
53
self .elexer = None
56
54
57
- text = bytearray (str .encode ("Arial" ))
55
+ style_ok = False
56
+ if style_data is not None :
57
+ try :
58
+ self .setMarginsBackgroundColor (QColor (style_data ['EditorQsciMarginsBackgroundColor' ]))
59
+ self .setMarginsForegroundColor (QColor (style_data ['EditorQsciMarginsForegroundColor' ]))
60
+ self .setMarkerBackgroundColor (QColor (style_data ['EditorQsciMarkerBackgroundColor' ]), self .ARROW_MARKER_NUM )
61
+ self .setFoldMarginColors (
62
+ QColor (style_data ['EditorQsciFoldMarginColor1' ]),
63
+ QColor (style_data ['EditorQsciFoldMarginColor2' ])
64
+ )
65
+ self .setCaretLineBackgroundColor (style_data ['EditorQsciCaretLineBackgroundColor' ])
66
+
67
+ self .setColor (QColor (style_data ['EditorQsciDefaultTextColor' ]))
68
+ self .setPaper (QColor (style_data ['EditorQsciDefaultBackgroundColor' ]))
69
+
70
+ if self .elexer is not None :
71
+ self .elexer .setDefaultColor (QColor (style_data ['EditorQsciDefaultTextColor' ]))
72
+ self .elexer .setDefaultPaper (QColor (style_data ['EditorQsciDefaultBackgroundColor' ]))
73
+ self .elexer .setPaper (QColor (style_data ['EditorQsciDefaultBackgroundColor' ]))
74
+
75
+ if isinstance (lexer_type , QsciLexerXML ) is True :
76
+ self .elexer .setColor (QColor (style_data ['EditorQsciXMLDefaultTextColor' ]), QsciLexerXML .Default )
77
+ self .elexer .setColor (QColor (style_data ['EditorQsciXMLDefaultTagColor' ]), QsciLexerXML .Tag )
78
+ self .elexer .setColor (QColor (style_data ['EditorQsciXMLDefaultTagColor' ]), QsciLexerXML .UnknownTag )
79
+
80
+ style_ok = True
81
+ except Exception :
82
+ ""
83
+ if style_ok is False :
84
+ self .setMarginsBackgroundColor (QColor ("#333333" ))
85
+ self .setMarginsForegroundColor (QColor ("#ffffff" ))
86
+ self .setMarkerBackgroundColor (QColor ("#ee1111" ), self .ARROW_MARKER_NUM )
87
+ self .setFoldMarginColors (QColor ("#cccccc" ), QColor ("#333333" ))
88
+ self .setCaretLineBackgroundColor (QColor ("#ffe4e4" ))
89
+
90
+ self .setColor (QColor ("#ffffff" ))
91
+ self .setPaper (QColor ("#A6A6A6" ))
92
+
93
+ if self .elexer is not None :
94
+ self .elexer .setDefaultPaper (QColor ("#A6A6A6" ))
95
+ self .elexer .setDefaultColor (QColor ("#ffffff" ))
96
+ self .elexer .setPaper (QColor ("#A6A6A6" ))
97
+
98
+ if isinstance (lexer_type , QsciLexerXML ) is True :
99
+ self .elexer .setColor (QColor .fromRgb (255 , 255 , 255 ), QsciLexerXML .Default )
100
+ self .elexer .setColor (QColor ('#000080' ), QsciLexerXML .Tag )
101
+ self .elexer .setColor (QColor ('#000080' ), QsciLexerXML .UnknownTag )
102
+
103
+ text = bytearray (str .encode (font_family ))
58
104
# 32, "Courier New"
59
105
self .SendScintilla (QsciScintilla .SCI_STYLESETFONT , 1 , text )
60
106
0 commit comments