Can you please specify <i>what line</i> this AttributeError is pointing at?<br><br><div class="gmail_quote">On Wed, Sep 7, 2011 at 14:04, <span dir="ltr"><<a href="mailto:admin@mbnoimi.net">admin@mbnoimi.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div text="#000000" bgcolor="#FFFFFF">
<font face="Tahoma">Hi guys,<br>
<br>
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!<br>
<br>
I got "AttributeError TeSplashScreen object has no attribut
QFrate" although TeSplashScreen inherited from QFrame<br>
<br>
Could you please help me, I'm still a newbie in PyQt and Python.</font><br>
<br>
tesplashscreen.py<br>
<pre><pre>from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
<font color="#FF0000">class</font> TeSplashScreen(QFrame):
<font color="#008B00">""</font>"
Splash doc
<font color="#008B00">""</font>"
app = QApplication(sys.argv)
sPixmap = QPixmap(10, 10)
sMessage = QString()
messages = [<font color="#008B00">"nothing"</font>]
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)
<font color="#FF0000">class</font> SleeperThread(QThread):
msecs = 0
QThread.msleep(msecs)
aSplashScreen = TeSplashScreen(self.sPixmap)
aSplashScreen.show
<font color="#FF0000">for</font> 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()
# <font color="#FF0000">class</font> SleeperThread(QThread):
# msecs = 0
# QThread.msleep(msecs)
# aSplashScreen = TeSplashScreen(sPixmap)
# aSplashScreen.show()
# <font color="#FF0000">for</font> i in range(messages.count()):
# aSplashScreen.showMessage(messages[i], alignment, color)
# SleeperThread.msleep(delay)
</pre></pre>
<br>
tesplashscreen.h<br>
<pre><pre><font color="#0000CD">#ifndef</font> TSPLASHSCREEN_H
<font color="#0000CD">#define</font> TSPLASHSCREEN_H
<font color="#0000CD">
#include</font> <QFrame>
<font color="#0000CD">#include</font> <QPainter>
<font color="#0000CD">#include</font> <QThread>
<font color="#FF0000">class</font> TeSplashScreen : <font color="#FF0000">public</font> QFrame
{
<font color="#FF0000">public</font>:
TeSplashScreen(<font color="#FF0000">const</font> QPixmap& pixmap);
<font color="#4682B4">void</font> showMessage(<font color="#FF0000">const</font> QString& theMessage, <font color="#4682B4">int</font> theAlignment = <font color="#8B0000">Qt::</font><font color="#FF0000">AlignLeft</font>, <font color="#FF0000">const</font> QColor& theColor = <font color="#8B0000">Qt::</font><font color="#FF0000">black</font>);
<font color="#4682B4">void</font> showSplash(<font color="#4682B4">int</font> delay, QStringList messages, <font color="#4682B4">int</font> alignment = <font color="#8B0000">Qt::</font><font color="#FF0000">AlignLeft</font>, <font color="#FF0000">const</font> QColor& color = <font color="#8B0000">Qt::</font><font color="#FF0000">black</font>);
<font color="#4682B4">void</font> showSplash(QList<<font color="#4682B4">int</font>> delaies, <font color="#4682B4">int</font> defaultDelay, QStringList messages, <font color="#4682B4">int</font> alignment = <font color="#8B0000">Qt::</font><font color="#FF0000">AlignLeft</font>, <font color="#FF0000">const</font> QColor& color = <font color="#8B0000">Qt::</font><font color="#FF0000">black</font>);
<font color="#FF0000">private</font>:
<font color="#FF0000">virtual</font> <font color="#4682B4">void</font> paintEvent(QPaintEvent* pe);
<font color="#4682B4">void</font> clearMessage();
QPixmap sPixmap;
QString sMessage;
<font color="#4682B4">int</font> sAlignment;
QColor sColor;
};
<font color="#0000CD">
#endif</font> <font color="#0000FF">// TSPLASHSCREEN_H</font>
</pre></pre>
<br>
tesplashscreen.cpp<br>
<pre><pre><font color="#0000CD">#include</font> <font color="#008B00">"tesplashscreen.h"</font>
<font color="#8B0000">TeSplashScreen::</font><font color="#FF0000">TeSplashScreen</font>(<font color="#FF0000">const</font> QPixmap& thePixmap)
: QFrame(0, <font color="#8B0000">Qt::</font><font color="#FF0000">FramelessWindowHint</font>|<font color="#8B0000">Qt::</font><font color="#FF0000">WindowStaysOnTopHint</font>)
, sPixmap(thePixmap)
{
setAttribute(<font color="#8B0000">Qt::</font><font color="#FF0000">WA_TranslucentBackground</font>);
setFixedSize(sPixmap.size());
};
<font color="#4682B4">void</font> <font color="#8B0000">TeSplashScreen::</font><font color="#FF0000">clearMessage</font>()
{
sMessage.clear();
repaint();
}
<font color="#4682B4">void</font> <font color="#8B0000">TeSplashScreen::</font><font color="#FF0000">showMessage</font>(<font color="#FF0000">const</font> QString& theMessage, <font color="#4682B4">int</font> theAlignment, <font color="#FF0000">const</font> QColor& theColor)
{
sMessage = theMessage;
sAlignment = theAlignment;
sColor = theColor;
repaint();
}
<font color="#4682B4">void</font> <font color="#8B0000">TeSplashScreen::</font><font color="#FF0000">paintEvent</font>(QPaintEvent* pe)
{
QRect aTextRect(rect());
aTextRect.setRect(aTextRect.x()+5, aTextRect.y()+5, aTextRect.width()-10, aTextRect.height()-10);
QPainter aPainter(<font color="#FF0000">this</font>);
aPainter.drawPixmap(rect(), sPixmap);
aPainter.setPen(sColor);
aPainter.drawText(aTextRect, sAlignment, sMessage);
}
<font color="#4682B4">void</font> <font color="#8B0000">TeSplashScreen::</font><font color="#FF0000">showSplash</font>(<font color="#4682B4">int</font> delay, QStringList messages, <font color="#4682B4">int</font> alignment, <font color="#FF0000">const</font> QColor& color)
{
<font color="#FF0000">class</font> SleeperThread : <font color="#FF0000">public</font> QThread
{
<font color="#FF0000">public</font>:
<font color="#FF0000">static</font> <font color="#4682B4">void</font> msleep(<font color="#4682B4">unsigned</font> <font color="#4682B4">long</font> msecs) {<font color="#8B0000">QThread::</font><font color="#FF0000">msleep</font>(msecs);}
};
TeSplashScreen* aSplashScreen = <font color="#FF0000">new</font> TeSplashScreen(sPixmap);
aSplashScreen->show();
<font color="#FF0000">for</font>(<font color="#4682B4">int</font> i=0; i<messages.count();++i)
{
aSplashScreen->showMessage(messages[i], alignment, color);
<font color="#8B0000">SleeperThread::</font><font color="#FF0000">msleep</font>(delay);
}
<font color="#FF0000">delete</font> aSplashScreen;
}
<font color="#4682B4">void</font> <font color="#8B0000">TeSplashScreen::</font><font color="#FF0000">showSplash</font>(QList<<font color="#4682B4">int</font>> delaies, <font color="#4682B4">int</font> defaultDelay, QStringList messages, <font color="#4682B4">int</font> alignment, <font color="#FF0000">const</font> QColor& color)
{
<font color="#FF0000">class</font> SleeperThread : <font color="#FF0000">public</font> QThread
{
<font color="#FF0000">public</font>:
<font color="#FF0000">static</font> <font color="#4682B4">void</font> msleep(<font color="#4682B4">unsigned</font> <font color="#4682B4">long</font> msecs) {<font color="#8B0000">QThread::</font><font color="#FF0000">msleep</font>(msecs);}
};
TeSplashScreen* aSplashScreen = <font color="#FF0000">new</font> TeSplashScreen(sPixmap);
aSplashScreen->show();
<font color="#FF0000">for</font>(<font color="#4682B4">int</font> i=0; i<messages.count();++i)
{
aSplashScreen->showMessage(messages[i], alignment, color);
<font color="#FF0000">if</font>(i<delaies.count())
<font color="#8B0000">SleeperThread::</font><font color="#FF0000">msleep</font>(delaies[i]);
<font color="#FF0000">else</font>
<font color="#8B0000">SleeperThread::</font><font color="#FF0000">msleep</font>(defaultDelay);
}
<font color="#FF0000">delete</font> aSplashScreen;
}
</pre></pre><font color="#888888">
<br>
<pre cols="72">--
Best Regards
Muhammad Bashir Al-Noimi
My Blog: <a href="http://mbnoimi.net" target="_blank">http://mbnoimi.net</a></pre>
</font></div>
<br>_______________________________________________<br>
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Nick Gaens<br>