简体   繁体   English

Pyqt4-QProgressBar如何在函数循环处理数据时指示每次

[英]Pyqt4 - QProgressBar how to indicate everytime while a function loops around processing data

  1. It worked the first time but not again when the function that loops around processing data is re-called. 它是第一次工作,但是在调用围绕处理数据的功能时却没有再次工作。 I have 2 python programs. 我有2个python程序。 The main shows the progress bar and the second loops around processing data. 主要显示进度条,第二个显示处理数据的循环。 I've researched all over stackoverflow and google and tried so hard to find a solution. 我已经对stackoverflow和google进行了全面研究,并尽力寻找解决方案。 The closest solution was question asked 'unexplained delay after QProgressBar finish loading 2' but I'm unable to apply it to my problem. 最接近的解决方案是问“ QProgressBar完成加载2后无法解释的延迟”的问题,但我无法将其应用于我的问题。 I also tried applying QApplication.processEvents() but I was not successful. 我也尝试应用QApplication.processEvents(),但未成功。

    Main program... etc... 主程序...等等...

     def connectDevice(self) if self.usb_serial != None: self.ui.ProgressBar.setMinimum(0) # settings for showing pyqt4 progress bar self.ui.ProgressBar.setMaximum(0) # not indicating as expected self.ui.ProgressBar.setValue(0) # first showing 0% self.device = ScopeDev(self.usb_serial) # device.py my second Python program self.device.start() # Connect Call... class ScopeDev/def run(self): self.device.init_received.connect(self.init_received) # end of data processing signal received else: self.Display_MSG("Connection Error", "device not plug into USB port." ) def reprocessdata(self): logging.info("Re-Processing Data...") self.ui.ProgressBar.setMaximum(0) # hoping to kick off the progress bar again. Not even showing 0% self.ui.ProgressBar.setValue(0) # I tried insert QApplication.processEvents() here but did not work self.device.init() # Call class ScopeDev/def init(self): data was being processed def init_received(self): logging.debug("Init received") self.ui.ProgressBar.setMaximum(1) # indicated 100% on both times, when data processing completed self.ui.ProgressBar.setValue(1) # first from connectDevice and second time from reprocessdata 
  2. My second python program... etc... 我的第二个python程序...等等...

     class ScopeDev (QtCore.QThread): init_received = QtCore.pyqtSignal() def __init__(self, usb_serial, usb_serial_baud=9600, timeout=2): QtCore.QThread.__init__(self, None) self.serial = serial.Serial(usb_serial, usb_serial_baud, timeout=timeout) # connect to Arduino logging.debug("Connected (%s)" % usb_serial) def run(self): self.init() #1 Call...def init(self): def init(self): self.serial.readline().rstrip() # read println put out by Arduino/plaser.ino self.serial.write(b'init') self.sread(expect=b'^done_init$') def sread(self, expect=b'^cmd$'): # loops around to process data from Arduino...etc. when completed... self.init_received.emit() # emits the outbound signal back to the main 

Here are some sugestion: 这是一些建议:

First of all remove first initialization, this 3 lines: 首先删除第一个初始化,这3行:

self.ui.ProgressBar.setMinimum(0)  # settings for showing pyqt4 progress bar            
self.ui.ProgressBar.setMaximum(0)  # not indicating as expected          
self.ui.ProgressBar.setValue(0)    # first showing 0%

that is done by default. 默认情况下完成。

Second thing to do: in reprocessdata try to switch those two lines: 第二件事:在reprocessdata尝试切换这两行:

  self.ui.ProgressBar.setMaximum(0)        
  self.ui.ProgressBar.setValue(0)

3. Instead with previous two lines, try to reset progress bar with: 3.而不是使用前两行,请尝试使用以下方法重置进度条:

void QProgressBar::reset () [slot] 无效的QProgressBar :: reset()[slot]

Reset the progress bar. 重置进度栏。 The progress bar "rewinds" and shows no progress. 进度栏“倒带”,并且没有进度。

in your case: self.ui.ProgressBar.reset() 在您的情况下: self.ui.ProgressBar.reset()

- what I don't understand is that why you use progress bar? -我不明白为什么要使用进度条? because you have only two states - 0 (0%) and 1 (100%) 因为您只有两种状态-0(0%)和1(100%)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM