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()
	def __present__(self, fragment, inheritedState):
		pythonModule = self.getPythonModule()

		executionResult = self.getExecResult()

		caughtException = executionResult.getCaughtException()
		result = executionResult.getResult()
		streams = executionResult.getStreams()

		moduleView = StyleSheet.style( Primitive.editable( False ) ).applyTo( Python2.python2EditorPerspective.applyTo( pythonModule ) )
		caughtExceptionView = ApplyPerspective.defaultPerspective( caughtException )   if caughtException is not None   else None
		resultView = ApplyPerspective.defaultPerspective( result[0] )   if result is not None   else None

		code = _pythonModuleBorderStyle.applyTo( Border( moduleView.alignHExpand() ).alignHExpand() )
		outputContents = []
		for stream in streams:
			if stream.name == 'out':
				outputContents.append( execStdout( stream.richString, True ) )
			elif stream.name == 'err':
				outputContents.append( execStderr( stream.richString, True ) )
			else:
				raise ValueError, 'Unreckognised stream \'{0}\''.format( stream.name )
		if caughtExceptionView is not None:
			outputContents.append( execException( caughtExceptionView ) )
		if resultView is not None:
			outputContents.append( execResult( resultView ) )
		outputColumn = _blockOutputStyle.applyTo( Column( outputContents ).alignHExpand() )
		return _blockStyle.applyTo( Border( Column( [ code, outputColumn ] ) ) ).alignHExpand()
def execStderr(richString, bUseDefaultPerspectiveForResult):
    return ApplyStyleSheetFromAttribute(
        ExecutionStyle.stdErrStyle,
        Border(
            _richStringLines('STDERR', richString, ExecutionStyle.stdErrStyle,
                             bUseDefaultPerspectiveForResult).alignHExpand()).
        alignHExpand())
def execException(exceptionView):
    label = ApplyStyleSheetFromAttribute(ExecutionStyle.labelStyle,
                                         StaticText('EXCEPTION:'))
    return ApplyStyleSheetFromAttribute(
        ExecutionStyle.exceptionBorderStyle,
        Border(
            Column([label, exceptionView.padX(5.0, 0.0).alignHExpand()
                    ]).alignHExpand()).alignHExpand())
    def PythonCode(self, fragment, inheritedState, node):
        if node.isVisible():
            if node.isCodeVisible():
                codeView = Python2.python2EditorPerspective.applyTo(
                    Pres.coerce(node.getCode()))
                if node.isCodeEditable():
                    codeView = StyleSheet.style(
                        Primitive.editable(True)).applyTo(codeView)
            else:
                codeView = None

            executionResultView = None
            executionResult = node.getResult()
            if executionResult is not None:
                if not node.isResultVisible():
                    executionResult = executionResult.suppressStdOut(
                    ).suppressResult()
                if node.isMinimal():
                    executionResultView = executionResult.minimalView()
                else:
                    executionResultView = executionResult.view()

            if node.isMinimal():
                return executionResultView.alignHExpand(
                ) if executionResultView is not None else Blank()
            else:
                boxContents = []
                if node.isCodeVisible():
                    boxContents.append(
                        _pythonCodeBorderStyle.applyTo(
                            Border(codeView.alignHExpand()).alignHExpand()))
                if node.isResultVisible() and executionResultView is not None:
                    boxContents.append(executionResultView.alignHExpand())
                box = StyleSheet.style(Primitive.columnSpacing(5.0)).applyTo(
                    Column(boxContents))

                return _pythonCodeEditorBorderStyle.applyTo(
                    Border(box.alignHExpand()).alignHExpand())
        else:
            return Blank()
Beispiel #6
0
def unquote(ctx, style, valueView, title, sequentialEditor):
    unquoteBorderStyle = style.get(PythonEditorStyle.unquoteBorderStyle)
    unquoteTitleStyle = style.get(PythonEditorStyle.unquoteTitleStyle)

    titleLabel = unquoteTitleStyle.applyTo(Label(title))

    region = sequentialEditor.region(valueView)

    header = titleLabel.alignHLeft()
    box = unquoteBorderStyle.applyTo(
        Border(Column([header.alignHExpand(),
                       region.pad(3.0, 3.0)]))).pad(1.0, 1.0)

    segment = Segment(box)
    return segment.present(ctx, style)
Beispiel #7
0
def externalExpr(ctx, style, exprView, title, deleteButton):
    externalExprBorderStyle = style.get(
        PythonEditorStyle.externalExprBorderStyle)
    externalExprTitleStyle = style.get(
        PythonEditorStyle.externalExprTitleStyle)

    titleLabel = externalExprTitleStyle.applyTo(Label(title))

    header = Row(
        [titleLabel.alignHLeft(),
         deleteButton.alignHRight().alignVCentre()])
    box = externalExprBorderStyle.applyTo(
        Border(Column([header.alignHExpand(),
                       exprView.pad(3.0, 3.0)]))).pad(1.0, 1.0)

    segment = Segment(box)
    return segment.present(ctx, style)
