-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_example.py
More file actions
109 lines (83 loc) · 2.95 KB
/
api_example.py
File metadata and controls
109 lines (83 loc) · 2.95 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
109
from dataclasses import dataclass, field
# Instead of using dataclass it could also
# subclass BaseDataClass from ulauncher.utils.
# These classes should not include any logic except validation.
@dataclass
class Action:
"""
Base class for actions that can be performed on a result.
"""
type: str = "default"
label: str = "Open" # Default label for the action rendered in the UI
class OpenUrlAction(Action):
type = "open_url"
label = "Open In Browser"
url: str
keep_app_open: bool = False
def __init__(self, url: str, keep_app_open: bool = False) -> None:
super().__init__()
self.url = url
self.keep_app_open = keep_app_open
@dataclass
class Result:
name: str
# First Action in the list is the default action, activated by Enter key.
# If empty, no action will be performed on Enter key.
# For compatibility with current ExtensionResultItem
# we can on_alt_enter as a second action with label "More Actions"
actions: list[Action | object] = field(default_factory=list)
icon: str | None = None
description: str | None = None
compact: bool = False
@dataclass
class ImageResult:
image: str
name: str
description: str | None = None
actions: list[Action | object] = field(default_factory=list)
@dataclass
class DetailResult:
markdown: str # Markdown support with a limited set of features
actions: list[Action | object] = field(default_factory=list)
@dataclass
class RowResultContainer:
items: list[Result] = field(default_factory=list)
show_header: bool = False
header_title: str = ""
@dataclass
class ImageResultContainer:
items: list["ImageResult"] = field(default_factory=list)
show_header: bool = False
header_title: str = ""
@dataclass
class Results:
items: list[Result | RowResultContainer | ImageResultContainer | DetailResult] = (
field(default_factory=list)
)
# just an idea. Could help developers to enable pagination without coding it
auto_pagination: bool = False
items_per_page: int = 10
class Extension:
preferences: dict[str, str]
def __init__(self) -> None:
self.preferences = {}
def set_query_modifiers(
self, modifiers: dict[str, str], default_key: str | None = None
) -> None:
raise NotImplementedError()
def run(self) -> None:
raise NotImplementedError()
def on_input(
self, input_text: str, trigger_id: str
) -> list[Result] | Results | Action | None:
"""
list[RowResult] in the return type is for backward compatibility and convenience
when needed to return a simple list of results.
"""
raise NotImplementedError()
# TODO: action was dataclass in Result but now it's a dict. Need to find a consistent way
def on_action(self, action: dict) -> list[Result] | Results | Action | None:
"""
Extensions should implement this method to handle actions
"""
pass