Debian Codegraph @

wxgeometrie/GUI/pythonSTC.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #-------------------------------------------------------------------------
3 # qsci_simple_pythoneditor.pyw
4 #
5 # QScintilla sample with PyQt
6 #
7 # Eli Bendersky ([email protected])
8 # This code is in the public domain
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 # Set the default font
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 # Margin 0 is used for line numbers
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 # Clickable margin 1 for showing markers
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 # Brace matching: enable for a brace immediately before or after
51 # the current position
52 #
53 self.setBraceMatching(QsciScintilla.SloppyBraceMatch)
54
55 # Current line visible with special background color
56 self.setCaretLineVisible(True)
57 self.setCaretLineBackgroundColor(QColor("#ffe4e4"))
58
59 # Set Python lexer
60 # Set style for Python comments (style number 1) to a fixed-width
61 # courier.
62 #
63 lexer = QsciLexerPython()
64 lexer.setDefaultFont(font)
65 self.setLexer(lexer)
66 self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, b'Courier')
67
68 # Don't want to see the horizontal scrollbar at all
69 # Use raw message to Scintilla here (all messages are documented
70 # here: http://www.scintilla.org/ScintillaDoc.html)
71 self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
72
73 # not too small
74 self.setMinimumSize(600, 450)
75
76 def on_margin_clicked(self, nmargin, nline, modifiers):
77 # Toggle marker for the line the margin was clicked on
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_()