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("")
    sAlignment = 0
    sColor = QColor(255,  255,  0)
   
    def __init__(self,  pixmap):
        super(QFrame,  self).__init__()
        self.sPixmap =  pixmap
        self.setWindowFlags(Qt.FramelessWindowHint|Qt.WindowStaysOnTopHint)
        self.setAttribute(Qt.WA_TranslucentBackground)
        self.setFixedSize(pixmap.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):
        class SleeperThread(QThread):
            msecs = 0
            QThread.msleep(msecs)
        aSplashScreen = TeSplashScreen(self.sPixmap)
        aSplashScreen.show()
        for i in range(len(messages)):
            aSplashScreen.showMessage(messages[i], self.sAlignment, color)
            SleeperThread.msleep(delay)
            
    def showSplash(self,  delaies, defaultDelay,  messages, alignment, 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], self.sAlignment, color)
            if i<len(delaies):
                SleeperThread.msleep(delaies[i])
            else:
                SleeperThread.msleep(defaultDelay)
            
#    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)
