class _FrameBox (object): def __init__(self, frame, valuesLive): self._frame = frame self._valuesLive = valuesLive def __present__(self, fragment, inheritedState): interactor = _FrameInteractor( self._frame, self._valuesLive ) box = Box( 15.0, 5.0 ).withElementInteractor( interactor ) if self._valuesLive.getValue() is self._frame.values: return self._selectedTabFrameStyle.applyTo( box ) else: return self._tabFrameStyle.applyTo( box ) _tabFrameStyle = StyleSheet.style( Primitive.shapePainter( FilledOutlinePainter( Color( 0.85, 0.9, 0.85 ), Color( 0.6, 0.8, 0.6 ) ) ), Primitive.hoverShapePainter( FilledOutlinePainter( Color( 0.6, 0.8, 0.6 ), Color( 0.0, 0.5, 0.0 ) ) ) ) _selectedTabFrameStyle = StyleSheet.style( Primitive.shapePainter( FilledOutlinePainter( Color( 1.0, 1.0, 0.85 ), Color( 1.0, 0.8, 0.0 ) ) ), Primitive.hoverShapePainter( FilledOutlinePainter( Color( 1.0, 1.0, 0.6 ), Color( 1.0, 0.5, 0.0 ) ) ) )
class GUIArrow(GUILeafComponent): componentName = 'Arrow' size = TypedEvalField(float, 12.0) direction = TypedEvalField(Arrow.Direction, Arrow.Direction.RIGHT) def _presentLeafContents(self, fragment, inheritedState): return Arrow(self.direction.getValueForEditor(), self.size.getValueForEditor()) _offStyle = StyleSheet.style( Primitive.shapePainter(FillPainter(Color(0.4, 0.4, 0.4)))) _onStyle = StyleSheet.style( Primitive.shapePainter(FillPainter(Color(0.2, 0.2, 0.2)))) @staticmethod def _arrowDirectionEditor(live): offOptions = [ GUIArrow._offStyle(Arrow(dir, 14.0).alignVCentre()) for dir in Arrow.Direction.values() ] onOptions = [ GUIArrow._onStyle(Arrow(dir, 14.0).alignVCentre()) for dir in Arrow.Direction.values() ] return enumSwitchButtonEditor(live, Arrow.Direction, offOptions, onOptions) def _editUIFormSections(self): direction = Form.SmallSection( 'Direction', None, self.direction.editUI(self._arrowDirectionEditor)) size = Form.SmallSection( 'Size', None, self.size.editUI( lambda live: RealSpinEntry(live, 0.0, 1048576.0, 1.0, 10.0))) superSections = super(GUIArrow, self)._editUIFormSections() return [direction, size] + superSections def __component_py_evalmodel__(self, codeGen): arrow = codeGen.embeddedValue(Arrow) direction = self.direction.__py_evalmodel__(codeGen) size = self.size.__py_evalmodel__(codeGen) return Py.Call(target=arrow, args=[direction, size])
_commentStyle = StyleSheet.style( Primitive.foreground( Color( 0.3, 0.3, 0.3 ) ) ) _flagsStyle = StyleSheet.style( Primitive.foreground( Color( 1.0, 0.5, 0.0 ) ) ) _escapeBorder = SolidBorder( 1.0, 2.0, 4.0, 4.0, Color( 0.5, 0.6, 0.75 ), Color( 0.75, 0.85, 1.0 ) ) _pythonEscapeBorder = SolidBorder( 1.0, 2.0, 4.0, 4.0, Color( 0.75, 0.6, 0.5 ), Color( 1.0, 0.85, 0.75 ) ) _charSetBorder = SolidBorder( 1.0, 4.0, 3.0, 3.0,Color( 0.5, 0.5, 0.6 ), Color( 0.7, 0.7, 0.8 ) ) _charSetItemBorder = FilledBorder( 1.0, 1.0, 1.0, 1.0, Color( 0.9, 0.9, 0.9 ) ) _groupBorder = SolidBorder( 1.0, 4.0, 3.0, 3.0, Color( 0.0, 0.7, 0.0 ), Color( 0.85, 1.0, 0.85 ) ) _nonCapturingGroupBorder = SolidBorder( 1.0, 4.0, 3.0, 3.0, Color( 0.55, 0.6, 0.55 ), Color( 0.8, 0.85, 0.8 ) ) _lookaheadBorder = SolidBorder( 1.0, 4.0, 3.0, 3.0, Color( 0.5, 1.0, 0.75 ), Color( 0.9, 1.0, 0.95 ) ) _lookbehindBorder = SolidBorder( 1.0, 4.0, 3.0, 3.0, Color( 0.6, 0.9, 0.75 ), Color( 0.875, 0.925, 0.9 ) ) _repeatBorder = SolidBorder( 1.0, 1.0, 3.0, 3.0, Color( 0.7, 0.4, 1.0 ), Color( 0.9, 0.8, 1.0 ) ) _choiceBorder = SolidBorder( 1.0, 4.0, 3.0, 3.0, Color( 1.0, 0.7, 0.4 ), Color( 1.0, 1.0, 0.8 ) ) _choiceRuleStyle = StyleSheet.style( Primitive.shapePainter( FillPainter( Color( 0.0, 0.0, 0.0, 0.35 ) ) ) ) _commentBorder = SolidBorder( 1.0, 2.0, 4.0, 4.0, Color( 0.4, 0.4, 0.4 ), Color( 0.8, 0.8, 0.8 ) ) _flagsBorder = SolidBorder( 1.0, 2.0, 4.0, 4.0, Color( 1.0, 0.6, 0.2 ), Color( 1.0, 1.0, 0.8 ) ) _charClasses = { 'A' : 'START', 'b' : 'WORD-START', 'B' : '!WORD-START', 'd' : 'DEC', 'D' : '!DEC', 's' : 'WS', 'S' : '!WS', 'w' : 'WORD', 'W' : '!WORD',
def _badIndentationRectangleStyle(style): painter = style.get(PythonEditorStyle.badIndentationRectanglePainter) return style.withValues(Primitive.shapePainter(painter))
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))