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 (43 loc) · 1.66 KB
/
Copy path__init__.py
File metadata and controls
56 lines (43 loc) · 1.66 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) 2017-2024 Manuel Schneider
import os
import shutil
from albert import *
md_iid = "3.0"
md_version = "2.0"
md_name = "GoldenDict"
md_description = "Quick access to GoldenDict"
md_license = "MIT"
md_url = "https://github.com/albertlauncher/python/tree/main/goldendict"
md_authors = "@manuelschneid3r"
class Plugin(PluginInstance, TriggerQueryHandler):
def __init__(self):
PluginInstance.__init__(self)
TriggerQueryHandler.__init__(self)
commands = [
'/var/lib/flatpak/exports/bin/org.goldendict.GoldenDict', # flatpak
'/var/lib/flatpak/exports/bin/io.github.xiaoyifang.goldendict_ng', # flatpak ng
'goldendict', # native
'goldendict-ng', # native ng
]
executables = [e for e in [shutil.which(c) for c in commands] if e]
if not executables:
raise RuntimeError(f'None of the GoldenDict distributions found.')
self.executable = executables[0]
self.iconUrls = [f'xdg:{os.path.basename(self.executable)}']
if len(executables) > 1:
warning(f"Multiple GoldenDict commands found: {', '.join(executables)}")
warning(f"Using {self.executable}")
def defaultTrigger(self):
return "gd "
def handleTriggerQuery(self, query):
q = query.string.strip()
query.add(
StandardItem(
id=md_name,
text=md_name,
subtext=f"Look up '{q}' in GoldenDict",
iconUrls=self.iconUrls,
actions=[Action(md_name, md_name, lambda e=self.executable: runDetachedProcess([e, q]))],
)
)