def InlinePythonCode(self, fragment, inheritedState, node): assert isinstance(node, ViewSchema.InlinePythonCodeView) if node.isCodeVisible(): exprView = Python2.python2EditorPerspective.applyTo( Pres.coerce(node.getExpr())) if node.isCodeEditable(): exprView = StyleSheet.style( Primitive.editable(True)).applyTo(exprView) else: exprView = None executionResultView = None executionResult = node.getResult() if executionResult is not None: if node.isResultMinimal(): executionResultView = executionResult.minimalView() else: executionResultView = executionResult.view() if node.isCodeVisible(): boxContents = [ _pythonCodeBorderStyle.applyTo( Border(exprView.alignHExpand()).alignHExpand()) ] if executionResultView is not None: boxContents.append(executionResultView.alignHExpand()) box = StyleSheet.style(Primitive.rowSpacing(5.0)).applyTo( Row(boxContents)) return _pythonCodeEditorBorderStyle.applyTo( Border(box.alignHExpand()).alignHExpand()) else: return executionResultView.alignHPack( ) if executionResultView is not None else Proxy()
class FontConfiguration(object): def __init__(self, generic=Primitive.genericFontName, normal=Primitive.normalTextFontName, heading=Primitive.headingFontName, title=Primitive.titleFontName, uiHeading=Primitive.lightFontName): self._generic = LiveValue(generic) self._normal = LiveValue(normal) self._heading = LiveValue(heading) self._title = LiveValue(title) self._uiHeading = LiveValue(uiHeading) def __getstate__(self): state = {} state['generic'] = self._generic.getStaticValue() state['normal'] = self._normal.getStaticValue() state['heading'] = self._heading.getStaticValue() state['title'] = self._title.getStaticValue() state['uiHeading'] = self._uiHeading.getStaticValue() return state def __setstate__(self, state): self._generic = LiveValue(state.get('generic', 'SansSerif')) self._normal = LiveValue(state.get('normal', 'SansSerif')) self._heading = LiveValue(state.get('heading', 'Serif')) self._title = LiveValue(state.get('title', 'Serif')) self._uiHeading = LiveValue(state.get('uiHeading', 'SansSerif')) def copyFrom(self, config): self._generic.setLiteralValue(config._generic.getStaticValue()) self._normal.setLiteralValue(config._normal.getStaticValue()) self._heading.setLiteralValue(config._heading.getStaticValue()) self._title.setLiteralValue(config._title.getStaticValue()) self._uiHeading.setLiteralValue(config._uiHeading.getStaticValue()) 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 def apply(self): StyleValues.setRootStyleSheet(self._createStyleSheet()) def __present__(self, fragment, inheritedState): helpText = NormalText( 'Click to open the font choosers. Click on a font sample to choose it. Ctrl-click to select additional fonts.' ) def titleSample(fontName, text='The quick brown fox'): style = StyleSheet.style( RichText.titleTextAttrs( RichText.titleTextAttrs.defaultValue.withValues( Primitive.fontFace(fontName)))) return style(TitleBar(text)) titleChooser = _collapsibleFontChooser('Titles', self._title, titleSample) 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)) headingChooser = _collapsibleFontChooser('Headings', self._heading, headingSample) 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)) normalChooser = _collapsibleFontChooser('Normal text', self._normal, normalSample) 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)) uiHeadingChooser = _collapsibleFontChooser('UI Headings', self._uiHeading, uiHeadingSample) def genericSample(fontName, text='The quick brown fox jumps over the lazy dog'): style = StyleSheet.style(Primitive.fontFace(fontName)) return style(Label(text)) genericChooser = _collapsibleFontChooser('Generic text', self._generic, genericSample) chooserColumn = self._chooserColumnStyle( Column([ titleChooser, headingChooser, normalChooser, uiHeadingChooser, genericChooser ])) # Sample page @LiveFunction def samplePage(): label = Label('Sample page:') title = titleSample(self._title.getValue(), 'Example Page Title') heading = headingSample(self._heading.getValue(), 'Main heading') normal1 = normalSample(self._normal.getValue(), 'Normal text will appear like this.') normal2 = normalSample( self._normal.getValue(), 'Paragraphs of normal text are used for standard content.') ui1 = uiHeadingSample(self._uiHeading.getValue(), 'UI heading') genericLabel = Label( 'Generic text (within controls, code, etc) will appear like this.' ) buttons = self._buttonRowStyle( Row([ Button.buttonWithLabel('Button %d' % (i, ), None) for i in xrange(0, 5) ])) ui = Section(ui1, Column([genericLabel, Spacer(0.0, 7.0), buttons])) page = Page([title, Body([heading, normal1, normal2, ui])]) return Column([label, Spacer(0.0, 15.0), page]) return self._mainColumnStyle( Column([helpText, chooserColumn, samplePage])) _mainColumnStyle = StyleSheet.style(Primitive.columnSpacing(30.0)) _chooserColumnStyle = StyleSheet.style(Primitive.columnSpacing(5.0)) _buttonRowStyle = StyleSheet.style(Primitive.rowSpacing(10.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), Color(0.85, 0.95, 0.85)) _frontPageNoteStyle = StyleSheet.style( Primitive.foreground(Color(0.0, 0.5, 0.0)), Primitive.fontSize(10)) _startupPageNoteBorder = SolidBorder(1.0, 1.0, 3.0, 3.0, Color(0.75, 0.5, 1.0), Color(0.925, 0.9, 0.95)) _startupPageNoteStyle = StyleSheet.style( Primitive.foreground(Color(0.25, 0.0, 0.5)), Primitive.fontSize(10)) _notesRowStyle = StyleSheet.style(Primitive.rowSpacing(10.0)) _notesGap = 15.0 _packageContentsIndentation = 20.0 _packageIcon = Image( Image.getResource('/LarchCore/Project/images/Package.png')) _nameRegex = Pattern.compile('[a-zA-Z_][a-zA-Z0-9_]*') _pythonPackageNameRegex = Pattern.compile( '([a-zA-Z_][a-zA-Z0-9_]*(\\.[a-zA-Z_][a-zA-Z0-9_]*)*)?') def _buildProjectJar(element, document): component = element.getRootElement().getComponent()
from BritefuryJ.Controls import Hyperlink from BritefuryJ.Pres import Pres from BritefuryJ.Pres.Primitive import Primitive, Border, Row, Column, RGrid, GridRow from BritefuryJ.Pres.RichText import TitleBar, HSeparator, Head, Body, Page, SplitLinkHeaderBar, NormalText, StrongSpan, EmphSpan from BritefuryJ.Pres.UI import Section, SectionHeading1 from BritefuryJ.Pres.Help import AttachTooltip, TipBox from BritefuryJ.Projection import Perspective from LarchCore.MainApp import Application from LarchCore.MainApp import DocumentManagement _appDocRightPadding = 30.0 _controlsPadding = 5.0 _appDocumentControlsStyle = StyleSheet.style(Primitive.rowSpacing(20.0)) _appDocumentControlsBorder = FilledBorder(5.0, 5.0, 5.0, 5.0, Color(0.9, 0.9, 0.9)) _documentListTableStyle = StyleSheet.style(Primitive.tableColumnSpacing(15.0), Primitive.tableRowSpacing(5.0)) def _newDocumentName(docs): usedNames = set([doc.getName() for doc in docs]) name = 'Untitled' if name not in usedNames: return name index = 2 name = 'Untitled' + str(index)
from BritefuryJ.Pres import Pres from BritefuryJ.Pres.Primitive import Primitive, Label, Arrow, Spacer, Box, Row, Column from BritefuryJ.StyleSheet import StyleSheet from BritefuryJ.Util.Coroutine import Coroutine from BritefuryJ.Live import LiveValue 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