I'm trying to run a simple 'for' loop to execute some external programs (ripping tracks with cdparanoia/lame, but I've stripped the problem down to bare essentials that demonstrate the problem).

Each loop should update a gui label with the current loop number.  The
setText statement is within the 'for' loop, but the gui doesn't get
updated until the loop is either completed or several iterations into
the complete loop.  The loop works, but the updates to the  label do not.

The Gui was created with QTDesigner, and I'm using python 2.6.4 on
Ubuntu 9.10.

The statements that are crucial follow below, and I've attached the two
py files if you care to see the full code.

Any suggestions for getting the label.setText statements to update the gui with each loop iteration, would be appreciated.

TIA,
Dan Cherry


    def runloop(self):
self.ui.label.setText('Begin Loop') ## <--doesn't update before loop

        for i in range(1,6):
self.ui.label.setText('loop %s' % i) ## <--doesn't update for each loop - but does update after the loop completes
            rval = self.loop(i)

    def loop(self, loop_no):
        time.sleep(3)
print loop_no ## <--the print statements display properly as the loop progresses
        return



# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'settext.ui'
#
# Created: Mon Feb 15 11:01:26 2010
#      by: PyQt4 UI code generator 4.6
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

class Ui_SetTextTest(object):
    def setupUi(self, SetTextTest):
        SetTextTest.setObjectName("SetTextTest")
        SetTextTest.resize(383, 247)
        self.centralwidget = QtGui.QWidget(SetTextTest)
        self.centralwidget.setObjectName("centralwidget")
        self.pushButton_Loop = QtGui.QPushButton(self.centralwidget)
        self.pushButton_Loop.setGeometry(QtCore.QRect(100, 30, 115, 30))
        self.pushButton_Loop.setObjectName("pushButton_Loop")
        self.label = QtGui.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(110, 140, 221, 21))
        self.label.setObjectName("label")
        SetTextTest.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(SetTextTest)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 383, 27))
        self.menubar.setObjectName("menubar")
        SetTextTest.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(SetTextTest)
        self.statusbar.setObjectName("statusbar")
        SetTextTest.setStatusBar(self.statusbar)

        self.retranslateUi(SetTextTest)
        QtCore.QMetaObject.connectSlotsByName(SetTextTest)

    def retranslateUi(self, SetTextTest):
        SetTextTest.setWindowTitle(QtGui.QApplication.translate("SetTextTest", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_Loop.setText(QtGui.QApplication.translate("SetTextTest", "Start Loop", None, QtGui.QApplication.UnicodeUTF8))
        self.label.setText(QtGui.QApplication.translate("SetTextTest", "Ready", None, QtGui.QApplication.UnicodeUTF8))

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, time
from PyQt4 import QtCore, QtGui
from settextgui import Ui_SetTextTest

class StartQT4(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_SetTextTest()
        self.ui.setupUi(self)
        QtCore.QObject.connect(self.ui.pushButton_Loop,QtCore.SIGNAL("clicked()"), self.runloop)

    def runloop(self):
        self.ui.label.setText('Begin Loop') ## <--doesn't update before loop

        for i in range(1,6):
            self.ui.label.setText('loop %s' % i) ## <--doesn't update for each loop
            rval = self.loop(i)

    def loop(self, loop_no):
        time.sleep(3)
        print loop_no
        return

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    myapp = StartQT4()
    myapp.show()
    sys.exit(app.exec_())
_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to