silx-kit / silx

silx toolkit
http://www.silx.org/doc/silx/latest/
MIT License
134 stars 73 forks source link

mouseover values for ImageView #2723

Open alexbjorling opened 5 years ago

alexbjorling commented 5 years ago

I have a much used ImageView application which displays live feeds from detectors. My users are asking for the image value to be displayed in the status bar when hovering with the mouse. For applications based directly on PlotWindow, I've been using some trick which I probably found in the docs,

    def __init__(self, parent=None, **kwargs):
        # List of information to display at the bottom of the plot
        posInfo = [
            ('X', lambda x, y: x),
            ('Y', lambda x, y: y),
            ('Data', self._getActiveImageValue)]

        super(CustomPlotWindow, self).__init__(parent=parent, position=posInfo, **kwargs)

    def _getActiveImageValue(self, x, y):
        """Get value of active image at position (x, y)

        :param float x: X position in plot coordinates
        :param float y: Y position in plot coordinates
        :return: The value at that point or '-'
        """
        image = self.getActiveImage()
        if image is not None:
            data, params = image[0], image[4]
            ox, oy = params['origin']
            sx, sy = params['scale']
            if (y - oy) >= 0 and (x - ox) >= 0:
                # Test positive before cast otherwisr issue with int(-0.5) = 0
                row = int((y - oy) / sy)
                col = int((x - ox) / sx)
                if (row < data.shape[0] and col < data.shape[1]):
                    return data[row, col]
        return '-'

but ImageView sets position=False in its constructor. Is there some smart way to accomplish mouseover values, other than overriding the whole ImageView constructor?

vallsv commented 5 years ago

I found ImageViewMainWindow. It looks to provide the data on the toolbar. Does it fit your needs?

vallsv commented 5 years ago

Else, I think it would be better to stop using constructor attributes and provide the same feature as a proper getter/setter. But a small fix as your requested makes sens. I think we have to ask feed back from @t20100 first.

alexbjorling commented 5 years ago

I found ImageViewMainWindow. It looks to provide the data on the toolbar. Does it fit your needs?

Is that a silxclass?

alexbjorling commented 5 years ago

I ended up doing the same hack as above, and in the ImageView constructor I did this,

self._positionWidget = tools.PositionInfo(plot=self, converters=posInfo)
self.statusBar().addWidget(self._positionWidget)

Then since it's a live viewer, where the image might change while the mouse is still, this gets done repeatedly,

self._positionWidget.updateInfo()
alexbjorling commented 5 years ago

Else, I think it would be better to stop using constructor attributes and provide the same feature as a proper getter/setter.

Exactly!

t20100 commented 5 years ago

ImageViewMainWindow was initially an example of using ImageView.

And, yes it's better not to use constructor parameters and add getter/setters, it's more Qt-ish and more versatile. I'll look at that.

t20100 commented 5 years ago

To me it is fine to compose your GUI with the widgets you need (rather than a widget with everything and then disabling what you don't need), but we can add getter for retrieving the PositionInfo widget of PlotWindow and allowing to update it's "converters" and to toggle its visibility.

Also it would be good to have a smarter PositionInfo which automatically updates when the data changes (probably as a mode that can be turned off).