On 07/09/2011 11:27 م, Hans-Peter Jansen wrote: Thanks a lot Pete, You mean I don't need to use both import lines?On Wednesday 07 September 2011, 14:04:02 ad...@mbnoimi.net wrote:Hi guys,I wrote a tiny class for delaying splash screen in C++ but when I tired to re-write it in python it didn't work! I got "AttributeError TeSplashScreen object has no attribut QFrate" although TeSplashScreen inherited from QFrame Could you please help me, I'm still a newbie in PyQt and Python. tesplashscreen.py from PyQt4.QtCore import * from PyQt4.QtGui import *Hmm, that * imports are easily avoided. I did as you mentioned exactly.import sys class TeSplashScreen(QFrame): """ Splash doc """ app = QApplication(sys.argv) sPixmap = QPixmap(10, 10) sMessage = QString() messages = ["nothing"] sAlignment = 0 sColor = QColor() def __init__(self, pixmap):You need to call the base class c'tor here, e.g.: super(QFrame, self).__init__() Most of your code below has issues with missing self. references, which will result in access to undefined variables and instances, that are prematurely garbarge collected. I got new issue because I don't know how can I use QStringList class, I read in some article that it's unavailable in PyQt so I tried to use python lists instead but I got an exception at for loop here's the modified class:TypeError object of type int has no len() from PyQt4.QtCore import * from PyQt4.QtGui import * import sys class TeSplashScreen(QFrame): """ Splash doc """ app = QApplication(sys.argv) sPixmap = QPixmap(10, 10) sMessage = QString() # messages = ["nothing"] sAlignment = 0 sColor = QColor() def __init__(self, pixmap): super(QFrame, self).__init__() self.sPixmap = pixmap self.setWindowFlags(Qt.FramelessWindowHint|Qt.WindowStaysOnTopHint) self.setAttribute(Qt.WA_TranslucentBackground) self.setFixedSize(self.sPixmap.size()) def clearMessage(self): self.sMessage.clear() self.repaint() def showMessage(self, theMessage, theAlignment, theColor): self.sMessage = theMessage self.sAlignment = theAlignment self.sColor = theColor self.repaint() def paintEvent(self, pe): aTextRect = QRect(self.rect()) aTextRect.setRect(aTextRect.x()+5, aTextRect.y()+5, aTextRect.width()-10, aTextRect.height()-10) aPainter = QPainter(self) aPainter.drawPixmap(self.rect(), self.sPixmap) aPainter.setPen(self.sColor) aPainter.drawText(aTextRect, self.sAlignment, self.sMessage) def showSplash(self, delay, messages, alignment, color): delay = 0 # self.messages = messages alignment = 0 color = QColor(color) class SleeperThread(QThread): msecs = 0 QThread.msleep(msecs) aSplashScreen = TeSplashScreen(self.sPixmap) aSplashScreen.show for i in range(len(messages)): aSplashScreen.showMessage(messages[i], alignment, color) SleeperThread.msleep(delay) ----- Best Regards Muhammad Bashir Al-Noimi My Blog: http://mbnoimi.net |
_______________________________________________ PyQt mailing list PyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt