I have a large application that has many small windows. I wanted to use traitsui's file dialog to open some files from these windows. However, when I do, the file dialog correctly spawns and picks a file, but it also consistently switches the active window to an undesirable window after it is finished. I am really confused why.
Here is a simplified test which displays the same problem:
from traitsui.api import *
from traits.api import *
from traitsui.file_dialog import *
class BigApplication(HasTraits):
subwindow=Instance(HasTraits)
open_subwindow=Button('clickme')
traits_view=View(Item(name='open_subwindow'),height=500,width=500)
def _subwindow_default(self):
return Subwindow()
def _open_subwindow_fired(self):
self.subwindow.edit_traits()
class Subwindow(HasTraits):
f=File
some_option = Bool
openf=Button('Browse for file')
traits_view=View(Item(name='f',style='text'),
Item(name='some_option'),
Item(name='openf'),buttons=OKCancelButtons)
def _openf_fired(self):
self.f=open_file()
BigApplication().configure_traits()
When open_file returns and selects the desired file, the active window is switched to the BigApplication window and not back to the Subwindow window (so that the user can select some additional options before clicking OK).