|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | # Copyright (c) 2024 Manuel Schneider |
3 | 3 |
|
4 | | -from albert import * |
| 4 | +import albert |
5 | 5 |
|
6 | | -md_iid = '2.3' |
7 | | -md_version = '2.0' |
8 | | -md_name = 'Zeal' |
9 | | -md_description = 'Search in Zeal docs' |
| 6 | +md_iid = "3.0" |
| 7 | +md_version = "3.0" |
| 8 | +md_name = "Zeal" |
| 9 | +md_description = "Search in Zeal docs" |
10 | 10 | md_license = "MIT" |
11 | | -md_url = 'https://github.com/albertlauncher/python/tree/main/zeal' |
| 11 | +md_url = "https://github.com/albertlauncher/python/tree/main/zeal" |
12 | 12 | md_authors = "@manuelschneid3r" |
13 | 13 | md_bin_dependencies = ['zeal'] |
14 | 14 |
|
| 15 | +def createItem(query: str): |
| 16 | + return albert.StandardItem( |
| 17 | + id=md_name, |
| 18 | + text=md_name, |
| 19 | + subtext=f"Search '{query}' in Zeal", |
| 20 | + iconUrls=["xdg:zeal"], |
| 21 | + actions=[albert.Action("zeal", "Search in Zeal", |
| 22 | + lambda q=query: albert.runDetachedProcess(['zeal', q]))] |
| 23 | + ) |
| 24 | + |
| 25 | +class FBH(albert.FallbackHandler): |
| 26 | + |
| 27 | + def id(self): |
| 28 | + return "zeal_fbh" |
| 29 | + |
| 30 | + def name(self): |
| 31 | + return md_name |
| 32 | + |
| 33 | + def description(self): |
| 34 | + return md_description |
15 | 35 |
|
16 | | -class FBH(FallbackHandler): |
17 | 36 | def fallbacks(self, s): |
18 | | - return [Plugin.createItem(s)] if s else [] |
| 37 | + return [createItem(s)] if s else [] |
19 | 38 |
|
20 | 39 |
|
21 | | -class Plugin(PluginInstance, TriggerQueryHandler): |
| 40 | +class Plugin(albert.PluginInstance, albert.TriggerQueryHandler): |
22 | 41 |
|
23 | 42 | def __init__(self): |
24 | | - PluginInstance.__init__(self) |
25 | | - TriggerQueryHandler.__init__( |
26 | | - self, self.id, self.name, self.description, |
27 | | - defaultTrigger='z ' |
28 | | - ) |
29 | | - self.fbh = FBH( |
30 | | - id=self.id + 'fb', |
31 | | - name=self.name, |
32 | | - description=self.description |
33 | | - ) |
34 | | - |
35 | | - self.registerExtension(self.fbh) |
36 | | - |
37 | | - def __del__(self): |
38 | | - self.deregisterExtension(self.fbh) |
| 43 | + albert.PluginInstance.__init__(self) |
| 44 | + albert.TriggerQueryHandler.__init__(self) |
| 45 | + self.fbh = FBH() |
| 46 | + |
| 47 | + def defaultTrigger(self): |
| 48 | + return "z " |
| 49 | + |
| 50 | + def extensions(self): |
| 51 | + return [self, self.fbh] |
39 | 52 |
|
40 | 53 | def handleTriggerQuery(self, query): |
41 | 54 | if stripped := query.string.strip(): |
42 | | - query.add(self.createItem(stripped)) |
43 | | - |
44 | | - @staticmethod |
45 | | - def createItem(query: str) -> Item: |
46 | | - return StandardItem( |
47 | | - id=md_name, |
48 | | - text=md_name, |
49 | | - subtext=f"Search '{query}' in Zeal", |
50 | | - iconUrls=["xdg:zeal"], |
51 | | - actions=[Action("zeal", "Search in Zeal", |
52 | | - lambda q=query: runDetachedProcess(['zeal', q]))] |
53 | | - ) |
54 | | - |
| 55 | + query.add(createItem(stripped)) |
0 commit comments