我在实时更新wx.Gauage时遇到问题。wx.Gauge在一个名为ProgressWindow的类中实例化。ProgressWindow用于在工作完成时提供进度条。更新仪表是在一个单独的线程上完成的,这样它就不会阻塞正在完成的工作。不幸的是,当我实例化并启动进度窗口时,仪表仅在"fn_testing_progress_window“测试函数的最后更新。有谁知道为什么会发生这种情况吗?我正在尝试在调用"fn_increment_count“时更新仪表。
注意:我之所以有一个队列来处理更新仪表的请求,是因为如果正在完成的工作分布在多个线程中,每个线程都可以更新仪表。
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)https://stackoverflow.com/questions/44638547
复制相似问题