%PDF- %PDF-
Direktori : /snap/core/17212/usr/lib/python3/dist-packages/urwid/__pycache__/ |
Current File : //snap/core/17212/usr/lib/python3/dist-packages/urwid/__pycache__/signals.cpython-35.pyc |
:$�Vz1 � @ s� d d l Z d d l Z Gd d � d e � Z d d � Z Gd d � d e � Z Gd d � d e � Z e � Z e j Z e j Z e j Z e j Z e j Z d S) � Nc s( e Z d Z d Z � f d d � Z � S)�MetaSignalszk register the list of signals in the class varable signals, including signals in superclasses. c s� | j d g � } x* | j D] } | j t | d g � � q Wt t d d � | D� � j � � } | | d <t | | � t t | � j | | | � d S)N�signalsc S s g | ] } | d f � q S)N� )�.0�xr r �//usr/lib/python3/dist-packages/urwid/signals.py� <listcomp>$ s z(MetaSignals.__init__.<locals>.<listcomp>)�get� __bases__�extend�getattr�list�dict�keys�register_signal�superr �__init__)�cls�name�bases�dr Z superclass)� __class__r r r s % zMetaSignals.__init__)�__name__� __module__�__qualname__�__doc__r r r )r r r s r c C s0 t | | � r t | | � St | | | � | S)N)�hasattrr �setattr)�objr �valuer r r �setdefaultattr) s r c @ s e Z d Z d Z g Z d S)�KeyzX Minimal class, whose only purpose is to produce objects with a unique hash N)r r r r � __slots__r r r r r! 0 s r! c @ s� e Z d Z d Z d d � Z d d � Z d d d d d � Z d d d � Z d d d d d � Z d d � Z d d � Z d d � Z d S)�SignalsZ_urwid_signalsc C s i | _ d S)N)� _supported)�selfr r r r : s zSignals.__init__c C s | | j | <d S)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 emiting any signals from that class' objects N)r$ )r% �sig_clsr r r r �register= s zSignals.registerNc s� | j } � � j j | g � k r: t d � | f � � t � � t | � j i � } | j � g � } t j | � � � � � � f d d � } � j | | | � } | j � | | | 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 %rc sF � � } | rB y t | � j i � � � =Wn t k rA Yn Xd S)N)r �_signal_attr�KeyError)�weakref�o)�keyr �obj_weakr% r r �weakref_callback� s z)Signals.connect.<locals>.weakref_callback)r r$ r � NameErrorr! r r( � setdefaultr* �ref�_prepare_user_args�append)r% r r �callback�user_arg� weak_args� user_argsr&