1+ import sys , os
12from PyQt5 .QtGui import *
23from PyQt5 .Qsci import *
34
45
56class SimplePythonEditor (QsciScintilla ):
67 ARROW_MARKER_NUM = 8
78
8- def __init__ (self , lexer_type , parent = None ):
9+ def __init__ (self , lexer_type , parent = None , style_data : dict = None ):
910 super (SimplePythonEditor , self ).__init__ (parent )
1011
1112 # 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 )
1423 font .setFixedPitch (True )
1524 font .setPointSize (10 )
1625 self .setFont (font )
@@ -21,17 +30,11 @@ def __init__(self, lexer_type, parent=None):
2130 self .setMarginsFont (font )
2231 self .setMarginWidth (0 , fontmetrics .width ("00000" ) + 6 )
2332 self .setMarginLineNumbers (0 , True )
24- self .setMarginsBackgroundColor (QColor ("#cccccc" ))
2533
2634 # Clickable margin 1 for showing markers
2735 self .setMarginSensitivity (1 , True )
28- # self.connect(self,
29- # SIGNAL('marginClicked(int, int, Qt::KeyboardModifiers)'),
30- # self.on_margin_clicked)
3136 self .markerDefine (QsciScintilla .RightArrow , self .ARROW_MARKER_NUM )
32- self .setMarkerBackgroundColor (QColor ("#ee1111" ), self .ARROW_MARKER_NUM )
3337 self .setFolding (QsciScintilla .BoxedTreeFoldStyle )
34- self .setFoldMarginColors (QColor ("#cccccc" ), QColor ("#333333" ))
3538
3639 # Brace matching: enable for a brace immediately before or after
3740 # the current position
@@ -40,21 +43,64 @@ def __init__(self, lexer_type, parent=None):
4043
4144 # Current line visible with special background color
4245 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- #
4946
5047 if lexer_type is not None :
5148 self .elexer = lexer_type
49+ self .elexer .setFont (font )
5250 self .elexer .setDefaultFont (font )
5351 self .setLexer (self .elexer )
5452 else :
5553 self .elexer = None
5654
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 ))
58104# 32, "Courier New"
59105 self .SendScintilla (QsciScintilla .SCI_STYLESETFONT , 1 , text )
60106
0 commit comments