efro.call

Call related functionality shared between all efro components.

 1# Released under the MIT License. See LICENSE for details.
 2#
 3"""Call related functionality shared between all efro components."""
 4
 5from __future__ import annotations
 6
 7# import functools
 8from typing import TYPE_CHECKING, TypeVar, Generic
 9
10T = TypeVar('T')
11
12if TYPE_CHECKING:
13    pass
14
15
16class SimpleCallbackSet(Generic[T]):
17    """A simple way to manage a set of callbacks."""
18
19    def __init__(self) -> None:
20        self._entries: list[SimpleCallbackSetEntry[T]] = []
21
22    def add(self, call: T) -> None:
23        """Add a callback."""
24        self._entries.append(SimpleCallbackSetEntry(call))
25
26    def getcalls(self) -> list[T]:
27        """Return the current set of registered calls."""
28        return [e.call for e in self._entries]
29
30
31class SimpleCallbackSetEntry(Generic[T]):
32    """An entry for a callback set."""
33
34    def __init__(self, call: T) -> None:
35        self.call = call
class SimpleCallbackSet(typing.Generic[~T]):
17class SimpleCallbackSet(Generic[T]):
18    """A simple way to manage a set of callbacks."""
19
20    def __init__(self) -> None:
21        self._entries: list[SimpleCallbackSetEntry[T]] = []
22
23    def add(self, call: T) -> None:
24        """Add a callback."""
25        self._entries.append(SimpleCallbackSetEntry(call))
26
27    def getcalls(self) -> list[T]:
28        """Return the current set of registered calls."""
29        return [e.call for e in self._entries]

A simple way to manage a set of callbacks.

def add(self, call: ~T) -> None:
23    def add(self, call: T) -> None:
24        """Add a callback."""
25        self._entries.append(SimpleCallbackSetEntry(call))

Add a callback.

def getcalls(self) -> list[~T]:
27    def getcalls(self) -> list[T]:
28        """Return the current set of registered calls."""
29        return [e.call for e in self._entries]

Return the current set of registered calls.

class SimpleCallbackSetEntry(typing.Generic[~T]):
32class SimpleCallbackSetEntry(Generic[T]):
33    """An entry for a callback set."""
34
35    def __init__(self, call: T) -> None:
36        self.call = call

An entry for a callback set.

SimpleCallbackSetEntry(call: ~T)
35    def __init__(self, call: T) -> None:
36        self.call = call
call