Exemplo n.º 1
0
    def emit(self, *args, **kwargs):
        """
        Emits the signal which means that all connected handlers will be
        called.

        It is advised to have signals as instance attributes and emit signals
        only in the class which owns the signal::

            class Abc(object):
                def __init__(self):
                    self.colorChanged = Signal('Abc.colorChanged')
                    ...
                def setColor(self, color):
                    ...
                    self.colorChanged.emit(oldColor=self.Color, newColor=color)
                    ...

        Documentation of an signal should be placed to the class documentation
        or to the code (this need to be more specified).

        Calling a signal from outside the class is usually not good
        practice. The only case when it is permitted is when signal is the part
        of some globaly shared object and permission to emit is stayed in the
        documentation.

        The parameters of the emit function must be the same as the parameters
        of the handlers. However, handler can omit some parameters.
        The associated parameters shall be documented for each Signal instance.
        Use only keyword arguments when emitting.

        >>> signal1 = Signal('signal1')
        >>> def mywrite(text):
        ...     print text
        >>> signal1.connect(mywrite)
        >>> signal1.emit(text='Hello')
        Hello
        >>> signal1.emit()
        Traceback (most recent call last):
        TypeError: mywrite() takes exactly 1 argument (0 given)
        >>> signal1.emit('Hello')
        Traceback (most recent call last):
        TypeError: send() got multiple values for keyword argument 'signal'
        """
        dispatcher.send(signal=self, *args, **kwargs)
Exemplo n.º 2
0
    def emit(self, *args, **kwargs):
        """
        Emits the signal which means that all connected handlers will be
        called.

        It is advised to have signals as instance attributes and emit signals
        only in the class which owns the signal::

            class Abc(object):
                def __init__(self):
                    self.colorChanged = Signal('Abc.colorChanged')
                    ...
                def setColor(self, color):
                    ...
                    self.colorChanged.emit(oldColor=self.Color, newColor=color)
                    ...

        Documentation of an signal should be placed to the class documentation
        or to the code (this need to be more specified).

        Calling a signal from outside the class is usually not good
        practice. The only case when it is permitted is when signal is the part
        of some globaly shared object and permision to emit is stayed in the
        documentation.

        The parameters of the emit function must be the same as the parameters
        of the handlers. However, handler can ommit some parameters.
        The associated parameters shall be documented for each Signal instance.
        Use only keyword arguments when emitting.

        >>> signal1 = Signal('signal1')
        >>> def mywrite(text):
        ...     print text
        >>> signal1.connect(mywrite)
        >>> signal1.emit(text='Hello')
        Hello
        >>> signal1.emit()
        Traceback (most recent call last):
        TypeError: mywrite() takes exactly 1 argument (0 given)
        >>> signal1.emit('Hello')
        Traceback (most recent call last):
        TypeError: send() got multiple values for keyword argument 'signal'
        """
        dispatcher.send(signal=self, *args, **kwargs)