Python (Windows XP) - wx.FileDialog partially remains after Destroy()

Go To


I'm new to Python (and, indeed, new to PC development) and would like to know how I should properly solve a problem I have using FileDialog in a Windows application I am writing...

Here is the relevant part of my code so far...

def SelectLogs(self, event):

    dir = os.getcwd()
    paths = []

    open_dlg = wx.FileDialog(self, message='Select log file',
        defaultDir=dir, style=wx.OPEN | wx.CHANGE_DIR | wx.MULTIPLE)


    if open_dlg.ShowModal() == wx.ID_OK:
        paths = open_dlg.GetPaths()



    def RetrieveLogData(self, paths):

        count = 0
        loglines = []

        self.tc2.WriteText('Loading selected logs...')


        for log in paths:
            read_data = []
            f = open(log, 'r')

            self.tc2.WriteText('\r\n    ' + log)

            read_data = f.readlines()

            count = count + 1

            for line in read_data:

        self.tc2.WriteText('\r\nCompleted loading ' + str(count) + ' log(s)')

My problem is that even though I call open_dlg.Destroy() and self.splitter.Refresh() I still have remnants of the FileDialog showing over the lower one of my wx.TextCtrl (tc2) objects (tc1 is in the top half of the splitter and tc2 in the bottom half).

Once the file(s) are fully loaded and contents displayed in tc1 then tc2 refreshes and displays as I would expect.

I have tried calling the refresh methods on tc1 and tc2 instead of on the splitter but this doesn't seem to have any effect.

Any useful suggestions will be welcome. Thanks.

2012-04-04 07:16
by NoName


You do not need any calls to Refresh() and those will not work. The reason why your GUI freezes is different. Your callback function runs for too long and blocks your GUI thread.

Your should never run any task which may take more than just a few milliseconds in a callback function without creating a new thread.

You should create a new thread for your long running task. I recommend using wx.lib.delayedresult and wx.CallAfter as these are the most convenient. There are many questions / answers on this topic on SO. For example: How to implement a thread in a wxPython GUI application

2012-04-04 10:28
by Fenikso
Thanks very much for your help - I will read up on the solutions you recommend and implement them in my application - NoName 2012-04-05 07:06