The urwid.*_signal() functions use a shared Signals object instance for tracking registered and connected signals. There is no reason to instantiate your own Signals object.
Parameters: |
|
---|
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.
Parameters: |
|
---|
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.
Parameters: |
|
---|
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.
Parameters: |
|
---|
This function must be called for a class before connecting any signal callbacks or emiting any signals from that class’ objects
Parameters: |
|
---|
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.