I need to have a file open dialog for my project. Ideally I need to have the input to BGE responsive while the file dialog is open. Even though BGE continues in the background while the wxFileDialog is open BGE won’t accept any keyboard or mouse input and the display freezes, but sound keeps playing OK. The actual file dialog itself does accept input. Here’s the relevant code which is triggered by a keyboard press …
def openFile (cont): print ("File load triggered") def fileDialog (event): style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST dialog = wx.FileDialog(None, 'Open', wildcard='*.txt', style=style) if dialog.ShowModal() == wx.ID_OK: path = dialog.GetPath() else: path = None dialog.Destroy() print (path) app = wx.App(redirect=True) top = wx.Frame(None, title="Hello World", size=(300,200)) # top.Bind(wx.EVT_CLOSE, fileDialog) top.Show() app.MainLoop()
I’m experimenting there with “Show()” which is supposed to create a GUI element while not blocking the parent. Does not work though, I guess the parent here is Blender which is not a wxPython GUI element. The file dialog can only be called with ShowModal() which does “block” the parent part of the GUI.
The full blend file is here: http://files.djbarney.org/dj_turntable_platter_physics_simulation_111.blend
If the user needs to open a file or cancel to be able to continue interacting with the game engine then so be it, but I’m not certain yet that what I’m thinking of can’t be achieved. There’s a way of using non-gui-blocking code but that’s more, I think for calculations. I’m not sure it’s possible to put the file dialog on another thread to prevent blocking of the game engine because apparently your’re not supposed to make GUI code on the other thread which leads to crashes, which is exactly what I’ve been getting.