Bug report: Exception when closing a workbench with status bar
Environment
OS: Windows Python version: 3.10 Toolkit: Wx
Description
When creating a Workbench with a status_bar, the following exception is raised when closing the window:
Traceback (most recent call last):
File "D:\ANSYSDev\thirdparty_sources\pyface\pyface\dock\dock_sizer.py", line 4022, in CalcMin
dx, dy = self._contents.calc_min()
File "D:\ANSYSDev\thirdparty_sources\pyface\pyface\dock\dock_sizer.py", line 3190, in calc_min
dx, dy = item.calc_min(use_size)
File "D:\ANSYSDev\thirdparty_sources\pyface\pyface\dock\dock_sizer.py", line 2402, in calc_min
theme = self.theme
File "D:\ANSYSDev\thirdparty_sources\pyface\pyface\dock\dock_sizer.py", line 503, in _get_theme
return self.control.GetParent().owner.theme
RuntimeError: wrapped C/C++ object of type TraitsUIPanel has been deleted
Steps to Reproduce
-
Run the following script (adapted and minimized from the
workbenchexample):from traits.etsconfig.api import ETSConfig ETSConfig.toolkit = 'wx' from traits.api import HasTraits, Int, Str from pyface.api import GUI from pyface.action.api import StatusBarManager from pyface.workbench.api import WorkbenchWindow, Workbench class ExampleWorkbenchWindow(WorkbenchWindow): def _status_bar_manager_default(self): return StatusBarManager(messages=['', '']) class Person(HasTraits): name = Str() age = Int() def __str__(self): return self.name if __name__ == "__main__": gui = GUI() fred = Person(name="fred", age=42) workbench = Workbench(state_location=gui.state_location, window_factory=ExampleWorkbenchWindow) window = workbench.create_window() window.open() window.edit(fred) gui.start_event_loop() -
Close the application
Other observations
The exception does not occur if the window tab (fred) is closed before closing the Application.
Changing the toolkit to 'qt' also makes the exception disappear.
A crude way to get rid of the error is by removing
https://github.com/enthought/pyface/blob/85fd54431983b6472eab5e341b139a9b53f150a9/pyface/i_application_window.py#L132-L133
added in #1141. I suspect this is not the correct solution though, and #1141 simply exposed the underlying issue.
Possibly related to this recent PR: https://github.com/enthought/pyface/pull/1192
Directly reverting #1192 (and passing self.control as parent) doesn't fix the issue, but it might indeed be related to why parent was maybe used at some earlier point.
Also note: I've noticed this particular repro doesn't produce an error on Linux, but have seen the same error in a more complex application. If desired, I can try and find a version that fails on both platforms.
I have a hypothesis that this is because the status bar is not being removed from the owning window before it is destroyed.