RemoveAllObservers do not work

I want to remove all observers in interactor, but it do not work. My code is:


from PyQt5.QtWidgets import *
import sys, os
import vtk
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor

def mouseMoveEvent(iren, event):
    print('move')

class MyWin(QWidget):
    def __init__(self):
        super().__init__()

        layout = QVBoxLayout()
        self.setLayout(layout)

        self.vtkWidget = QVTKRenderWindowInteractor()
        layout.addWidget(self.vtkWidget)
        self.ren = vtk.vtkRenderer()
        self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)

        interactor = self.vtkWidget.GetRenderWindow().GetInteractor()
        interactor.Initialize()
        interactor.RemoveAllObservers()
        interactor.AddObserver('MouseMoveEvent', mouseMoveEvent)
        interactor.Start()

        self.imageViewer = vtk.vtkImageViewer2()
        self.imageViewer.SetupInteractor(interactor)
        self.imageViewer.SetRenderWindow(self.vtkWidget.GetRenderWindow())

        img = vtk.vtkDICOMImageReader()
        img.SetFileName('C:\\Users\\MLoong\\Desktop\\dicom_data\\Chang Cheng\\TOF\\IM_0174')
        img.Update()

        self.imageViewer.SetInputData(img.GetOutput())
        self.imageViewer.Render()




if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MyWin()
    window.show()
    app.exec_()

Is there anything wrong with my code?

Hi,
Could you please be more specific and explain what do you get, what do you expect and what you think is not working here?
J.

Very sorry for the unclearing question. I want to remove all observers and implement myself observers. I hope interactor.RemoveAllObservers() can remove all observers. If it work, nothing will happen for zoom in and pan operation (press left/right mouse and move). However, I find that the image still zoom in when I press the left mouse and move.

Also, the following code works:

        self.vtkWidget = QVTKRenderWindowInteractor()
        layout.addWidget(self.vtkWidget)
        self.ren = vtk.vtkRenderer()
        self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)

        interactor = self.vtkWidget.GetRenderWindow().GetInteractor()
        interactor.Initialize()
        

        self.imageViewer = vtk.vtkImageViewer2()
        self.imageViewer.SetupInteractor(interactor)
        self.imageViewer.SetRenderWindow(self.vtkWidget.GetRenderWindow())

        img = vtk.vtkDICOMImageReader()
        img.SetFileName('C:\\Users\\MLoong\\Desktop\\dicom_data\\Chang Cheng\\TOF\\IM_0174')
        img.Update()

        self.imageViewer.SetInputData(img.GetOutput())
        self.imageViewer.Render()

        interactor.RemoveAllObservers()
        interactor.AddObserver('MouseMoveEvent', mouseMoveEvent)
        interactor.Start()

However, I need to firstly create interactor the myself observer, and then (click a button) create the imageviewer. So, is there any method to RemoveAllObservers before imageViewer.SetupInteractor(interactor) ?