如何对wxPython进度条进行线程化 [英] How to thread wxPython progress bar

查看:74
本文介绍了如何对wxPython进度条进行线程化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对wx.ProgressDialog进行线程化.我有一个Progress线程课程

I'm trying to thread wx.ProgressDialog. I got a Progress threading class

class Progress(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
    def run(self):
        max = 1000000

        dlg = wx.ProgressDialog("Progress dialog example",
                               "An informative message",
                               maximum = max,
                               parent=None,
                               style = wx.PD_CAN_ABORT
                                | wx.PD_APP_MODAL
                                | wx.PD_ELAPSED_TIME
                                | wx.PD_ESTIMATED_TIME
                                | wx.PD_REMAINING_TIME
                                )
        keepGoing = True
        count = 0

        while keepGoing and count < max:
            count += 1
            wx.MilliSleep(250)

            if count >= max / 2:
                (keepGoing, skip) = dlg.Update(count, "Half-time!")
            else:
                (keepGoing, skip) = dlg.Update(count)
        dlg.Destroy()

当我按下按钮时会被调用

which gets called when I push a button by

class MiPPanel ( wx.Panel ):
    [...]
    def runmiP(self, event):
        thread1 = Progress() 
        thread1.start() 

当我运行thread1.start()时,会收到100个类型为2012-12-01 00:31:19.215 Python[3235:8807] *** __NSAutoreleaseNoPool(): Object 0x11a88f300 of class NSConcreteAttributedString autoreleased with no pool in place - just leaking 的警告,并且进度条不会显示.

When I run thread1.start() I get 100s of warnings of the type 2012-12-01 00:31:19.215 Python[3235:8807] *** __NSAutoreleaseNoPool(): Object 0x11a88f300 of class NSConcreteAttributedString autoreleased with no pool in place - just leaking and the progress bar doesn't show up.

如何在wxPython中使用线程制作进度条?

How can I use threading with wxPython to make a progress bar?

推荐答案

所有wxPython小部件和操作都应在单个线程中.如果要让对话框由另一个线程控制,则必须使用计时器和队列从另一个线程向对话框发送消息.

All wxPython widgets and manipulation should be in a single thread. If you want to have a dialog controlled by another thread then you will have to use timers and queues to message the dialog from the other thread.

我理解的另一种方法应该起作用(我尚未测试过),它可以在另一个线程中为您的对话框创建一个完全独立的wxApp.您将不得不仍然以某种方式与主线程进行通信.

Another way I understand is supposed to work (I have not tested this) it to create a completely separate wxApp in another thread just for your dialog. You will have to communicate somehow back to the main thread still.

这是更多信息的链接.它在底部有一些有关使用wx.CallAfter更新工作线程进度的信息.它还显示了如何在单独的线程中运行单个函数而不创建单独的类.

Here is a link to more information. It has some info at the bottom about using wx.CallAfter to update progress of a worker thread. It also shows how to run a single function in a separate thread without creating a separate class.

wxPython线程

这篇关于如何对wxPython进度条进行线程化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