Пример #1
0
from BritefuryJ.Editor.SyntaxRecognizing import SREInnerFragment
from BritefuryJ.Editor.SyntaxRecognizing.SyntaxRecognizingController import EditMode



from LarchTools.PythonTools.VisualRegex import Schema
from LarchTools.PythonTools.VisualRegex.Parser import VisualRegexGrammar
from LarchTools.PythonTools.VisualRegex.SRController import VisualRegexSyntaxRecognizingController


PRECEDENCE_NONE = -1




_unparsedTextStyle = StyleSheet.style( Primitive.textSquiggleUnderlinePaint( Color.RED ) )
_controlCharStyle = StyleSheet.style( Primitive.foreground( Color( 0.0, 0.0, 0.0, 0.5 ) ) )
_invertControlCharStyle = StyleSheet.style( Primitive.foreground( Color( 1.0, 0.0, 0.0, 0.5 ) ) )

_specialCharStyle = StyleSheet.style( Primitive.foreground( Color( 0.25, 0.25, 0.35 ) ), Primitive.fontSize( 10 ) )
_specialBorder = SolidBorder( 1.0, 1.0, 4.0, 4.0, Color( 0.6, 0.6, 0.7 ), Color( 0.75, 0.75, 0.85 ) )

_charClassStyle = StyleSheet.style( Primitive.foreground( Color( 0.2, 0.3, 0.4 ) ), Primitive.fontSize( 10 ) )
_charClassBorder = SolidBorder( 1.0, 1.0, 4.0, 4.0, Color( 0.6, 0.65, 0.7 ), Color( 0.8, 0.85, 0.9 ) )


#_charClassStyle = StyleSheet.style( Primitive.foreground( Color( 0.0, 0.25, 0.5 ) ) )
#_charClassEscapeStyle = StyleSheet.style( Primitive.foreground( Color( 0.0, 0.25, 0.5, 0.5 ) ) )
#_charClassBorder = SolidBorder( 1.0, 2.0, 4.0, 4.0, Color( 0.0, 0.25, 0.5 ), Color( 0.8, 0.9, 1.0 ) )

