[PyQt] Delaying splash screen
Nick Gaens
mail at nickgaens.com
Wed Sep 7 13:57:33 BST 2011
Can you please specify *what line* this AttributeError is pointing at?
On Wed, Sep 7, 2011 at 14:04, <admin at 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 *
> import sysclass TeSplashScreen(QFrame):
> """
> Splash doc
> """
>
> app = QApplication(sys.argv)
> sPixmap = QPixmap(10, 10)
> sMessage = QString()
> messages = ["nothing"]
> sAlignment = 0
> sColor = QColor()
>
> def __init__(self, pixmap):
> self.sPixmap = pixmap
> self.QFrame(self, Qt.FramelessWindowHint|Qt.WindowStaysOnTopHint)
> self.setAttribute(Qt.WA_TranslucentBackground)
> self.setFixedSize(sPixmap.size())
>
> def clearMessage(self):
> sMessage.clear()
> repaint()
>
> def showMessage(self, theMessage, theAlignment, theColor):
> self.sMessage = theMessage
> self.sAlignment = theAlignment
> self.sColor = theColor
> repaint()
>
> def paintEvent(self, pe):
> aTextRect(rect())
> aTextRect.setRect(aTextRect.x()+5, aTextRect.y()+5, aTextRect.width()-10, aTextRect.height()-10)
> aPainter = QPainter(self)
> aPainter.drawPixmap(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)
>
> # def showSplash(delay, messages, alignment, color):
> # delay = 0
> # messages = QStringList()
> # alignment = 0
> # color = QColor()
> # class SleeperThread(QThread):
> # msecs = 0
> # QThread.msleep(msecs)
> # aSplashScreen = TeSplashScreen(sPixmap)
> # aSplashScreen.show()
> # for i in range(messages.count()):
> # aSplashScreen.showMessage(messages[i], alignment, color)
> # SleeperThread.msleep(delay)
>
>
> tesplashscreen.h
>
> #ifndef TSPLASHSCREEN_H#define TSPLASHSCREEN_H
> #include <QFrame>#include <QPainter>#include <QThread>
> class TeSplashScreen : public QFrame
> {public:
> TeSplashScreen(const QPixmap& pixmap);
> void showMessage(const QString& theMessage, int theAlignment = Qt::AlignLeft, const QColor& theColor = Qt::black);
> void showSplash(int delay, QStringList messages, int alignment = Qt::AlignLeft, const QColor& color = Qt::black);
> void showSplash(QList<int> delaies, int defaultDelay, QStringList messages, int alignment = Qt::AlignLeft, const QColor& color = Qt::black);
> private:
> virtual void paintEvent(QPaintEvent* pe);
> void clearMessage();
> QPixmap sPixmap;
> QString sMessage;
> int sAlignment;
> QColor sColor;
> };
> #endif // TSPLASHSCREEN_H
>
>
> tesplashscreen.cpp
>
> #include "tesplashscreen.h"
> TeSplashScreen::TeSplashScreen(const QPixmap& thePixmap)
> : QFrame(0, Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint)
> , sPixmap(thePixmap)
> {
> setAttribute(Qt::WA_TranslucentBackground);
> setFixedSize(sPixmap.size());
> };
> void TeSplashScreen::clearMessage()
> {
> sMessage.clear();
> repaint();
> }
> void TeSplashScreen::showMessage(const QString& theMessage, int theAlignment, const QColor& theColor)
> {
> sMessage = theMessage;
> sAlignment = theAlignment;
> sColor = theColor;
> repaint();
> }
> void TeSplashScreen::paintEvent(QPaintEvent* pe)
> {
> QRect aTextRect(rect());
> aTextRect.setRect(aTextRect.x()+5, aTextRect.y()+5, aTextRect.width()-10, aTextRect.height()-10);
>
> QPainter aPainter(this);
> aPainter.drawPixmap(rect(), sPixmap);
> aPainter.setPen(sColor);
> aPainter.drawText(aTextRect, sAlignment, sMessage);
> }
> void TeSplashScreen::showSplash(int delay, QStringList messages, int alignment, const QColor& color)
> {
> class SleeperThread : public QThread
> {
> public:
> static void msleep(unsigned long msecs) {QThread::msleep(msecs);}
> };
>
> TeSplashScreen* aSplashScreen = new TeSplashScreen(sPixmap);
> aSplashScreen->show();
>
> for(int i=0; i<messages.count();++i)
> {
> aSplashScreen->showMessage(messages[i], alignment, color);
> SleeperThread::msleep(delay);
> }
>
> delete aSplashScreen;
> }
> void TeSplashScreen::showSplash(QList<int> delaies, int defaultDelay, QStringList messages, int alignment, const QColor& color)
> {
> class SleeperThread : public QThread
> {
> public:
> static void msleep(unsigned long msecs) {QThread::msleep(msecs);}
> };
>
> TeSplashScreen* aSplashScreen = new TeSplashScreen(sPixmap);
> aSplashScreen->show();
>
> for(int i=0; i<messages.count();++i)
> {
> aSplashScreen->showMessage(messages[i], alignment, color);
> if(i<delaies.count())
> SleeperThread::msleep(delaies[i]);
> else
> SleeperThread::msleep(defaultDelay);
> }
>
> delete aSplashScreen;
> }
>
>
> --
> Best Regards
> Muhammad Bashir Al-Noimi
> My Blog: http://mbnoimi.net
>
>
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
--
Nick Gaens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110907/a36be328/attachment-0001.html>
More information about the PyQt
mailing list