# coding:utf-8
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
from os import getenv
class NotifyWedget(QtGui.QDialog):
    """
    消息通知窗口，用来通知用户发生的异常信息
    """
    def __init__(self,parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.imagePath=getenv("WIN_UI_IMAGES_PATH")
        self.setWindowFlags(QtCore.Qt.Dialog | QtCore.Qt.CustomizeWindowHint | QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint)
        self.setAttribute(QtCore.Qt.WA_NoSystemBackground,False)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)
        self.setWindowModality(QtCore.Qt.WindowModal)
        self.setModal(True)
        self.setObjectName('NotifyWedget')
        rect=QtCore.QRect(0,0,305,138)
        self.setGeometry(rect)
        desktop=QtGui.QApplication.desktop()        
        self.move((desktop.width()-self.width())//2,(desktop.height()-self.height())//2)
        self.setWindowTitle('通知'.decode('utf-8'))
        self.backLabel=QtGui.QLabel(self)
        self.backLabel.setGeometry(rect)
        self.backLabel.setStyleSheet('QLabel{border-image: url(%s/appImage/set-conten-pop-bg.png);}'%self.imagePath)
        self.okButton=QtGui.QPushButton(''.decode('utf-8'),self.backLabel)    
#         okButton=QtGui.QPushButton('确定'.decode('utf-8'),backLabel)
        self.okButton.setGeometry(120,108,65,20)
        self.okButton.setStyleSheet("""QPushButton{border-image: url(%s/appImage/set-button-sure.png);}"""%self.imagePath)
#         okButton.setStyleSheet("background-color:blue;")
        self.msgLabel=QtGui.QLabel(self.backLabel)
        self.msgLabel.setGeometry(rect.left(),(rect.bottom()-rect.top())//2-20,rect.width(),20)
        self.msgLabel.setAlignment(QtCore.Qt.AlignCenter)
        font=QtGui.QFont()
        font.setPointSize(10)
        self.msgLabel.setFont(font)
        self.msgLabel.setFrameStyle(QtGui.QFrame.NoFrame)
        self.msgLabel.setStyleSheet('QLabel{border-image: url();background:transparent;}')
#         self.msgLabel.setAutoFillBackground(False)
#         backLayout=QtGui.QVBoxLayout(self.backLabel)
#         backLayout.addWidget(self.msgLabel)
        self.connect(self.okButton, QtCore.SIGNAL('clicked()'), self,QtCore.SLOT('onOKBtn()'))

    def mousePressEvent(self,event):
        if event.button() == QtCore.Qt.LeftButton:
            self.dragPosition = event.globalPos() - self.frameGeometry().topLeft()
            event.accept()
            
    def mouseMoveEvent(self,event):
        if event.buttons() == QtCore.Qt.LeftButton:
            self.move(event.globalPos() - self.dragPosition)
            event.accept()
    @QtCore.pyqtSlot()
    def showMessage(self,msg):
        print 'showMessage '+msg.decode('utf-8')
        self.msgLabel.setText(msg.decode('utf-8'))
        self.show()

    @QtCore.pyqtSlot() 
    def onOKBtn(self):
        print "pressed ok!"
        self.hide()

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    notify=NotifyWedget()
    notify.showMessage('通知')  
    sys.exit(app.exec_())     