Skip to content

Commit b13835e

Browse files
[python_eval] Interface v2.0
1 parent 33d6ad9 commit b13835e

File tree

1 file changed

+18
-27
lines changed

1 file changed

+18
-27
lines changed

python_eval/__init__.py

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,30 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (c) 2022-2023 Manuel Schneider
32

4-
from albert import *
53
from builtins import pow
64
from math import *
7-
import os
5+
from pathlib import Path
6+
7+
from albert import *
88

9-
md_iid = '1.0'
10-
md_version = "1.4"
9+
md_iid = '2.0'
10+
md_version = "1.5"
1111
md_name = "Python Eval"
1212
md_description = "Evaluate Python code"
1313
md_license = "BSD-3"
1414
md_url = "https://github.com/albertlauncher/python/tree/master/python_eval"
15-
md_maintainers = "@manuelschneid3r"
16-
17-
18-
class Plugin(TriggerQueryHandler):
19-
20-
def id(self):
21-
return md_id
22-
23-
def name(self):
24-
return md_name
25-
26-
def description(self):
27-
return md_description
2815

29-
def defaultTrigger(self):
30-
return "py "
3116

32-
def synopsis(self):
33-
return "<Python expression>"
17+
class Plugin(PluginInstance, TriggerQueryHandler):
3418

35-
def initialize(self):
36-
self.iconPath = os.path.dirname(__file__)+"/python.svg"
19+
def __init__(self):
20+
TriggerQueryHandler.__init__(self,
21+
id=md_id,
22+
name=md_name,
23+
description=md_description,
24+
synopsis='<Python expression>',
25+
defaultTrigger='py ')
26+
PluginInstance.__init__(self, extensions=[self])
27+
self.iconUrls = [f"file:{Path(__file__).parent}/python.svg"]
3728

3829
def handleTriggerQuery(self, query):
3930
stripped = query.string.strip()
@@ -45,12 +36,12 @@ def handleTriggerQuery(self, query):
4536

4637
result_str = str(result)
4738

48-
query.add(Item(
39+
query.add(StandardItem(
4940
id=md_id,
5041
text=result_str,
5142
subtext=type(result).__name__,
52-
completion=query.trigger + result_str,
53-
icon=[self.iconPath],
43+
inputActionText=query.trigger + result_str,
44+
iconUrls=self.iconUrls,
5445
actions = [
5546
Action("copy", "Copy result to clipboard", lambda r=result_str: setClipboardText(r)),
5647
Action("exec", "Execute python code", lambda r=result_str: exec(stripped)),

0 commit comments

Comments
 (0)