Beispiel #8
0
def stringLiteral(format, quotation, value, isUnicode, raw):
    boxContents = []

    if format is not None and format != '':
        boxContents.append(
            ApplyStyleSheetFromAttribute(PythonEditorStyle.literalFormatStyle,
                                         Text(format)))

    # Split the value into pieces of escaped and non-escaped content
    if raw:
        valuePres = ApplyStyleSheetFromAttribute(
            PythonEditorStyle.stringLiteralStyle, Text(value))
    else:
        segments = _non_escaped_string_re.split(value)
        if len(segments) == 1:
            valuePres = ApplyStyleSheetFromAttribute(
                PythonEditorStyle.stringLiteralStyle, Text(value))
        else:
            escape = False
            segsAsPres = []
            for seg in segments:
                if seg is not None and len(seg) > 0:
                    if escape:
                        segsAsPres.append(
                            ApplyStyleSheetFromAttribute(
                                PythonEditorStyle.stringLiteralEscapeStyle,
                                Border(Text(seg))))
                    else:
                        segsAsPres.append(Text(seg))
                escape = not escape
            valuePres = ApplyStyleSheetFromAttribute(
                PythonEditorStyle.stringLiteralStyle, Span(segsAsPres))

    quotationPres = ApplyStyleSheetFromAttribute(
        PythonEditorStyle.quotationStyle, Text(quotation))
    boxContents.extend([quotationPres, valuePres, quotationPres])

    return Row(boxContents)
    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])))
Beispiel #10
0
def embeddedObjectMacro(ctx, style, valueView, modelView):
    modelView = StyleSheet.style(Primitive.editable(False)).applyTo(modelView)

    embeddedObjectBorderStyle = style.get(
        PythonEditorStyle.embeddedObjectBorderStyle)
    embeddedObjectLineStyle = style.get(
        PythonEditorStyle.embeddedObjectLineStyle)
    embeddedObjectExpansionLabelStyle = style.get(
        PythonEditorStyle.embeddedObjectExpansionLabelStyle)

    hLine = embeddedObjectLineStyle.applyTo(Box(1, 1).alignHExpand()).pad(
        8.0, 2.0).alignHExpand()

    expansionLabel = embeddedObjectExpansionLabelStyle.applyTo(
        Label('Expansion'))

    expander = DropDownExpander(expansionLabel, modelView)

    view = embeddedObjectBorderStyle.applyTo(
        Border(Column([valueView, expander])))

    segment = Segment(view)
    return segment.present(ctx, style)
def execResult(resultView):
    return ApplyStyleSheetFromAttribute(
        ExecutionStyle.resultBorderStyle,
        Border(Bin(Paragraph([resultView]))).alignHExpand())
Beispiel #12
0
def classStmtHighlight(ctx, style, header):
    highlightStyle = PythonEditorStyle._classStmtHighlightStyle.get(style)
    return highlightStyle.applyTo(Border(header)).present(ctx, style)
Beispiel #13
0
    quotationPres = ApplyStyleSheetFromAttribute(
        PythonEditorStyle.quotationStyle, Text(quotation))
    boxContents.extend([quotationPres, valuePres, quotationPres])

    return Row(boxContents)


_string_escape_re = Pattern.compile(
    r'\\(?:[abnfrt\\' + '\'\"' +
    r']|(?:x[0-9a-fA-F]{2})|(?:u[0-9a-fA-F]{4})|(?:U[0-9a-fA-F]{8}))')

_stringTextPresFn = TextArea.RegexPresTable()
_stringTextPresFn.addPattern(
    _string_escape_re, lambda text: ApplyStyleSheetFromAttribute(
        PythonEditorStyle.stringLiteralEscapeStyle, Border(Text(text))))


def multilineStringLiteral(valueLiveFunction, isUnicode, raw, editFn):
    class _Listener(TextArea.TextAreaListener):
        def onTextChanged(self, area):
            editFn(area.getDisplayedText())

    t = TextArea(valueLiveFunction, _Listener())
    if not raw:
        t = t.withTextToPresFunction(_stringTextPresFn)

    return t


def intLiteral(format, value):
Beispiel #14
0
	def __present__(self, fragment, inherited_state):
		return Border(_img(self._image, 640, 400.0))
Beispiel #15
0
	def __present__(self, fragment, inheritedState):
		return Border(_img(self._image, 128.0, 80.0))
