Hello all,

I'm making a user interface for my lab's micrographs using QT and I'm 
trying to incorporate pyqtgraph as it seems to be much faster than 
matplotlib.

That being said, what I am trying to accomplish is to have groups of images 
synchronized on their z axis. I have a MainWindow class with a slider, and 
when the slider moves, I am trying to get multiple ImageItems to set their 
image to the corresponding frame. Here is the code I have right now (pared 
down to what is relevant)

import pickle
import sys

import pyqtgraph as pg
from PyQt5 import QtWidgets, QtCore
from pyqtgraph import GraphicsLayoutWidget, ImageItem

from gui.gui_pyqtgraph import Ui_MainWindow


class ImageGridWidget(GraphicsLayoutWidget):

    def __init__(self, experiment, **kwargs):
        super(ImageGridWidget, self).__init__(**kwargs)
        self.experiment = experiment
        self.frame = 0
        self.wavelengths = self.experiment.midline_map.keys()

        self.image_items = {
            wvl: 
ImageItem(image=self.experiment.rot_fl.sel(wavelength=wvl).data[self.frame], 
border='w')
            for wvl in self.wavelengths
        }

        self.image_viewboxes = {}
        for i, (wvl, image_item) in enumerate(self.image_items.items()):
            if (i > 0) and (i % 2 == 0):
                self.nextRow()
            self.image_viewboxes[wvl] = self.addViewBox(name=wvl)
            self.image_viewboxes[wvl].addItem(self.image_items[wvl])
            self.image_viewboxes[wvl].setAspectLocked(True)

    def set_frame(self, frame):
        self.frame = frame
        for wvl in self.wavelengths:
            
self.image_items[wvl].setImage(self.experiment.rot_fl.sel(wavelength=wvl).data[self.frame])


class MainWindow(QtWidgets.QMainWindow):

    def __init__(self):
        super(MainWindow, self).__init__()

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.frame = 0

        self.experiment = 
pickle.load(open('/Users/sean/code/wormAnalysis/data/experiment.pickle', 'rb'))

        self.ui.horizontalSlider.setMinimum(0)
        
self.ui.horizontalSlider.setMaximum(self.experiment.raw_image_data.shape[0] - 1)

        
self.ui.horizontalSlider.valueChanged.connect(self.handle_slider_changed)

        # Set up images
        self.rot_image_grid = ImageGridWidget(self.experiment)
        
self.ui.rotatedImagesBox.layout().addWidget(ImageGridWidget(self.experiment))

        # Event Handlers
        
self.ui.horizontalSlider.valueChanged.connect(self.handle_slider_changed)

    def handle_slider_changed(self):
        self.frame = int(self.ui.horizontalSlider.value())
        self.ui.label.setText(str(self.frame))
        self.rot_image_grid.set_frame(self.frame)


if __name__ == '__main__':
    pg.setConfigOption('imageAxisOrder', 'row-major')
    qapp = QtWidgets.QApplication([])
    qapp.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
    window = MainWindow()
    window.show()
    qapp.exec_()



The problem I am having is that the ImageItems inside the ImageGridWidget 
do not update. They display correctly at startup. I have verified that the 
set_frame method is being called on the slider update with the correct 
frame using print statements. Does anyone have any insight as to what could 
be going wrong?

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/814f1a68-1420-49a7-81aa-39918c82ff32%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to