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

vmin and vmax viewer properties set color range #723

Closed PaulHax closed 11 months ago

PaulHax commented 11 months ago

I don't know how to wrap get/set of color range with matplotlib like vmin and vmax properties. How to do synchronous wrapping of async Viewer methods?

Goal is something like adding this to Viewer class

    @property
    def vmin(self):
        range = self.get_image_color_range()
        return range[0]
    @vmin.setter
    def vmin(self, vmin):
        range = self.get_image_color_range()
        range[0] = vmin
        self.set_image_color_range(range)
bnmajor commented 11 months ago

Nice! The synchronous wrapping is added with the @fetch_value decorator, and you'll need to make make anything awaiting a network request async:

    @property
    @fetch_value
    async def vmin(self):
        range = await self.get_image_color_range()
        return range[0]
    @vmin.setter
    @fetch_value
    async def vmin(self, vmin):
        range = await self.get_image_color_range()
        range[0] = value
        self.set_image_color_range(range)

And just a reminder that if you're providing an example we need to resolve anything requiring a network request in the next cell (for now at least):

viewer.vmin = 10
vmin = viewer.vmin
vmin