Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement an event system #39

Open
dalonsoa opened this issue Nov 10, 2021 · 0 comments
Open

Implement an event system #39

dalonsoa opened this issue Nov 10, 2021 · 0 comments
Assignees

Comments

@dalonsoa
Copy link
Collaborator

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)
def foo(a, b) -> None:
	# Do something
	pass

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.

@dalonsoa dalonsoa pinned this issue Nov 10, 2021
@dalonsoa dalonsoa self-assigned this Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant