def conditionalExpr(ctx, style, condition, expr, elseExpr): conditionalSpacing = style.get(PythonEditorStyle.conditionalSpacing) return LineBreakCostSpan([ expr, Whitespace(' ', conditionalSpacing), _lineBreak, _keyword('if'), _space, condition, Whitespace(' ', conditionalSpacing), _lineBreak, _keyword('else'), _space, elseExpr ]).present(ctx, style)
def dictComp(ctx, style, resultExpr, comprehensionItems): comprehensionSpacing = style.get(PythonEditorStyle.comprehensionSpacing) itemViewsSpaced = [] if len(comprehensionItems) > 0: for x in comprehensionItems[:-1]: itemViewsSpaced.append(x) itemViewsSpaced.append(Whitespace(' ', comprehensionSpacing)) itemViewsSpaced.append(_lineBreak) itemViewsSpaced.append(comprehensionItems[-1]) return LineBreakCostSpan( [_openBrace, resultExpr, Whitespace(' ', comprehensionSpacing)] + itemViewsSpaced + [_closeBrace]).present(ctx, style)
def call(target, args, bArgsTrailingSeparator): argElements = [] if len(args) > 0: argElements.append(_space) argSpanElements = [] for a in args[:-1]: argSpanElements.append(a) argSpanElements.append(_comma) argSpanElements.append(_space) argSpanElements.append(_lineBreak) argSpanElements.append(args[-1]) if bArgsTrailingSeparator: argSpanElements.append(_comma) argElements.append(ParagraphIndentMatchSpan(argSpanElements)) argElements.append(_space) return LineBreakCostSpan([target, _openParen] + argElements + [_closeParen])
def lambdaExpr(params, bParamsTrailingSeparator, expr): elements = [] if len(params) > 0: for p in params[:-1]: elements.append(p) elements.append(_comma) elements.append(_space) elements.append(_lineBreak) elements.append(params[-1]) if bParamsTrailingSeparator: elements.append(_comma) elements.append(_space) elements.append(_lineBreak) return LineBreakCostSpan([ _keyword('lambda'), _space, ParagraphIndentMatchSpan(elements), _colon, _space, _lineBreak, expr ])
def compare(x, cmpOps): return LineBreakCostSpan([x] + cmpOps)
def spanBinOp(x, y, op): opView = ApplyStyleSheetFromAttribute(PythonEditorStyle.operatorStyle, Text(op)) return LineBreakCostSpan([x, Text(' '), opView, Text(' '), _lineBreak, y])
def spanPrefixOp(x, op): opView = ApplyStyleSheetFromAttribute(PythonEditorStyle.operatorStyle, Text(op)) return LineBreakCostSpan([opView, x])