Super Callbacks

The methods get_super_callback() and call_super_callback() get and call VTK’s original responses to user interactions which may have been overwritten. See Super Callbacks? for why you need them and where to use them.

vtkplotlib.interactive.get_super_callback(invoker=None, event_name=None)[source]

Finds the original VTK callback function for a given event. Like the builtin super in Python 3.x, this method should be able to find its own arguments.

Parameters
  • invoker (vtkObject) – The vtkObject you used in invoker.AddObserver(..).

  • event_name (str) – The name of the interaction.

Returns

A method of invoker or a dummy null_super_callback function.

Return type

types.FunctionType

Raises

SuperError if called without (an) argument(s) and the argument(s) couldn’t be determined automatically.

The original callback (if there is one) is always a method of the invoker*. VTK has some rather loose naming rules which make this deceptively fiddly.

If called inside function which takes a vtkObject and a str as its first two arguments, then get_super_callback() will use the values of those two arguments as its own arguments. Or, if you provide those arguments explicitly, you can call this function anywhere. e.g.

>>> vpl.i.get_super_callback(fig.style, "MouseMoveEvent")
<built-in method OnMouseMove of vtkmodules.vtkInteractionStyle.vtkInteractorStyleTrackballCamera object at ...>

Not all events have parent events. In these cases a dummy function is returned. This is also the case for non-existant event types.

>>> vpl.i.get_super_callback(fig.style, "WindowIsCurrentEvent")
<function null_super_callback at ...>
>>> vpl.i.get_super_callback(fig.style, "BlueMoonEvent")
<function null_super_callback at ...>

Should you want to, you can also overide the one or both arguments. The following will swap the left and right mouse-click functionallities.

import vtkplotlib as vpl
fig = vpl.figure()
vpl.quick_test_plot()

def callback(invoker, event_name):
    # Swap left for right and vice-versa.
    if "Left" in event_name:
        swapped = event_name.replace("Left", "Right")
    else:
        swapped = event_name.replace("Right", "Left")

    # Call the callback for the switched event_name.
    vpl.i.call_super_callback(event_name=swapped)

for event_name in ["LeftButtonPressEvent", "LeftButtonReleaseEvent",
                   "RightButtonPressEvent", "RightButtonReleaseEvent"]:
    fig.style.AddObserver(event_name, callback)

fig.show()
vtkplotlib.interactive.call_super_callback(invoker=None, event_name=None)[source]

Just runs get_super_callback(invoker, event_name)(). See get_super_callback().

exception vtkplotlib.interactive.SuperError[source]

Bases: RuntimeError

Raised if get_super_callback() or call_super_callback() are called in an inappropriate context. i.e. Outside of a callback.

vtkplotlib.interactive.null_super_callback()[source]

A placeholder callback for when an event doesn’t have a parent callback which needs calling. Calling this function has no effect.