MCPcopy Create free account
hub / github.com/PyQt5/PyQt / CodeScintilla

Class CodeScintilla

Test/ChartView/ChatWidget.py:81–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79
80
81class CodeScintilla(QsciScintilla):
82
83 def __init__(self, *args, **kwargs):
84 super(CodeScintilla, self).__init__(*args, **kwargs)
85 self.init()
86 self.linesChanged.connect(self.onLinesChanged)
87
88 def onLinesChanged(self):
89 self.setMarginWidth(0, self.fontMetrics().width(str(self.lines())) + 6)
90
91 def init(self):
92 self.setUtf8(True)
93 lexer = QsciLexerJSON(self)
94 self.setLexer(lexer)
95 self.setAutoCompletionCaseSensitivity(False) # 忽略大小写
96 self.setAutoCompletionSource(self.AcsAll)
97 self.setAutoCompletionThreshold(1) # 一个字符就弹出补全
98 self.setAutoIndent(True) # 自动缩进
99 self.setBackspaceUnindents(True)
100 self.setBraceMatching(self.StrictBraceMatch)
101 self.setIndentationGuides(True)
102 self.setIndentationsUseTabs(False)
103 self.setIndentationWidth(4)
104 self.setTabIndents(True)
105 self.setTabWidth(4)
106 self.setWhitespaceSize(1)
107 self.setWhitespaceVisibility(self.WsVisible)
108 self.setWhitespaceForegroundColor(Qt.gray)
109 self.setWrapIndentMode(self.WrapIndentFixed)
110 self.setWrapMode(self.WrapWord)
111 # 折叠
112 self.setFolding(self.BoxedTreeFoldStyle, 2)
113 self.setFoldMarginColors(QColor("#676A6C"), QColor("#676A6D"))
114 font = self.font() or QFont()
115 font.setFamily("Consolas")
116 font.setFixedPitch(True)
117 font.setPointSize(13)
118 self.setFont(font)
119 self.setMarginsFont(font)
120 self.fontmetrics = QFontMetrics(font)
121 lexer.setFont(font)
122 self.setMarginWidth(0, self.fontmetrics.width(str(self.lines())) + 6)
123 self.setMarginLineNumbers(0, True)
124 self.setMarginsBackgroundColor(QColor("gainsboro"))
125 self.setMarginWidth(1, 0)
126 self.setMarginWidth(2, 14) # 折叠区域
127 # 绑定自动补齐热键Alt+/
128 completeKey = QShortcut(QKeySequence(Qt.ALT + Qt.Key_Slash), self)
129 completeKey.setContext(Qt.WidgetShortcut)
130 completeKey.activated.connect(self.autoCompleteFromAll)
131
132
133class CodeWidget(QWidget):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected