def _createStyleSheet(self): def suffix(fontName, defaultFont): if defaultFont in [f.strip() for f in fontName.split(';')]: return fontName elif fontName.strip() == '': return defaultFont else: return fontName + '; ' + defaultFont style = StyleSheet.style( Primitive.fontFace(suffix(self._generic.getValue(), 'SansSerif')), RichText.titleTextAttrs( RichText.titleTextAttrs.defaultValue.withValues( Primitive.fontFace(suffix(self._title.getValue(), 'Serif')))), RichText.headingTextAttrs( RichText.headingTextAttrs.defaultValue.withValues( Primitive.fontFace( suffix(self._heading.getValue(), 'Serif')))), RichText.normalTextAttrs( RichText.normalTextAttrs.defaultValue.withValues( Primitive.fontFace( suffix(self._normal.getValue(), 'SansSerif')))), UI.uiTextAttrs( UI.uiTextAttrs.defaultValue.withValues( Primitive.fontFace( suffix(self._uiHeading.getValue(), 'SansSerif'))))) return style
class XmlElemSpan(abstract_text.MRTAbstractText): contents_query = elem_query.children()\ .map(abstract_text.remove_whitespace, elem.identity)\ .project_to_objects(mappings.text_mapping) def __init__(self, projection_table, elem, contents=None): super(XmlElemSpan, self).__init__(projection_table, elem, contents) elem_tag_and_attrs = XmlElemTagAndAttrs.from_xml_elem(elem) self._elem_tag_and_attrs = elem_tag_and_attrs self._editorModel = controller.MallardRichTextController.instance.editorModelSpan( [], self._span_attrs(elem_tag_and_attrs)) def node_init(self): self._editorModel.setModelContents( controller.MallardRichTextController.instance, list(self.contents_query)) def setElementTagAndAttrs(self, elem_tag_and_attrs): self._elem_tag_and_attrs = elem_tag_and_attrs self._editorModel.setSpanAttrs(self._span_attrs(elem_tag_and_attrs)) self._incr.onChanged() def getElementTagAndAttrs(self): self._incr.onAccess() return self._elem_tag_and_attrs def __present__(self, fragment, inheritedState): self._incr.onAccess() open_tag = self._tag_border.surround( self._open_tag_style(Label(self._elem_tag_and_attrs.tag))) close_tag = self._tag_border.surround( self._close_tag_style(Label('/' + self._elem_tag_and_attrs.tag))) x = RichSpan([open_tag] + list(self.contents_query) + [close_tag]) x = controller.MallardRichTextController.instance.editableSpan(self, x) return x @staticmethod def _span_attrs(elem_tag_and_attrs): return RichTextAttributes.fromValues(None, {XML_ELEM: [elem_tag_and_attrs]}) @staticmethod def new_span(mapping, contents, elem_tag_and_attrs): return XmlElemSpan(mapping, elem_tag_and_attrs.create_xml_elem(), contents) _tag_border = SolidBorder(1.0, 1.0, 4.0, 4.0, Color(0.4, 0.42, 0.45), Color(0.95, 0.975, 1.0)) _open_tag_style = StyleSheet.style( Primitive.fontSize(10), Primitive.foreground(Color(0.0, 0.3, 0.8)), Primitive.fontFace('Monospaced')) _close_tag_style = StyleSheet.style( Primitive.fontSize(10), Primitive.foreground(Color(0.3, 0.35, 0.4)), Primitive.fontFace('Monospaced'))
def normalSample(fontName, text='The quick brown fox jumps over the lazy dog'): style = StyleSheet.style( RichText.normalTextAttrs( RichText.normalTextAttrs.defaultValue.withValues( Primitive.fontFace(fontName)))) return style(NormalText(text))
def headingSample(fontName, text='The quick brown fox jumps over the lazy dog'): style = StyleSheet.style( RichText.headingTextAttrs( RichText.headingTextAttrs.defaultValue.withValues( Primitive.fontFace(fontName)))) return style(Heading1(text))
def uiHeadingSample(fontName, text='The quick brown fox jumps over the lazy dog' ): style = StyleSheet.style( UI.uiTextAttrs( UI.uiTextAttrs.defaultValue.withValues( Primitive.fontFace(fontName)))) return style(SectionHeading1(text))
def genericSample(fontName, text='The quick brown fox jumps over the lazy dog'): style = StyleSheet.style(Primitive.fontFace(fontName)) return style(Label(text))
def titleSample(fontName, text='The quick brown fox'): style = StyleSheet.style( RichText.titleTextAttrs( RichText.titleTextAttrs.defaultValue.withValues( Primitive.fontFace(fontName)))) return style(TitleBar(text))
fragment = element.fragmentContext pageSubject = fragment.subject._pageSubject(model) return pageSubject def _dragSourceCreateLink(element, aspect): return LinkSubjectDrag(_getSubjectOfPageNameElement(element)) _linkDragSource = ObjectDndHandler.DragSource(LinkSubjectDrag, _dragSourceCreateLink) _controlsStyle = StyleSheet.style(Controls.bClosePopupOnActivate(True)) _projectIndexNameStyle = StyleSheet.style( Primitive.foreground(Color(0.25, 0.35, 0.5)), Primitive.fontSize(16), Primitive.fontFace(Primitive.lightFontName)) _packageNameStyle = StyleSheet.style( Primitive.foreground(Color(0.0, 0.0, 0.5)), Primitive.fontSize(14), Primitive.fontFace(Primitive.lightFontName)) _itemHoverHighlightStyle = StyleSheet.style( Primitive.hoverBackground( FilledOutlinePainter(Color(0.8, 0.825, 0.9), Color(0.125, 0.341, 0.574), BasicStroke(1.0)))) _pythonPackageNameStyle = StyleSheet.style( Primitive.foreground(Color(0.0, 0.0, 0.5))) _pythonPackageNameNotSetStyle = StyleSheet.style( Primitive.foreground(Color(0.5, 0.0, 0.0))) _pythonPackageNameNotSetCommentStyle = StyleSheet.style( Primitive.foreground(Color(0.2, 0.2, 0.2)), Primitive.fontItalic(True)) _frontPageNoteBorder = SolidBorder(1.0, 1.0, 3.0, 3.0, Color(0.0, 1.0, 0.0),
if value: e = xmlmodel.XmlElem(self.tag_name) if child is not None: e.append(child) return e else: return child def store_value_from_element(self, rich_text_attributes, element): rich_text_attributes.putOverride(self.tag_name, True) _italic_style = StyleSheet.instance.withValues(Primitive.fontItalic(True)) _bold_style = StyleSheet.instance.withValues(Primitive.fontBold(True)) _code_style = StyleSheet.instance.withValues( Primitive.fontFace(Primitive.monospacedFontName), Primitive.background( FilledOutlinePainter(Color(0.9, 0.9, 0.9), Color(0.75, 0.75, 0.75)))) _cmd_style = StyleSheet.instance.withValues( Primitive.fontFace(Primitive.monospacedFontName), Primitive.background( FilledOutlinePainter(Color(0.9, 0.9, 0.9), Color(0.75, 0.75, 0.75))), Primitive.foreground(Color(0.0, 0.5, 0.0))) _cmd_prompt_style = StyleSheet.instance.withValues( Primitive.foreground(Color(0.0, 0.6, 0.5))) _app_style = StyleSheet.instance.withValues( Primitive.fontItalic(True), Primitive.foreground(Color(0.5, 0.0, 0.0))) _sys_style = StyleSheet.instance.withValues( Primitive.fontFace(Primitive.monospacedFontName), Primitive.foreground(Color(0.25, 0.0, 0.5)))
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))
def style_button(text, on_click, *style_values): sty = StyleSheet.instance.withValues(Primitive.fontFace(Primitive.monospacedFontName), *style_values) return Button(sty.applyTo(Label(text)), on_click)
from BritefuryJ.Util import TypeUtils from LarchCore.Languages.Python2 import Python2 from LarchCore.Languages.Python2.Execution.ExecutionPresCombinators import execStdout, execStderr, execException, execResult from LarchCore.Languages.Python2.Execution import Execution _executeShortcut = Shortcut( KeyEvent.VK_ENTER, Modifier.CTRL ) _executeNoEvalShortcut = Shortcut( KeyEvent.VK_ENTER, Modifier.CTRL | Modifier.SHIFT ) _historyPreviousShortcut = Shortcut( KeyEvent.VK_UP, Modifier.ALT ) _historyNextShortcut = Shortcut( KeyEvent.VK_DOWN, Modifier.ALT ) _bannerTextStyle = StyleSheet.style( Primitive.fontFace( 'Serif' ), Primitive.fontSmallCaps( True ), Primitive.editable( False ) ) _bannerHelpKeyTextStyle = StyleSheet.style( Primitive.fontFace( 'Serif' ), Primitive.fontSmallCaps( True ), Primitive.fontItalic( True ), Primitive.foreground( Color( 0.25, 0.25, 0.25 ) ) ) _bannerHelpTextStyle = StyleSheet.style( Primitive.fontFace( 'Serif' ), Primitive.fontItalic( True ), Primitive.foreground( Color( 0.25, 0.25, 0.25 ) ) ) _bannerBorder = SolidBorder( 2.0, 5.0, 8.0, 8.0, Color( 0.3, 0.5, 0.3 ), Color( 0.875, 0.9, 0.875 ) ) _labelStyle = StyleSheet.style( Primitive.fontSize( 10 ) ) #_blockStyle = StyleSheet.style( Primitive.columnSpacing( 2.0 ), Primitive.border( SolidBorder( 1.0, 5.0, 15.0, 15.0, Color( 0.25, 0.25, 0.25 ), Color( 0.8, 0.8, 0.8 ) ) ) ) _blockStyle = StyleSheet.style( Primitive.columnSpacing( 3.0 ), Primitive.border( SolidBorder( 1.0, 3.0, 13.0, 13.0, Color( 0.6, 0.6, 0.6 ), Color( 0.9, 0.9, 0.9 ) ) ) ) _blockOutputStyle = StyleSheet.style( Primitive.columnSpacing( 2.0 ) ) _pythonModuleBorderStyle = StyleSheet.style( Primitive.border( SolidBorder( 1.5, 5.0, 10.0, 10.0, Color( 0.65, 0.65, 0.65 ), Color.WHITE ) ) ) _dropPromptStyle = StyleSheet.style( Primitive.border( SolidBorder( 1.0, 3.0, 10.0, 10.0, Color( 0.0, 0.8, 0.0 ), None ) ) ) _varAssignVarNameStyle = StyleSheet.style( Primitive.fontItalic( True ), Primitive.foreground( Color( 0.0, 0.0, 0.5 ) ) )