# coding=utf-8
"""create by pbc ...
"""
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'untitled.ui'
#
# Created: Thu May 26 16:05:11 2016
#      by: PyQt4 UI code generator 4.10.3
#
# 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_InfItem(object):
    def setupUi(self, InfItem):
        InfItem.setObjectName(_fromUtf8("InfItem"))
        InfItem.resize(557, 53)
        self.verticalLayout = QtGui.QVBoxLayout(InfItem)
        self.verticalLayout.setSpacing(0)
        self.verticalLayout.setMargin(0)
        self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
        self.horizontalLayout = QtGui.QHBoxLayout()
        self.horizontalLayout.setSpacing(0)
        self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
        self.pushButton_value = QtGui.QPushButton(InfItem)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Ignored)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.pushButton_value.sizePolicy().hasHeightForWidth())
        self.pushButton_value.setSizePolicy(sizePolicy)
        self.pushButton_value.setObjectName(_fromUtf8("pushButton_value"))
        self.horizontalLayout.addWidget(self.pushButton_value)
        self.pushButton_choose = QtGui.QPushButton(InfItem)
        self.pushButton_choose.setText(_fromUtf8(""))
        self.pushButton_choose.setObjectName(_fromUtf8("pushButton_choose"))
        self.horizontalLayout.addWidget(self.pushButton_choose)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.line = QtGui.QFrame(InfItem)
        self.line.setFrameShape(QtGui.QFrame.HLine)
        self.line.setFrameShadow(QtGui.QFrame.Sunken)
        self.line.setObjectName(_fromUtf8("line"))
        self.line.setMaximumHeight(2)
        self.line.setMinimumHeight(2)
        self.verticalLayout.addWidget(self.line)

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

    def retranslateUi(self, InfItem):
        InfItem.setWindowTitle(_translate("InfItem", "Form", None))
        self.pushButton_value.setText(_translate("InfItem", "PushButton", None))


from PyQt4.QtGui import QMenu, QWidget, QVBoxLayout, QDialog
from PyQt4.QtCore import QString, Qt, SIGNAL
from os import getenv
from common import common_run

class BaseDialog(QDialog, Ui_InfItem):
    def __init__(self, parent=None):
        super(BaseDialog,self).__init__(parent)
        self.setupUi(self)
        self.__borderImagesPath = getenv('WIN_UI_IMAGES_PATH')

        self.setStyleSheet(QString("background-color:rgb(255,255,255);"))

        __font_size = str(int(common_run.get_height(14.0)))
        self.pushButton_value.setFocusPolicy(Qt.NoFocus)
        self.pushButton_choose.setFocusPolicy(Qt.NoFocus)
        self.pushButton_choose.setFlat(True)
        self.pushButton_value.setFlat(True)

        self.pushButton_choose.setStyleSheet(QString(
            "QPushButton:hover{border-image:url(%1/loginWindow/login/choose_done.png);border: 2px;}")
        .arg(self.__borderImagesPath))

        self.horizontalLayout.setContentsMargins(0,
                                               0,
                                               15,
                                               2)

        self.pushButton_value.setStyleSheet(QString(
            "color: rgba(9, 26, 35, 102);"
            "font: 63 "+__font_size+"pt \"Ubuntu\";"))

        self.connect(self.pushButton_value,SIGNAL("clicked()"),self.choose_item)

        self.number = 0

    def choose_item(self):
        s = self.sender().parent().objectName()
        print s,"this is s .."
        # self.emit(SIGNAL("upload_center_name"),s)
        self.emit(SIGNAL("upload_center_name"),s,self.number)
        self.pushButton_choose.setStyleSheet(QString(
            "QPushButton{border-image:url(%1/loginWindow/login/choose_done.png);border: 2px;}").arg(self.__borderImagesPath))


    def leaveEvent(self, QEvent):
        self.setStyleSheet(QString("background-color:rgb(255,255,255);"))

    def enterEvent(self, QEvent):
        self.setStyleSheet(QString("background-color:rgb(70, 141, 211);"))

class ChooseCenterDialog(QMenu):
    def __init__(self,parent=None):
        super(ChooseCenterDialog,self).__init__(parent)
        self.__borderImagesPath = getenv('WIN_UI_IMAGES_PATH')

    # def show_t(self,w,value_list,_current_value):
    def show_t(self,w,value_list,_current_index):
        self.setMinimumWidth(w)
        self.__v_layout = QVBoxLayout(self)
        self.wid_v = QWidget(self)
        self.wid_v.setLayout(self.__v_layout)
        for i in range(len(value_list)):
            temp_c = BaseDialog()
            temp_c.number = i
            temp_c.setObjectName(value_list[i])
            # if _current_value == value_list[i]:
            if _current_index == i:
                temp_c.pushButton_choose.setStyleSheet(QString(
                "QPushButton{border-image:url(%1/loginWindow/login/choose_done.png);border: 2px;}")
                                                     .arg(self.__borderImagesPath))

            temp_c.pushButton_choose.setMaximumWidth(int(common_run.get_width(35.0)))
            temp_c.pushButton_choose.setMinimumWidth(int(common_run.get_width(35.0)))
            temp_c.pushButton_choose.setMaximumHeight(int(common_run.get_height(22.0)))
            temp_c.pushButton_choose.setMinimumHeight(int(common_run.get_height(22.0)))
            temp_c.pushButton_value.setMinimumWidth(w - int(common_run.get_width(48.0)))
            temp_c.pushButton_value.setMinimumHeight(int(common_run.get_height(50.0)))
            temp_c.pushButton_value.setText(value_list[i])
            self.__v_layout.addWidget(temp_c)
            self.__v_layout.setContentsMargins(0,
                                               0,
                                               common_run.get_width(18.0),
                                               0)
            self.connect(temp_c,SIGNAL("upload_center_name"),self.upload_value)

        self.__v_layout.setContentsMargins(0,
                                           0,
                                           int(common_run.get_width(10.0)),
                                           0)
        self.__v_layout.setSpacing(0)
        self.setMinimumHeight(len(value_list) * int(common_run.get_height(50.0)) + 3 * len(value_list))

        self.exec_()

    def upload_value(self,v,i):
        self.emit(SIGNAL("upload_center_name"),v,i)

    def __set_stylesheet(self):
        pass

