Reputation: 468
I am trying to pass a counter from a python COM thread back into a wxpython tabpanel. Anyone have a solution that would work. Some of my code below:
This class is seperate from my wxPython code but is called out and data sent to this thread.
class Log_COM_thread(Thread):
............
def run(self):
.............
int_log_cnt = int_log_cnt + 1
int_log.TabPanel.gauge.SetValue(int_log_cnt)
if int_log_cnt == 64:
int_log.TabPanel.Int_Log_Status.SetLabel('Extraction Complete')
The seperate module, int_log, this counter value is being sent to is called out like this:
class TabPanel(wx.Panel):
def __init__(self, parent):
self.gauge = wx.Gauge(self, range=72, size=(250, 25))
.....and then more wxpython code.
The error I run into is:
Exception in thread Thread-8:
Traceback (most recent call last):
File "F:\Python27\lib\threading.py", line 551, in __bootstrap_inner
self.run()
File "F:\Documents and Settings\swhite\Desktop\OG GUI Working Jan 13\nbm.py", line 267, in run
int_log.TabPanel.gauge.SetValue(int_log_cnt)
AttributeError: type object 'TabPanel' has no attribute 'gauge'
How would I send my counter back to that gauge in wxpython from my external thread. Any help in direction of how to do this would be extremely helpful.
Upvotes: 1
Views: 382
Reputation: 33071
You cannot call wx methods directly from a separate thread. You need to use one of wxPython thread-safe methods to communicate back to the main GUI thread. They are wx.CallAfter, wx.CallLater and wx.PostEvent.
There is lots of information on threads and wx on the wxPython wiki. I also wrote a tutorial on the subject that might help you.
Upvotes: 1