Learning the inner workings of Napari

Hi,

first of all, I would like to thanks all the Napari main developers for their kind and friendly replies to all my questions, as well as for their advice, suggestions and encouragement on my journey to continue learning the inner workings of Napari. Thanks to the help of @jni I just started to play how to modify Napari’s source code repository, while at the same time I re-learn how to use git to keep track of all the changes :slight_smile: . In order to continue familiarizing myself with Napari, I would like to ask you
the following questions:

  • Let’s say I am working with a pyramid image, and I use the wheel-zoom on it. I would like to be able to intercept the method that is called in response to this event and print a simple message on the console. In particular, I would like include the print line just after Napari decides which part/level of the pyramid should be rendered, that is, just before Napari talks to VisPy and asks: “VisPy, could you please render this array for me as an image?”…Due to my beginner level I am getting a little bit lost in the Napari source code, could you please point me to the exact place in the code where this happens?

  • Thanks to Napari I decided to re-learn Qt (I used it in the past, but that was long time ago, so I need to re-learn it and get up-to-date with all the changes included in the recent versions of this nice framework). While playing with Qt again, an idea came to my mind: Can I use in my own python Qt code, somehow, just the napari canvas with all its events? I would like to develop a very
    minimal example, just a Qt Widget that shows a pyramid image on top of it, and reacts to the wheel-zoom event and re-renders the corresponding image pyramid level/viewport in response to it. Is this possible?..If so, could you please provide me with some suggestions on how would
    you recommend me to accomplish this tiny example app?

Once again thank you very much for all your help!

And please keep up going with this amazing open source project, you guys are building a really powerful Python image viewer!

2 Likes

Hi @jmontoyam that happens right here in the source code https://github.com/napari/napari/blob/b1d75c24e401227ba3bb17aa9a6f71dd21eef641/napari/layers/base/base.py#L791. We’ll likely be improving our multiscale rendering over the next couple months, but for now the variable you are interested in is the data_level and checked here.

You could embed the napari viewer into a new Qt widget, but a way we’re excited about encouraging people to extend the Qt functionality of napari is through adding their own dock widgets through the viewer.window.add_dock_widget method. You can also use a library like magicgui to autogenerate simple dock widgets for you, see https://magicgui.readthedocs.io/en/latest/examples/napari_parameter_sweep/ for example). While this isn’t quite what you asked for with the pyramid, this might give you some more ideas.

Good luck!!

1 Like

Thank you very much for all your advice and suggestions @sofroniewn!