2011-01-14 33 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.