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
580 stars 83 forks source link

Need to make getters available #568

Closed bnmajor closed 9 months ago

bnmajor commented 1 year ago

We should expose the getter functions to users so that they can access the information that they may need. Currently progress on this is barred by two issues, the first of which being the major barrier:

image = imageio.imread("https://data.kitware.com/api/v1/file/5b843d468d777f43cc8d4f6b/download/engine.nrrd")

class ImJoyPlugin(): async def setup(self): pass

async def run(self, ctx):
    # create a viewer
    viewer = await api.createWindow(src="https://bafybeicuvbx4cfp3zgo25j376bmmysh73a2ui5dbapuwqtmjcvcaipmpbi.on.fleek.co/")
    # show an image
    viewer.setImage(image)

async def getUICollapsed(self):
    return await self.viewer.getUICollapsed()

viewer = ImJoyPlugin() api.export(viewer) await viewer.getUICollapsed()


- (Useful but lower priority) To handle the case of "Run All" we need to think about how to handle calls to these getters so that they don't produce errors that interrupt the notebook. Some ideas:
  - Use the background thread like we do with the setters. In this case we would need to rethink the current approach a little to make sure we get the result back. We'd also need a way to associate the result with the correct cell. Would also need a "placeholder" for the returned value to indicate that it hasn't yet returned even though the cell has "completed". Less than ideal.
  - Try to move the rpc to the background thread so that cells can block while they wait for results.
bnmajor commented 1 year ago

Linking this discussion here to keep this issue updated.

thewtex commented 1 year ago

Related:

bnmajor commented 9 months ago

Fixed in #587 and improved in #702. Closing.