crahan / ipyfilechooser

Python file chooser widget for use in Jupyter/IPython in conjunction with ipywidgets
MIT License
103 stars 19 forks source link

callback interface suggestions #64

Open marscher opened 2 years ago

marscher commented 2 years ago

Hi there,

thanks for this very useful utility! I just have a few things on my mind to make the callback interface more convenient. First of all, it would be nice to support multiple callbacks (e.g. like IPyWidgets). So they will be stored in a list, and just invoked in the order of registration. I wonder why the parent interface has not been adopted here, since it is well designed.

Another nice to have feature would be to determine, how the value (path, file) have changed. This could also be analogous to ipywidgets, where you get passed a dictionary with "new", "old" keys to see the difference. Also the reference to the originating widget (e.g. the FileChooser triggering the event) is passed in this dictionary as the "owner" key.

This feature can be used to create backups prior saving a file. But I guess it is pretty general.

In the meantime I'd have to access the private ipywidgets for the Selection and obtain my values from there. But this is not very clean.

crahan commented 2 years ago

Hi @marscher,

Thanks for the input and it's great to hear people are getting some value out of what started as nothing more than a small tool to scratch a personal itch 😄 . That said, that's also the biggest reason things like the Widget interface were never adopted. ipyfilechooser never started out as a real widget, but more as a collection of several other widget types that work together.

Just to make sure I'm understanding you correctly, you're refering to the CallbackDispatcher in the Widget class, correct? If so I think it makes a lot of sense to implement the Widget interface so we can leverage that functionality in ipyfilechooser.

Right now I have a few other priorities to focus on first, but I'll keep the issue open for follow-up. If you want to take a stab at a pull request or share a code sample of how you'd implement this, I'm more than happy to take a look at that as well.