silx icon indicating copy to clipboard operation
silx copied to clipboard

mouseover values for ImageView

Open alexbjorling opened this issue 6 years ago • 7 comments

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?

alexbjorling avatar Aug 20 '19 09:08 alexbjorling

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

vallsv avatar Aug 20 '19 12:08 vallsv

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.

vallsv avatar Aug 20 '19 12:08 vallsv

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

Is that a silxclass?

alexbjorling avatar Aug 22 '19 20:08 alexbjorling

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 avatar Aug 22 '19 21:08 alexbjorling

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

Exactly!

alexbjorling avatar Aug 22 '19 21:08 alexbjorling

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 avatar Aug 30 '19 14:08 t20100

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).

t20100 avatar Aug 30 '19 15:08 t20100