-
Notifications
You must be signed in to change notification settings - Fork 52
Widget observer framework #733
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
base: main
Are you sure you want to change the base?
Conversation
I believe Traits is already dropping Python 3.5, which means we can use descriptors with If I understand the intention here, we can alternatively have a decorator
Implementation for `@observe_later`
The benefit is that the name of the method is irrelevant, it can support more than one handlers for observing the same trait, it can observe extended traits and the side-effect intended is colocated/transparent. One point to note that if the method used as the change handler is to be overridden by subclasses, the What do you think about this? |
Had some time to digest the approach and think about it a bit. It's interesting, and generically useful, and I could see some system like this having a place in Traits. I think it would want a little generalization to allow grouping: perhaps using a dictionary of handlers instead of a list, and do In terms of capabilities, the only real improvement of this approach over the one using metadata is the ability to observe expressions rather than single traits - multiple observers could be handled by having a list of handlers in the metadata, and the first implementation of this allowed any callable as a handler in addition to named methods. But I can see the utility in being able to handle All of that said, I also realised that most of the desired goals from dynamically turning observers on or off could be obtained by writing a decorator that returns immediately if the
or some variation thereof. Coupled with almost all use-cases being effectively covered by #737, I think that this PR might not be quite the right thing in many cases. |
This adds the infrastructure for simple widget observer configuration via trait metadata.
This adds code to the
MWidget
implementation of the current private API methods_add_event_listeners
and_remove_event_listeners
to automatically hook up methods to trait observers where thewidget_observer
metadata holds the name of the method to handle the calls.Some changes are needed to the various
Widget
classes to make sure that things are always called correctly: the addition of severalsuper()
calls, and the addition of a base implementation ofdispose
onMWidget
.Other than in a test, this does not change any widget to use the framework, and so should have no impact on behaviour.
This is the first step of #732.