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

from PyQt4.QtGui import QWidget
from PyQt4.QtCore import SIGNAL,pyqtSlot
from common.info_dialog import InfoDialog

from ui_qss.muiltScreenQss import MuiltScreenQss
from settingModel.multimonitor import MultiMonitor
#  yugl
from userInfoConfFile.userInfoConf import UserInfoConfFile
from logger.logrecord import LogRecord

class MuiltScreen (MuiltScreenQss):

    __MutiScreeStyMode = 0

    def __init__(self, parent=None):
        super(MuiltScreen, self).__init__(parent)
        self.__monitor = MultiMonitor()
        self.connect(self.radioButton_2,SIGNAL("clicked()"),self.__on_radioBtnSingleMonitor_clicked)
        self.connect(self.radioButton,SIGNAL("clicked()"),self.__on_radioBtnEnableDifferentDoubleMonitor_clicked)
        self.connect(self.radioButton_3,SIGNAL("clicked()"),self.__on_radioBtnEnableGroupDoubleMonitor_clicked)
        self.connect(self.radioButton_5,SIGNAL("clicked()"),self.__on_radioBtnEnableSameDoubleMonitor_clicked)
        self.refresh()

    def refresh(self):
        # 0
        # 1 多屏显示,双屏 异显
        # 2
        # 3 双屏 组合显
        self.__MutiScreeSty = 0
        # yugl
        try:
            conf = UserInfoConfFile()
            self.__MutiScreeSty = int(conf.getValue("muiltscreen","mutiscreesty"))
            MuiltScreen.__MutiScreeStyMode = self.__MutiScreeSty
        except Exception,err:
            LogRecord.instance().logger.exception('read muiltiscreen config occurs exception!')
        #
        if MuiltScreen.__MutiScreeStyMode == 0:
            self.radioButton_2.setChecked(True)
            self.radioButton.setChecked(False)
            self.radioButton_3.setChecked(False)
            self.radioButton_5.setChecked(False)
        if MuiltScreen.__MutiScreeStyMode == 1:
            self.radioButton_2.setChecked(False)
            self.radioButton.setChecked(True)
            self.radioButton_3.setChecked(False)
            self.radioButton_5.setChecked(False)
        elif MuiltScreen.__MutiScreeStyMode == 2:
            self.radioButton_2.setChecked(False)
            self.radioButton.setChecked(False)
            self.radioButton_3.setChecked(True)
            self.radioButton_5.setChecked(False)
        elif MuiltScreen.__MutiScreeStyMode == 3:
            self.radioButton_2.setChecked(False)
            self.radioButton.setChecked(False)
            self.radioButton_3.setChecked(False)
            self.radioButton_5.setChecked(True)

    # print mutimonitor.disableMultiMonitor()
    def __on_radioBtnSingleMonitor_clicked(self):
        self.__MutiScreeSty = 0
        self.radioButton_2.setChecked(True)
        self.radioButton.setChecked(False)
        self.radioButton_3.setChecked(False)
        self.radioButton_5.setChecked(False)
    # @pyqtSlot()
    def __on_radioBtnEnableDifferentDoubleMonitor_clicked(self):
        self.__MutiScreeSty = 1
        # self.__monitor.enableMultiMonitor()#启用多显示器(双平异显）
        self.radioButton_2.setChecked(False)
        self.radioButton.setChecked(True)
        self.radioButton_3.setChecked(False)
        self.radioButton_5.setChecked(False)
    def __on_radioBtnEnableGroupDoubleMonitor_clicked(self):
        self.__MutiScreeSty = 2
        # self.__monitor.enableMultiMonitor()#启用多显示器(双平异显）
        self.radioButton_2.setChecked(False)
        self.radioButton.setChecked(False)
        self.radioButton_3.setChecked(True)
        self.radioButton_5.setChecked(False)

    # @pyqtSlot()
    def __on_radioBtnEnableSameDoubleMonitor_clicked(self):
        self.__MutiScreeSty = 3
        # self.__monitor.enableSameDoubleMonitor()#启用多显示器(双平同显）
        self.radioButton_2.setChecked(False)
        self.radioButton.setChecked(False)
        self.radioButton_3.setChecked(False)
        self.radioButton_5.setChecked(True)

    def setMuiltScreen(self):
        print 'self.__MutiScreeSty',self.__MutiScreeSty
        state = 1

        if self.__MutiScreeSty == 0:
            # state = self.__monitor.disableMultiMonitor()#禁用多显示器
            print "set singnel monitors"
            state = MultiMonitor.setSingelMonitors()
        elif self.__MutiScreeSty == 1:
            state = self.__monitor.enableMultiMonitor()#启用多显示器(双平异显）
        elif self.__MutiScreeSty == 2:
            state = self.__monitor.enableMultiMonitor()#启用多显示器(双平异显）
        elif self.__MutiScreeSty == 3:
            state = self.__monitor.enableSameDoubleMonitor()#启用多显示器(双平同显）
        #多屏模式设置失败，使用单屏模式
        if state != 0:
            if self.__MutiScreeSty != 0:
                InfoDialog.instance().Information(u'提示',u'设置多屏显示失败，使用单屏显示！')

            self.__on_radioBtnSingleMonitor_clicked()
            self.__monitor.disableMultiMonitor()#禁用多屏显示
            self.refresh()

        MuiltScreen.__MutiScreeStyMode = self.__MutiScreeSty

        # yugl
        conf = UserInfoConfFile()
        print conf.changeSectionValue("muiltscreen","mutiscreesty",MuiltScreen.__MutiScreeStyMode)

if __name__ == "__main__":
    from PyQt4 import QtGui
    from os import environ
    environ["WIN_UI_IMAGES_PATH"]="../../images"
    app = QtGui.QApplication([])
    win = MuiltScreen()
    win.show()
    app.exec_()