3 <_r&@sjddlZddlmZdejko(dknr6ddZGdd d eZGd d d eZd d ZddZ dS)N)_gicCs t|dS)N__call__)hasattr)fnr %/usr/lib64/python3.6/_signalhelper.pycallablesr c@sjeZdZdZGdddeZdddZddejdddddfdd Z dd d Z d d Z dddZ ddZ dS)SignalaObject which gives a nice API for creating and binding signals. :param name: Name of signal or callable closure when used as a decorator. :type name: str or callable :param callable func: Callable closure method. :param GObject.SignalFlags flags: Flags specifying when to run closure. :param type return_type: Return type of the Signal. :param list arg_types: List of argument types specifying the signals function signature :param str doc: Documentation of signal object. :param callable accumulator: Accumulator method with the signature: func(ihint, return_accu, handler_return, accu_data) -> boolean :param object accu_data: User data passed to the accumulator. :Example: .. code-block:: python class Spam(GObject.Object): velocity = 0 @GObject.Signal def pushed(self): self.velocity += 1 @GObject.Signal(flags=GObject.SignalFlags.RUN_LAST) def pulled(self): self.velocity -= 1 stomped = GObject.Signal('stomped', arg_types=(int,)) @GObject.Signal def annotated_signal(self, a:int, b:str): "Python3 annotation support for parameter types. def on_pushed(obj): print(obj) spam = Spam() spam.pushed.connect(on_pushed) spam.pushed.emit() c@sPeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dS)zSignal.BoundSignalz Temporary binding object which can be used for connecting signals without specifying the signal name string to connect. cOs tj||S)N)str__new__)clsnameargskargsr r r rXszSignal.BoundSignal.__new__cCstj|||_||_dS)N)r __init__signalgobj)selfrrr r r r[s zSignal.BoundSignal.__init__cCsd|S)NzBoundSignal("%s")r )rr r r __repr__`szSignal.BoundSignal.__repr__cOs|jj|jf||S)zCall the signals closure.)rfuncr)rrrr r r rcszSignal.BoundSignal.__call__cOs|jj||f||S)z^Same as GObject.Object.connect except there is no need to specify the signal name.)rconnect)rcallbackrrr r r rgszSignal.BoundSignal.connectcOs|jj|d||f||S)a Same as GObject.Object.connect except there is no need to specify the signal name. In addition concats "::" to the signal name when connecting; for use with notifications like "notify" when a property changes. z::)rr)rrZdetailrrr r r connect_detailedlsz#Signal.BoundSignal.connect_detailedcCs|jj|dS)z"Same as GObject.Object.disconnect.N)instance disconnect)rZ handler_idr r r rtszSignal.BoundSignal.disconnectcOs|jjt|f||S)z[Same as GObject.Object.emit except there is no need to specify the signal name.)remitr )rrrr r r rxszSignal.BoundSignal.emitN) __name__ __module__ __qualname____doc__rrrrrrrrr r r r BoundSignalSsr#cOst|r|j}tj||S)N)r rr r)rrrrr r r r}szSignal.__new__Nc Cs|r| r|j}nt|r$|}|j}|r4| r4|j}tj||rX|pH| rXt|\}}|dkrft}||_||_||_ ||_ ||_||_ ||_ dS)N) rr r"r rget_signal_annotationstuplerflags return_type arg_types accumulator accu_data) rrrr'r(r)docr*r+r r r rs&    zSignal.__init__cCs|dkr |S|j||S)z:Returns a BoundSignal when accessed on an object instance.N)r#)rrownerr r r __get__szSignal.__get__c Osdt|tjr |j|f||n@t|r2t|}n|j}t||||j|j|j |j |j |j dSdS)zmAllows for instantiated Signals to be used as a decorator or calling of the underlying signal method.)rrr'r(r)r,r*r+N) isinstancerZGObjectrr rtyper'r(r)r"r*r+)robjrrrr r r rs  zSignal.__call__c Cs8|dkr|j}t|||j|j|j|j|j|j|jdS)z%Returns a renamed copy of the Signal.N)rrr'r(r)r,r*r+) rr0rr'r(r)r"r*r+)rZnewNamer r r copys z Signal.copycCs|j|j|j|j|jfS)zKReturns a tuple of: (flags, return_type, arg_types, accumulator, accu_data))r'r(r)r*r+)rr r r get_signal_argsszSignal.get_signal_args)r$)N)N)rr r!r"r r#rrZSIGNAL_RUN_FIRSTrr.rr2r3r r r r r !s1*   r c@seZdZdZddZdS)SignalOverridea&Specialized sub-class of Signal which can be used as a decorator for overriding existing signals on GObjects. :Example: .. code-block:: python class MyWidget(Gtk.Widget): @GObject.SignalOverride def configure_event(self): pass cCsdS)zReturns the string 'override'.overrider )rr r r r3szSignalOverride.get_signal_argsN)rr r!r"r3r r r r r4s r4csZt}d}t|drRddl}|j|tfddjD}djkrRjd}||fS)aAttempt pulling python 3 function annotations off of 'func' for use as a signals type information. Returns an ordered nested tuple of (return_type, (arg_type1, arg_type2, ...)). If the given function does not have annotations then (None, tuple()) is returned. N__annotations__rc3s"|]}|jkrj|VqdS)N) annotations).0arg)specr r sz)get_signal_annotations..return)r&rinspectZgetfullargspecrr7)rr)r(r=r )r:r r%s    r%cCs|jjdi}i}xn|jjD]`\}}t|trt|}|sV|}|j|}t|||||krjtd||||<|j ||<qW||_ xF|jD]:\}}|j dk rd|j dd}t ||st|||j qWdS)zAdds Signal instances on a GObject derived class into the '__gsignals__' dictionary to be picked up and registered as real GObject signals. __gsignals__z(Signal "%s" has already been registered.NZdo_-_)__dict__getitemsr/r r r2setattr ValueErrorr3r>rreplacer)rZgsignalsZ newsignalsrrZ signalNameZfuncNamer r r install_signalss&      rG)rr)rr) sysr$r version_infor r r r4r%rGr r r r s "