#!/usr/bin/python
#coding=utf8

from PyQt4.QtGui import QDialog,QDesktopWidget,QPainter,QBrush,QColor
from PyQt4.QtCore import Qt,QString
from os import getenv
from ui.ui_winCheckUpgrade import Ui_Dialog

class WinCheckUpgradeQss (QDialog, Ui_Dialog):

    def __init__(self, parent=None):
        super(WinCheckUpgradeQss, self).__init__(parent)

        self.setupUi(self)
        self.__borderImagesPath = getenv('WIN_UI_IMAGES_PATH') # 读取环境变量 图片路径
        self.setModal(True)

        self.setAttribute(Qt.WA_TranslucentBackground,True)
        self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint | Qt.WindowSystemMenuHint
                            | Qt.WindowMinimizeButtonHint | Qt.WindowMaximizeButtonHint)

        self.title.setStyleSheet(
            QString(
            "QLabel{font: 63 16pt \"Ubuntu\";}"
            )
        )
        self.label.setStyleSheet(
            QString(
            "QLabel{font: 63 12pt \"Ubuntu\";}"
            )
        )
        self.btn_ok.setStyleSheet(
             QString(
            "QPushButton{font: 63 12pt \"Ubuntu\"; color: rgb(255, 255, 255);}"
            "QPushButton{border-image: url(%1/btn_border.png);border: 2px;}"
            "QPushButton:hover{border-image:url(%1/btn_hover.png);border: 2px;}"
            "QPushButton:pressed{border-image: url(%1/btn_press.png);border: 2px;}").arg(str(self.__borderImagesPath))
        )

        self.btn_cancle.setStyleSheet(
             QString(
            "QPushButton{font: 63 12pt \"Ubuntu\"; color: rgb(255, 255, 255);}"
            "QPushButton{border-image: url(%1/btn_border.png);border: 2px;}"
            "QPushButton:hover{border-image:url(%1/btn_hover.png);border: 2px;}"
            "QPushButton:pressed{border-image: url(%1/btn_press.png);border: 2px;}").arg(str(self.__borderImagesPath))
        )

        # 使窗口位于屏幕 中央
        screen = QDesktopWidget().screenGeometry()
        self.move((screen.width() - self.width() ) / 2,(screen.height() - self.height()) / 2)


    def paintEvent(self, event):
        p = QPainter(self)
        p.setBrush(QColor(230,230,230,255))
        p.drawRoundedRect(0,0,self.width() -1,self.height() -1,0,0)


###############################
#   单元测试
##############################
if __name__ == "__main__":
    from PyQt4 import QtGui
    from os import environ
    environ["WIN_UI_IMAGES_PATH"]="../../../images"
    app = QtGui.QApplication([])
    win = WinCheckUpgradeQss()
    win.show()
    app.exec_()