LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Python/PyQt4 - Newbie Structure question (http://www.linuxquestions.org/questions/programming-9/python-pyqt4-newbie-structure-question-616871/)

ocularb0b 01-28-2008 10:42 AM

Python/PyQt4 - Newbie Structure question
 
Ok i've been playing with PyQt4
i have made the following app that works fine:

Code:

#!/usr/bin/env python

import sys
import time
from PyQt4 import QtGui, QtCore

class MainWindow(QtGui.QWidget):
    def __init__(self):
        self.buildWindow()
       
    def buildWindow(self, parent=None):
            QtGui.QWidget.__init__(self, parent)
        self.setGeometry(150, 100, 800, 600)
        self.setWindowTitle('::System Log::')
        quitBtn = QtGui.QPushButton('close', self)
        quitBtn.setGeometry(720, 550, 60, 40)
        self.connect(quitBtn, QtCore.SIGNAL('clicked()'),
            QtGui.qApp, QtCore.SLOT('quit()'))
        self.logwidget = QtGui.QTextEdit('', self)
        self.logwidget.setGeometry(5, 5, 790, 540)
        self.logwidget.isReadOnly()
        self.logwidget.setFontPointSize(7)
        self.logwidget.append('Welcome Jerks!')

    def LogParse(self):
        logfile = open('/var/log/syslog', 'r')
        self.logwidget.clear()
        for line in logfile:
            self.logwidget.append(line)
        logfile.close()

app = QtGui.QApplication(sys.argv)
mainwindow = MainWindow()
mainwindow.show()
mainwindow.LogParse()
sys.exit(app.exec_())

However im confused about how it is exectued. I would like see the main window and then run 'LogParse()' to fill the QTextEdit widget. As is the main window doesn't appear until after 'LogParse' runs. Ultimately i want 'LogParse' inside a 'while' loop with a sleep() to update the contents of the QTextEdit widget every few seconds.
I've missed something fundamental here and cant seem to rearange things to work this way.
Can someone show me what that might look like?
Thanks in advance


All times are GMT -5. The time now is 07:43 AM.