Open source cms for mobile and desktop websites

nive.events

Object based events

Events are object based and registered with the object itself. So they will only be called as long as the object exists and are meant in the first place to be used in conjunction with object extension.

Events work quite simple: the signal representing the event is just a string and is registered in combination with a function. If the event is fired somewhere, the linked function will be called with event specific paramaters.

signals have not to be registered. They are just fired by calling Signal(signal).

Every object and root fires the init event linked to Init() on creation. So it is not necessary to register for init yourself and but use it as plugin point to register your own events.

For example if you would like to get your function Edit() called if the object is updated, add this function to your objects class:

class myObject:

    def Init(self):
        self.ListenEvent("update", "Edit")
    

    def Edit(self, data):
        # e.g. process data 
        return

Inventing custom events is quite easy:

def SomeEvent(self):
    self.Signal("some_event")

For non Object or Root derived classes initialize the event system by adding a signal to the __init__ function:

def __init__(self):
    self.Signal("init")
© 2013 Nive GmbH