How do I detect whether picking mode is enabled when using rubber band picking via Python?

I’m trying to write a rubber band picker using the vtk Python bindings on Windows, VTK 8.2.

I based my code off of one of the C++ examples, by creating my own Interactor style, inheriting from vtkInteractorStyleRubberBandPick, handling the LeftButtonReleaseEvent and then putting my selection code into the event handler as shown below.

Picking is supposed to be enabled by vtkInteractorStyleRubberBandPick if the ‘r’ key is pressed before the LMB down/Drag/Release gesture

My problem is that my handler gets called for every left mouse button release event, not just the ones following the ‘r’ key being pressed. In the C++ example, this is handled by checking the value of

vtkInteractorStyleRubberBandPick.CurrentMode

But this property doesn’t seem to be available via Python.

So - am I missing something? Is there an established pattern for this type of behavior when using Python or do I have handle the ‘r’ key press myself and set a state on my interactor style?

Thanks in advance for any guidance you can offer.

Doug

class InteractorStyle(vtk.vtkInteractorStyleRubberBandPick):
def __init__(self, parent = None):
    self.AddObserver("LeftButtonReleaseEvent",self.OnLeftButtonUpEvent)

def OnLeftButtonUpEvent(self,obj,event):
    self.OnLeftButtonUp()
    print("Left button Up Event")

 #if self.CurrentMode == == VTKISRBP_SELECT:

    print("Target type is ", type(self.Points))
    print("Number of points in target = ", self.Points.GetNumberOfPoints())
    print("Number of cells in target = ", self.Points.GetNumberOfCells())

    frustum = self.GetInteractor().GetPicker().GetFrustum()
    print("Number of planes = ", frustum.GetNumberOfPlanes())
    plane_normals = frustum.GetNormals()
    plane_points = frustum.GetPoints()
    for i in range(6):
        print(plane_normals.GetTuple(i))
        print(plane_points.GetPoint(i))


    extract_geometry = vtk.vtkExtractGeometry()
    extract_geometry.SetImplicitFunction(frustum)

    if vtk.VTK_MAJOR_VERSION <= 5:
        extract_geometry.SetInput(self.Points)
    else:
        extract_geometry.SetInputData(self.Points)
    extract_geometry.Update()

    selected = extract_geometry.GetOutput()

    print("selected type is ", type(selected))
    print("Number of points in selected = ", selected.GetNumberOfPoints())
    print("Number of cells in selected = ", selected.GetNumberOfCells())

    return

I got the code working by adding a keyPressEvent handler and adding a Boolean member variable to keep track of whether or not picking is enabled as shown below.

It still seems odd that CurrentMode is not available via Python, but this workaround works fine for me

class InteractorStyle(vtk.vtkInteractorStyleRubberBandPick):
def __init__(self, parent = None):
    self.AddObserver("LeftButtonReleaseEvent",self.OnLeftButtonUpEvent)
    self.AddObserver("KeyPressEvent",self.OnKeyPress)
    self.pickingEnabled = False

    self.SelectedMapper = vtk.vtkCompositePolyDataMapper2()
    self.SelectedActor = vtk.vtkActor()
    self.SelectedActor.SetMapper(self.SelectedMapper)

#
def OnKeyPress(self,obj,event):
    key = self.GetInteractor().GetKeySym()
    if key == 'r': self.pickingEnabled = not self.pickingEnabled

def OnLeftButtonUpEvent(self,obj,event):
    self.OnLeftButtonUp()
    if self.pickingEnabled:

        frustum = self.GetInteractor().GetPicker().GetFrustum()