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
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
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
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 program.
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt