Themes, wxpython and statusbar

I am making a program in which I use wxStatusBar, when the download starts, I start the child stream as follows:

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

Loading is another function without parameters (except self). I would like to update my status bar from there with some information about the download progress, but when I try to do this, I often get Xwindow, glib and segfaults errors. Any idea to solve this?

Solved: I just needed to turn on wx.MutexGuiEnter () before changing anything in the GUI inside the stream and wx.MutexGuiLeave () at the end. for instance

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

And that's all: D

+4
source share
2 answers

How do you update the status bar?

I think you should be fine if you create your own event and then post it via wx.PostEvent to notify the frame / status bar in the GUI thread.

To load in the status bar, you might want your event to look something like this:

 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 are some more details from the wxPython wiki.

0
source

Most people access the wxPython wiki:

http://wiki.wxpython.org/LongRunningTasks

I also wrote a small snippet on this:

http://www.blog.pythonlibrary.org/2010/05/22/wxpython-and-threads/

I do not think that I have seen your solution before.

+1
source

Source: https://habr.com/ru/post/1335566/


All Articles