import pn, scintilla @script("Calculator") def DoMaths(): s = scintilla.Scintilla(pn.CurrentDoc()) if s.SelectionEnd - s.SelectionStart < 1: return sel = s.SelText i = eval(sel) if type(i) in [int, float, complex]: pn.AddOutput(str(i))