tuikit/core/signal.py
changeset 109 105b1affc3c2
parent 86 0978fb755d31
equal deleted inserted replaced
97:0c2e0c09ba5c 109:105b1affc3c2
    13 
    13 
    14     Then window.close() will be called.
    14     Then window.close() will be called.
    15 
    15 
    16     """
    16     """
    17 
    17 
    18     def __init__(self):
    18     def __init__(self, allow_stop=False):
    19         self._handlers = []
    19         self._handlers = []
       
    20         #: Allow one of the handlers to stop processing signal
       
    21         #: The handler should return True value,
       
    22         #: then other handlers will not be called
       
    23         self.allow_stop = allow_stop
    20 
    24 
    21     def __call__(self, *args, **kwargs):
    25     def __call__(self, *args, **kwargs):
    22         """Emit the signal to all connected handlers."""
    26         """Emit the signal to all connected handlers."""
    23         for handler in self._handlers:
    27         for handler in self._handlers:
    24             handler(*args, **kwargs)
    28             res = handler(*args, **kwargs)
       
    29             if self.allow_stop and res:
       
    30                 return True
    25 
    31 
    26     def connect(self, handler):
    32     def connect(self, handler):
    27         if not handler in self._handlers:
    33         if not handler in self._handlers:
    28             self._handlers.append(handler)
    34             self._handlers.append(handler)
    29 
    35