首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wx.Gauge未实时更新

wx.Gauge未实时更新
EN

Stack Overflow用户
提问于 2017-06-20 03:35:25
回答 0查看 703关注 0票数 0

我在实时更新wx.Gauage时遇到问题。wx.Gauge在一个名为ProgressWindow的类中实例化。ProgressWindow用于在工作完成时提供进度条。更新仪表是在一个单独的线程上完成的,这样它就不会阻塞正在完成的工作。不幸的是,当我实例化并启动进度窗口时,仪表仅在"fn_testing_progress_window“测试函数的最后更新。有谁知道为什么会发生这种情况吗?我正在尝试在调用"fn_increment_count“时更新仪表。

注意:我之所以有一个队列来处理更新仪表的请求,是因为如果正在完成的工作分布在多个线程中,每个线程都可以更新仪表。

代码语言:javascript
复制
def fn_testing_progress_window():
    pw = ProgressWindow(self.main_panel)
    pw.fn_start()

    pw.fn_increment_count(increment = 50, msg = "50 Now")
    time.sleep(3)
    pw.fn_increment_count(increment = 75, msg = "75 Now")
    time.sleep(3)
    pw.fn_increment_count(increment = 100, msg = "Finished")


def fn_start(self):
    print "Starting Progress"
    _runner_thread = threading.Thread(target = self.fn_run)
    _runner_thread.start()

def fn_run(self):
    self._running = True
    self._current_count = 0

    while(self._running):
        # Wait til there is something in queue or til run is stopped
        while True:
            if (not self._update_queue.empty()):
                print "not empty"
                break

            if (not self._running):
                break

        _value, _msg = self._update_queue.get()

        # Update progress bar accordingly
        if _value:
            self._current_count += _value
            print "Updating value: %d" %(self._current_count)
            wx.CallAfter(self._progress_gauge.SetValue, self._current_count)

        if _msg:
            print "Updating msg: %s" %(_msg)
            wx.CallAfter(self._progress_output.SetValue, str(_msg))

        if (self._current_count >= self._total_count):
            pass

        # Have time for msg to appear
        time.sleep(0.1)


def fn_increment_count(self,
                       increment = 1,
                       msg = None):
    """
    Ability to update current count on progress bar and progress msg.
    If nothing provided increments current count by 1
    """
    _item_l = (increment, msg)
    self._update_queue.put(_item_l)
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44638547

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档