The program listed below downloads the broadcast schedule of a radio station 
for the cureent day and the three following. 
For each date , it reads an url, updates the progressBar and prints out in a 
QListWidget the date corresponding to the url just downloaded.

When I run this program, the progressBar is updated as soon as each page is 
received, but the rows added into the QListWidget are displayed, all at the 
same time, 
only when all the pages are received, i.e. when the loop "for jour in jours" 
ends.

(in the program listed below the lines commented out "" and/or "" change 
nothing if uncommented).

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from PyQt4.QtCore import *
from PyQt4.QtGui import *

from mx.DateTime import *
import urllib

class radioUi(object):
    def setupUi(self, radioUi):
        radioUi.setObjectName("radioUi")
        
radioUi.resize(QSize(QRect(0,0,268,352).size()).expandedTo(radioUi.minimumSizeHint()))

        self.log = QListWidget(radioUi)
        self.log.setGeometry(QRect(10,80,248,261))
        self.log.setObjectName("log")

        self.btnGo = QPushButton(radioUi)
        self.btnGo.setGeometry(QRect(160,20,80,26))
        self.btnGo.setObjectName("pushButton")
        self.btnGo.setText(u"start")
    
        self.progressBar = QProgressBar(radioUi)
        self.progressBar.setGeometry(QRect(10,50,241,23))
        self.progressBar.setProperty("value",QVariant(24))
        
class radioProgDialog(QDialog, radioUi):
    def __init__(self):
        QDialog.__init__(self)
        # Set up the user interface 
        self.setupUi(self)
        self.connect(self.btnGo,SIGNAL("clicked()"),self.extraire)
        #

    def extraire(self):
        url='http://www.radiofrance.fr/francevivace/prog/index.php?time=%u'
        # 
        jours=[(int((now() + (j * oneDay)).ticks())) for j in range(0, 4)]
        self.progressBar.setMaximum(len(jours))
        self.progressBar.setValue(0)
        print 'maxi', self.progressBar.maximum()
        for jour in jours:
                print self.log.updatesEnabled()
                next_url=url % jour
                p=urllib.urlopen(next_url).read()
                #self.pagesEmissions.append(p)
                d=DateFromTicks(jour)
                logText=u'téléchargement %02d/%02d/%d' % (d.day,d.month,d.year)
                self.log.addItem(logText)
                self.progressBar.setValue(self.progressBar.value() + 1) 
                print 'value', self.progressBar.value()
                #self.log.update()
                #self.log.repaint()
                QCoreApplication.processEvents(QEventLoop.AllEvents)
                print logText
        print 'fini Vivace'

if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)
    radioProg = radioProgDialog()
    radioProg.show()
    sys.exit(app.exec_())

Version Numbers Used
Python 2.5.1
Qt 4.3.2
PyQt 4.3.1
sip 4.7
QScintilla 2.1
Eric4 4.0.3 (r1529)

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to