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
108 lines (85 loc) · 3.3 KB
/
Copy path__init__.py
File metadata and controls
108 lines (85 loc) · 3.3 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# -*- coding: utf-8 -*-
"""This is a simple python template extension that should show the API in a comprehensible way. \
Use the module docstring to provide a detailed description of the extension"""
from albertv0 import *
import os
from time import sleep
__iid__ = "PythonInterface/v0.1"
__prettyname__ = "Api Test"
__version__ = "1.0"
__trigger__ = "test "
__author__ = "Manuel Schneider"
__dependencies__ = ["whatever"]
iconPath = iconLookup("albert")
# Can be omitted
def initialize():
pass
# Can be omitted
def finalize():
pass
def handleQuery(query):
if not query.isTriggered:
return
# Note that when storing a reference to query, e.g. in a closure, you must not use
# query.isValid. Apart from the query beeing invalid anyway it will crash the appplication.
# The Python type holds a pointer to the C++ type used for isValid(). The C++ type will be
# deleted when the query is finished. Therfore getting isValid will result in a SEGFAULT.
if query.string.startswith("delay"):
sleep(2)
return Item(id=__prettyname__,
icon=os.path.dirname(__file__)+"/plugin.svg",
text="Delayed test item",
subtext="Query string: %s" % query.string)
if query.string.startswith("throw"):
raise ValueError('EXPLICITLY REQUESTED TEST EXCEPTION!')
info(query.string)
info(query.rawString)
info(query.trigger)
info(str(query.isTriggered))
info(str(query.isValid))
critical(query.string)
warning(query.string)
debug(query.string)
debug(query.string)
results = []
item = Item()
item.icon = iconPath
item.text = 'Python item containing %s' % query.string
item.subtext = 'Python description'
item.completion = __trigger__ + 'Completion Harharhar'
item.urgency = ItemBase.Notification # Alert, Normal
info(item.icon)
info(item.text)
info(item.subtext)
info(item.completion)
info(str(item.urgency))
def function(): info(query.string)
item.addAction(FuncAction("Print info", function))
item.addAction(FuncAction("Print warning", lambda: warning(query.string)))
results.append(item)
item = Item(id=__prettyname__,
icon=os.path.dirname(__file__)+"/plugin.svg",
text="This is the primary text",
subtext="This is the subtext, some kind of description",
completion=__trigger__ + 'Hellooohooo!',
urgency=ItemBase.Alert,
actions=[
FuncAction(text="FuncAction",
callable=lambda: critical(query.string)),
ClipAction(text="ClipAction",
clipboardText="blabla"),
UrlAction(text="UrlAction",
url="https://www.google.de"),
ProcAction(text="ProcAction",
commandline=["espeak", "hello"],
cwd="~"), # optional
TermAction(text="TermAction",
commandline=["sleep", "5"],
cwd="~/git") # optional
])
results.append(item)
# Api v 0.2
info(configLocation())
info(cacheLocation())
info(dataLocation())
return results