| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
import sys |
| 15 |
|
| 16 |
from PyQt5.QtCore import * |
| 17 |
from PyQt5.QtGui import * |
| 18 |
from PyQt5.QtWidgets import * |
| 19 |
from PyQt5.Qsci import QsciScintilla, QsciLexerPython |
| 20 |
|
| 21 |
class PythonSTC(QsciScintilla): |
| 22 |
ARROW_MARKER_NUM = 8 |
| 23 |
|
| 24 |
def __init__(self, parent=None): |
| 25 |
super(PythonSTC, self).__init__(parent) |
| 26 |
|
| 27 |
|
| 28 |
font = QFont() |
| 29 |
font.setFamily('Courier') |
| 30 |
font.setFixedPitch(True) |
| 31 |
font.setPointSize(10) |
| 32 |
self.setFont(font) |
| 33 |
self.setMarginsFont(font) |
| 34 |
|
| 35 |
|
| 36 |
fontmetrics = QFontMetrics(font) |
| 37 |
self.setMarginsFont(font) |
| 38 |
self.setMarginWidth(0, fontmetrics.width("00000") + 6) |
| 39 |
self.setMarginLineNumbers(0, True) |
| 40 |
self.setMarginsBackgroundColor(QColor("#cccccc")) |
| 41 |
|
| 42 |
|
| 43 |
self.setMarginSensitivity(1, True) |
| 44 |
self.marginClicked[int, int, Qt.KeyboardModifiers].connect(self.on_margin_clicked) |
| 45 |
self.markerDefine(QsciScintilla.RightArrow, |
| 46 |
self.ARROW_MARKER_NUM) |
| 47 |
self.setMarkerBackgroundColor(QColor("#ee1111"), |
| 48 |
self.ARROW_MARKER_NUM) |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
self.setBraceMatching(QsciScintilla.SloppyBraceMatch) |
| 54 |
|
| 55 |
|
| 56 |
self.setCaretLineVisible(True) |
| 57 |
self.setCaretLineBackgroundColor(QColor("#ffe4e4")) |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
lexer = QsciLexerPython() |
| 64 |
lexer.setDefaultFont(font) |
| 65 |
self.setLexer(lexer) |
| 66 |
self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, b'Courier') |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) |
| 72 |
|
| 73 |
|
| 74 |
self.setMinimumSize(600, 450) |
| 75 |
|
| 76 |
def on_margin_clicked(self, nmargin, nline, modifiers): |
| 77 |
|
| 78 |
if self.markersAtLine(nline) != 0: |
| 79 |
self.markerDelete(nline, self.ARROW_MARKER_NUM) |
| 80 |
else: |
| 81 |
self.markerAdd(nline, self.ARROW_MARKER_NUM) |
| 82 |
|
| 83 |
if __name__ == "__main__": |
| 84 |
app = QApplication(sys.argv) |
| 85 |
editor = PythonSTC() |
| 86 |
editor.show() |
| 87 |
editor.setText(open(sys.argv[0]).read()) |
| 88 |
app.exec_() |