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())
Exemplo n.º 2
0
def intLiteral(format, value):
    valuePres = ApplyStyleSheetFromAttribute(PythonEditorStyle.numLiteralStyle,
                                             Text(value))
    boxContents = [valuePres]
    if format is not None:
        boxContents.append(
            ApplyStyleSheetFromAttribute(PythonEditorStyle.literalFormatStyle,
                                         Text(format)))

    return Row(boxContents)
def _richStringLines(labelText, richString, textStyleAttribute,
                     bUseDefaultPerspectiveForResult):
    label = ApplyStyleSheetFromAttribute(ExecutionStyle.labelStyle,
                                         StaticText(labelText))
    lines = [
        _richStringItem(item, textStyleAttribute,
                        bUseDefaultPerspectiveForResult)
        for item in richString.getItems()
    ]
    return Overlay(
        [Column(lines).alignHExpand(),
         label.alignHRight().alignVTop()])
Exemplo n.º 4
0
def classStmtHeader(name, bases, bBasesTrailingSeparator):
    nameView = ApplyStyleSheetFromAttribute(PythonEditorStyle.varStyle,
                                            Text(name))

    elements = [_keyword('class'), _space, nameView]
    if bases is not None:
        basesSeq = SpanSequenceView(
            bases, None, None, _comma, _space, TrailingSeparator.ALWAYS
            if bBasesTrailingSeparator else TrailingSeparator.NEVER)
        basesView = ApplyStyleSheetFromAttribute(
            PythonEditorStyle.sequenceStyle, basesSeq)
        elements.extend([_space, _openParen, basesView, _closeParen])
    elements.append(_colon)
    return Span(elements)
Exemplo n.º 5
0
def decoStmtHeader(name, args, bArgsTrailingSeparator):
    nameView = ApplyStyleSheetFromAttribute(PythonEditorStyle.varStyle,
                                            Text(name))

    elements = [_at, nameView]
    if args is not None:
        argsSeq = SpanSequenceView(
            args, _openParen, _closeParen, _comma, _space,
            TrailingSeparator.ALWAYS
            if bArgsTrailingSeparator else TrailingSeparator.NEVER)
        argsView = ApplyStyleSheetFromAttribute(
            PythonEditorStyle.sequenceStyle, argsSeq)
        elements.append(argsView)
    return Span(elements)
Exemplo n.º 6
0
def defStmtHeader(name, params, bParamsTrailingSeparator):
    nameView = ApplyStyleSheetFromAttribute(PythonEditorStyle.varStyle,
                                            Text(name))

    elements = [_keyword('def'), _space, nameView, _openParen]
    if len(params) > 0:
        paramsSeq = SpanSequenceView(
            params, None, None, _comma, _space, TrailingSeparator.ALWAYS
            if bParamsTrailingSeparator else TrailingSeparator.NEVER)
        paramsView = ApplyStyleSheetFromAttribute(
            PythonEditorStyle.sequenceStyle, paramsSeq)
        elements.append(paramsView)

    elements.extend([_closeParen, _colon])
    return Span(elements)
def execStderr(richString, bUseDefaultPerspectiveForResult):
    return ApplyStyleSheetFromAttribute(
        ExecutionStyle.stdErrStyle,
        Border(
            _richStringLines('STDERR', richString, ExecutionStyle.stdErrStyle,
                             bUseDefaultPerspectiveForResult).alignHExpand()).
        alignHExpand())
def executionResultBox(streams, exception, resultInTuple,
                       bUseDefaultPerspecitveForException,
                       bUseDefaultPerspectiveForResult):
    boxContents = []
    for stream in streams:
        if stream.name == 'out':
            boxContents.append(
                execStdout(stream.richString, bUseDefaultPerspectiveForResult))
        elif stream.name == 'err':
            boxContents.append(
                execStderr(stream.richString, bUseDefaultPerspectiveForResult))
        else:
            raise ValueError, 'Unreckognised stream \'{0}\''.format(
                stream.name)
    if exception is not None:
        exceptionView = Pres.coerce(exception).alignHPack()
        if bUseDefaultPerspecitveForException:
            exceptionView = ApplyPerspective.defaultPerspective(exceptionView)
        boxContents.append(execException(exceptionView))
    if resultInTuple is not None:
        resultView = Pres.coercePresentingNull(resultInTuple[0]).alignHPack()
        if bUseDefaultPerspectiveForResult:
            resultView = ApplyPerspective.defaultPerspective(resultView)
        boxContents.append(execResult(resultView))

    if len(boxContents) > 0:
        return ApplyStyleSheetFromAttribute(ExecutionStyle.resultBoxStyle,
                                            Column(boxContents).alignHExpand())
    else:
        return None
Exemplo n.º 9
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)
Exemplo n.º 10
0
def relativeModule(name):
    return ApplyStyleSheetFromAttribute(PythonEditorStyle.importStyle,
                                        Text(name))
