How to disable VTK's hotkey in Python-VTK

275 Views Asked by At

I want to disable some VTK hotkeys, in the Python version. While there exist answers here for C++ (and maybe js), it does not seem to work with the Python version.

I tried overloading OnKeyPress on my InterfactionStyle or my QVTKRenderWindowInteractor but it does not work. For example I would like to disable the wireframe/surface view switch that are on keys "w" and "s".

1

There are 1 best solutions below

0
Nico Vuaille On BEST ANSWER

It is defined in vtkInteractorStyle::OnChar. So try overload this method, with something like that:

class MyInteractorStyle(vtk.vtkInteractorStyleTrackballCamera):                                                                                                                                                                                                                             
  def __init__(self, parent = None):                                                                                                                                                                                                                                                        
    self.AddObserver('CharEvent', self.OnChar)                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                            
  def OnChar(self, obj, event):                                                                                                                                                                                                                                                             
      if obj.GetInteractor().GetKeyCode() == "w":                                                                                                                                                                                                                                           
          return                                                                                                                                                                                                                                                                            
      super(MyInteractorStyle, obj).OnChar()