[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">&nbsp;</div><div class="yiv1496782098MsoNormal"><b>Main \
program.... ..etc...</b></div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">&nbsp;</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">def \
connectDevice(self)</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self.usb_serial != \
None:</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.ui.ProgressBar.setMinimum(0)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;">	</span>&nbsp;# settings for \
showing pyqt4 progress \
bar&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div \
class="yiv1496782098MsoNormal" style="margin-bottom:  \
0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.ui.ProgressBar.setMaximum(0)&nbsp;&nbsp;<span class="yiv1496782098Apple-tab-span" \
style="white-space: pre;">		</span>&nbsp;# not indicating as \
expected&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div \
class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.ui.ProgressBar.setValue(0)&nbsp;&nbsp;&nbsp;&nbsp;<span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;">			</span>&nbsp;# first showing \
0%</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.device = \
ScopeDev(self.usb_serial)&nbsp;&nbsp;&nbsp;<span class="yiv1496782098Apple-tab-span" \
style="white-space: pre;">	</span>&nbsp;# device.py my second Python program</div><div \
class="yiv1496782098MsoNormal" style="margin-bottom:  \
0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.device.start()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;">			</span>&nbsp;# Connect Call... \
class ScopeDev/def run(self):</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.device.init_received.connect(self.init_received) &nbsp;&nbsp;&nbsp;&nbsp;<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;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:</div><div \
class="yiv1496782098MsoNormal" style="margin-bottom:  \
0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.Display_MSG("Connection Error", "device not plug into USB port." )</div><div \
class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">&nbsp;</div><div \
class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">&nbsp;def \
reprocessdata(self):</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logging.info("Re-Processing \
Data...")</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.ui.ProgressBar.setMaximum(0)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;">		</span>&nbsp;# hoping to kick \
off the progress bar again. Not even showing 0%</div><div class="yiv1496782098MsoNormal" \
style="margin-bottom:  0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.ui.ProgressBar.setValue(0)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;">			</span>&nbsp;# I tried insert \
QApplication.processEvents() here but did not work</div><div class="yiv1496782098MsoNormal" \
style="margin-bottom: 0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.device.init()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;">				</span>&nbsp;# Call class \
ScopeDev/def init(self): data was being processed</div><div class="yiv1496782098MsoNormal" \
style="margin-bottom: 0.0001pt;">&nbsp;</div><div class="yiv1496782098MsoNormal" \
style="margin-bottom: 0.0001pt;">&nbsp;def init_received(self):</div><div \
class="yiv1496782098MsoNormal" style="margin-bottom:  \
0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logging.debug("Init \
received")</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.ui.ProgressBar.setMaximum(1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;">		</span>&nbsp;# indicated 100% \
on both times, when data processing completed</div><div class="yiv1496782098MsoNormal" \
style="margin-bottom: 0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.ui.ProgressBar.setValue(1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;">		</span>&nbsp;# first from \
connectDevice and second time from reprocessdata</div><div class="yiv1496782098MsoNormal" \
style="margin-bottom: 0.0001pt;">&nbsp;</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;">&nbsp;</div><div \
class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">class ScopeDev \
(QtCore.QThread):</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; init_received = \
QtCore.pyqtSignal()</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">&nbsp;</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;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QtCore.QThread.__init__(self, \
None)</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.serial = \
serial.Serial(usb_serial,  usb_serial_baud, timeout=timeout)&nbsp;&nbsp;&nbsp;<span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;">	</span># connect to \
Arduino</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logging.debug("Connected \
(%s)" % usb_serial)</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">&nbsp;</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">def \
run(self):</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.init()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;">					</span>&nbsp;#1 Call...def \
init(self):</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">&nbsp;</div><div  class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">def init(self):</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.serial.readline().rstrip()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.serial.write(b'init')&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div \
class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.sread(expect=b'^done_init$')</div><div class="yiv1496782098MsoNormal" \
style="margin-bottom: 0.0001pt;">&nbsp;</div><div  class="yiv1496782098MsoNormal" \
style="margin-bottom: 0.0001pt;">&nbsp; def sread(self, \
expect=b'^cmd$'):&nbsp;&nbsp;&nbsp;<span class="yiv1496782098Apple-tab-span" \
style="white-space: pre;">			</span>&nbsp;# loops around to process data from Arduino...etc. \
when completed...</div><div class="yiv1496782098MsoNormal" style="margin-bottom: \
0.0001pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.init_received.emit()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span \
class="yiv1496782098Apple-tab-span" style="white-space: pre;">			</span>&nbsp;# 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