コード例 #1
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)
コード例 #2
0
def charSet(invert, items):
	items = [ Row( [ Segment( item ) ] )   for item in items ]
	if len( items ) == 1:
		itemsCollection = items[0]
	else:
		width = int( math.ceil( math.sqrt( float( len( items ) ) ) ) )
		itemsCollection = FlowGrid( width, items )
	contents = [ _controlCharStyle( Text( '[' ) ) ]
	if invert:
		contents.append( _invertControlCharStyle( Text( '^' ) ) )
	contents.extend( [ itemsCollection,  _controlCharStyle( Text( ']' ) ) ] )
	return _charSetBorder.surround( Row( contents ) )
コード例 #3
0
def choice(subexps):
	rows = []
	for subexp in subexps[:-1]:
		rows.append( Row( [ subexp.alignHPack(), _controlCharStyle( Text( '|' ).alignHRight() ) ] ).alignHExpand() )
		rows.append( _choiceRuleStyle.applyTo( Box( 1.0, 1.0 ).pad( 5.0, 3.0 ).alignHExpand() ) )
	rows.append( subexps[-1].alignHPack() )
	return _choiceBorder.surround( Column( rows ) )
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #7
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)
コード例 #8
0
def matchNumberedGroup(number):
	groupNumber = _groupNumberStyle( Text( number ) )
	return _groupBorder.surround( Row( [ _controlCharStyle( Text( '\\' ) ), groupNumber ] ) )
コード例 #9
0
def lookbehind(subexp, positive):
	posNegIndicator = _controlCharStyle( Text( '=' ) )   if positive   else _invertControlCharStyle( Text( '!' ) )
	return _lookbehindBorder.surround( Row( [ _controlCharStyle( Text( '(?<' ) ), posNegIndicator, subexp, _controlCharStyle( Text( ')' ) ) ] ) )
コード例 #10
0
def defineNamedGroup(subexp, name):
	groupName = Row( [ _controlCharStyle( Text( 'P<' ) ), _groupNameStyle( Text( name ) ), _controlCharStyle( Text( '>' ) ) ] )
	nameBlock = Script.scriptRSub(  _controlCharStyle( Text( '?' ) ), groupName )
	return _groupBorder.surround( Row( [ _controlCharStyle( Text( '(' ) ), nameBlock, subexp, _controlCharStyle( Text( ')' ) ) ] ) )
コード例 #11
0
def matchNamedGroup(name):
	groupName = Row( [ _controlCharStyle( Text( 'P=' ) ), _groupNameStyle( Text( name ) ) ] )
	nameBlock = Script.scriptRSub(  _controlCharStyle( Text( '?' ) ), groupName )
	return _groupBorder.surround( Row( [ _controlCharStyle( Text( '(' ) ), nameBlock, _controlCharStyle( Text( ')' ) ) ] ) )
コード例 #12
0
def augAssignStmt(op, target, value):
    opView = ApplyStyleSheetFromAttribute(PythonEditorStyle.operatorStyle,
                                          Text(op))

    return Span([target, _space, opView, _space, value])
コード例 #13
0
def simpleParam(name):
    return ApplyStyleSheetFromAttribute(PythonEditorStyle.paramStyle,
                                        Text(name))
コード例 #14
0
def pythonEscapedChar(char):
	return _pythonEscapeBorder.surround( Row( [ _controlCharStyle( Text( '\\' ) ), Text( char ) ] ) )
コード例 #15
0
def repeat(subexp, repetitions):
	return _repetition( subexp, Row( [ _controlCharStyle( Text( '{' ) ), Text( repetitions ), _controlCharStyle( Text( '}' ) ) ] ) )
コード例 #16
0
def unparseableText(text):
	return _unparsedTextStyle( Text( text ) )
コード例 #17
0
def literalChar(char):
	return Text( char )
コード例 #18
0
def moduleContentImport(name):
    return ApplyStyleSheetFromAttribute(PythonEditorStyle.importStyle,
                                        Text(name))
コード例 #19
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])
コード例 #20
0
def relativeModule(name):
    return ApplyStyleSheetFromAttribute(PythonEditorStyle.importStyle,
                                        Text(name))
コード例 #21
0
def setFlags(flags):
	flagsText = _flagsStyle( Text( flags ) )
	return _flagsBorder.surround( Row( [ _controlCharStyle( Text( '(?' ) ), flagsText, _controlCharStyle( Text( ')' ) ) ] ) )
コード例 #22
0
def oneOrMore(subexp, greedy):
	return _repetition( subexp, Text( '+?'   if greedy   else '+' ) )
コード例 #23
0
def comment(text):
	commentText = _commentStyle( Text( text ) )
	return _commentBorder.surround( Row( [ _controlCharStyle( Text( '(?#' ) ), commentText, _controlCharStyle( Text( ')' ) ) ] ) )
コード例 #24
0
def repeatRange(subexp, min, max, greedy):
	greedyness = []   if greedy   else [ _controlCharStyle( Text( '?' ) ) ]
	return _repetition( subexp, Row( [ _controlCharStyle( Text( '{' ) ), Text( min ),  _controlCharStyle( Text( ',' ) ), Text( max ), _controlCharStyle( Text( '}' ) ) ]  +  greedyness ) )
コード例 #25
0
def zeroOrMore(subexp, greedy):
	return _repetition( subexp, Text( '*?'   if greedy   else '*' ) )
コード例 #26
0
def kwParamList(name):
    nameView = ApplyStyleSheetFromAttribute(PythonEditorStyle.paramStyle,
                                            Text(name))
    return Span([_doubleAsterisk, nameView])
コード例 #27
0
def optional(subexp, greedy):
	return _repetition( subexp, Text( '??'   if greedy   else '?' ) )
コード例 #28
0
def group(subexp, capturing):
	contents = [ subexp ]   if capturing   else [ _controlCharStyle( Text( '?:' ) ), subexp ]
	b = _groupBorder   if capturing   else _nonCapturingGroupBorder
	return b.surround( Row( [ Segment( Span( [ _controlCharStyle( Text( '(' ) ) ] + contents + [ _controlCharStyle( Text( ')' ) ) ] ) ) ] ) )
コード例 #29
0
def charSetRange(min, max):
	return _charSetItemBorder.surround( Row( [ min, _controlCharStyle( Text( '-' ) ), max ] ) )
コード例 #30
0
def spanCmpOp(op, y):
    opView = ApplyStyleSheetFromAttribute(PythonEditorStyle.operatorStyle,
                                          Text(op))
    return Span([Text(' '), opView, Text(' '), _lineBreak, y])