Hello,
I have a question on threading with wxPython. I've started a thread
using:
threading.Thread(target=self.RunProgram).start()
From within the thread, I cannot access many things outside of the
class without getting errors. For example, see the following (self is
a class from wx.Panel, the parent is the frame, and sb is a
StatusBar):
self.parent.sb.SetStatusText('Program Running...')
I get the following error (only on Linux, it runs without problems on
Windows):
python: Fatal IO error 0 (Success) on X server :0.0.
I understand that I am not supposed to code it this way and I've found
a solution to this problem by creating a custom event, sending the
event to the panel class that started the thread, and then having a
separate method that updates the status. A bit long winded, but it
works.
However, I can't find a solution to my next problem. I want to create
a modal dialog and have the thread wait for the response of it:
dial = wx.MessageDialog(None, msg, 'Error, Save Current Data?',
wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
if dial.ShowModal() == wx.ID_YES:
do stuff....
else:
do other stuff...
Again, this works fine under Windows, but linux/GTK gives me a
segmentation fault when ShowModal() is called. I've tried changing
the parent, "None", to be "self" and several other things, but it
would still not work. I can't use the solution I used above, because
I need to get the result of this modal dialog. The thread must not
process anymore until ShowModal returns.
I'm new to programming with threads, can anyone point me in the right
direction? I've tried googling for hours now without any success.
Thanks!