[PyQt] QProgressBar not indicating after running once successfully

Richard Lang r1lang at yahoo.com
Sun Apr 21 23:25:00 BST 2013

I have 2 .py programs one main and the other starts serial communication to Arduino and has a function that loops around to process data from Arduino. So I use QProgressBar in the main program to indicate data being processed (takes about 2 minutes). In the second program when it is first called, it will serial connected and then it calls the functions to process data. At the end of data processing, it emits signal back to the main. So far all works fine. But a second and subsequent call to the second program function to re-process data, the QProgressBar does not indicate anymore and it is not even showing 0% to begin with, why? But it does show 100% each time when data processing is completed. Here's my code related to my problem. I research all over stackoverflow and google and tried so hard to find a solution.
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
            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
My second python program... ...etc...
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
  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 program.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130421/e19e0071/attachment-0001.html>

More information about the PyQt mailing list