I’m using ObjectListView to display data sourced from a local sqlite database. Sqlalchemy is used to perform sql queries.
I want to remove the items selected from the ListCtrl/ObjectListView, then in a thread run a query to delete the records associated with those items from the database so the GUI does not hang. Here is what my code looks like (with all the extraneous parts cut out):
class FileWindow(wx.Frame):
def __init__(self):
wx.Frame.__init__(self)
panel = wx.Panel(self, -1)
self.fileOlv = FastObjectListView(panel, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
self.fileOlv.Bind(wx.EVT_KEY_DOWN, self.deleteFile)
def deleteFile(self,evt):
t=threading.Thread(target=self.__deleteFile)
t.start()
def __deleteFile(self):
removedFiles = self.fileOlv.GetSelectedObjects()
self.fileOlv.RemoveObjects(removedFiles)
# Gui freezes until self.deleteFileInThread is finished running
wx.CallAfter(self.deleteFileInThread, removedFiles)
def deleteFileInThread(self, removedFiles):
d = file_collection.delete().where(file_collection.c.id == bindparam('file_id'))
for file in removedFiles:
self.conn.execute(d, file_id = file.id)
However GUI hangs until the for loop is finished. What is incorrect about my thread and wx.CallAfter implementation?