The avoidable * imports Pete mentioned involve typing<div><br></div><div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
from PyQt4 import QtGui</blockquote><div>and then do:</div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
class Foo(QtGui.QLabel) </blockquote><div><br></div><div>or</div><div> </div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
from PyQt4.QtGui import QLabel</blockquote><div>and then do:</div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
class Foo(QLabel)</blockquote><div><br></div><div>Using one of the above causes not all modules to be loaded, whereas your * imports actually does load all a lot of unrequired modules.</div><div><br></div><div><br></div>
<div class="gmail_quote">
On Thu, Sep 8, 2011 at 00:32, Muhammad Bashir Al-Noimi <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 style="direction:ltr" bgcolor="#FFFFFF" text="#000000"><div class="im">
<p><font face="Tahoma"></font>On 07/09/2011 11:27 م, Hans-Peter
Jansen wrote: </p>
<blockquote type="cite">
<pre>On Wednesday 07 September 2011, 14:04:02 <a href="mailto:admin@mbnoimi.net" target="_blank">admin@mbnoimi.net</a> wrote:
</pre>
<blockquote type="cite">
<pre>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 *
</pre>
</blockquote>
<pre>Hmm, that * imports are easily avoided.</pre>
</blockquote></div>
Thanks a lot Pete, You mean I don't need to use both import lines?<div class="im"><br>
<br>
<blockquote type="cite">
<pre></pre>
<blockquote type="cite">
<pre>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):
</pre>
</blockquote>
<pre>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.</pre>
</blockquote></div>
I did as you mentioned exactly.<br>
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
<br>
<pre><pre>TypeError object of type <font color="#4682B4">int</font> has no len()</pre></pre>
here's the modified class:<br>
<pre><pre>from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
<div class="im"><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></div>]
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)
<div class="im"><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)</div></pre></pre>
<br>
<br>
<br>
-----<div class="im"><br>
Best Regards<br>
Muhammad Bashir Al-Noimi<br>
My Blog: <a href="http://mbnoimi.net" target="_blank">http://mbnoimi.net</a><br>
<br>
</div></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>
</div>