[PyQt] Delaying splash screen
Nick Gaens
mail at nickgaens.com
Thu Sep 8 13:34:40 BST 2011
The avoidable * imports Pete mentioned involve typing
from PyQt4 import QtGui
and then do:
> class Foo(QtGui.QLabel)
or
> from PyQt4.QtGui import QLabel
and then do:
> class Foo(QLabel)
Using one of the above causes not all modules to be loaded, whereas your *
imports actually does load all a lot of unrequired modules.
On Thu, Sep 8, 2011 at 00:32, Muhammad Bashir Al-Noimi <admin at mbnoimi.net>wrote:
> On 07/09/2011 11:27 م, Hans-Peter Jansen wrote:
>
> On Wednesday 07 September 2011, 14:04:02 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 *
>
> Hmm, that * imports are easily avoided.
>
> Thanks a lot Pete, You mean I don't need to use both import lines?
>
>
> 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 did as you mentioned exactly.
> 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
>
> TypeError object of type int has no len()
>
> here's the modified class:
>
> 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 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/20110908/2cd21d10/attachment.html>
More information about the PyQt
mailing list