def _dropPrompt(varNameTextEntryListener):
	textEntry = TextEntry( 'var', varNameTextEntryListener ).regexValidated( _varNameRegex, 'Please enter a valid identifier' )
	prompt = Label( 'Place object into a variable named: ' )
	textEntry.grabCaretOnRealise()
	textEntry.selectAllOnRealise()
	return _dropPromptStyle.applyTo( Border( Paragraph( [ prompt.alignVCentre(), textEntry.alignVCentre() ] ).alignHPack() ) )
	def __present__(self, fragment, inheritedState):
		x = Border(self._value.value).withContextMenuInteractor(_paraEmbedContextMenuFactory)
		x = GUIRichTextController.instance.editableParagraphEmbed(self, x)
		return x
	def __present__(self, fragment, inheritedState):
		blocks = self.getBlocks()
		currentModule = Python2.python2EditorPerspective.applyTo( self.getCurrentPythonModule() )

		def _onDrop(element, pos, data, action):
			class _VarNameEntryListener (TextEntry.TextEntryListener):
				def onAccept(listenerSelf, entry, text):
					self.assignVariable( text, data.getModel() )
					_finish( entry )

				def onCancel(listenerSelf, entry, text):
					_finish( entry )

			def _finish(entry):
				caret.moveTo( marker )
				dropPromptLive.setLiteralValue( Blank() )

			dropPrompt = _dropPrompt( _VarNameEntryListener() )
			rootElement = element.getRootElement()
			caret = rootElement.getCaret()
			marker = caret.getMarker().copy()
			dropPromptLive.setLiteralValue( dropPrompt )
			rootElement.grabFocus()

			return True



		# Header
		if self._showBanner:
			bannerVersionText = [ _bannerTextStyle.applyTo( NormalText( v ) )   for v in sys.version.split( '\n' ) ]
			helpText1 = Row( [ _bannerHelpKeyTextStyle.applyTo( Label( 'Ctrl+Enter' ) ),
					   _bannerHelpTextStyle.applyTo( Label( ' - execute and evaluate, ' ) ),
					   _bannerHelpKeyTextStyle.applyTo( Label( 'Ctrl+Shift+Enter' ) ),
					   _bannerHelpTextStyle.applyTo( Label( ' - execute only' ) ) ] )
			helpText2 = Row( [ _bannerHelpKeyTextStyle.applyTo( Label( 'Alt+Up' ) ),
					   _bannerHelpTextStyle.applyTo( Label( ' - previous, ' ) ),
					   _bannerHelpKeyTextStyle.applyTo( Label( 'Alt+Down' ) ),
					   _bannerHelpTextStyle.applyTo( Label( ' - next' ) ) ] )
			bannerText = Column( bannerVersionText + [ helpText1, helpText2 ] ).alignHPack()

			banner = _bannerBorder.surround( bannerText )
		else:
			banner = None


		dropDest = ObjectDndHandler.DropDest( FragmentData, _onDrop )

		def _onExecute(element):
			self.execute( True )

		def _onExecuteNoEval(element):
			self.execute( False )

		def _onHistoryPrev(element):
			self.backwards()

		def _onHistoryNext(element):
			self.forwards()

		currentModule = Span( [ currentModule ] )
		currentModule = currentModule.withShortcut( _executeShortcut, _onExecute )
		currentModule = currentModule.withShortcut( _executeNoEvalShortcut, _onExecuteNoEval )
		currentModule = currentModule.withShortcut( _historyPreviousShortcut, _onHistoryPrev )
		currentModule = currentModule.withShortcut( _historyNextShortcut, _onHistoryNext )

		m = _pythonModuleBorderStyle.applyTo( Border( currentModule.alignHExpand() ) ).alignHExpand()
		m = m.withDropDest( dropDest )
		def _ensureCurrentModuleVisible(element, ctx, style):
			element.ensureVisible()
		m = m.withCustomElementAction( _ensureCurrentModuleVisible )

		dropPromptLive = LiveValue( Span( [] ) )
		dropPromptView = dropPromptLive

		consoleColumnContents = [ banner.alignVRefY() ]   if self._showBanner   else []
		if len( blocks ) > 0:
			blockList = _consoleBlockListStyle.applyTo( Column( blocks ) ).alignHExpand()
			consoleColumnContents += [ blockList.alignVRefY(), dropPromptView.alignVRefY(), m.alignVRefY() ]
		else:
			consoleColumnContents += [ dropPromptView.alignVRefY(), m.alignVRefY() ]
		return _consoleStyle.applyTo( Column( consoleColumnContents ) ).alignHExpand().alignVTop()