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

Add support for event callbacks #153

Open
jni opened this issue Apr 10, 2022 · 3 comments
Open

Add support for event callbacks #153

jni opened this issue Apr 10, 2022 · 3 comments

Comments

@jni
Copy link
Member

jni commented Apr 10, 2022

Just creating this issue to discuss a way for plugins to register events that happen on specific callbacks. For example, in napari/napari#4361, @psobolewskiPhD wants to be able to reset the dims sliders whenever new images are added.

Adding an on: argument for commands that would trigger function calls whenever specific events happen seems like a pretty useful thing for plugins to do!

Of course there's still questions about when these things get activated... I might argue that if I install a plugin that provides specific callbacks, I want it activated every time I launch napari. Or maybe this goes in plugin preferences?

@Czaki
Copy link
Collaborator

Czaki commented Apr 20, 2022

I might argue that if I install a plugin that provides specific callbacks, I want it activated every time I launch napari

I cannot agree. You may install a plugin for only one widget and do not want to use all others things from the plugin.

@jni
Copy link
Member Author

jni commented Apr 21, 2022

Agreed, I think a preference like "startup items", similar to an OS, would be useful for this.

@tlambert03
Copy link
Collaborator

tlambert03 commented Aug 3, 2022

just going through some issues here. I'm not sure this particular use case makes as much sense in the declarative schema. I kinda picture an API where a plugin would receive an object that looked very much like viewer, but which was capable of tracking event connections, such that they could be disconnected upon deactivation:

# pass plugin an object, that can track what gets connected
event_subscriptions = pass_plugin_the_viewer_proxy(plugin, viewer_proxy)
# add a callback that can undo those event connections to the plugin context
plugin_context.register_disposable(subscriptions)
# when plugin is deactivated, `context._dispose()` gets called that will call all "undo" things

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

3 participants