a bug in traitsui CloseAction?

54 views
Skip to first unread message

Jean-Paul Davis

unread,
Aug 30, 2020, 7:19:29 PM8/30/20
to Enthought Tool Suite users
I came across what looks like another (annoying) bug in traitsui/pyface 7.0 with PyQt5 5.14, this time with the menu CloseAction. (This is under Python 3.6.10 on RHEL 7.7.)  If I try to close the main window using the CloseAction item in a menu in the menubar, Qt hangs in an infinite loop after destroying the window.  Closing the window by clicking on the window's "X" close icon works just fine, with a message in the shell from which Python was executed indicating the python process has been killed.  Following is a super-short example that reproduces the problem:

from traits.api import HasTraits, Float
from traitsui.api import Item, View
from traitsui.menu import MenuBar, Menu, Action, CloseAction

class MyApp(HasTraits):
    a
= Float(1.0)
    menubar
= MenuBar(
       
Menu(
           
CloseAction,
            name
='File'
       
)
   
)
    traits_view
= View(
       
Item('a'),
        menubar
=menubar
   
)

app
= MyApp()
app
.configure_traits()

By adding a custom handler to this code to override the Handler.close method and insert a "import ipdb; ipdb.set_trace()" statement, then stepping, it appears the infinite loop occurs after exiting traitsui.qt4.toolkit._KeyEventHook.eventFilter a number of times.  Each time that method gets called, the "event" argument is a different QEvent, with a type such as 25 (WindowDeactivate), 52 (DeferredDelete), 71 (ChildRemoved), and so on.  Eventually, it gets called with a QEvent type of 16, which does not appear to be a defined QEvent; after returning from this call, even with an ipdb step command, Python hangs.

Perhaps this is a bug upstream in PyQt5 instead of PyFace or traitsui, but I wouldn't know how to determine this.  Hopefully a developer would like to look at it, and if it is a bug, report this as such for the appropriate package?

Jean-Paul Davis

Kit Choi

unread,
Dec 11, 2020, 8:45:34 AM12/11/20
to Enthought Tool Suite users
Dear Jean-Paul,

Thank you for the report and diving into the issue. This does look like a bug in TraitsUI to me. I opened https://github.com/enthought/traitsui/issues/1442 on the issue tracker for this.

Really sorry for the late response.

Best,
Kit

Corran Webster

unread,
Dec 21, 2020, 5:20:23 AM12/21/20
to Enthought Tool Suite users
Hi Jean-Paul,

a possible quick work-around for the issue is to invoke with `app.configure_traits(kind="livemodal")`.  Not optimal, as the layout wants to include space for buttons at the bottom, but you at least see the behaviour you expect.

Hope this helps,

-- Corran

jpd...@sandia.gov

unread,
Dec 1, 2023, 2:36:52 PM12/1/23
to Enthought Tool Suite users
Three years later, I finally thought of a simple work-around: call Python's built-in exit() function from inside the appropriate method (the one called by my "quit" file menu item) of my custom Handler, after closing/disposing all windows.  And yes, the original bug still seems to be there in traitsui/pyface 8.0 and PyQt 5.15.2.

Jean-Paul
Reply all
Reply to author
Forward
0 new messages