2011-01-14 34 views
4

我在做一个节目中,我使用的是wxStatusBar,当下载开始,我开始一个子线程这样的:线程,wxPython的和状态

def OnDownload(self, event): 
    child = threading.Thread(target=self.Download) 
    child.setDaemon(True) 
    child.start() 

下载是不带参数的另一个功能(除自)。我想从那里更新状态栏,并提供关于下载进度的一些信息,但是当我尝试这样做时,我经常会遇到Xwindow,glib和segfaults错误。任何想法解决这个问题?

已解决:我只需要在完成之前在线程内的GUI和wx.MutexGuiLeave()更改某些内容之前包含wx.MutexGuiEnter()。例如

def Download(self): 
    #stuff that doesn't affect the GUI 
    wx.MutexGuiEnter() 
    self.SetStatusText("This is a thread") 
    wx.MutexGuiLeave() 

而这一切:d

回答

0

你如何更新状态栏?

我认为你应该没问题,如果你创建一个自定义事件,然后通过wx.PostEvent发布它来通知GUI线程中的帧/状态栏。

在状态栏下载进度,您可能希望事件看起来是这样的:

DownloadProgressEvent, EVT_DL_PROGRESS = wx.lib.newevent.NewEvent() 

# from the thread... 

event = DownloadProgressEvent(current=100, total=1000, filename="foo.jpg") 
wx.PostEvent(frame, event) 

# from the frame: 

def OnDownloadProgress(self, event): 
    self.statusbar.update_dl_msg(event.current, event.total, event.filename) 

Here's some more detail from the wxPython wiki.