Exemplo n.º 11
0
def augAssignStmt(op, target, value):
    opView = ApplyStyleSheetFromAttribute(PythonEditorStyle.operatorStyle,
                                          Text(op))

    return Span([target, _space, opView, _space, value])
Exemplo n.º 12
0
def kwParamList(name):
    nameView = ApplyStyleSheetFromAttribute(PythonEditorStyle.paramStyle,
                                            Text(name))
    return Span([_doubleAsterisk, nameView])
Exemplo n.º 13
0
def singleTarget(name):
    return ApplyStyleSheetFromAttribute(PythonEditorStyle.targetStyle,
                                        Text(name))
Exemplo n.º 14
0
def _initKeywords(keywords):
    for keyword in keywords:
        #keyword = keyword[0].upper() + keyword[1:]
        _keywordMap[keyword] = ApplyStyleSheetFromAttribute(
            PythonEditorStyle.keywordStyle, Text(keyword, keyword))
Exemplo n.º 15
0
def unparseableText(text):
    return ApplyStyleSheetFromAttribute(PythonEditorStyle.unparseableStyle,
                                        Text(text))
Exemplo n.º 16
0
def spanPrefixOp(x, op):
    opView = ApplyStyleSheetFromAttribute(PythonEditorStyle.operatorStyle,
                                          Text(op))
    return LineBreakCostSpan([opView, x])
Exemplo n.º 17
0
def callKWArg(name, value):
    nameView = ApplyStyleSheetFromAttribute(PythonEditorStyle.kwNameStyle,
                                            Text(name))
    return Span([nameView, _equals, value])
Exemplo n.º 18
0
def subscriptTuple(items, bTrailingSeparator):
    seq = SpanSequenceView(
        items, None, None, _comma, _space, TrailingSeparator.ALWAYS
        if bTrailingSeparator else TrailingSeparator.NEVER)
    return ApplyStyleSheetFromAttribute(PythonEditorStyle.sequenceStyle, seq)
Exemplo n.º 19
0
def attributeRef(target, name):
    attribView = ApplyStyleSheetFromAttribute(PythonEditorStyle.attributeStyle,
                                              Text(name))
    return Span([target, _dot, attribView])
Exemplo n.º 20
0
def setLiteral(items, bTrailingSeparator):
    seq = SpanSequenceView(
        items, _openBrace, _closeBrace, _comma, _space,
        TrailingSeparator.ALWAYS
        if bTrailingSeparator else TrailingSeparator.NEVER)
    return ApplyStyleSheetFromAttribute(PythonEditorStyle.sequenceStyle, seq)
Exemplo n.º 21
0
def load(name):
    return ApplyStyleSheetFromAttribute(PythonEditorStyle.varStyle, Text(name))
Exemplo n.º 22
0
def moduleImportAs(name, asName):
    nameView = ApplyStyleSheetFromAttribute(PythonEditorStyle.importStyle,
                                            Text(name))
    asNameView = ApplyStyleSheetFromAttribute(PythonEditorStyle.importStyle,
                                              Text(asName))
    return Span([nameView, _space, _keyword('as'), _space, asNameView])
Exemplo n.º 23
0
def moduleContentImport(name):
    return ApplyStyleSheetFromAttribute(PythonEditorStyle.importStyle,
                                        Text(name))
Exemplo n.º 24
0
def spanCmpOp(op, y):
    opView = ApplyStyleSheetFromAttribute(PythonEditorStyle.operatorStyle,
                                          Text(op))
    return Span([Text(' '), opView, Text(' '), _lineBreak, y])
def execResult(resultView):
    return ApplyStyleSheetFromAttribute(
        ExecutionStyle.resultBorderStyle,
        Border(Bin(Paragraph([resultView]))).alignHExpand())
Exemplo n.º 26
0
def div(x, y, fractionBarContent):
    bar = ApplyStyleSheetFromAttribute(PythonEditorStyle.operatorStyle,
                                       Fraction.FractionBar('/'))
    return Fraction(x, y, bar)
def _textLines(text, textStyleAttribute):
    if text.endswith('\n'):
        text = text[:-1]
    return ApplyStyleSheetFromAttribute(
        textStyleAttribute,
        Column([StaticText(line) for line in text.split('\n')]))
Exemplo n.º 28
0
def simpleParam(name):
    return ApplyStyleSheetFromAttribute(PythonEditorStyle.paramStyle,
                                        Text(name))
Exemplo n.º 29
0
def spanBinOp(x, y, op):
    opView = ApplyStyleSheetFromAttribute(PythonEditorStyle.operatorStyle,
                                          Text(op))
    return LineBreakCostSpan([x, Text(' '), opView, Text(' '), _lineBreak, y])
Exemplo n.º 30
0
def imaginaryLiteral(value):
    return ApplyStyleSheetFromAttribute(PythonEditorStyle.numLiteralStyle,
                                        Text(value))