-
Notifications
You must be signed in to change notification settings - Fork 18
/
main.py
49 lines (36 loc) · 1.94 KB
/
main.py
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
import json
import logging
from time import sleep
from ulauncher.api.client.Extension import Extension
from ulauncher.api.client.EventListener import EventListener
from ulauncher.api.shared.event import KeywordQueryEvent, ItemEnterEvent
from ulauncher.api.shared.item.ExtensionResultItem import ExtensionResultItem
from ulauncher.api.shared.action.RenderResultListAction import RenderResultListAction
from ulauncher.api.shared.action.ExtensionCustomAction import ExtensionCustomAction
from ulauncher.api.shared.action.HideWindowAction import HideWindowAction
logger = logging.getLogger(__name__)
class DemoExtension(Extension):
def __init__(self):
super(DemoExtension, self).__init__()
self.subscribe(KeywordQueryEvent, KeywordQueryEventListener())
self.subscribe(ItemEnterEvent, ItemEnterEventListener())
class KeywordQueryEventListener(EventListener):
def on_event(self, event, extension):
items = []
logger.info('preferences %s' % json.dumps(extension.preferences))
for i in range(5):
item_name = extension.preferences['item_name']
data = {'new_name': '%s %s was clicked' % (item_name, i)}
items.append(ExtensionResultItem(icon='images/icon.png',
name='%s %s' % (item_name, i),
description='Item description %s' % i,
on_enter=ExtensionCustomAction(data, keep_app_open=True)))
return RenderResultListAction(items)
class ItemEnterEventListener(EventListener):
def on_event(self, event, extension):
data = event.get_data()
return RenderResultListAction([ExtensionResultItem(icon='images/icon.png',
name=data['new_name'],
on_enter=HideWindowAction())])
if __name__ == '__main__':
DemoExtension().run()