File size: 10,544 Bytes
1a942eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
from typing import Any, Literal, NotRequired, Protocol, Self, TypedDict

import dataclasses
from collections import UserString
from collections.abc import Callable, Sequence
from collections.abc import Set as AbstractSet

from _typeshed import SupportsKeysAndGetItem

from gradio.blocks import Block, BlockContext, Component
from gradio.components import Timer
from gradio.data_classes import FileData, FileDataDict

type Dependency = _Dependency[Any, Any, Any]
type EventListenerCallable = _EventListenerCallable[Any, Any, Any]
type EventListener = _EventListener[Any, Any, Any]

class _EventListenerCallable[T, V, **P](Protocol):
    def __call__(
        self,
        fn: Callable[P, T] | Literal["decorator"] | None = "decorator",
        inputs: (
            Component
            | BlockContext
            | Sequence[Component | BlockContext]
            | AbstractSet[Component | BlockContext]
            | None
        ) = None,
        outputs: (
            Component
            | BlockContext
            | Sequence[Component | BlockContext]
            | AbstractSet[Component | BlockContext]
            | None
        ) = None,
        api_name: str | Literal[False] | None = None,
        scroll_to_output: bool = False,
        show_progress: Literal["full", "minimal", "hidden"] = "full",
        queue: bool = True,
        batch: bool = False,
        max_batch_size: int = 4,
        preprocess: bool = True,
        postprocess: bool = True,
        cancels: Dependency | list[Dependency] | None = None,
        trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
        js: str | None = None,
        concurrency_limit: int | Literal["default"] | None = "default",
        concurrency_id: str | None = None,
        show_api: bool = True,
        stream_every: float = 0.5,
        like_user_message: bool = False,
    ) -> _Dependency[T, V, P]: ...

class _EventListenerCallableFull[T, V, **P](Protocol):
    def __call__(
        self,
        block: Block | None,
        fn: Callable[P, T] | Literal["decorator"] | None = "decorator",
        inputs: (
            Component
            | BlockContext
            | Sequence[Component | BlockContext]
            | AbstractSet[Component | BlockContext]
            | None
        ) = None,
        outputs: (
            Component
            | BlockContext
            | Sequence[Component | BlockContext]
            | AbstractSet[Component | BlockContext]
            | None
        ) = None,
        api_name: str | Literal[False] | None = None,
        scroll_to_output: bool = False,
        show_progress: Literal["full", "minimal", "hidden"] = "full",
        queue: bool = True,
        batch: bool = False,
        max_batch_size: int = 4,
        preprocess: bool = True,
        postprocess: bool = True,
        cancels: Dependency | list[Dependency] | None = None,
        trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
        js: str | None = None,
        concurrency_limit: int | Literal["default"] | None = "default",
        concurrency_id: str | None = None,
        show_api: bool = True,
        time_limit: int | None = None,
        stream_every: float = 0.5,
        like_user_message: bool = False,
    ) -> _Dependency[T, V, P]: ...

def set_cancel_events(
    triggers: Sequence[EventListenerMethod],
    cancels: Dependency | list[Dependency] | None,
) -> None: ...

class _Dependency[T, V, **P](dict[str, V]):
    fn: Callable[P, T]
    associated_timer: Timer | None
    then: EventListenerCallable
    success: EventListenerCallable

    def __init__(
        self,
        trigger: Block | None,
        key_vals: SupportsKeysAndGetItem[str, V],
        dep_index: int | None,
        fn: Callable[P, T],
        associated_timer: Timer | None = None,
    ) -> None: ...
    def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T: ...

class EventData[T]:
    target: Block | None
    _data: T

    def __init__(self, target: Block | None, _data: T) -> None: ...

class _SelectData(TypedDict):
    index: int | tuple[int, int]
    value: Any
    row_value: NotRequired[list[Any]]
    col_value: NotRequired[list[Any]]
    selected: NotRequired[bool]

class SelectData(EventData[_SelectData]):
    index: int | tuple[int, int]
    value: Any
    row_value: list[Any] | None
    col_value: list[Any] | None
    selected: bool

    def __init__(self, target: Block | None, data: _SelectData) -> None: ...

class _KeyUpData(TypedDict):
    key: str
    input_value: str

class KeyUpData(EventData[_KeyUpData]):
    key: str
    input_value: str

    def __init__(self, target: Block | None, data: _KeyUpData) -> None: ...

class DeletedFileData(EventData[FileDataDict]):
    file: FileData

    def __init__(self, target: Block | None, data: FileDataDict) -> None: ...

class _LikeData(TypedDict):
    index: int | tuple[int, int]
    value: Any
    liked: NotRequired[bool]

class LikeData(EventData[_LikeData]):
    index: int | tuple[int, int]
    value: Any
    liked: bool

    def __init__(self, target: Block | None, data: _LikeData) -> None: ...

class _RetryData(TypedDict):
    index: int | tuple[int, int]
    value: Any

class RetryData(EventData[_RetryData]):
    index: int | tuple[int, int]
    value: Any

    def __init__(self, target: Block | None, data: _RetryData) -> None: ...

