Blink allows you to easily bind jQuery-like events to your Python apps.
Python 2.6+ and tested on Python 3+
- nose 1.1.2
- yanc 0.2.3
make install
installs Blink locally in development mode.make uninstall
removes Blink locallymake test
runs the unit test suitemake clean
removes any garbage files that usage and installation generates
$: pip install git+git://github.com/wilhelm-murdoch/blink.git
Or, add the following line to a requirements.txt
file:
-e git+ssh://git@github.com/wilhelm-murdoch/blink.git#egg=blink
from blink import blink
@blink.bind('blink:event')
def blinker_event(message):
print message
blink.trigger('blink:event', message='This is a message.')
>>> 'This is a message.'
Or, create your own blink.Blink
instance to pass throughout your application:
import blink
blinker = blink.Blink()
Bind a callback to the specified event.
def callback(message):
print message
blink.bind('blink:event', callback)
blink.trigger('blink:event', message='This is a message.')
>>> 'This is a message.'
You can also use the blink.bind()
method as a decorator:
@blink.bind('blink:event')
def callback(message):
print message
blink.trigger('blink:event', message='This is a message.')
>>> 'This is a message.'
Unbinds the specified callback
from the specified event
:
blink.unbind('blink:event', callback)
However, if you wish to unbind all callbacks from a specified event
, just leave out the callback
parameter:
blink.unbind('blink:event')
Invokes all callbacks associated with the specified event
name. You may pass
arbitrary arguments through and they will be appear as *args
and or **kwargs
within each associated callback.
from blink import blink
@blink.bind('blink:event')
def blinker_event(*args, **kwargs):
print args, kwargs
blink.trigger('blink:event', 1, 2, 3, 4, foo=True, bar=False)
>>> (1, 2, 3, 4) {'foo': True, 'bar': False}