Creating wxVTKRenderWindowInteractor fails on Ubuntu 24.04.1

Hi, creating a wxVTKRenderWindowInteractor fails with NotImplementedError and SystemError: <slot wrapper '__init__' of 'sip.simplewrapper' objects> returned a result with an exception set .

This happens on a second computer running Ubuntu 24.04.1, its working fine on 22.04.1. This might also be due to some other issue, the only difference I can make out at the moment is the different ubuntu version.

Example code:

import wx
import vtk
from vtkmodules.wx.wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor


class MyFrame(wx.Frame):
    def __init__(self, parent):
        super().__init__(parent, title="wxVTK Example", size=(800, 600))

        panel = wx.Panel(self)

        self.vtk_widget = wxVTKRenderWindowInteractor(panel, -1)    # This fails

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.vtk_widget, 1, wx.EXPAND)
        panel.SetSizer(sizer)

        renderer = vtk.vtkRenderer()
        self.vtk_widget.GetRenderWindow().AddRenderer(renderer)

        interactor = self.vtk_widget.GetRenderWindow().GetInteractor()

        sphere = vtk.vtkSphereSource()
        sphere.SetRadius(1.0)

        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(sphere.GetOutputPort())

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)

        renderer.AddActor(actor)
        renderer.ResetCamera()

        self.vtk_widget.Enable(1)
        self.vtk_widget.Initialize()


if __name__ == "__main__":
    app = wx.App()
    frame = MyFrame(None)
    frame.Show()
    app.MainLoop()

This fails with the following stack trace:

NotImplementedError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/user/developer/3d-medical-imaging/wx_test.py", line 41, in <module>
    frame = MyFrame(None)
            ^^^^^^^^^^^^^
  File "/home/user/developer/3d-medical-imaging/wx_test.py", line 12, in __init__
    self.vtk_widget = wxVTKRenderWindowInteractor(panel, -1)    # This fails
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/developer/3d-medical-imaging/venv/lib/python3.11/site-packages/vtkmodules/wx/wxVTKRenderWindowInteractor.py", line 167, in __init__
    baseClass.__init__(self, parent, ID, pos=position, size=size,
SystemError: <slot wrapper '__init__' of 'sip.simplewrapper' objects> returned a result with an exception set

Specs on machine where it doesn’t work:

python 3.11.14
24.04.1-Ubuntu
vtk==9.5.2
wx==4.2.5
OpenGL version string: 4.6 (Compatibility Profile) Mesa 25.2.8-0ubuntu0.24.04.1
$XDG_SESSION_TYPE = x11 (originally on wayland but also didn't work)

Spec on machine where it does work:

python 3.11.13
22.04.1-Ubuntu
vtk==9.5.2
wx==4.2.3
OpenGL version string: 4.6 (Compatibility Profile) Mesa 22.04.3-1ubuntu3.1-22.04.1
$XDG_SESSION_TYPE = wayland

Maybe I’m having driver issues? I don’t really know how to track down the not implemented thing.. I guess some parameter combination doesn’t work for some reason.

Thanks for your advice!

Since the wx.Frame __init__ method is what raises the exception, you can try removing or commenting out the line that calls that method to see what the effect is:

 class MyFrame(wx.Frame):
     def __init__(self, parent):
-        super().__init__(parent, title="wxVTK Example", size=(800, 600))
+        #super().__init__(parent, title="wxVTK Example", size=(800, 600))

I don’t think this is a driver issue, but it might be the result of a change in the version of gtk that wx uses. What versions of gtk are installed on these two machines? Whats the status of support for x11 for the versions of gtk that are installed?

Thanks for your reply!

Working: libgtk-3-dev:amd64 3.24.33-1ubuntu2.2
Not working: libgtk-3-dev:amd64 3.24.41-4ubuntu1.3

I’m not exactly sure what you mean by status of X11 support… Running GDK_BACKEND=x11 gtk3-demo works fine.

Could there be any other packages/libraries I would need to check for version mismatches?

The exception is raised by self.vtk_widget = wxVTKRenderWindowInteractor(panel, -1). More specifically by this:

baseClass.__init__(self, parent, ID, pos=position, size=size,
                                   style=style,
                                   attribList=attribList)

The super().__init__() call is required. I tried to do wxVTKRenderWindowInteractor(self, -1) but it results in the same error.

Hmm, yeah, they’re both gtk 3.24 so I wouldn’t expect differences in behavior. You’re right about super().__init__(), I was misreading the stack trace.

If gtk works with GDK_BACKEND=x11, then I would expect it to work fine with VTK 9.5, which is also x11. However you can’t trust me 100% on that, it’s been ages since I did any gtk programming. Have you tried setting GDK_BACKEND=x11 before running your code?

The baseClass stuff is at line 47 in wxVTKRenderWindowInteractor.py:

baseClass = wx.Window
if wx.Platform == "__WXGTK__":
    import wx.glcanvas
    baseClass = wx.glcanvas.GLCanvas

This if statement was added to the code 20 yrs ago, so I don’t know if GLCanvas is still the best base class to use.