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 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 ) )
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 ) )
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)
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)
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 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 matchNumberedGroup(number): groupNumber = _groupNumberStyle( Text( number ) ) return _groupBorder.surround( Row( [ _controlCharStyle( Text( '\\' ) ), groupNumber ] ) )
def lookbehind(subexp, positive): posNegIndicator = _controlCharStyle( Text( '=' ) ) if positive else _invertControlCharStyle( Text( '!' ) ) return _lookbehindBorder.surround( Row( [ _controlCharStyle( Text( '(?<' ) ), posNegIndicator, subexp, _controlCharStyle( Text( ')' ) ) ] ) )
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( ')' ) ) ] ) )
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( ')' ) ) ] ) )
def augAssignStmt(op, target, value): opView = ApplyStyleSheetFromAttribute(PythonEditorStyle.operatorStyle, Text(op)) return Span([target, _space, opView, _space, value])
def simpleParam(name): return ApplyStyleSheetFromAttribute(PythonEditorStyle.paramStyle, Text(name))
def pythonEscapedChar(char): return _pythonEscapeBorder.surround( Row( [ _controlCharStyle( Text( '\\' ) ), Text( char ) ] ) )
def repeat(subexp, repetitions): return _repetition( subexp, Row( [ _controlCharStyle( Text( '{' ) ), Text( repetitions ), _controlCharStyle( Text( '}' ) ) ] ) )
def unparseableText(text): return _unparsedTextStyle( Text( text ) )
def literalChar(char): return Text( char )
def moduleContentImport(name): return ApplyStyleSheetFromAttribute(PythonEditorStyle.importStyle, Text(name))
def moduleImportAs(name, asName): nameView = ApplyStyleSheetFromAttribute(PythonEditorStyle.importStyle, Text(name)) asNameView = ApplyStyleSheetFromAttribute(PythonEditorStyle.importStyle, Text(asName)) return Span([nameView, _space, _keyword('as'), _space, asNameView])
def relativeModule(name): return ApplyStyleSheetFromAttribute(PythonEditorStyle.importStyle, Text(name))
def setFlags(flags): flagsText = _flagsStyle( Text( flags ) ) return _flagsBorder.surround( Row( [ _controlCharStyle( Text( '(?' ) ), flagsText, _controlCharStyle( Text( ')' ) ) ] ) )
def oneOrMore(subexp, greedy): return _repetition( subexp, Text( '+?' if greedy else '+' ) )
def comment(text): commentText = _commentStyle( Text( text ) ) return _commentBorder.surround( Row( [ _controlCharStyle( Text( '(?#' ) ), commentText, _controlCharStyle( Text( ')' ) ) ] ) )
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 ) )
def zeroOrMore(subexp, greedy): return _repetition( subexp, Text( '*?' if greedy else '*' ) )
def kwParamList(name): nameView = ApplyStyleSheetFromAttribute(PythonEditorStyle.paramStyle, Text(name)) return Span([_doubleAsterisk, nameView])
def optional(subexp, greedy): return _repetition( subexp, Text( '??' if greedy else '?' ) )
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( ')' ) ) ] ) ) ] ) )
def charSetRange(min, max): return _charSetItemBorder.surround( Row( [ min, _controlCharStyle( Text( '-' ) ), max ] ) )
def spanCmpOp(op, y): opView = ApplyStyleSheetFromAttribute(PythonEditorStyle.operatorStyle, Text(op)) return Span([Text(' '), opView, Text(' '), _lineBreak, y])