You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
wxPython comes with a built in event system that let's you code your own events and callbacks, and having the application mainloop schedule and execute the callbacks at the appropriate time (see events in the thread system). It is not that intuitive to use, though, and all callbacks are executed in the main thread, which might not be convenient.
An alternative method is suggested that mixes the builtin events system and PyPubSub messaging tool. An implementation using decorators will look like the following:
@event.listen("some.channel", in_thread=False)deffoo(a, b) ->None:
# Do somethingpass
If in_thread=True, the decorated function will be executed in the same thread than the one broadcasting messages via "some.channel". Otherwise, the event will be connected to the main window of the program and executed with wx.PostEvent. Again, see the handling of the end of a thread in the thread system.
The broadcasting of a message is independent on who will be handling the message or where. A simple event.broadcast function with the same API than pubsub.pub.sendMessage will work. Under the hood, it will send the message to the normal pubsub system - probably "as is" if the API is the same -, but additionally will send an approrpiately crafted signal via the built-in event system to trigger those events that have been configured with in_thread=False.
The text was updated successfully, but these errors were encountered:
wxPython comes with a built in event system that let's you code your own events and callbacks, and having the application mainloop schedule and execute the callbacks at the appropriate time (see events in the thread system). It is not that intuitive to use, though, and all callbacks are executed in the main thread, which might not be convenient.
An alternative method is suggested that mixes the builtin events system and
PyPubSub
messaging tool. An implementation using decorators will look like the following:If
in_thread=True
, the decorated function will be executed in the same thread than the one broadcasting messages via"some.channel"
. Otherwise, the event will be connected to the main window of the program and executed withwx.PostEvent
. Again, see the handling of the end of a thread in the thread system.The broadcasting of a message is independent on who will be handling the message or where. A simple
event.broadcast
function with the same API thanpubsub.pub.sendMessage
will work. Under the hood, it will send the message to the normalpubsub
system - probably "as is" if the API is the same -, but additionally will send an approrpiately crafted signal via the built-in event system to trigger those events that have been configured within_thread=False
.The text was updated successfully, but these errors were encountered: