Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bjarneo/pythonevents

Fire events with dictionary attached, and listen to events. Small library.
https://github.com/bjarneo/pythonevents

Last synced: 3 days ago
JSON representation

Fire events with dictionary attached, and listen to events. Small library.

Awesome Lists containing this project

README

        

PythonEvents
============

Fire events with dictionary attached, and listen to events. Small library.

### Example (see cli.py)
```python
import events

e = events.Events()

e.register('Fire', {
'name': 'Bjarne Oeverli',
'nick': 'bjarneo',
'e-mail': '[email protected]',
'options': {
'uno': 'my first',
'dos': 'my second'
}
})

# Callback
def test(item):
print item

# Listen to event and add callback
e.listen('Fire', test)
# Output:
# {'nick': 'bjarneo', 'options': {'dos': 'my second', 'uno': 'my first'}, 'name': 'Bjarne Oeverli', 'e-mail': '[email protected]'}

# Listen to all events
e.listenAll(test)
# Output:
# {'Fire': {'nick': 'bjarneo', 'options': {'dos': 'my second', 'uno': 'my first'}, 'name': 'Bjarne Oeverli', 'e-mail': '[email protected]'}}

# Listen to event once, and it gets deleted
e.listenOnce('Fire', test)
# Output:
# {'nick': 'bjarneo', 'options': {'dos': 'my second', 'uno': 'my first'}, 'name': 'Bjarne Oeverli', 'e-mail': '[email protected]'}

# Remove event
e.remove('Fire')
```