Skip to main content

A package for event-driven paradigm

Project description

Package Events++

Classes

Events

This class is runtime created and its purpose is to be inhereted by the event-driven target class. It has the following structure:

class Events:
    def _event1(...):
        # Implementation...

    @property
    def event1(self):
        return self._event1

    @event1.setter
    def event1(self, value):
        self._event1 = EventManager.make_event(value)

    def _event2(...):
        # Implementation...

    @property
    def event2(self):
        return self._event1

    @event2.setter
    def event1(self, value):
        self._event2 = EventManager.make_event(value)

    ...

EventManager

This class builds the Events class, which must be inherited by the event-driven target class. Its implementation is omitted in this tutorial for it is not relevant for the package usage.

event_driven function

This function gets events names-docstring tuples as attributes, creates an EventManager instance and returns an Events class ready to be inherited.

Example:

events_class = event_driven(
                    ('event1', '...'),
                    ('event2', '...'),
                    ('event3', '...'),
                    ...
                )

Usage example

class TargetClass(event_driven(('event1', '...'), ('event2', '...'))):
    __slots__ = 'baa', 'foo'

    def __init__(self):
        # Implementation...

    def foo_maker(self, value):
        self.baa = self.event2(baa)
        self.foo = self.event1(value, self.baa)

When an event is declared, it is created as None, so that nothing will happen during the execution of self.event2, nor self.event1(value, self.baa). Furthermore, even though None is not callable, when an event is None, it is simply not called, no exception is called.

target_instance = TargetClass()

@target_instance.set_event1
def new_event1(self, *args):
    # Implementation...

@target_instance.set_event2
def new_event2(self, baa):
    # Implementation...

Those lines would change event1 and event2 behaviour for target_instance. Although it is not a rule, it is undoubtedly a good habit to use docstring to events for the TargetClass implementation probably expects event1 and event2 to have specific arguments, or none.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

EventsPP-0.0.3.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

EventsPP-0.0.3-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page