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))
from BritefuryJ.Projection import Perspective, Subject, SubjectPathEntry from LarchCore.Languages.Python2 import Python2 from LarchCore.Languages.Python2.CodeGenerator import compileForModuleExecution from LarchCore.Worksheet import Schema from LarchCore.Worksheet.WorksheetViewer import ViewSchema from LarchCore.Worksheet.WorksheetEditor.View import WorksheetEditorSubject _editableStyle = StyleSheet.style(Primitive.editable(True)) _worksheetMargin = 10.0 _pythonCodeBorderStyle = StyleSheet.style( Primitive.border( SolidBorder(1.0, 5.0, 10.0, 10.0, Color(0.2, 0.4, 0.8), None))) _pythonCodeEditorBorderStyle = StyleSheet.style( Primitive.border( SolidBorder(1.5, 4.0, 10.0, 10.0, Color(0.4, 0.4, 0.5), None))) def _worksheetContextMenuFactory(element, menu): def _onRefresh(button, event): model.refreshResults() model = element.getFragmentContext().getModel() refreshButton = Button.buttonWithLabel('Refresh', _onRefresh) worksheetControls = ControlsRow([refreshButton.alignHPack()]) menu.add(Section(SectionHeading2('Worksheet'), worksheetControls)) return True
class GraphVizConfigurationPage(ConfigurationPage): def __init__(self): super(GraphVizConfigurationPage, self).__init__() self._graphVizDir = None self._config = None self._incr = IncrementalValueMonitor() def initPage(self, config): super(GraphVizConfigurationPage, self).initPage(config) GraphVizConfiguration.setConfigurationPageSubject(self.subject()) def __getstate__(self): state = super(GraphVizConfigurationPage, self).__getstate__() state['graphVizDir'] = self._graphVizDir return state def __setstate__(self, state): super(GraphVizConfigurationPage, self).__setstate__(state) self._graphVizDir = state['graphVizDir'] self._config = None self._incr = IncrementalValueMonitor() self._refreshConfig() def _checkedToolPath(self, name): path = os.path.join(self._graphVizDir, name + _exeExtension) if os.path.exists(path): return path else: return None def _setGraphVizDir(self, dir): self._graphVizDir = dir self._refreshConfig() self._incr.onChanged() def __isConfigured(self): if self._graphVizDir is not None and os.path.isdir(self._graphVizDir): dotPath = self._checkedToolPath('dot') neatoPath = self._checkedToolPath('neato') twopiPath = self._checkedToolPath('twopi') circoPath = self._checkedToolPath('circo') fdpPath = self._checkedToolPath('fdp') sfdpPath = self._checkedToolPath('sfdp') osagePath = self._checkedToolPath('osage') return dotPath is not None and neatoPath is not None and twopiPath is not None and circoPath is not None and fdpPath is not None and sfdpPath is not None and osagePath is not None return False def _refreshConfig(self): if self._graphVizDir is not None and os.path.isdir(self._graphVizDir): dotPath = self._checkedToolPath('dot') neatoPath = self._checkedToolPath('neato') twopiPath = self._checkedToolPath('twopi') circoPath = self._checkedToolPath('circo') fdpPath = self._checkedToolPath('fdp') sfdpPath = self._checkedToolPath('sfdp') osagePath = self._checkedToolPath('osage') self._config = GraphVizConfiguration(dotPath, neatoPath, twopiPath, circoPath, fdpPath, sfdpPath, osagePath) GraphVizConfiguration.setInstance(self._config) else: self._config = None GraphVizConfiguration.setInstance(None) self._incr.onChanged() def getSubjectTitle(self): return '[CFG] GraphViz' def getTitleText(self): return 'GraphViz Configuration' def getLinkText(self): return 'GraphViz' def _presentDir(self): def _onSet(hyperlink, event): component = hyperlink.getElement().getRootElement().getComponent() openDialog = JFileChooser() openDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY) response = openDialog.showDialog(component, 'Choose path') if response == JFileChooser.APPROVE_OPTION: sf = openDialog.getSelectedFile() if sf is not None: filename = sf.getPath() if filename is not None and os.path.isdir(filename): self._graphVizDir = filename self._refreshConfig() self._incr.onChanged() dirLabel = Label( self._graphVizDir ) if self._graphVizDir is not None else self._notSetStyle.applyTo( Label('<Not set>')) setLink = Hyperlink('CHANGE', _onSet) return self._dirBorderStyle.applyTo( Border(Row([dirLabel, Spacer(25.0, 0.0), setLink]))) def _toolLabel(self, name): return self._configTableToolNameStyle.applyTo(Label(name)) def _presentConfig(self): if self._config is not None: rows = [] rows.append([SectionHeading3('Tool'), SectionHeading3('Path')]) rows.append( [self._toolLabel('dot'), Label(self._config.getDotPath())]) rows.append( [self._toolLabel('neato'), Label(self._config.getNeatoPath())]) rows.append( [self._toolLabel('twopi'), Label(self._config.getTwopiPath())]) rows.append( [self._toolLabel('circo'), Label(self._config.getCircoPath())]) rows.append( [self._toolLabel('fdp'), Label(self._config.getFdpPath())]) rows.append( [self._toolLabel('sfdp'), Label(self._config.getSfdpPath())]) rows.append( [self._toolLabel('osage'), Label(self._config.getOsagePath())]) return self._configTableStyle.applyTo(Table(rows)).pad(15.0, 5.0) def __present_contents__(self, fragment, inheritedState): self._incr.onAccess() dirPres = self._presentDir() note = NotesText([ 'Note: please choose the location of the GraphViz ', EmphSpan('bin'), ' directory.' ]) columnContents = [note, dirPres] if self._config is not None: columnContents.append(self._presentConfig()) pathContents = Column(columnContents) pathSection = Section(SectionHeading2('GraphViz path'), pathContents) downloadText = '' if self.__isConfigured(): downloadText = 'GraphViz appears to be installed on this machine and configured. If it does not work correctly, you may need to install it. You can download it from the ' else: downloadText = 'If GraphViz is not installed on this machine, please install it. You can download it from the ' downloadLink = Hyperlink('GraphViz homepage', URI('http://www.graphviz.org/')) download = NormalText([downloadText, downloadLink, '.']) downloadSec = Section( SectionHeading2('GraphViz download/installation'), download) return Body([pathSection, downloadSec]) _dirBorderStyle = StyleSheet.style( Primitive.border( SolidBorder(1.0, 3.0, 10.0, 10.0, Color(1.0, 0.85, 0.0), Color(1.0, 1.0, 0.85)))) _notSetStyle = StyleSheet.style(Primitive.fontItalic(True)) _configTableStyle = StyleSheet.style(Primitive.tableColumnSpacing(10.0)) _configTableToolNameStyle = StyleSheet.style( 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 _classStmtHighlightStyle(style): border = _outlineHighlightBorder( style, style.get(PythonEditorStyle.classStmtHighlightColour)) return style.withValues(Primitive.border(border))
def _defStmtHeaderHighlightStyle(style): border = _solidHighlightBorder( style, style.get(PythonEditorStyle.defStmtHighlightColour)) return style.withValues(Primitive.border(border))
_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 ) ) ) _consoleBlockListStyle = StyleSheet.style( Primitive.columnSpacing( 5.0 ) ) _consoleStyle = StyleSheet.style( Primitive.columnSpacing( 9.0 ) )