Package imagizer :: Module signals |
[hide private]
[frames] | no frames]

# Module signals

source code

Provide Signal class.

A signals implementation.

# Example usage

    >>> class Button:
    ...     def __init__(self):
    ...         # Creating a signal as a member of a class
    ...         self.sigClick = Signal()

    >>> class Listener:
    ...     # a sample method that will be connected to the signal
    ...     def onClick(self):
    ...         print "onClick ", repr(self)

    >>> # a sample function to connect to the signal
    >>> def listenFunction():
    ...     print "listenFunction"

    >>> # a function that accepts arguments
    >>> def listenWithArgs(text):
    ...     print "listenWithArgs: ", text

    >>> b = Button()
    >>> l = Listener()

    >>> b.sigClick.connect(l.onClick)
    >>> b.sigClick()
    onClick  <__main__.Listener instance at 0x4024cf2c>

    >>> # Disconnecting all signals
    >>> b.sigClick.disconnectAll()
    >>> b.sigClick()

    >>> # connecting multiple functions to a signal
    >>> l2 = Listener()
    >>> b.sigClick.connect(l.onClick)
    >>> b.sigClick.connect(l2.onClick)
    >>> b.sigClick()
    onClick  <__main__.Listener instance at 0x4024cf2c>
    onClick  <__main__.Listener instance at 0x4024ce0c>

    >>> # disconnecting individual functions
    >>> b.sigClick.disconnect(l.onClick)
    >>> b.sigClick.connect(listenFunction)
    >>> b.sigClick()
    onClick  <__main__.Listener instance at 0x4024ce0c>
    listenFunction

    >>> # signals disconnecting automatically
    >>> b.sigClick.disconnectAll()
    >>> b.sigClick.connect(l.onClick)
    >>> b.sigClick.connect(l2.onClick)
    >>> del l2
    >>> b.sigClick()
    onClick  <__main__.Listener instance at 0x4024cf2c>

    >>> # example with arguments and a local signal
    >>> sig = Signal()
    >>> sig.connect(listenWithArgs)
    >>> sig("Hello, World!")
    listenWithArgs:  Hello, World!

Based on a Patrick Chasco's code.

Authors:
  Benjamin Longuet, Frederic Mantegazza, Cyrille Boullier

Copyright: 2003-2005

Organization: CEA-Grenoble

License: GPL

Classes | [hide private]
| Signal class Signal.
| _WeakMethod_FuncHost
| WeakMethod This class was generously donated by a poster on ASPN

Variables | [hide private]
| __revision__ = ``'``$Id: signals.py,v 1.2 2007-05-15 15:19:42 jero``...``

Variables Details | [hide private]

  ### __revision__ Value:
      '$Id: imagizer.signals-module.html,v 1.1 2010-04-28 19:44:10 jerome Exp $'