<commit_before>from silx.gui import qt
from silx.gui.plot import items, PlotWindow
import sys
print(sys.path)
import silx_monkey_patch


class TestItem(items.ImageData):

    sigVisibleExtentChanged = qt.Signal()

    def _setPlot(self, plot):
        super()._setPlot(plot)
        xaxis = plot.getXAxis()
        xaxis.sigLimitsChanged.connect(self._limitsChanged)
        xaxis.sigScaleChanged.connect(self._scaleChanged)

        yaxis = plot.getYAxis() # TODO handle left axis
        yaxis.sigLimitsChanged.connect(self._limitsChanged)
        yaxis.sigScaleChanged.connect(self._scaleChanged)

    def _limitsChanged(self, begin, end):
        self.sigVisibleExtentChanged.emit()

    def _scaleChanged(self, scale):
        pass


if __name__ == "__main__":
    from silx.gui import qt
    import numpy

    qt.QApplication.setAttribute(qt.Qt.AA_ShareOpenGLContexts, True)
    qt.QApplication.setAttribute(qt.Qt.AA_EnableHighDpiScaling, True)

    app = qt.QApplication([])
    w = PlotWindow()
    item = TestItem()
    item.setData(numpy.arange(100).reshape(10, 10))
    w.addItem(item)
    w.show()
    app.exec_()<commit_msg>some update (WIP)<commit_after>from silx.gui import qt
from silx.gui.plot import items, PlotWindow

import os
import sys
sys.path.insert(0, os.path.dirname(__file__))
import silx_monkey_patch


class TestItem(items.ImageData):

    sigVisibleExtentChanged = qt.Signal()

    def _setPlot(self, plot):
        super()._setPlot(plot)

        xaxis = plot.getXAxis()
        xaxis.sigLimitsChanged.connect(self._limitsChanged)
        xaxis.sigScaleChanged.connect(self._scaleChanged)

        yaxis = plot.getYAxis(
            self.getYAxis() if isinstance(self, items.YAxisMixIn) else 'left')
        yaxis.sigLimitsChanged.connect(self._limitsChanged)
        yaxis.sigScaleChanged.connect(self._scaleChanged)

        self.__previousVisibleExtent = self.getVisibleExtent()
        self.sigVisibleExtentChanged.emit()

    def _limitsChanged(self, begin, end):
        extent = item.getVisibleExtent()
        if extent != self.__previousVisibleExtent:
            self.__previousVisibleExtent = extent
            self.sigVisibleExtentChanged.emit()

    def _scaleChanged(self, scale):
        pass  # TODO ?

    def _update(self, backend):
        super()._update(backend)
        width, height = item.getPlot().getPixelSizeInData()
        print('Pixel size', width, height)
        sx, sy = item.getScale()
        print('Array size', width / sx, height / sy)


if __name__ == "__main__":
    from silx.gui import qt
    import numpy

    qt.QApplication.setAttribute(qt.Qt.AA_ShareOpenGLContexts, True)
    qt.QApplication.setAttribute(qt.Qt.AA_EnableHighDpiScaling, True)

    app = qt.QApplication([])
    w = PlotWindow(backend='gl')
    item = TestItem()

    def cb():
        print('Extent', item.getVisibleExtent())
        print('Slices', item.getVisibleSlices())
    item.sigVisibleExtentChanged.connect(cb)

    item.setData(numpy.arange(100, dtype='float16').reshape(10, 10))
    w.addItem(item)
    w.show()
    app.exec_()
{'fraction_non_alphanumeric': 0.11132749107432652, 'fraction_numerical': 0.00551768906199286, 'mean_word_length': 3.251034482758621, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2449958', 'n_tokens_mistral': 1013, 'n_tokens_neox': 974, 'n_words': 179}