[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyQt] QProgressBar not indicating after running once successfully
From: Richard Lang <r1lang () yahoo ! com>
Date: 2013-04-21 22:25:00
Message-ID: 1366583100.34938.YahooMailNeo () web125002 ! mail ! ne1 ! yahoo ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
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.
[Attachment #5 (text/html)]
<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new \
york, times, serif;font-size:10pt"><div><div class="yiv1496782098MsoNormal">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.</div><div \
class="yiv1496782098MsoNormal"> </div><div class="yiv1496782098MsoNormal"><b>Main \
program.... ..etc...</b></div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> </div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">def \
connectDevice(self)</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> if self.usb_serial != \
None:</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> \
self.ui.ProgressBar.setMinimum(0) <span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;"> </span> # settings for \
showing pyqt4 progress \
bar </div><div \
class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> \
self.ui.ProgressBar.setMaximum(0) <span class="yiv1496782098Apple-tab-span" \
style="white-space: pre;"> </span> # not indicating as \
expected </div><div \
class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> \
self.ui.ProgressBar.setValue(0) <span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;"> </span> # first showing \
0%</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;"> \
self.device = \
ScopeDev(self.usb_serial) <span class="yiv1496782098Apple-tab-span" \
style="white-space: pre;"> </span> # device.py my second Python program</div><div \
class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> \
self.device.start() <span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;"> </span> # Connect Call... \
class ScopeDev/def run(self):</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> \
self.device.init_received.connect(self.init_received) <span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;"> </span># end of data processing \
signal received</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> else:</div><div \
class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> \
self.Display_MSG("Connection Error", "device not plug into USB port." )</div><div \
class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;"> </div><div \
class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;"> def \
reprocessdata(self):</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> logging.info("Re-Processing \
Data...")</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> \
self.ui.ProgressBar.setMaximum(0) <span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;"> </span> # hoping to kick \
off the progress bar again. Not even showing 0%</div><div class="yiv1496782098MsoNormal" \
style="margin-bottom: 0.0001pt;"> \
self.ui.ProgressBar.setValue(0) <span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;"> </span> # I tried insert \
QApplication.processEvents() here but did not work</div><div class="yiv1496782098MsoNormal" \
style="margin-bottom: 0.0001pt;"> \
self.device.init() <span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;"> </span> # Call class \
ScopeDev/def init(self): data was being processed</div><div class="yiv1496782098MsoNormal" \
style="margin-bottom: 0.0001pt;"> </div><div class="yiv1496782098MsoNormal" \
style="margin-bottom: 0.0001pt;"> def init_received(self):</div><div \
class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> logging.debug("Init \
received")</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> \
self.ui.ProgressBar.setMaximum(1) <span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;"> </span> # indicated 100% \
on both times, when data processing completed</div><div class="yiv1496782098MsoNormal" \
style="margin-bottom: 0.0001pt;"> \
self.ui.ProgressBar.setValue(1) <span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;"> </span> # first from \
connectDevice and second time from reprocessdata</div><div class="yiv1496782098MsoNormal" \
style="margin-bottom: 0.0001pt;"> </div><div class="yiv1496782098MsoNormal" \
style="margin-bottom: 0.0001pt;"><b>My second python program... ...etc...</b></div><div \
class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;"> </div><div \
class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">class ScopeDev \
(QtCore.QThread):</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> init_received = \
QtCore.pyqtSignal()</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> </div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">def \
__init__(self, usb_serial, usb_serial_baud=9600, timeout=2):</div><div \
class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> QtCore.QThread.__init__(self, \
None)</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> self.serial = \
serial.Serial(usb_serial, usb_serial_baud, timeout=timeout) <span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;"> </span># connect to \
Arduino</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> logging.debug("Connected \
(%s)" % usb_serial)</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> </div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">def \
run(self):</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> \
self.init() <span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;"> </span> #1 Call...def \
init(self):</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> </div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">def init(self):</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> \
self.serial.readline().rstrip() <span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;"> </span># read println put out \
by Arduino/plaser.ino</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> \
self.serial.write(b'init') </div><div \
class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> \
self.sread(expect=b'^done_init$')</div><div class="yiv1496782098MsoNormal" \
style="margin-bottom: 0.0001pt;"> </div><div class="yiv1496782098MsoNormal" \
style="margin-bottom: 0.0001pt;"> def sread(self, \
expect=b'^cmd$'): <span class="yiv1496782098Apple-tab-span" \
style="white-space: pre;"> </span> # loops around to process data from Arduino...etc. \
when completed...</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;"> \
self.init_received.emit() <span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;"> </span> # emits the \
outbound signal back to the main program.</div></div></div></body></html>
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic