How to use the eventkit.ops.op.Op function in eventkit

To help you get started, we’ve selected a few eventkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github erdewit / eventkit / eventkit / ops / timing.py View on Github external
# update status and schedule new emits
        if q:
            if not self._is_throttling:
                self.status_event.emit(True)
            loop.call_at(times[0] + self._interval, self._try_emit)
        elif self._is_throttling:
            self.status_event.emit(False)
        self._is_throttling = bool(q)

        if not q and self._source is None:
            self.set_done()
            self.status_event.set_done()


class Sample(Op):
    __slots__ = ('_timer',)

    def __init__(self, timer, source=None):
        Op.__init__(self, source)
        self._timer = timer
        timer.connect(
            self._on_timer,
            self.on_source_error,
            self.on_source_done)

    def on_source(self, *args):
        self._value = args

    def _on_timer(self, *args):
        if self._value is not NO_VALUE:
            self.emit(*self._value)
github erdewit / eventkit / eventkit / ops / array.py View on Github external
class ArrayMax(Op):
    __slots__ = ()

    def on_source(self, arg):
        self.emit(arg.max())


class ArraySum(Op):
    __slots__ = ()

    def on_source(self, arg):
        self.emit(arg.sum())


class ArrayProd(Op):
    __slots__ = ()

    def on_source(self, arg):
        self.emit(arg.prod())


class ArrayMean(Op):
    __slots__ = ()

    def on_source(self, arg):
        self.emit(arg.mean())


class ArrayStd(Op):
    __slots__ = ()
github erdewit / eventkit / eventkit / ops / aggregate.py View on Github external
class Sum(Reduce):
    __slots__ = ()

    def __init__(self, start=0, source=None):
        Reduce.__init__(self, operator.add, start, source)


class Product(Reduce):
    __slots__ = ()

    def __init__(self, start=1, source=None):
        Reduce.__init__(self, operator.mul, start, source)


class Mean(Op):
    __slots__ = ('_count', '_sum')

    def __init__(self, source=None):
        Op.__init__(self, source)
        self._count = 0
        self._sum = 0

    def on_source(self, arg):
        self._count += 1
        self._sum += arg
        self.emit(self._sum / self._count)


class Any(Reduce):
    __slots__ = ()
github erdewit / eventkit / eventkit / ops / aggregate.py View on Github external
def __init__(self, source=None):
        Op.__init__(self, source)
        self._values = []

    def on_source(self, *args):
        self._values.append(
            args[0] if len(args) == 1 else args if args else NO_VALUE)

    def on_source_done(self, source):
        self.emit(self._values)
        self._disconnect_from(self._source)
        self._source = None
        self.set_done()


class Deque(Op):
    __slots__ = ('_count', '_q')

    def __init__(self, count, source=None):
        Op.__init__(self, source)
        self._count = count
        self._q = deque()

    def on_source(self, *args):
        self._q.append(
            args[0] if len(args) == 1 else args if args else NO_VALUE)
        if self._count and len(self._q) > self._count:
            self._q.popleft()
        self.emit(self._q)
github erdewit / eventkit / eventkit / ops / array.py View on Github external
class ArrayProd(Op):
    __slots__ = ()

    def on_source(self, arg):
        self.emit(arg.prod())


class ArrayMean(Op):
    __slots__ = ()

    def on_source(self, arg):
        self.emit(arg.mean())


class ArrayStd(Op):
    __slots__ = ()

    def on_source(self, arg):
        self.emit(arg.std(ddof=1) if len(arg) > 1 else np.nan)


class ArrayAny(Op):
    __slots__ = ()

    def on_source(self, arg):
        self.emit(arg.any())


class ArrayAll(Op):
    __slots__ = ()
github erdewit / eventkit / eventkit / ops / aggregate.py View on Github external
__slots__ = ('_prev', '_has_prev')

    def __init__(self, source=None):
        Op.__init__(self, source)
        self._has_prev = False

    def on_source(self, *args):
        value = args[0] if len(args) == 1 else args if args else NO_VALUE
        if self._has_prev:
            self.emit(self._prev, value)
        else:
            self._has_prev = True
        self._prev = value


class List(Op):
    __slots__ = ('_values')

    def __init__(self, source=None):
        Op.__init__(self, source)
        self._values = []

    def on_source(self, *args):
        self._values.append(
            args[0] if len(args) == 1 else args if args else NO_VALUE)

    def on_source_done(self, source):
        self.emit(self._values)
        self._disconnect_from(self._source)
        self._source = None
        self.set_done()
github erdewit / eventkit / eventkit / ops / timing.py View on Github external
from collections import deque

from ..event import Event
from ..util import NO_VALUE, loop
from .op import Op


class Delay(Op):
    __slots__ = ('_delay',)

    def __init__(self, delay, source=None):
        Op.__init__(self, source)
        self._delay = delay

    def on_source(self, *args):
        loop.call_later(self._delay, self.emit, *args)

    def on_source_error(self, error):
        loop.call_later(self._delay, self.error_event.emit, error)

    def on_source_done(self, source):
        loop.call_later(self._delay, self.set_done)