grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a BjŒjš1ã@s€ddlmZmZddlZddlZGdd„deƒZdd„ZGdd„deƒZ Gd d „d eƒZ e ƒZ e j Z e jZe jZe jZe jZdS) é)ÚdivisionÚprint_functionNcs eZdZdZ‡fdd„Z‡ZS)Ú MetaSignalszl register the list of signals in the class variable signals, including signals in superclasses. csn| dg¡}|jD]}| t|dgƒ¡qttdd„|Dƒƒ ¡ƒ}||d<t||ƒtt |ƒ  |||¡dS)NÚsignalscSsg|] }|df‘qS©N©)Ú.0Úxrrú3/usr/lib64/python3.9/site-packages/urwid/signals.pyÚ $óz(MetaSignals.__init__..) ÚgetÚ __bases__ÚextendÚgetattrÚlistÚdictÚkeysÚregister_signalÚsuperrÚ__init__)ÚclsÚnameÚbasesÚdrZ superclass©Ú __class__rr r s   zMetaSignals.__init__)Ú__name__Ú __module__Ú __qualname__Ú__doc__rÚ __classcell__rrrr rsrcCs$t||ƒrt||ƒSt|||ƒ|Sr)ÚhasattrrÚsetattr)ÚobjrÚvaluerrr Úsetdefaultattr)s   r&c@seZdZdZgZdS)ÚKeyzX Minimal class, whose only purpose is to produce objects with a unique hash N)rrrr Ú __slots__rrrr r'0sr'c@sVeZdZdZdd„Zdd„Zddd„Zdd d „Zdd d „Zd d„Z dd„Z dd„Z dS)ÚSignalsZ_urwid_signalscCs i|_dSr©Ú _supported)Úselfrrr r:szSignals.__init__cCs||j|<dS)a± :param sig_class: the class of an object that will be sending signals :type sig_class: class :param signals: a list of signals that may be sent, typically each signal is represented by a string :type signals: signal names This function must be called for a class before connecting any signal callbacks or emitting any signals from that class' objects Nr*)r,Úsig_clsrrrr Úregister=s zSignals.registerNc sˆ|j}ˆˆj |g¡vr(tdˆ|fƒ‚tƒ‰t|ˆjiƒ}| ˆg¡} t  |¡‰‡‡‡‡fdd„} ˆ  ||| ¡}|   ˆ|||f¡ˆS)a7 :param obj: the object sending a signal :type obj: object :param name: the signal to listen for, typically a string :type name: signal name :param callback: the function to call when that signal is sent :type callback: function :param user_arg: deprecated additional argument to callback (appended after the arguments passed when the signal is emitted). If None no arguments will be added. Don't use this argument, use user_args instead. :param weak_args: additional arguments passed to the callback (before any arguments passed when the signal is emitted and before any user_args). These arguments are stored as weak references (but converted back into their original value before passing them to callback) to prevent any objects referenced (indirectly) from weak_args from being kept alive just because they are referenced by this signal handler. Use this argument only as a keyword argument, since user_arg might be removed in the future. :type weak_args: iterable :param user_args: additional arguments to pass to the callback, (before any arguments passed when the signal is emitted but after any weak_args). Use this argument only as a keyword argument, since user_arg might be removed in the future. :type user_args: iterable When a matching signal is sent, callback will be called. The arguments it receives will be the user_args passed at connect time (as individual arguments) followed by all the positional parameters sent with the signal. As an example of using weak_args, consider the following snippet: >>> import urwid >>> debug = urwid.Text('') >>> def handler(widget, newtext): ... debug.set_text("Edit widget changed to %s" % newtext) >>> edit = urwid.Edit('') >>> key = urwid.connect_signal(edit, 'change', handler) If you now build some interface using "edit" and "debug", the "debug" widget will show whatever you type in the "edit" widget. However, if you remove all references to the "debug" widget, it will still be kept alive by the signal handler. This because the signal handler is a closure that (implicitly) references the "edit" widget. If you want to allow the "debug" widget to be garbage collected, you can create a "fake" or "weak" closure (it's not really a closure, since it doesn't reference any outside variables, so it's just a dynamic function): >>> debug = urwid.Text('') >>> def handler(weak_debug, widget, newtext): ... weak_debug.set_text("Edit widget changed to %s" % newtext) >>> edit = urwid.Edit('') >>> key = urwid.connect_signal(edit, 'change', handler, weak_args=[debug]) Here the weak_debug parameter in print_debug is the value passed in the weak_args list to connect_signal. Note that the weak_debug value passed is not a weak reference anymore, the signals code transparently dereferences the weakref parameter before passing it to print_debug. Returns a key associated by this signal handler, which can be used to disconnect the signal later on using urwid.disconnect_signal_by_key. Alternatively, the signal handler can also be disconnected by calling urwid.disconnect_signal, which doesn't need this key. zNo such signal %r for object %rcs:ˆƒ}|r6zt|ˆjiƒˆˆ=Wnty4Yn0dSr)rÚ _signal_attrÚKeyError)ÚweakrefÚo©ÚkeyrZobj_weakr,rr Úweakref_callback­s  z)Signals.connect..weakref_callback) rr+r Ú NameErrorr'r&r/Ú setdefaultr1ÚrefÚ_prepare_user_argsÚappend) r,r$rÚcallbackÚuser_argÚ weak_argsÚ user_argsr-rÚhandlersr5rr3r ÚconnectJsMÿ zSignals.connectcs‡fdd„|pgDƒ|pgS)Ncsg|]}t |ˆ¡‘qSr)r1r8)rÚa©r;rr r ¼r z.Signals._prepare_user_args..r)r,r=r>r;rrBr r9ºszSignals._prepare_user_argsc Csht||jiƒ}||vrdS||}| ||¡}|D]0} | dd…|||fkr2| ||| d¡Sq2dS)aI :param obj: the object to disconnect the signal from :type obj: object :param name: the signal to disconnect, typically a string :type name: signal name :param callback: the callback function passed to connect_signal :type callback: function :param user_arg: the user_arg parameter passed to connect_signal :param weak_args: the weak_args parameter passed to connect_signal :param user_args: the weak_args parameter passed to connect_signal This function will remove a callback from the list connected to a signal with connect_signal(). The arguments passed should be exactly the same as those passed to connect_signal(). If the callback is not connected or already disconnected, this function will simply do nothing. Nér)r&r/r9Údisconnect_by_key) r,r$rr;r<r=r>rr?Úhrrr Ú disconnect¿s zSignals.disconnectcs8t||jiƒ}| |g¡}‡fdd„|Dƒ|dd…<dS)an :param obj: the object to disconnect the signal from :type obj: object :param name: the signal to disconnect, typically a string :type name: signal name :param key: the key for this signal handler, as returned by connect_signal(). :type key: Key This function will remove a callback from the list connected to a signal with connect_signal(). The key passed should be the value returned by connect_signal(). If the callback is not connected or already disconnected, this function will simply do nothing. csg|]}|dˆur|‘qS)rr)rrE©r4rr r ôr z-Signals.disconnect_by_key..N)r&r/r )r,r$rr4rr?rrGr rDás zSignals.disconnect_by_keyc GsHd}t||jiƒ}| |g¡}|D] \}}} } || || | |¡O}q"|S)aø :param obj: the object sending a signal :type obj: object :param name: the signal to send, typically a string :type name: signal name :param \*args: zero or more positional arguments to pass to the signal callback functions This function calls each of the callbacks connected to this signal with the args arguments as positional parameters. This function returns True if any of the callbacks returned True. F)rr/r Ú_call_callback) r,r$rÚargsÚresultrr?r4r;r<r>rrr Úemitös  z Signals.emitcCsn|rHg}|D].}t|tjƒr0|ƒ}|dur0dS| |¡q | |¡n|}|durbt ||f¡}t||ŽƒS)NF)Ú isinstancer1Ú ReferenceTyper:rÚ itertoolsÚchainÚbool)r,r;r<r>Z emit_argsZ args_to_passÚargrrr rH s   zSignals._call_callback)NNN)N)NNN) rrrr/rr.r@r9rFrDrKrHrrrr r)7s p  "r))Z __future__rrrNr1Útyperr&Úobjectr'r)Z_signalsrKZ emit_signalr.rr@Zconnect_signalrFZdisconnect_signalrDZdisconnect_signal_by_keyrrrr Úsr