_groupNameStyle = StyleSheet.style( Primitive.foreground( Color( 0.0, 0.65, 0.0 ) ) )
Пример #2
0
class PythonEditorStyle(object):
    pythonEditor = AttributeNamespace('pythonEditor')

    _pythonCodeFont = 'Noto Sans; SansSerif'

    #keywordStyle = InheritedAttributeNonNull( pythonEditor, 'keywordStyle', StyleSheet,
    #StyleSheet.style( Primitive.fontFace( _pythonCodeFont ), Primitive.fontSize( 14 ), Primitive.fontBold( True ),
    #Primitive.foreground( Color( 0.25, 0.0, 0.5 ) ), Primitive.fontSmallCaps( True ) )

    keywordStyle = InheritedAttributeNonNull(
        pythonEditor, 'keywordStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14), Primitive.fontBold(True),
                         Primitive.foreground(Color(0.25, 0.0, 0.5))))
    literalFormatStyle = InheritedAttributeNonNull(
        pythonEditor, 'literalFormatStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color(0.0, 0.25, 0.25))))
    quotationStyle = InheritedAttributeNonNull(
        pythonEditor, 'quotationStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color(0.0, 0.0, 0.5))))
    stringLiteralStyle = InheritedAttributeNonNull(
        pythonEditor, 'stringLiteralStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color(0.25, 0.0, 0.5))))
    stringLiteralEscapeStyle = InheritedAttributeNonNull(
        pythonEditor, 'stringLiteralEscapeStyle', StyleSheet,
        StyleSheet.style(
            Primitive.fontFace(_pythonCodeFont), Primitive.fontSize(14),
            Primitive.foreground(Color(0.25, 0.2, 0.15)),
            Primitive.border(
                SolidBorder(1.0, 1.0, 4.0, 4.0, Color(0.75, 0.6, 0.5),
                            Color(1.0, 0.85, 0.75)))))
    numLiteralStyle = InheritedAttributeNonNull(
        pythonEditor, 'numLiteralStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color(0.0, 0.5, 0.5))))
    punctuationStyle = InheritedAttributeNonNull(
        pythonEditor, 'punctuationStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color(0.0, 0.0, 1.0))))
    delimStyle = InheritedAttributeNonNull(
        pythonEditor, 'delimStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color(0.0, 0.0, 1.0))))
    targetStyle = InheritedAttributeNonNull(
        pythonEditor, 'targetStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color.black)))
    varStyle = InheritedAttributeNonNull(
        pythonEditor, 'varStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color.black)))
    attributeStyle = InheritedAttributeNonNull(
        pythonEditor, 'attributeStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color.black)))
    kwNameStyle = InheritedAttributeNonNull(
        pythonEditor, 'kwNameStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color.black)))
    operatorStyle = InheritedAttributeNonNull(
        pythonEditor, 'operatorStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontBold(True), Primitive.fontSize(14),
                         Primitive.foreground(Color(0.0, 0.5, 0.0))))
    paramStyle = InheritedAttributeNonNull(
        pythonEditor, 'paramStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color.black)))
    importStyle = InheritedAttributeNonNull(
        pythonEditor, 'importStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color.black)))
    commentStyle = InheritedAttributeNonNull(
        pythonEditor, 'commentStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color(0.4, 0.4, 0.4))))
    unparseableStyle = InheritedAttributeNonNull(
        pythonEditor, 'unparseableStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color.black),
                         Primitive.textSquiggleUnderlinePaint(Color.red)))

    sequenceStyle = InheritedAttributeNonNull(
        pythonEditor, 'sequenceStyle', StyleSheet,
        StyleSheet.style(Sequence.addLineBreaks(True),
                         Sequence.matchOuterIndentation(True),
                         Sequence.addLineBreakCost(True)))

    quoteBorderStyle = InheritedAttributeNonNull(
        pythonEditor, 'quoteBorderStyle', StyleSheet,
        StyleSheet.style(
            Primitive.border(
                SolidBorder(1.0, 3.0, 5.0, 5.0, Color(0.5, 0.3, 0.7), None))))
    quoteTitleStyle = InheritedAttributeNonNull(
        pythonEditor, 'quoteTitleStyle', StyleSheet,
        StyleSheet.style(Primitive.foreground(Color(0.3, 0.1, 0.5)),
                         Primitive.fontSize(10)))

    unquoteBorderStyle = InheritedAttributeNonNull(
        pythonEditor, 'unquoteBorderStyle', StyleSheet,
        StyleSheet.style(
            Primitive.border(
                SolidBorder(1.0, 3.0, 5.0, 5.0, Color(1.0, 0.5, 0.3), None))))
    unquoteTitleStyle = InheritedAttributeNonNull(
        pythonEditor, 'unquoteTitleStyle', StyleSheet,
        StyleSheet.style(Primitive.foreground(Color(0.7, 0.35, 0.0)),
                         Primitive.fontSize(10)))

    externalExprBorderStyle = InheritedAttributeNonNull(
        pythonEditor, 'externalExprBorderStyle', StyleSheet,
        StyleSheet.style(
            Primitive.border(
                SolidBorder(1.0, 3.0, 5.0, 5.0, Color(0.3, 0.7, 1.0), None))))
    externalExprTitleStyle = InheritedAttributeNonNull(
        pythonEditor, 'externalExprTitleStyle', StyleSheet,
        StyleSheet.style(Primitive.foreground(Color(0.0, 0.5, 1.0)),
                         Primitive.fontSize(10)))

    embeddedObjectBorder = InheritedAttributeNonNull(
        pythonEditor, 'embeddedObjectBorder', AbstractBorder,
        SolidBorder(1.5, 1.5, 4.0, 4.0, Color(0.6, 0.65, 0.8), None))
    embeddedObjectLiteralBorder = InheritedAttributeNonNull(
        pythonEditor, 'embeddedObjectLiteralBorder', AbstractBorder,
        SolidBorder(1.5, 1.5, 4.0, 4.0, Color(0.4, 0.433, 0.533), None))
    embeddedObjectTagLabelStyle = InheritedAttributeNonNull(
        pythonEditor, 'embeddedObjectTagLabelStyle', StyleSheet,
        StyleSheet.style(Primitive.foreground(Color(0.0, 0.0, 0.0, 0.6)),
                         Primitive.fontSize(9)))
    embeddedObjectTagBorder = InheritedAttributeNonNull(
        pythonEditor, 'embeddedObjectTagBorder', AbstractBorder,
        SolidBorder(1.0, 1.0, 3.0, 3.0, Color(0.45, 0.4, 0.533),
                    Color(0.925, 0.9, 0.95)))
    embeddedObjectLineStyle = InheritedAttributeNonNull(
        pythonEditor, 'embeddedObjectLineStyle', StyleSheet,
        StyleSheet.style(
            Primitive.shapePainter(FillPainter(Color(0.1, 0.2, 0.3)))))
    embeddedObjectExpansionLabelStyle = InheritedAttributeNonNull(
        pythonEditor, 'embeddedObjectExpansionLabelStyle', StyleSheet,
        StyleSheet.style(Primitive.fontSize(10)))

    paragraphIndentationStyle = InheritedAttributeNonNull(
        pythonEditor, 'paragraphIndentationStyle', StyleSheet,
        StyleSheet.style(Primitive.paragraphIndentation(40.0)))

    solidHighlightRounding = InheritedAttributeNonNull(
        pythonEditor, 'solidHighlightRounding', float, 3.0)
    outlineHighlightThickness = InheritedAttributeNonNull(
        pythonEditor, 'outlineHighlightThickness', float, 1.5)
    outlineHighlightInset = InheritedAttributeNonNull(pythonEditor,
                                                      'outlineHighlightInset',
                                                      float, 2.0)
    outlineHighlightRounding = InheritedAttributeNonNull(
        pythonEditor, 'outlineHighlightRounding', float, 5.0)

    defStmtHighlightColour = InheritedAttributeNonNull(
        pythonEditor, 'defStmtHighlightColour', Color,
        Color(0.420, 0.620, 0.522))
    classStmtHighlightColour = InheritedAttributeNonNull(
        pythonEditor, 'classStmtHighlightColour', Color,
        Color(0.522, 0.420, 0.620))
    badIndentationRectanglePainter = InheritedAttributeNonNull(
        pythonEditor, 'badIndentationRectanglePainter', Painter,
        FilledOutlinePainter(lerpColour(Color.RED, Color.WHITE, 0.75),
                             lerpColour(Color.RED, Color.WHITE, 0.5)))

    comprehensionSpacing = InheritedAttributeNonNull(pythonEditor,
                                                     'comprehensionSpacing',
                                                     float, 15.0)
    conditionalSpacing = InheritedAttributeNonNull(pythonEditor,
                                                   'conditionalSpacing', float,
                                                   15.0)
    blockIndentation = InheritedAttributeNonNull(pythonEditor,
                                                 'blockIndentation', float,
                                                 30.0)

    @PyDerivedValueTable(pythonEditor)
    def _defStmtHeaderHighlightStyle(style):
        border = _solidHighlightBorder(
            style, style.get(PythonEditorStyle.defStmtHighlightColour))
        return style.withValues(Primitive.border(border))

    @PyDerivedValueTable(pythonEditor)
    def _defStmtHighlightStyle(style):
        border = _outlineHighlightBorder(
            style, style.get(PythonEditorStyle.defStmtHighlightColour))
        return style.withValues(Primitive.border(border))

    @PyDerivedValueTable(pythonEditor)
    def _classStmtHeaderHighlightStyle(style):
        border = _solidHighlightBorder(
            style, style.get(PythonEditorStyle.classStmtHighlightColour))
        return style.withValues(Primitive.border(border))

    @PyDerivedValueTable(pythonEditor)
    def _classStmtHighlightStyle(style):
        border = _outlineHighlightBorder(
            style, style.get(PythonEditorStyle.classStmtHighlightColour))
        return style.withValues(Primitive.border(border))

    @PyDerivedValueTable(pythonEditor)
    def _badIndentationRectangleStyle(style):
        painter = style.get(PythonEditorStyle.badIndentationRectanglePainter)
        return style.withValues(Primitive.shapePainter(painter))