#coding=utf8
""" created by pbc for informaition dialog
"""

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file '../../../../ui/logout.ui'
#
# Created: Thu May 26 05:03:39 2016
#      by: PyQt4 UI code generator 4.10.4
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName(_fromUtf8("Dialog"))
        Dialog.resize(452, 262)
        Dialog.setStyleSheet(_fromUtf8("background-color: rgb(230, 230,230);"))
        self.verticalLayout = QtGui.QVBoxLayout(Dialog)
        self.verticalLayout.setSpacing(0)
        self.verticalLayout.setMargin(0)
        self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
        self.widget_3 = QtGui.QWidget(Dialog)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(12)
        sizePolicy.setHeightForWidth(self.widget_3.sizePolicy().hasHeightForWidth())
        self.widget_3.setSizePolicy(sizePolicy)
        self.widget_3.setObjectName(_fromUtf8("widget_3"))
        self.horizontalLayout = QtGui.QHBoxLayout(self.widget_3)
        self.horizontalLayout.setSpacing(0)
        self.horizontalLayout.setMargin(0)
        self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
        self.label_2 = QtGui.QLabel(self.widget_3)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.label_2.sizePolicy().hasHeightForWidth())
        self.label_2.setSizePolicy(sizePolicy)
        self.label_2.setStyleSheet(_fromUtf8(""))
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.horizontalLayout.addWidget(self.label_2)
        spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)
        self.btn_close = QtGui.QPushButton(self.widget_3)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.btn_close.sizePolicy().hasHeightForWidth())
        self.btn_close.setSizePolicy(sizePolicy)
        self.btn_close.setText(_fromUtf8(""))
        self.btn_close.setObjectName(_fromUtf8("btn_close"))
        self.horizontalLayout.addWidget(self.btn_close)
        self.verticalLayout.addWidget(self.widget_3)
        self.widget = QtGui.QWidget(Dialog)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(36)
        sizePolicy.setHeightForWidth(self.widget.sizePolicy().hasHeightForWidth())
        self.widget.setSizePolicy(sizePolicy)
        self.widget.setStyleSheet(_fromUtf8("background-color: rgba(255, 255, 255,200);"))
        self.widget.setObjectName(_fromUtf8("widget"))
        self.gridLayout_2 = QtGui.QGridLayout(self.widget)
        self.gridLayout_2.setMargin(0)
        self.gridLayout_2.setSpacing(0)
        self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
        self.label = QtGui.QLabel(self.widget)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName(_fromUtf8("label"))
        self.label.setWordWrap(True)                     #设置自动换行
        self.gridLayout_2.addWidget(self.label, 0, 0, 1, 1)
        self.verticalLayout.addWidget(self.widget)
        self.widget_2 = QtGui.QWidget(Dialog)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(14)
        sizePolicy.setHeightForWidth(self.widget_2.sizePolicy().hasHeightForWidth())
        self.widget_2.setSizePolicy(sizePolicy)
        self.widget_2.setObjectName(_fromUtf8("widget_2"))
        self.horizontalLayout_2 = QtGui.QHBoxLayout(self.widget_2)
        self.horizontalLayout_2.setSpacing(0)
        self.horizontalLayout_2.setMargin(0)
        self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
        spacerItem1 = QtGui.QSpacerItem(369, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
        self.horizontalLayout_2.addItem(spacerItem1)
        self.btn_ok = QtGui.QPushButton(self.widget_2)
        self.btn_ok.setText(_fromUtf8(""))
        self.btn_ok.setObjectName(_fromUtf8("btn_ok"))
        self.horizontalLayout_2.addWidget(self.btn_ok)
        self.btn_cancle = QtGui.QPushButton(self.widget_2)
        self.btn_cancle.setText(_fromUtf8(""))
        self.btn_cancle.setObjectName(_fromUtf8("btn_cancle"))
        self.horizontalLayout_2.addWidget(self.btn_cancle)
        self.verticalLayout.addWidget(self.widget_2)

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
        self.label_2.setText(_translate("Dialog", " 注 销", None))
        self.label.setText(_translate("Dialog", "确定要注销当前用户吗？", None))



from PyQt4.QtGui import QDialog,QDesktopWidget,QPainter,QColor, QApplication, QPixmap, QPalette, QBrush
from PyQt4.QtCore import Qt, QString, SIGNAL, QTimer, QObject
from common import common_run
from os import getenv

class InfoDialogQss (QDialog, Ui_Dialog):
    def __init__(self, parent=None):
        super(InfoDialogQss, 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.mousePressed = False


        jpeg = QPixmap(self.__borderImagesPath + "/winVirturlList/background_down.png").scaled(self.size())  # scaled适应窗口大小
        palette1 = QPalette(self)
        palette1.setBrush(self.backgroundRole(), QBrush(jpeg))
        self.setPalette(palette1)
        self.setAutoFillBackground(True)

        self.__set_stylesheet()

    def setstyleshteet_info(self):
        self.__set_stylesheet()

    def __set_stylesheet(self):
        self.setMaximumHeight(int(common_run.get_height(213.0)))
        self.setMinimumHeight(int(common_run.get_height(213.0)))
        self.setMaximumWidth(int(common_run.get_width(514.0)))
        self.setMinimumWidth(int(common_run.get_width(514.0)))

        self.horizontalLayout.setContentsMargins(int((20.0/1440.0)*common_run.SCREEN_WITH),
                                               0,
                                               int((20.0/1440.0)*common_run.SCREEN_WITH),
                                               0)
        self.horizontalLayout_2.setSpacing(int((10.0/1440.0)*common_run.SCREEN_WITH))
        self.horizontalLayout_2.setContentsMargins(int((20.0/1440.0)*common_run.SCREEN_WITH),
                                               0,
                                               int((20.0/1440.0)*common_run.SCREEN_WITH),
                                               0)

        self.btn_close.setMaximumHeight(int(common_run.get_height(29.0)))
        self.btn_close.setMinimumHeight(int(common_run.get_height(29.0)))
        self.btn_close.setMaximumWidth(int(common_run.get_width(21.0)))
        self.btn_close.setMinimumWidth(int(common_run.get_width(21.0)))

        __button_size_height = common_run.SCREEN_HEIGHT * 31.5 / 900.0
        __button_size_with = common_run.SCREEN_WITH * 81.0 / 1440.0
        self.btn_cancle.setMinimumHeight(int(__button_size_height))
        self.btn_cancle.setMinimumWidth(int(__button_size_with))
        self.btn_cancle.setMaximumHeight(int(__button_size_height))
        self.btn_cancle.setMaximumWidth(int(__button_size_with))
        self.btn_ok.setMinimumHeight(int(__button_size_height))
        self.btn_ok.setMinimumWidth(int(__button_size_with))
        self.btn_ok.setMaximumHeight(int(__button_size_height))
        self.btn_ok.setMaximumWidth(int(__button_size_with))

        self.btn_close.setFocusPolicy(Qt.NoFocus)
        self.btn_close.setStyleSheet(QString("border-image: url(%1/settingWindow/close.png);"
                                             "border: 2px;").arg(self.__borderImagesPath))

        __font_size = str(common_run.get_height(13.0))
        self.label_2.setStyleSheet("font: 63 "+__font_size+"pt;")
        self.label.setStyleSheet("font: 63 "+__font_size+"pt;")

        self.widget_2.setStyleSheet("QWidget#widget_2{background-color:rgba(230,230,230,255);}")
        self.widget_3.setStyleSheet("QWidget#widget_3{background-color:rgba(230,230,230,255);}")

        # 确定 按钮样式
        self.btn_ok.setText(u'确定')
        self.btn_ok.setFocusPolicy(Qt.NoFocus)
        self.btn_ok.setStyleSheet(
             QString("QPushButton{color: rgb(255,255,255);font: 63 "+__font_size+"pt;border-image: url(%1/settingWindow/btn_backgound1.png);border: 2px;}"
            "QPushButton:hover{border-image:url(%1/settingWindow/btn_backgound2.png);border: 2px;}"
            "QPushButton:pressed{border-image: url(%1/settingWindow/btn_backgound3.png);border: 2px;}").arg(str(self.__borderImagesPath))
        )
        # 取消 按钮样式
        self.btn_cancle.setText(u'取消')
        self.btn_cancle.setFocusPolicy(Qt.NoFocus)
        self.btn_cancle.setStyleSheet(
             QString("QPushButton{color: rgb(255,255,255);font: 63 "+__font_size+"pt;border-image: url(%1/settingWindow/btn_backgound1.png);border: 2px;}"
            "QPushButton:hover{border-image:url(%1/settingWindow/btn_backgound2.png);border: 2px;}"
            "QPushButton:pressed{border-image: url(%1/settingWindow/btn_backgound3.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.setPen(Qt.black)
        p.drawRoundedRect(0,0,self.width() -1,self.height() -1,0,0)


    def mousePressEvent(self, event):
        if event.buttons() == Qt.LeftButton:
            self.currentPos = event.pos()
            self.mousePressed = True

    def mouseReleaseEvent(self, event):
        self.mousePressed = False

    def mouseMoveEvent(self, event):
        if self.mousePressed:
            self.move(self.pos() + event.pos() - self.currentPos)
        self.default = QString()

#---------------------------------------------- class made

def moveWidgetToScreenCenter(widget):
    desktopWidget = QApplication.desktop()
    clientRect = desktopWidget.availableGeometry()
    width = clientRect.width()
    height = clientRect.height()
    widget.move((width - widget.width())/2,  (height - widget.height())/2)


class InfoDialog(InfoDialogQss):
    _instance = 0
    def __init__(self, parent=None):
        super(InfoDialog,self).__init__(parent)
        self.connect(self.btn_close,SIGNAL("clicked()"),self.close)
        self.connect(self.btn_ok,SIGNAL("clicked()"),self._accept)
        self.connect(self.btn_cancle,SIGNAL("clicked()"),self._reject)
        self._timer = QTimer()
        self.connect(self._timer,SIGNAL("timeout()"),self.over_info)

    def over_info(self):
        self.accept()

    def _accept(self):
        self.accept()

    def _reject(self):
        self.reject()

    def MessageBox(self,v=u'选择',v2 = '...'):
        self.setstyleshteet_info()
        moveWidgetToScreenCenter(self)
        self.btn_cancle.setHidden(False)
        self.label_2.setText(v)
        self.label.setText(v2)
        if self.exec_() == QDialog.Accepted:
            return "yes"
        else:
            return "no"

    def Information(self,v=u'提示信息',v2 = '...'):
        self.setstyleshteet_info()
        moveWidgetToScreenCenter(self)
        self.btn_cancle.setHidden(True)
        self.label_2.setText(v)
        self.label.setText(v2)
        self.exec_()

    def InformationTimer(self,v=u'提示信息',v2 = '.......',t=3):
        self.setstyleshteet_info()
        moveWidgetToScreenCenter(self)
        self.btn_cancle.setHidden(True)
        self.btn_ok.setHidden(True)
        self.label_2.setText(v)
        self.label.setText(v2)
        self._timer.start(t*1000)
        self.exec_()

    def keyPressEvent(self,event):
        if (event.key() == Qt.Key_Enter) or (event.key() == Qt.Key_Return):
            self.btn_ok.click()

    @classmethod
    def instance(cls):
        if (cls._instance == 0):
            cls._instance = InfoDialog()
        return cls._instance



# if __name__ == "__main__":
    # app = QApplication([])
    # timer = QTimer()
    # def run_t():
    #     print "passsss"
    #     InfoDialog.instance().Information('eee','gggggggg')
    # QObject.connect(timer,SIGNAL("timeout()"),run_t)
    # timer.start(3000)
    # app.exec_()

    # from PyQt4.QtGui import QApplication
    # import os,sys
    # app = QApplication(sys.argv)
    # InfoDialog.instance().MessageBox(u'提示',u'您确定要注销登录吗?')# choose yes or no
    # InfoDialog.instance().Information(u'提示',u'.......')#
    # app.exec_()