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'))
class LiterateExpression(object): def __init__(self, expr=None): if expr is None: expr = EmbeddedPython2Expr() self._expr = expr self._incr = IncrementalValueMonitor() self.__change_history__ = None def __getstate__(self): return {'expr': self._expr} def __setstate__(self, state): self._expr = state['expr'] self._incr = IncrementalValueMonitor() self.__change_history__ = None def __get_trackable_contents__(self): return [self._expr] def __py_evalmodel__(self, codeGen): return self._expr.model def __py_replacement__(self): return deepcopy(self._expr.model['expr']) def _new_reference(self): return LiterateExpression(self._expr) def __present__(self, fragment, inheritedState): self._incr.onAccess() exprPres = self._expr header = Row([ self._angleQuoteStyle(Label(u'\u00ab')), self._angleQuoteStyle(Label(u'\u00bb')), Spacer(9.0, 0.0) ]).withDragSource(_dragSource) return ObjectBorder(Row([header.alignVCentre(), exprPres])) _angleQuoteStyle = StyleSheet.style( Primitive.foreground(Color(0.15, 0.15, 0.45)), Primitive.fontBold(True), Primitive.fontSize(12))
class ExecutionStyle(object): pythonExecution = AttributeNamespace('pythonExecution') labelStyle = InheritedAttributeNonNull( pythonExecution, 'labelStyle', StyleSheet, StyleSheet.style(Primitive.fontSize(10))) stdOutStyle = InheritedAttributeNonNull( pythonExecution, 'stdOutStyle', StyleSheet, StyleSheet.style( Primitive.border( SolidBorder(1.0, 3.0, 7.0, 7.0, Color(0.5, 1.0, 0.5), Color(0.9, 1.0, 0.9))), Primitive.foreground(Color(0.0, 0.5, 0.0)))) stdErrStyle = InheritedAttributeNonNull( pythonExecution, 'stdErrStyle', StyleSheet, StyleSheet.style( Primitive.border( SolidBorder(1.0, 3.0, 7.0, 7.0, Color(1.0, 0.75, 0.5), Color(1.0, 0.95, 0.9))), Primitive.foreground(Color(0.75, 0.375, 0.0)))) exceptionBorderStyle = InheritedAttributeNonNull( pythonExecution, 'exceptionBorderStyle', StyleSheet, StyleSheet.style( Primitive.border( SolidBorder(1.0, 3.0, 7.0, 7.0, Color(0.8, 0.0, 0.0), Color(1.0, 0.9, 0.9))))) resultBorderStyle = InheritedAttributeNonNull( pythonExecution, 'resultBorderStyle', StyleSheet, StyleSheet.style( Primitive.border( SolidBorder(1.0, 3.0, 10.0, 10.0, Color(0.0, 0.0, 0.8), Color.WHITE)))) resultBoxStyle = InheritedAttributeNonNull( pythonExecution, 'resultSpacing', StyleSheet, StyleSheet.style(Primitive.columnSpacing(5.0))) @PyDerivedValueTable(pythonExecution) def _resultBoxStyle(style): resultSpacing = style.get(ExecutionStyle.resultSpacing) return style.withValues(Primitive.columnSpacing(resultSpacing))
model) 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))
from BritefuryJ.Live import LiveFunction, LiveValue from BritefuryJ.Controls import Button, RealSpinEntry from BritefuryJ.Pres import Pres from BritefuryJ.Pres.Primitive import Primitive, Label, Bin, Row, Column, Table from BritefuryJ.StyleSheet import StyleSheet from LarchCore.Languages.Python2 import Schema as Py from LarchTools.PythonTools.GUIEditor.DataModel import GUIObject, TypedEvalField _uniformStyle = StyleSheet.style(Primitive.foreground(Color(0.2, 0.25, 0.3)), Primitive.fontSize(11)) _boxStyle = StyleSheet.style(Primitive.background(FilledOutlinePainter(Color(0.7, 0.75, 0.8), Color(0.6, 0.65, 0.7))), Primitive.fontSize(11), Primitive.foreground(Color(0.0, 0.0, 0.0, 0.5)), Primitive.fontItalic(True)) _tableStyle = StyleSheet.style(Primitive.tableColumnSpacing(2.0), Primitive.tableRowSpacing(2.0)) _liveLabelStyle = StyleSheet.style(Primitive.foreground(Color(0.4, 0.45, 0.5))) class AbstractPadding (GUIObject): def apply(self, p): raise NotImplementedError, 'abstract' def __apply_py_evalmodel__(self, codeGen, py_p): raise NotImplementedError, 'abstract'
def enumSwitchButtonEditorWithLabels(live, enumType, labelTexts): return enumSwitchButtonEditor(live, enumType, [Label(t) for t in labelTexts]) @LiveFunction def displayLive(): return live.getValue().ordinal() def _onChoice(control, prevChoice, choice): live.setLiteralValue(enumType.values()[choice]) options = [Label(t) for t in ['Larger', 'Smaller', 'Fixed', 'None']] return SwitchButton(options, options, SwitchButton.Orientation.HORIZONTAL, displayLive, _onChoice) _plusStyle = StyleSheet.style(Primitive.fontBold(True), Primitive.foreground(Color(0.0, 0.6, 0.0)), Primitive.fontSize(12)) def optionalTypedEditor(live, initialValue, editorFn): valueEditor = LiveValue(editorFn(live)) @LiveFunction def editor(): x = live.getValue() if x is None: def on_add(button, event): live.setLiteralValue(initialValue) return Button(_plusStyle(Label('+')), on_add).alignHPack() else: def on_delete(button, event): live.setLiteralValue(None)
from LarchCore.Languages.Python2.PythonCommands import pythonCommandSet, WrapSelectedStatementRangeInEmbeddedObjectAction, EmbeddedStatementAtCaretAction, chainActions from LarchCore.Languages.Python2.Embedded import EmbeddedPython2Suite _headerStyle = StyleSheet.style( Primitive.fontBold(True), Primitive.background(FillPainter(Color(1.0, 0.95, 0.8))), Primitive.rowSpacing(5.0)) _forwardArrow = Arrow(Arrow.Direction.RIGHT, 12.0) _codeBorder = SolidBorder(1.0, 2.0, 8.0, 8.0, Color(0.75, 0.737, 0.675), None) _stepperBorder = SolidBorder(2.0, 2.0, 8.0, 8.0, Color(0.55, 0.52, 0.4), None) _breakPointBorder = SolidBorder(1.0, 1.0, 5.0, 5.0, Color(0.3, 0.3, 0.3), Color(0.85, 0.85, 0.85)) _breakPointCurrentBorder = SolidBorder(1.0, 1.0, 5.0, 5.0, Color(0.0, 0.4, 0.0), Color(0.85, 1.0, 0.85)) _breakPointStyle = StyleSheet.style(Primitive.fontSize(10)) _breakPointArrow = Arrow(Arrow.Direction.RIGHT, 8.0) class StepperCode(object): def __init__(self, stepper, suite): self._stepper = stepper self._suite = EmbeddedPython2Suite(suite) self.__change_history__ = None def __getstate__(self): return {'stepper': self._stepper, 'suite': self._suite} def __setstate__(self, state): self._stepper = state['stepper'] self._suite = state['suite']
from BritefuryJ.StyleSheet import StyleSheet, StyleValues from BritefuryJ.LSpace.Interactor import PushElementInteractor from BritefuryJ.LSpace.Input import Modifier from BritefuryJ.Live import LiveValue, LiveFunction from Britefury.Config.UserConfig import loadUserConfig, saveUserConfig from Britefury.Config import Configuration from Britefury.Config.ConfigurationPage import ConfigurationPage # Font chooser _ge = GraphicsEnvironment.getLocalGraphicsEnvironment() _fontNames = sorted([font.name for font in _ge.allFonts]) _nameStyle = StyleSheet.style(Primitive.fontSize(10), Primitive.foreground(Color(0.45, 0.45, 0.45))) _hoverStyle = StyleSheet.style( Primitive.hoverBackground( FilledOutlinePainter(Color(0.95, 0.95, 0.95), Color(0.65, 0.65, 0.65)))) _headerNameStyle = StyleSheet.style(Primitive.fontItalic(True)) def _fontSample(fontName, sampleFn): sample = sampleFn(fontName) name = Label(fontName) return _hoverStyle( Bin( Column([ sample,
class EvalFieldInstance(FieldInstance): """ A field that contains a value, which can alternatively have an expression that generates the required value """ def __init__(self, field, object_instance, wrapped_source_value): super(EvalFieldInstance, self).__init__(field, object_instance, wrapped_source_value) self.__change_history__ = None if wrapped_source_value is not None: source_value = wrapped_source_value[0] if isinstance(source_value, _EvalFieldState): constantValue = source_value.constantValue expr = source_value.expr else: constantValue = source_value expr = None else: constantValue = field._getDefaultValue() expr = None self._live = TrackedLiveValue(constantValue) self._expr = expr self.__incr = IncrementalValueMonitor() def isConstant(self): return self._expr is None @property def constantValue(self): return self._live.getValue() @constantValue.setter def constantValue(self, x): self._live.setLiteralValue(x) @property def constantValueLive(self): return self._live @property def expr(self): return self._expr @expr.setter def expr(self, exp): oldExpr = self._expr self._expr = exp if self.__change_history__ is not None: if oldExpr is not None: self.__change_history__.stopTracking(oldExpr) def setExpression(): self.expr = exp def revertExpression(): self.expr = oldExpr self.__change_history__.addChange(setExpression, revertExpression, 'Set expression') if exp is not None: self.__change_history__.track(exp) self.__incr.onChanged() def _addTrackableContentsTo(self, contents): contents.append(self) def __field_getstate__(self): return _EvalFieldState(self._live.getValue(), self._expr) def __field_getstate_for_clipboard_copy__(self, memo): return _EvalFieldState(memo.copy(self._live.getValue()), memo.copy(self._expr)) def getValueForEditor(self): return self._live.getValue() def __py_evalmodel__(self, codeGen): self.__incr.onAccess() if self._expr is None: return self.__fixedvalue_py_evalmodel__(self._live.getValue(), codeGen) else: return self._expr.model def __fixedvalue_py_evalmodel__(self, value, codeGen): return Py.coerceToModel(value) def __get_trackable_contents__(self): if self._expr is not None: return [self._live, self._expr] else: return [self._live] def editUI(self, controlFactoryFn): self.__incr.onAccess() valueControl = controlFactoryFn(self._live) if self._expr is None: def _onAdd(button, event): self.expr = EmbeddedPython2Expr() addButton = Button(self._addButtonContents, _onAdd).alignHPack() return Row([valueControl, Spacer(10.0, 0.0), addButton]) else: def _onRemove(button, event): self.expr = None removeButton = Button(self._removeButtonContents, _onRemove).alignHPack() return Column([ valueControl, Row([ removeButton, Spacer(10.0, 0.0), exprBorder.surround(self._expr) ]) ]) _addStyle = StyleSheet.style(Primitive.foreground(Color(0.0, 0.5, 0.0)), Primitive.fontBold(True), Primitive.fontSize(11)) _removeStyle = StyleSheet.style(Primitive.foreground(Color(0.5, 0.0, 0.0)), Primitive.fontBold(True), Primitive.fontSize(11)) _fStyle = StyleSheet.style(Primitive.foreground(Color(0.0, 0.25, 0.5)), Primitive.fontItalic(True), Primitive.fontSize(11)) _parenStyle = StyleSheet.style(Primitive.foreground(Color(0.3, 0.3, 0.3)), Primitive.fontSize(11)) _addButtonContents = Row([ _addStyle(Label('+ ')), _fStyle(Label('f')), _parenStyle(Label('()')) ]) _removeButtonContents = Row([ _removeStyle(Label('- ')), _fStyle(Label('f')), _parenStyle(Label('()')) ])
_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 ) ) ) _varAssignTypeNameStyle = StyleSheet.style( Primitive.foreground( Color( 0.3, 0.0, 0.3 ) ) ) _varAssignJavaKindStyle = StyleSheet.style( Primitive.foreground( Color( 0.0, 0.0, 0.4 ) ), Primitive.fontItalic( True ) ) _varAssignPythonKindStyle = StyleSheet.style( Primitive.foreground( Color( 0.0, 0.4, 0.0 ) ), Primitive.fontItalic( True ) ) _varAssignDocModelKindStyle = StyleSheet.style( Primitive.foreground( Color( 0.4, 0.4, 0.4 ) ), Primitive.fontItalic( True ) ) _varAssignMsgStyle = StyleSheet.style( Primitive.foreground( Color( 0.0, 0.125, 0.0 ) ) )
from BritefuryJ.Controls import Button, RealSpinEntry, ColourPicker from BritefuryJ.Pres import Pres from BritefuryJ.Pres.Primitive import Primitive, Label, Bin, Row, Column, Table from BritefuryJ.Pres.UI import Form from BritefuryJ.StyleSheet import StyleSheet from LarchCore.Languages.Python2 import Schema as Py from LarchTools.PythonTools.GUIEditor.DataModel import GUIObject, TypedEvalField from LarchTools.PythonTools.GUIEditor.FieldEditor import optionalTypedEditor _uniformStyle = StyleSheet.style(Primitive.foreground(Color(0.2, 0.25, 0.3)), Primitive.fontSize(11)) _boxStyle = StyleSheet.style( Primitive.background( FilledOutlinePainter(Color(0.7, 0.75, 0.8), Color(0.6, 0.65, 0.7))), Primitive.fontSize(11), Primitive.foreground(Color(0.0, 0.0, 0.0, 0.5)), Primitive.fontItalic(True)) _tableStyle = StyleSheet.style(Primitive.tableColumnSpacing(2.0), Primitive.tableRowSpacing(2.0)) _liveLabelStyle = StyleSheet.style(Primitive.foreground(Color(0.4, 0.45, 0.5))) class AbstractGUIBorder(GUIObject): def formSections(self): raise NotImplementedError, 'abstract' def makeBorder(self):
from BritefuryJ.ObjectPresentation import PresentationStateListenerList from BritefuryJ.DefaultPerspective import DefaultPerspective from LarchCore.PythonConsole import Console _fragSelectorEntryBorder = SolidBorder(1.0, 3.0, 6.0, 6.0, Color(0.8, 0.8, 0.8), None, Color(0.5, 0.5, 0.5), Color(0.9, 0.9, 0.9)) _fragContentHighlighter = ElementHighlighter( FilledOutlinePainter(Color(0.0, 1.0, 0.0, 0.1), Color(0.0, 0.5, 0.0, 0.5))) _objectKindStyleJava = StyleSheet.style( Primitive.fontSize(10), Primitive.foreground(Color(0.0, 0.0, 0.5))) _objectKindStylePython = StyleSheet.style( Primitive.fontSize(10), Primitive.foreground(Color(0.0, 0.5, 0.0))) _objectKindStyleDocModel = StyleSheet.style( Primitive.fontSize(10), Primitive.foreground(Color(0.5, 0.5, 0.5))) _consoleStyle = StyleSheet.style(Primitive.editable(True), Primitive.selectable(True)) _inspectorStyle = StyleSheet.style(Primitive.editable(False), Primitive.selectable(False)) _objectKindJava = _objectKindStyleJava(Label('Java')) _objectKindPython = _objectKindStylePython(Label('Python')) _objectKindDocModel = _objectKindStyleDocModel(Label('DocModel')) _objectKindMap = { TypeUtils.ObjectKind.JAVA: _objectKindJava,
return self.factory() class PaletteComponentDrag(Object): def __init__(self, factory): self.factory = factory def getItem(self): return self.factory() # # #Control palette: _paletteItemStyle = StyleSheet.style( Primitive.fontSize(11), Primitive.foreground(Color(0.3, 0.3, 0.3)), Primitive.background( FilledOutlinePainter(Color.white, Color(0.8, 0.8, 0.8)))) _paletteItemBorder = SolidBorder(1.0, 2.0, Color(0.7, 0.7, 0.7), None).highlight(Color(0.6, 0.6, 0.6), Color(0.9, 0.9, 0.9)) _paletteSections = [] def paletteItem(contents, factoryCallable): p = _paletteItemStyle(_paletteItemBorder.surround( contents)).alignHExpand().alignVRefYExpand() p = p.withDragSource( PaletteComponentDrag, lambda element, aspect: PaletteComponentDrag(factoryCallable))
from BritefuryJ.Live import TrackedLiveValue from BritefuryJ.Editor.List import EditableListController from Britefury.Util.LiveList import LiveList from LarchCore.Languages.Python2 import Schema as Py from LarchTools.PythonTools.GUIEditor.DataModel import ChildField, ChildListField from LarchTools.PythonTools.GUIEditor.Component import GUIComponent from LarchTools.PythonTools.GUIEditor.ComponentPalette import PaletteComponentDrag # #Sequential components: _emptyStyle = StyleSheet.style(Primitive.fontItalic(True), Primitive.fontSize(10), Primitive.foreground(Color(0.4, 0.4, 0.4))) emptyLabel = _emptyStyle(Label('<empty>')) class GUIBranchComponent(GUIComponent): def removeChild(self, child): raise NotImplementedError, 'abstract' def getNextSiblingOf(self, child): raise NotImplementedError, 'abstract' class GUIUnaryBranchComponent(GUIBranchComponent): child = ChildField()
from LarchTools.PythonTools.GUIEditor.DataModel import GUINode, TypedEvalField, TypedField from LarchTools.PythonTools.GUIEditor.Properties import GUICProp from LarchTools.PythonTools.GUIEditor.Target import GUITargetInteractor, GUIScrollInteractor from LarchTools.PythonTools.GUIEditor.ContextMenu import componentContextMenu from LarchTools.PythonTools.GUIEditor.Padding import AbstractPadding, UniformPadding, NonUniformPadding componentBorder = SolidBorder(1.0, 2.0, Color(0.8, 0.8, 0.8), None) def blankCallModel(codeGen): blank = codeGen.embeddedValue(Blank) return Py.Call(target=blank, args=[]) _noAlignmentStyle = StyleSheet.style( Primitive.foreground(Color(0.4, 0.4, 0.4)), Primitive.fontSize(11)) def _hAlignmentEditor(live): @LiveFunction def displayLive(): x = live.getValue() if x is None: return 0 else: return x.ordinal() + 1 options = [ _noAlignmentStyle(Label('None')), Label('Pack'), Label('Left'),
from BritefuryJ.Controls import TextEntry from BritefuryJ.Pres.Primitive import Primitive, Label, Row from BritefuryJ.Pres.UI import Form from BritefuryJ.StyleSheet import StyleSheet from LarchCore.Languages.Python2 import Schema as Py from LarchCore.Languages.Python2.Embedded import EmbeddedPython2Expr from LarchTools.PythonTools.GUIEditor.DataModel import ExprField, TypedField from LarchTools.PythonTools.GUIEditor.LeafComponent import GUILeafComponent from LarchTools.PythonTools.GUIEditor.ComponentPalette import paletteItem, registerPaletteSubsection _evalLabelStyle = StyleSheet.style(Primitive.fontItalic(True), Primitive.fontSize(11), Primitive.foreground(Color(0.3, 0.4, 0.5))) _liveEvalLabelStyle = StyleSheet.style( Primitive.fontItalic(True), Primitive.fontSize(11), Primitive.foreground(Color(0.4, 0.3, 0.5))) _evalItemStyleF = StyleSheet.style(Primitive.fontItalic(True), Primitive.foreground(Color(0.2, 0.4, 0.6))) _evalItemStyleParens = StyleSheet.style( Primitive.foreground(Color(0.4, 0.4, 0.4))) class GUIEval(GUILeafComponent): componentName = 'Eval' expr = ExprField()
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))
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 ) ) ) _groupNumberStyle = StyleSheet.style( Primitive.foreground( Color( 0.1, 0.45, 0.1 ) ) ) _commentStyle = StyleSheet.style( Primitive.foreground( Color( 0.3, 0.3, 0.3 ) ) ) _flagsStyle = StyleSheet.style( Primitive.foreground( Color( 1.0, 0.5, 0.0 ) ) )
class LiterateSuite(object): def __init__(self, definition=None, expanded=True): if definition is None: definition = LiterateSuiteDefinition() self._definition = definition self._expanded = expanded self._incr = IncrementalValueMonitor() self.__change_history__ = None def __getstate__(self): return {'definition': self._definition, 'expanded': self._expanded} def __setstate__(self, state): self._definition = state.get('definition') self._expanded = state.get('expanded', True) if self._definition is None: self._definition = LiterateSuiteDefinition() self._incr = IncrementalValueMonitor() self.__change_history__ = None def __get_trackable_contents__(self): return [self._definition] def __py_execmodel__(self, codeGen): return self._definition._suite.model def __py_replacement__(self): return deepcopy(self._definition._suite.model['suite']) def _new_reference(self): return LiterateSuite(self._definition) def getName(self): return self._definition.getName() def setName(self, name): self._definition.setName(name) def isExpanded(self): return self._expanded def setExpanded(self, expanded): oldExpanded = self._expanded self._expanded = expanded self._incr.onChanged() if self.__change_history__ is not None: self.__change_history__.addChange( lambda: self.setExpanded(expanded), lambda: self.setExpanded(oldExpanded), 'Literate suite set expanded') def __present__(self, fragment, inheritedState): def _literateExpressionMenu(element, menu): def _onToggleExpanded(item): self.setExpanded(not self._expanded) menuItemName = 'Start as contracted' if self._expanded else 'Start as expanded' menu.add( MenuItem.menuItemWithLabel(menuItemName, _onToggleExpanded)) return False self._incr.onAccess() self._definition._incr.onAccess() suitePres = self._definition._suite nameLabel = self._nameStyle(Label(self._definition._name)) liveName = LiveValue(nameLabel) class _NameEntryListener(TextEntry.TextEntryListener): def onAccept(listener, textEntry, text): self.setName(text) def onCancel(listener, textEntry, orignalText): liveName.setLiteralValue(nameLabel) def _onNameButton(button, event): nameEntry = TextEntry(self._definition._name, _NameEntryListener()) nameEntry.grabCaretOnRealise() nameEntry = self._nameStyle(nameEntry) liveName.setLiteralValue(nameEntry) renameButton = self._nameButtonStyle( Button.buttonWithLabel('...', _onNameButton)) header = Row([ self._angleQuoteStyle(Label(u'\u00ab')), liveName, self._angleQuoteStyle(Label(u'\u00bb')), Spacer(10.0, 0.0), renameButton ]).withDragSource(_dragSource) dropDown = self._dropDownStyle( DropDownExpander(header, suitePres, self._expanded, None)) return ObjectBorder(dropDown).withContextMenuInteractor( _literateExpressionMenu) _nameStyle = StyleSheet.style( Primitive.foreground(Color(0.15, 0.15, 0.45)), Primitive.fontSize(12)) _nameButtonStyle = StyleSheet.style(Primitive.fontSize(10)) _angleQuoteStyle = StyleSheet.style( Primitive.foreground(Color(0.15, 0.15, 0.45)), Primitive.fontBold(True), Primitive.fontSize(12)) _dropDownStyle = StyleSheet.style( Controls.dropDownExpanderHeaderArrowSize(10.0), Controls.dropDownExpanderPadding(12.0))