def __init__(self, parent=None): super().__init__(parent) # Set the default font self.font = QFont() self.font.setFamily('Courier') self.font.setFixedPitch(True) self.font.setPointSize(10) self.setFont(self.font) self.setMarginsFont(self.font) # Margin 0 is used for line numbers fontmetrics = QFontMetrics(self.font) self.setMarginsFont(self.font) self.setMarginWidth(0, fontmetrics.width("000") + 6) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QColor("#E3F0FF")) # Brace matching: enable for a brace immediately before or after # the current position # self.setBraceMatching(QsciScintilla.SloppyBraceMatch) # Current line visible with special background color self.setCaretLineVisible(True) self.setCaretLineBackgroundColor(QColor("#A5ABBD")) # Set Python lexer # Set style for Python comments (style number 1) to a fixed-width # courier. # lexer = Qsci.QsciLexerMarkdown(self) lexer.setDefaultFont(self.font) self.setLexer(lexer) # self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, 'Courier') """ Customization - AUTOCOMPLETION (Partially usable without a lexer) """ # Set the autocompletions to case INsensitive self.setAutoCompletionCaseSensitivity(False) # Set the autocompletion to not replace the word to the right of the cursor self.setAutoCompletionReplaceWord(False) # Set the autocompletion source to be the words in the # document self.setAutoCompletionSource(Qsci.QsciScintilla.AcsDocument) # Set the autocompletion dialog to appear as soon as 1 character is typed self.setAutoCompletionThreshold(1) # Don't want to see the horizontal scrollbar at all # Use raw message to Scintilla here (all messages are documented # here: http://www.scintilla.org/ScintillaDoc.html) # self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) # not too small self.setMinimumSize(300, 100)
def setup_editor(self): "define the editor panel" # self.editor = qtw.QTextEdit(self) self.editor = qsc.QsciScintilla(self) self.editor.setWrapMode(qsc.QsciScintilla.WrapWord) self.editor.setBraceMatching(qsc.QsciScintilla.SloppyBraceMatch) self.editor.setAutoIndent(True) self.editor.setFolding(qsc.QsciScintilla.PlainFoldStyle) self.editor.setCaretLineVisible(True) self.editor.setCaretLineBackgroundColor(gui.QColor("#ffe4e4")) self.editor.setLexer(qsc.QsciLexerMarkdown()) self.editor.setEnabled(False) return self.editor
def setEditorType(self, tpe: EditorType, inner=False): self.editType = tpe if not inner: self.editorTypeBox.setCurrentIndex(tpe.value) if tpe == EditorType.JSON: self.editor.changeLexer(Qsci.QsciLexerJSON(self.editor), 'JSON') elif tpe == EditorType.XML: self.editor.changeLexer(Qsci.QsciLexerXML(self.editor), 'XML') elif tpe == EditorType.HTML: self.editor.changeLexer(Qsci.QsciLexerHTML(self.editor), 'HTML') elif tpe == EditorType.Javascript: self.editor.changeLexer(Qsci.QsciLexerJavaScript(self.editor), 'Javascript') else: self.editor.changeLexer(Qsci.QsciLexerMarkdown(self.editor), 'Text<') self.editorTypeChanged.emit(tpe.value)