InsightSoftwareConsortium / itkwidgets

An elegant Python interface for visualization on the web platform to interactively generate insights into multidimensional images, point sets, and geometry.
https://itkwidgets.readthedocs.io/
Apache License 2.0
585 stars 83 forks source link

Add support for getters #587

Closed bnmajor closed 11 months ago

bnmajor commented 1 year ago

-- WIP --

Guided by the items discussed in #568 this branch attempts to add support for getter functions. Adapting approaches in the ipython_blocking and jupyter-ui-poll libraries the general approach is to:

Issues:

review-notebook-app[bot] commented 1 year ago

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

bnmajor commented 1 year ago

This approach is making progress but is still a bit naive and has a lot of additional cases/needs to take into account. Starting a list here of key concerns and shortcomings so that they are addressed as this moves forward:

thewtex commented 1 year ago

Todos

which should help with all three points above.

-> merge

Create another issue as needed for setting cell output with a getter output.

thewtex commented 1 year ago

@bnmajor this timeout only occurs when the tests are executed through nbmake?

@alex-treebeard are notebook events processed in a different way when executed through nbmake?

thewtex commented 1 year ago

@alex-treebeard suggested that there may be a to resolve via the way nbmake uses nbclient.

bnmajor commented 1 year ago

@thewtex So it seems like the nbmake issue is not actually with the getters/setters but with the fact that in testing the itk-viewer is never actually created (so any cells with getters/setters timeout waiting for it to be created before being run). If I use the --overwrite flag to see the results produced from testing there is no embedded screenshot which seems to backup this theory....

thewtex commented 1 year ago

@bnmajor oh, good catch! :bulb:

Indeed

This widget rendering is not performed against a browser during execution

@oeway any ideas / suggestions / pointers to have ImJoy talk to a headless chromium browser?

alex-treebeard commented 1 year ago

@thewtex been doing a bit of reading around widgets. Is it necessary to load the browser in order to initialise the ITK widget?

What needs to run in order to unblock the getters from executing against an initialised viewer object?

thewtex commented 1 year ago

@alex-treebeard

Is it necessary to load the browser in order to initialise the ITK widget?

It is not necessary to import and run the Python code. However, a browser is necessary for the graphical context and JavaScript environment to perform renderings and work with the client-side widget state.

What needs to run in order to unblock the getters from executing against an initialised viewer object?

One way or another, we need to be talking to, e.g., Chrome / Electron in Headless Mode, when running in nbmake / nbclient.

alex-treebeard commented 1 year ago

@thewtex have you checked out galata?

It's possible to stand up a jupyter lab instance in a test environment, then we could potentially run nbmake against its kernel.

thewtex commented 1 year ago

@alex-treebeard great idea!!

Yes, we could use a version of nb_run.py that uses galata and something along the lines of:

https://github.com/jupyterlab/jupyterlab/blob/2250b956294558de58a99e4a26286270654eb416/galata/test/galata/notebook.spec.ts#L91-L115

thewtex commented 11 months ago

Let's merge this, then, in separate PR's