forked from James-Dumas/ulauncher-run
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·44 lines (33 loc) · 1.54 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
from ulauncher.api.client.Extension import Extension
from ulauncher.api.shared.action.ExtensionCustomAction import ExtensionCustomAction
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.HideWindowAction import HideWindowAction
import subprocess
class RunExtension(Extension):
def __init__(self):
super(RunExtension, self).__init__()
self.subscribe(KeywordQueryEvent, KeywordQueryEventListener())
self.subscribe(ItemEnterEvent, ItemEnterEventListener())
class KeywordQueryEventListener(EventListener):
def on_event(self, event, extension):
data = event.get_argument()
items = [
ExtensionResultItem(
icon="icon.png",
name="Emacs",
description="Open emacs client" if not data else 'Edit %s in emacs' % data,
on_enter=ExtensionCustomAction(data),
),
]
return RenderResultListAction(items)
class ItemEnterEventListener(EventListener):
def on_event(self, event, extension):
data = event.get_data() or ""
command= 'emacsclient -n -c '+data
subprocess.Popen(command, shell=True)
return RenderResultListAction([])
if __name__ == '__main__':
RunExtension().run()