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
56 lines (44 loc) · 1.44 KB
/
__init__.py
File metadata and controls
56 lines (44 loc) · 1.44 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
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
# Copyright (c) 2022-2023 Manuel Schneider
from albert import *
from builtins import pow
from math import *
import os
md_iid = "0.5"
md_version = "1.2"
md_name = "Python Eval"
md_description = "Evaluate Python code"
md_license = "BSD-3"
md_url = "https://github.com/albertlauncher/python/tree/master/python_eval"
md_maintainers = "@manuelschneid3r"
class Plugin(QueryHandler):
def id(self):
return md_id
def name(self):
return md_name
def description(self):
return md_description
def defaultTrigger(self):
return "py "
def synopsis(self):
return "<Python expression>"
def initialize(self):
self.iconPath = os.path.dirname(__file__)+"/python.svg"
def handleQuery(self, query):
stripped = query.string.strip()
if stripped:
try:
result = str(eval(stripped))
except Exception as ex:
result = str(ex)
query.add(Item(
id=md_id,
text=str(result),
subtext=type(result).__name__,
completion=query.trigger + result,
icon=[self.iconPath],
actions = [
Action("copy", "Copy result to clipboard", lambda r=str(result): setClipboardText(r)),
Action("exec", "Execute python code", lambda r=str(result): exec(stripped)),
]
))