Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
signals.cpython-313.pyc175 linesDownload Raw Back to __pycache__
1�

2��j}2��L�SSKJr SSKrSSKrSSKrSSKr\R(aSSKJrJ	r	J3r4JrJr "SS\R5rSr"SS5r"S	S55r\"5r\R&r\R*r\R.r\R2r\R6rg)�)�annotationsN)�Callable�6Collection�	Container�Hashable�Iterablec�0^�\rSrSrSrSU4SjjrSrU=r$)�MetaSignals� z`7register the list of signals in the class variable signals,8including signals in superclasses.9c�>�URS/5nURHnUR[US/55 M! [	[10R
U5R55nXCS'[X5 [TU])XU5 g)N�signals)�get�	__bases__�extend�getattr�list�dict�fromkeys�keys�register_signal�super�__init__)�cls�name�bases�dr
�11superclass�	__class__s      ��SD:\code\apps\devtools\python\user_packages\Python313\site-packages\urwid/signals.pyr�MetaSignals.__init__&sp����%�%�	�2�&���-�-�J��N�N�7�:�y�"�=�>�(��t�}�}�W�-�2�2�4�5���)����%�
����a�(��)r�strrztuple[type, ...]rzdict[str, typing.Any]�return�None)�__name__�12__module__�__qualname__�__firstlineno__�__doc__r�__static_attributes__�
__classcell__)rs@rr13r14 s����15)�)r!r16c�T�[X5(a[X5$[XU5 U$�N)�hasattrr�setattr)�objr�values   r�setdefaultattrr30s'���s����s�!�!��C�u���Lr!c��\rSrSrSrSrSrg)�Key�8zL17Minimal class, whose only purpose is to produce objects with a18unique hash19r"N)r&r'r(r)r*�	__slots__r+r"r!rr5r58s���20�Ir!r5c���\rSrSrSrSSjrSSjrSSSS.SSjjjrSSS	jjrSSSS.SS21jjjr	SSjr22SSjrSS
jrSr
g)�Signals�A�_urwid_signalsc��0Ulgr.��23_supported)�selfs rr�Signals.__init__Ds	����r!c� �X RU'g)am24:param sig_cls: the class of an object that will be sending signals25:type sig_cls: class26:param signals: a list of signals that may be sent, typically each27                signal is represented by a string28:type signals: signal names29 30This function must be called for a class before connecting any31signal callbacks or emitting any signals from that class' objects32Nr=)r?�sig_clsr
s   r�register�Signals.registerGs��$+���� r!Nr")�	weak_args�	user_argsc�|^^^33^�URnTTRRUS5;a[ST<SU<35e[	5m34[UTR05RT/5n[R"U5mSU35UUU4Sjjn	TRXVU	5nURT36X4U45 T37$)a/
38:param obj: the object sending a signal39:type obj: object40:param name: the signal to listen for, typically a string41:type name: signal name42:param callback: the function to call when that signal is sent43:type callback: function44:param user_arg: additional argument to callback45                 (appended  after the arguments passed when the signal is emitted).46                 If None no arguments will be added.47                 Don't use this argument, use user_args instead.48:param weak_args: additional arguments passed to the callback49                  (before any arguments passed when the signal50                  is emitted and before any user_args).51 52                  These arguments are stored as weak references53                  (but converted back into their original value54                  before passing them to callback) to prevent55                  any objects referenced (indirectly) from56                  weak_args from being kept alive just because57                  they are referenced by this signal handler.58 59                  Use this argument only as a keyword argument,60                  since user_arg might be removed in the future.61:type weak_args: iterable62:param user_args: additional arguments to pass to the callback,63                  (before any arguments passed when the signal64                  is emitted but after any weak_args).65 66                  Use this argument only as a keyword argument,67                  since user_arg might be removed in the future.68:type user_args: iterable69 70When a matching signal is sent, callback will be called. The71arguments it receives will be the user_args passed at connect72time (as individual arguments) followed by all the positional73parameters sent with the signal.74 75As an example of using weak_args, consider the following snippet:76 77>>> import urwid78>>> debug = urwid.Text("")79>>> def handler(widget, newtext):80...     debug.set_text("Edit widget changed to %s" % newtext)81>>> edit = urwid.Edit("")82>>> key = urwid.connect_signal(edit, "change", handler)83 84If you now build some interface using "edit" and "debug", the85"debug" widget will show whatever you type in the "edit" widget.86However, if you remove all references to the "debug" widget, it87will still be kept alive by the signal handler. This because the88signal handler is a closure that (implicitly) references the89"edit" widget. If you want to allow the "debug" widget to be90garbage collected, you can create a "fake" or "weak" closure91(it's not really a closure, since it doesn't reference any92outside variables, so it's just a dynamic function):93 94>>> debug = urwid.Text("")95>>> def handler(weak_debug, widget, newtext):96...     weak_debug.set_text("Edit widget changed to %s" % newtext)97>>> edit = urwid.Edit("")98>>> key = urwid.connect_signal(edit, "change", handler, weak_args=[debug])99 100Here the weak_debug parameter in print_debug is the value passed101in the weak_args list to connect_signal. Note that the102weak_debug value passed is not a weak reference anymore, the103signals code transparently dereferences the weakref parameter104before passing it to print_debug.105 106Returns a key associated by this signal handler, which can be107used to disconnect the signal later on using108urwid.disconnect_signal_by_key. Alternatively, the signal109handler can also be disconnected by calling110urwid.disconnect_signal, which doesn't need this key.111r"zNo such signal z for object c�J>�T"5=n(aTRUTT5 ggr.)�disconnect_by_key)�_ref�o�keyr�obj_weakr?s  ����r�weakref_callback�)Signals.connect.<locals>.weakref_callback�s%����J��q���&�&�q�$��4�r!)rJz!weakref.ReferenceType[typing.Any]r$r%)rr>r�	NameErrorr5r3�_signal_attr�112setdefault�weakref�ref�_prepare_user_args�append)r?r1r�callback�user_argrErFrB�handlersrNrLrMs` `       @@r�connect�Signals.connectTs����l�-�-���t���*�*�7�B�7�7��o�d�X�\�#��I�J�J��e��!�#�t�'8�'8�"�=�H�H��r�R���;�;�s�#��	5�	5��+�+�I�BR�S�	�����h�)�<�=��113r!c�\^�[U4SjU55n[U5=(d SnXE4$)Nc3�R># �UHn[R"UT5v� M g7fr.)rSrT)�.0�w_argrWs  �r�	<genexpr>�-Signals._prepare_user_args.<locals>.<genexpr>�s����K���w�{�{�5�(�3�3��s�$'r")�tuple)r?rErFrW�w_args�argss   `  rrU�Signals._prepare_user_args�s,����K��K�K���Y��%�2���~�r!c��[XR05nX';agXrnURXV5nUH%n	U	SSX4U4:XdMURXU	S5s $ g)a�114:param obj: the object to disconnect the signal from115:type obj: object116:param name: the signal to disconnect, typically a string117:type name: signal name118:param callback: the callback function passed to connect_signal119:type callback: function120:param user_arg: the user_arg parameter passed to connect_signal121:param weak_args: the weak_args parameter passed to connect_signal122:param user_args: the weak_args parameter passed to connect_signal123 124This function will remove a callback from the list connected125to a signal with connect_signal(). The arguments passed should126be exactly the same as those passed to connect_signal().127 128If the callback is not connected or already disconnected, this129function will simply do nothing.130N�r)r3rQrUrI)131r?r1rrWrXrErFr
rY�hs132          r�133disconnect�Signals.disconnect�ss��8!��&7�&7��<������=���+�+�I�A�	��A����u��Y�7�7��-�-�c��1��>�>��r!c��[XR05RU/5nUVs/sHoUSULdMUPM snUSS&gs snf)a134:param obj: the object to disconnect the signal from135:type obj: object136:param name: the signal to disconnect, typically a string137:type name: signal name138:param key: the key for this signal handler, as returned by139            connect_signal().140:type key: Key141 142This function will remove a callback from the list connected143to a signal with connect_signal(). The key passed should be the144value returned by connect_signal().145 146If the callback is not connected or already disconnected, this147function will simply do nothing.148rN)r3rQr)r?r1rrLrYrhs      rrI�Signals.disconnect_by_key�sF��""�#�'8�'8�"�=�A�A�$��K��"*�>�(�Q��d�#�o�q�(�>�����>s149�A�Ac	��Sn[XR05RU/5nUHupgnup�X@RXxX�U5-nM  U$)a�150:param obj: the object sending a signal151:type obj: object152:param name: the signal to send, typically a string153:type name: signal name154:param args: zero or more positional arguments to pass to the signal callback functions155 156This function calls each of the callbacks connected to this signal157with the args arguments as positional parameters.158 159This function returns True if any of the callbacks returned True.160F)rrQr�_call_callback)r?r1rrd�resultrY�_keyrWrXrErFs           r�emit�Signals.emits[�����3� 1� 1�2�6�:�:�4��D��@H�<�D�H�&<�y��)�)�(�i�TX�Y�Y�F�AI��
r!c��/nUH nU"5=nbURU5 M  g [R"XdXRbU4OS5n	[U"U	65$)NFr")rV�	itertools�chain�bool)161r?rWrXrErF�	emit_args�args_to_passr_�real_argrds162          rrn�Signals._call_callback&s^�����E�!�G�#��0��#�#�H�-������|�	�Rf�H�;�ln�o���H�d�O�$�$r!r=)r$r%)r
zContainer[Hashable]r$r%r.)rrrW�Callable[..., typing.Any]rX�163typing.AnyrE�Iterable[typing.Any]rFr}r$r5)r"r"N)rEr}rFr}rWz@Callable[[weakref.ReferenceType[typing.Any]], typing.Any] | Noner$z@tuple[Collection[weakref.ReferenceType], Collection[typing.Any]])rrrWr{rXr|rEr}rFr}r$r%)rrrLr5r$r%)rrr$rv)164rXr|rEzIterable[weakref.ReferenceType]rFr}rwr}r$rv)r&r'r(r)rQrrCrZrUrirIrqrnr+r"r!rr9r9As:��#�L��+�$ $�r�+-�*,�r��r�,�	r�165�r�(�r�(�r�166
�r�l+-�*,�UY�		�'�	�(�	�S�		�167168J�	�  $�*�+-�*,�*��*�,�	*�169�*�(�*�(�*�170�*�X?�(�&%��%�3�	%�171(�%�(�
%�172�%r!r9)�173__future__r�abcrt�typingrS�
TYPE_CHECKING�collections.abcrrrrr�ABCMetar174r3r5r9�_signalsrq�emit_signalrCrrZ�connect_signalri�disconnect_signalrI�disconnect_signal_by_keyr"r!r�<module>r�s���*#�175��
��	���S�S�
)�#�+�+�
)� ���y%�y%�x�9���m�m���#�#���!�!���'�'��#�5�5�r!
codekingpro/portable-devtools · Team Ai