class _UndoData(TypedDict):
    index: int | tuple[int, int]
    value: Any

class UndoData(EventData[_UndoData]):
    index: int | tuple[int, int]
    value: Any

    def __init__(self, target: Block | None, data: _UndoData) -> None: ...

class DownloadData(EventData[FileDataDict]):
    file: FileData

    def __init__(self, target: Block | None, data: FileDataDict) -> None: ...

@dataclasses.dataclass
class EventListenerMethod:
    block: Block | None
    event_name: str

class _EventListener[T, V, **P](UserString):
    __slots__ = (
        "callback",
        "config_data",
        "connection",
        "doc",
        "event_name",
        "event_specific_args",
        "has_trigger",
        "listener",
        "show_progress",
        "trigger_after",
        "trigger_only_on_success",
    )

    event_name: str
    has_trigger: bool
    config_data: Callable[..., dict[str, T]]
    show_progress: Literal["full", "minimal", "hidden"]
    callback: Callable[[Block], None] | None
    trigger_after: int | None
    trigger_only_on_success: bool
    doc: str
    connection: Literal["sse", "stream"]
    event_specific_args: list[dict[str, str]]
    listener: _EventListenerCallableFull[T, V, P]

    def __new__(
        cls,
        event_name: str,
        has_trigger: bool = True,
        config_data: Callable[..., dict[str, T]] = dict,  # noqa: PYI011
        show_progress: Literal["full", "minimal", "hidden"] = "full",
        callback: Callable[[Block], None] | None = None,
        trigger_after: int | None = None,
        trigger_only_on_success: bool = False,
        doc: str = "",
        connection: Literal["sse", "stream"] = "sse",
        event_specific_args: list[dict[str, str]] | None = None,
    ) -> Self: ...
    def __init__(
        self,
        event_name: str,
        has_trigger: bool = True,
        config_data: Callable[..., dict[str, T]] = dict,  # noqa: PYI011
        show_progress: Literal["full", "minimal", "hidden"] = "full",
        callback: Callable[[Block], None] | None = None,
        trigger_after: int | None = None,
        trigger_only_on_success: bool = False,
        doc: str = "",
        connection: Literal["sse", "stream"] = "sse",
        event_specific_args: list[dict[str, str]] | None = None,
    ) -> None: ...
    def set_doc(self, component: str) -> None: ...
    def copy(self) -> _EventListener[T, V, P]: ...
    @staticmethod
    def _setup(
        _event_name: str,
        _has_trigger: bool,
        _show_progress: Literal["full", "minimal", "hidden"],
        _callback: Callable[[Block], None] | None,
        _trigger_after: int | None,
        _trigger_only_on_success: bool,
        _event_specific_args: list[dict[str, str]],
        _connection: Literal["sse", "stream"] = "sse",
    ) -> _EventListenerCallableFull[T, V, P]: ...

def on[T, **P](
    triggers: Sequence[EventListenerCallable] | EventListenerCallable | None = None,
    fn: Callable[P, T] | Literal["decorator"] | None = "decorator",
    inputs: (
        Component
        | BlockContext
        | Sequence[Component | BlockContext]
        | AbstractSet[Component | BlockContext]
        | None
    ) = None,
    outputs: (
        Component
        | BlockContext
        | Sequence[Component | BlockContext]
        | AbstractSet[Component | BlockContext]
        | None
    ) = None,
    *,
    api_name: str | Literal[False] | None = None,
    scroll_to_output: bool = False,
    show_progress: Literal["full", "minimal", "hidden"] = "full",
    queue: bool = True,
    batch: bool = False,
    max_batch_size: int = 4,
    preprocess: bool = True,
    postprocess: bool = True,
    cancels: Dependency | list[Dependency] | None = None,
    trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
    js: str | None = None,
    concurrency_limit: int | Literal["default"] | None = "default",
    concurrency_id: str | None = None,
    show_api: bool = True,
    time_limit: int | None = None,
    stream_every: float = 0.5,
) -> _Dependency[T, Any, P]: ...

class Events:
    change: EventListener
    input: EventListener
    click: EventListener
    double_click: EventListener
    submit: EventListener
    edit: EventListener
    clear: EventListener
    play: EventListener
    pause: EventListener
    stop: EventListener
    end: EventListener
    start_recording: EventListener
    pause_recording: EventListener
    stop_recording: EventListener
    focus: EventListener
    blur: EventListener
    upload: EventListener
    release: EventListener
    select: EventListener
    stream: EventListener
    like: EventListener
    example_select: EventListener
    load: EventListener
    key_up: EventListener
    apply: EventListener
    delete: EventListener
    tick: EventListener
    undo: EventListener
    retry: EventListener
    expand: EventListener
    collapse: EventListener
    download: EventListener

__all__ = [
    "DeletedFileData",
    "Dependency",
    "DownloadData",
    "EventData",
    "EventListener",
    "EventListenerMethod",
    "Events",
    "KeyUpData",
    "LikeData",
    "RetryData",
    "SelectData",
    "UndoData",
    "on",
    "set_cancel_events",
]