wxPython: MainLoop() seems to hang
        Posted  
        
            by BandGap
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by BandGap
        
        
        
        Published on 2010-05-18T16:29:15Z
        Indexed on 
            2010/05/20
            21:00 UTC
        
        
        Read the original article
        Hit count: 245
        
wxpython
Hi all, my problem stems from the use of wxApp as far as I can tell.
Inside a litte subroutine I call a wx.MessageDialog to ask for a yes or no. I retrieve the answer an process some stuff acordingly. My example code below actually works (though it might be ugly) except that the Dialog box stays open after hitting one of the buttons...
import wx
from os import path
def HasFile(filename):
    if path.isfile(filename ):
        app = wx.App()
        dial = wx.MessageDialog(None, 
                                'Die Datei "'+filename+'" wurde gefunden.\nSoll sie eingelesen werden?',
                                'Bitte antworten',
                                wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
        result = dial.ShowModal()
        dial.EndModal(retCode=0)
        dial.Destroy()
        app.MainLoop()
        return result == wx.ID_YES
    else:
        return False
So while the rest of the program does whatever is expected, the box just sits there. It also seems like my calls to matplotlib later on are producing errors (a Tkinter error to be precise), maybe because of the wx stuff?
Edit: I tried to end the app with a call to app.Destroy(). This doesn't change the fact that the box is still there. When I issue a app.IsActive() afterwards the whole program exits (almost like a sys.exit())! How come?
Edit 2: Adding a wxApp like this isn't a good idea since the other scripts get affected as well. Subsequent plotting commands don't get displayed and I don't know how to fix this. Thus I decided to remove the DialogBox alltogether.
© Stack Overflow or respective owner