forked from albertlauncher/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
45 lines (36 loc) · 1.19 KB
/
__init__.py
File metadata and controls
45 lines (36 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-
"""Evaluate simple python expressions.
Synopsis: <trigger> <python expression>"""
from albertv0 import *
from math import *
from builtins import pow
try:
import numpy as np
except ImportError:
pass
import os
__iid__ = "PythonInterface/v0.1"
__prettyname__ = "Python Eval"
__version__ = "1.0"
__trigger__ = "py "
__author__ = "Manuel Schneider"
__dependencies__ = []
iconPath = os.path.dirname(__file__)+"/python.svg"
def handleQuery(query):
if query.isTriggered:
item = Item(id=__prettyname__, icon=iconPath, completion=query.rawString)
stripped = query.string.strip()
if stripped == '':
item.text = "Enter a python expression"
item.subtext = "Math is in the namespace and, if installed, also Numpy as 'np'"
return item
else:
try:
result = eval(stripped)
except Exception as ex:
result = ex
item.text = str(result)
item.subtext = type(result).__name__
item.addAction(ClipAction("Copy result to clipboard", str(result)))
item.addAction(FuncAction("Execute", lambda: exec(str(result))))
return item