Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug report: Exception when closing a workbench with status bar #1217

Open
greschd opened this issue Mar 13, 2023 · 4 comments
Open

Bug report: Exception when closing a workbench with status bar #1217

greschd opened this issue Mar 13, 2023 · 4 comments

Comments

@greschd
Copy link
Contributor

greschd commented Mar 13, 2023

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 workbench example):

    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.

@greschd
Copy link
Contributor Author

greschd commented Mar 13, 2023

A crude way to get rid of the error is by removing

if self.status_bar_manager is not None:
self.status_bar_manager.destroy()

added in #1141. I suspect this is not the correct solution though, and #1141 simply exposed the underlying issue.

@corranwebster
Copy link
Contributor

Possibly related to this recent PR: #1192

@greschd
Copy link
Contributor Author

greschd commented Mar 15, 2023

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.

@corranwebster
Copy link
Contributor

I have a hypothesis that this is because the status bar is not being removed from the owning window before it is destroyed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants