I'm using wxPython to build the GUI of my program,I am having trouble with running a function that uses a thread to get data from a file and display it in the ObjectListView, reading the data from the file runs fine but displaying the data from the thread sometimes crashes the whole program. gui.ProgressDialog is a wx.Frame that will show progress bar until the thread is finished. self.dv is an ObjectListView, an object that is derived from wx.ListCtrl, the set_data is a function I have written, that iterate over the data and adds it to the list.
def set_data(self,data):
"""set the data on the ObjectListView"""
pd = gui.ProgressDialog("Setting Data..")
def set_thread():
self.dv.set_data(data) #Takes time
pd.Close()
#opens a thread that sets the data
t = Thread(target = set_thread,name="SetDataThread")
t.start()
I have read something about wx.CallAfter and that I should use it but I didn't understand how. I tried calling the set_data like this -
wx.CallAfter(self.dv.set_data,data) but it didn't work either. can someone explain the functions wx.CallAfter , wx.CallLater , wx.PostEvent , how can they be helpful when using threads with wxPython and which one of them should I use? or another solution for this?
self.dv, and what does itsset_datado?