def __init__(self, parent=None): """ Constructor @param parent parent widget of this lexer """ QsciLexerYAML.__init__(self, parent) Lexer.__init__(self) self.commentString = "---"
def __init__(self, parent=None): """ Constructor @param parent parent widget of this lexer """ QsciLexerYAML.__init__(self, parent) Lexer.__init__(self) self.commentString = "#" self.keywordSetDescriptions = [ self.tr("Keywords"), ]
def defaultKeywords(self, kwSet): """ Public method to get the default keywords. @param kwSet number of the keyword set (integer) @return string giving the keywords (string) or None """ return QsciLexerYAML.keywords(self, kwSet)
def __init__( self, parent=None, font_family: str = None, font_point_size: float = 10.0, margins_background_color: str = None, marker_background_color: str = None, caret_line_background_color: str = None, caret_line_visible: bool = True, language: str = None, **kwargs ): """ :param parent: :param font_family: :param font_point_size: :param margins_background_color: :param marker_background_color: :param caret_line_background_color: :param caret_line_visible: :param language: a string that is set to select the lexer of the editor (either Python or JSON) the default lexer is a YAML lexer :param kwargs: """ super().__init__(parent) if font_point_size is None: font_point_size = chisurf.settings.gui['editor']['font_size'] if font_family is None: font_family = chisurf.settings.gui['editor']['font_family'] if margins_background_color is None: margins_background_color = chisurf.settings.gui[ 'editor' ]['margins_background_color'] if marker_background_color is None: marker_background_color = chisurf.settings.gui[ 'editor' ]['marker_background_color'] if caret_line_background_color is None: caret_line_background_color = chisurf.settings.gui[ 'editor' ]['caret_line_background_color'] # Set the default font font = QFont() font.setFamily(font_family) font.setFixedPitch(True) font.setPointSize(font_point_size) self.setFont(font) self.setMarginsFont(font) # Margin 0 is used for line numbers fontmetrics = QFontMetrics(font) self.setMarginsFont(font) self.setMarginWidth(0, fontmetrics.width("0000") + 6) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor( QColor(margins_background_color) ) # Clickable margin 1 for showing markers self.setMarginSensitivity(1, True) # self.connect(self, # SIGNAL('marginClicked(int, int, Qt::KeyboardModifiers)'), # self.on_margin_clicked) self.markerDefine(QsciScintilla.RightArrow, self.ARROW_MARKER_NUM) self.setMarkerBackgroundColor( QColor(marker_background_color), self.ARROW_MARKER_NUM ) # 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(caret_line_visible) self.setCaretLineBackgroundColor( QColor(caret_line_background_color) ) # Set Python lexer # Set style for Python comments (style number 1) to a fixed-width # courier. if language.lower() == "python": lexer = QsciLexerPython() elif language.lower() == "json": lexer = QsciLexerJSON() else: lexer = QsciLexerYAML() lexer.setDefaultFont(font) self.setLexer(lexer) text = bytearray(str.encode("Arial")) # 32, "Courier New" self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, text) # 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)
def getEditor(): editor = QsciScintilla() lexer = QsciLexerYAML() editor.setLexer(lexer) font = getFont() # lexer.setDefaultFont(font) lexer.setFont(font) settings = QSettings() lexer.readSettings(settings) print(settings.allKeys()) lexer.setDefaultPaper(QColor('#252721')) for i in range(10): lexer.setPaper(QColor('#252721'), i) lexer.setColor(QColor('#f8f8f2'), i) print(lexer.color(i).name()) lexer.setColor(QColor('#e6db74'), 0) # foreground (yellow) lexer.setColor(QColor('#75715e'), 1) # comment (gray) lexer.setColor(QColor('#f92672'), 2) # identifier (red) lexer.setColor(QColor('#ae81ff'), 3) # keyword (purple) lexer.setColor(QColor('#ae81ff'), 4) # number (purple) lexer.setColor(QColor('#ae81ff'), 5) # reference (purple) lexer.setColor(QColor('#ae81ff'), 6) # documentdelimiter (purple) lexer.setColor(QColor('#ae81ff'), 7) # text block marker (purple) lexer.setColor(QColor('#f92672'), 8) # syntax error marker (red) lexer.setColor(QColor('#f92672'), 9) # operator (red) # editor.setFont(font) # editor.setMarginsFont(font) editor.setCaretForegroundColor(QColor('#f8f8f0')) editor.setMarginWidth(0, getMarginWidth(font)) editor.setMarginWidth(1, 0) editor.setMarginLineNumbers(0, True) editor.setMarginsBackgroundColor(QColor('#252721')) editor.setMarginsForegroundColor(QColor('#f8f8f2')) editor.setExtraAscent(3) editor.setTabWidth(4) editor.setMinimumSize(600, 450) return editor