#coding:utf-8
'''
Created on Sep 3, 2014

@author: root
'''
import os

from PyQt4.QtCore import SIGNAL, Qt, QFile, QString
from PyQt4.QtGui import QComboBox
from PyQt4.QtGui import QGridLayout
from PyQt4.QtGui import QGroupBox
from PyQt4.QtGui import QPushButton
from PyQt4.QtGui import QRadioButton
from PyQt4.QtGui import QWidget, QLabel, QHBoxLayout, QVBoxLayout, QDialog

from base.infohintdialog import InfoHintDialog
from base.messagebox import MessageBox
from common import commondata
from logger.logrecord import LogRecord
from setting.getlogin import AutoLog

from setting.multimonitor import MultiMonitor
from setting.screenset import ScreenSet
from setting.upgrade import Upgrade


class SystemSetting(QWidget):
       
    def __init__(self,parent = None):
        super(SystemSetting,self).__init__(parent)
      
        self.screenSet = ScreenSet()
        self.upgrade = Upgrade()
        self.multiMonitor = MultiMonitor()
        self.autoLog = AutoLog()
        
        ratioSettingGroup = QGroupBox()
        
        ratioSettingGroup.setTitle(u"分辨率设置")
        self.screenLabel = QLabel(u"屏幕")
        self.ratioLabel = QLabel(u"分辨率")
        self.screenComboBox = QComboBox()
        self.ratioComboBox = QComboBox()
        self.setButton = QPushButton(u"设置")
        self.setButton.setObjectName("settingDlgBtn")
        self.setButton.setFixedSize(75,27)
        self.setButton.setFlat(True)
        
        ratioLayout = QGridLayout()
        ratioLayout.addWidget(self.screenLabel,0,0)
        ratioLayout.addWidget(self.screenComboBox,0,1)
        ratioLayout.addWidget(self.ratioLabel,1,0)
        ratioLayout.addWidget(self.ratioComboBox,1,1)
        ratioLayout.addWidget(self.setButton,2,2)
        
        screenLayout = QHBoxLayout()
        screenLayout.addSpacing(50)
        screenLayout.addLayout(ratioLayout)
        screenLayout.addSpacing(50)
        
        ratioSettingGroup.setLayout(screenLayout)
        ratioSettingGroup.setHidden(True)
        
        manyScreenSettingGroup = QGroupBox()
        manyScreenSettingGroup.setTitle(u"多屏设置")
        self.useRadio = QRadioButton(u"启用双屏异显")
        self.ratioConnect = QRadioButton(u"启用双屏组合显")
        self.noUseRadio = QRadioButton(u"启用双屏同显")
        
        radioLayout = QHBoxLayout()
        radioLayout.addSpacing(50)
        radioLayout.addWidget(self.useRadio)
        radioLayout.addWidget(self.ratioConnect)
        radioLayout.addWidget(self.noUseRadio)
        radioLayout.addSpacing(50)
        #radioLayout.addStretch()
        manyScreenSettingGroup.setLayout(radioLayout)
        
        screenSaverSettingGroup = QGroupBox()
        screenSaverSettingGroup.setTitle(u"屏保设置")
        self.useRadio1 = QRadioButton(u"启用")
        self.noUseRadio1 = QRadioButton(u"禁用")
        radioLayout1 = QHBoxLayout()
        radioLayout1.addSpacing(50)
        radioLayout1.addWidget(self.useRadio1)
        radioLayout1.addWidget(self.noUseRadio1)
        radioLayout1.addSpacing(120)
        
        screenSaverSettingGroup.setLayout(radioLayout1)
        screenSaverSettingGroup.setHidden(True)
        
        screenSettingGroup = QGroupBox()
        screenSettingGroup.setTitle(u"分辨率自适应")
        self.useRadio2 = QRadioButton(u"启用")
        self.noUseRadio2 = QRadioButton(u"禁用")
        radioLayout2 = QHBoxLayout()
        radioLayout2.addSpacing(50)
        radioLayout2.addWidget(self.useRadio2)
        radioLayout2.addWidget(self.noUseRadio2)
        radioLayout2.addSpacing(120)
      
        screenSettingGroup.setLayout(radioLayout2)
        
        openScreenFunGroup = QGroupBox()
        openScreenFunGroup.setTitle(u"在线虚拟机配置")
        self.radioButtonOpenSereenFun = QRadioButton(u"禁止退出全屏")
        self.radioButtonCloseSereenFun = QRadioButton(u"允许退出全屏")
        screenFunLayout = QHBoxLayout()
        screenFunLayout.addSpacing(50)
        screenFunLayout.addWidget(self.radioButtonOpenSereenFun)
        screenFunLayout.addWidget(self.radioButtonCloseSereenFun)
        screenFunLayout.addSpacing(120)
     
        openScreenFunGroup.setLayout(screenFunLayout)
        
        
        updateSettingGroup = QGroupBox()
        updateSettingGroup.setTitle(u"升级设置")
        self.noUpRadio = QRadioButton(u"手动升级")
        self.upRadio = QRadioButton(u"自动升级（开机自动检测，每隔六小时检测一次）")
        self.updateButton = QPushButton(u"升级")
        self.updateButton.setObjectName("settingDlgBtn")
        self.updateButton.setFixedSize(75,27)
        self.updateButton.setFlat(True)
        
        radioLayout3 = QGridLayout()
        radioLayout3.addWidget(self.noUpRadio,0,0)
        radioLayout3.addWidget(self.updateButton,0,1)
        radioLayout3.addWidget(self.upRadio,1,0,1,2)
       
        updateLayout= QHBoxLayout()
        updateLayout.addSpacing(50)
        updateLayout.addLayout(radioLayout3)
        updateSettingGroup.setLayout(updateLayout)
        
        self.closeButton = QPushButton(u"关闭")
        self.closeButton.setObjectName("settingDlgBtn")
        self.closeButton.setFixedSize(75,27)
        self.closeButton.setFlat(True)
        closeButtonLayout = QHBoxLayout()
        closeButtonLayout.addStretch()
        closeButtonLayout.addWidget(self.closeButton)
        
        miniWidget = QWidget()
        vLayout = QVBoxLayout(self)
        vLayout.setMargin(0)
        vLayout.addWidget(ratioSettingGroup)
        vLayout.addWidget(manyScreenSettingGroup)
        vLayout.addWidget(screenSaverSettingGroup)
        vLayout.addWidget(screenSettingGroup)
        vLayout.addWidget(openScreenFunGroup)
     
        vLayout.addLayout(closeButtonLayout)
        miniWidget.setLayout(vLayout)
        
        self.mainLayout = QHBoxLayout(self)
        self.mainLayout.addSpacing(50)
        self.mainLayout.addWidget(miniWidget)
        self.mainLayout.addSpacing(50)
        
        self.initProperty()
        
        
        self.connect(self.closeButton, SIGNAL("clicked()"),self.closeTabWidget)
        
        self.connect(self.updateButton,SIGNAL("clicked()"),self.on_pushButtoUpdate_clicked)
        self.connect(self.useRadio,SIGNAL("clicked()"),self.on_radioButtonEnableMulti_clicked)
        self.connect(self.noUseRadio,SIGNAL("clicked()"),self.on_radioButtonDisableMulti_clicked)
        self.connect(self.useRadio1,SIGNAL("clicked()"),self.on_radioButtonStartScreen_clicked)
        self.connect(self.noUseRadio1, SIGNAL("clicked()"),self.on_radioButtonCancelScreen_clicked)
        self.connect(self.useRadio2, SIGNAL("clicked()"),self.on_radioButtonOpenAutoAdjust_clicked)
        self.connect(self.noUseRadio2, SIGNAL("clicked()"),self.on_radioButtonCloseAutoAdjust_clicked)
        self.connect(self.screenComboBox, SIGNAL("activated(int)"),self.slotScreenSolution)

        self.connect(self.ratioConnect, SIGNAL("clicked()"),self.on_radioButtonMulConnect_clicked)
        self.connect(self.radioButtonOpenSereenFun, SIGNAL("clicked()"),self.radioButtonOpenSereen_clicked)
        self.connect(self.radioButtonCloseSereenFun, SIGNAL("clicked()"),self.radioButtonCloseSereen_clicked)
    
    def radioButtonOpenSereen_clicked(self):
        if (MessageBox(u"选择该项将不会启用双屏显示功能！是否继续此操作？").exec_() == QDialog.Accepted):
            self.screenSet.setVmScreenState("yes")
        else:
            self.updateVmSereenState()
    def radioButtonCloseSereen_clicked(self):
        self.screenSet.setVmScreenState("no")
        
    def updateVmSereenState(self):
        retv = self.screenSet.updateVmScreenState()
        if(retv!=""):
            if(retv=="yes"):
                self.radioButtonOpenSereenFun.setChecked(True)
            elif(retv=="no"):
                self.radioButtonCloseSereenFun.setChecked(True)
        else:
            self.radioButtonOpenSereenFun.setChecked(True)
            self.screenSet.setVmScreenState("yes")
        
        
    def initProperty(self):
        self.screensaveStatus()
        self.resolutionAutoAdjust()
        self.setMultiMonitorStatus()
        self.upgradeStatus()
        self.screenStatus()
        self.updateVmSereenState()
        
    def refreshWidget(self):
        
        LogRecord.instance().logger.info(u"屏保初始化")
        self.screensaveStatus()
        LogRecord.instance().logger.info(u"分辨率自适应初始化")
        self.resolutionAutoAdjust()
        LogRecord.instance().logger.info(u"多平设置初始化")
        self.setMultiMonitorStatus()
        LogRecord.instance().logger.info(u"分辨略初始化")
        self.screenStatus()

        
    def closeTabWidget(self):
        self.emit(SIGNAL("closetabwidget"))
        
    def screensaveStatus(self):
        # LogRecord.instance().logger.info(u"屏保文件读取")
        screen_status = self.screenSet.screensaveStatus()
        if(screen_status == "enable"):
            self.useRadio1.setChecked(True)
        elif(screen_status == "disable"):
            self.noUseRadio1.setChecked(True)
        elif (screen_status == ""):
            self.screenSet.ctrlScreenSave("off")
        return
    def resolutionAutoAdjust(self):
        LogRecord.instance().logger.info(u"分辨略自适应读取")
        action = self.screenSet.getResolutionAutoAdjustType()
        if (action == "open"):
            self.useRadio2.setChecked(True)
            self.screenSet.ctrlResolutionAutoAdjust("open")
        elif action == "close":
            self.noUseRadio2.setChecked(True)
            self.screenSet.ctrlResolutionAutoAdjust("close")
        else:
            self.screenSet.ctrlResolutionAutoAdjust("open")
            self.useRadio2.setChecked(True)
    # 多显示器按钮状态初始化
    def setMultiMonitorStatus(self):
        LogRecord.instance().logger.info(u"多屏幕读取")
        status = self.multiMonitor.getMultiMonitorStatus()
    
            
        if(QString(status).startsWith("enable")):
            if (status.split(":")[1] == "None"):
                self.useRadio.setChecked(True)
            else:
                self.ratioConnect.setChecked(True)
        else:
            self.noUseRadio.setChecked(True)
    # 分辨率
    def screenStatus(self):
        LogRecord.instance().logger.info(u"显示器读取")
        #获得显示器名称，连接状态及行号
    
        print ("getAmonitors")
        
        aMonitors = self.screenSet.getMonitors("xrandr | awk '{ if($2 ~ \"connected\") {print $1 \" \" $2 \" \" NR}}'")

        print "u显示器读取 ", aMonitors
        
        #根据组合列表把显示器名称和支持的分辨率放入到一个字典中
        #QMap<QString, QStringList> 
        self.resolutionMap = {}
        Monitors = []
        acount = len(aMonitors)
        
        for j in range(acount):
            if len(aMonitors[j].split(" ")) == 3:#得到正确的输出
                Monitors.append(aMonitors[j])
         
       
               
        count = len(Monitors)
  
        for i in range(count):
                rowStopNumber = ""
                rowStartNumber = ""
                monitorName = Monitors[i].split(" ")[0]
                linkStatus = Monitors[i].split(" ")[1]
                rowStartNumber = Monitors[i].split(" ")[2]
                
                print ("rowStartNumber",rowStartNumber)
                
                if (linkStatus == "disconnected"):
                    print ("disconnect")
                    continue
                if (i != count - 1):
                    
                    rowStopNumber = Monitors[i+1].split(" ")[2]
                    
                #QString resolutionCmd
                print (rowStartNumber)
                print (rowStopNumber)
                if (rowStopNumber == "" or rowStopNumber == rowStartNumber):
                    resolutionCmd = "xrandr | awk '{ if(NR > " + rowStartNumber + ")" + "{print $1}}'"
                else:
                    resolutionCmd = "xrandr | awk '{ if((NR > " + rowStartNumber + ") && (NR < " + rowStopNumber + "))" + "{print $1}}'"
        
                resolutionList = []
                lastResolutionList = []
                print (resolutionCmd)
                resolutionList = self.screenSet.getMonitors(resolutionCmd)
                
                num = len(resolutionList)
                for i in range(num):
                #for (int i = 0 i < num i++)
                    #if (resolutionList[i].contains("x")):
                    if (len(resolutionList[i].split("x"))>1 and len(resolutionList[i].split(" "))<2):
                    #if resolutionList[i].find("x")>-1:
                        lastResolutionList.append(resolutionList[i])
        
                self.resolutionMap[monitorName] = lastResolutionList
        
        #根据字典中的内容在下拉列表中显示相应的显示器名称和支持的分辨率
  
        self.screenComboBox.clear()
       
        index = 0
        for key in self.resolutionMap:
            name = key
            reList = self.resolutionMap[key]
            self.screenComboBox.addItem(name)
            self.screenComboBox.setItemData(index, reList, Qt.UserRole + 1)
            index += 1
            #print "-----",name
        curretIndex = self.screenComboBox.currentIndex()
        screenName = self.screenComboBox.itemText(curretIndex)
        variant = self.screenComboBox.itemData(curretIndex, Qt.UserRole + 1)
        
        if (variant.isValid()):
            self.ratioComboBox.clear()
            reList = variant.toStringList()
            count = len(reList)
            for i in range(count):
         
                self.ratioComboBox.addItem(reList[i])
    
        #显示当前屏幕的分辨率
        curscr =self.screenSet.getCurScreen(screenName)
        j = self.ratioComboBox.count()
        
        for i in range(j):
            if(curscr == self.ratioComboBox.itemText(i)):
                #print curscr
                self.ratioComboBox.setCurrentIndex(i)
    #升级
    def slotScreenSolution(self,index):
        self.ratioComboBox.clear()

        LogRecord.instance().logger.info(u"切换显示器显示分辨率下拉列表")
        screenlist = self.resolutionMap[str(self.screenComboBox.currentText())]
        self.ratioComboBox.addItems(screenlist)
        
        for i in range(self.screenComboBox.count()):
            screenName = self.screenComboBox.itemText(i)
            curscr =self.screenSet.getCurScreen(screenName)
            if (self.screenComboBox.currentText() == screenName):
                self.ratioComboBox.setCurrentIndex(self.ratioComboBox.findText(curscr))
    def upgradeStatus(self):
        LogRecord.instance().logger.info(u"升级")
        mode=self.upgrade.getUpgradeMode()
        if(mode =="mamual"):
            self.noUpRadio.setChecked(True)
            self.updateButton.setEnabled(True)
        elif(mode == "auto"):
            self.upRadio.setChecked(True)
            self.updateButton.setEnabled(False)
        else:
            self.noUpRadio.setChecked(True)
            self.updateButton.setEnabled(True)
            self.upgrade.setUpgradeMode("mamual")
        
    
    def on_radioButtonStartScreen_clicked(self):
        LogRecord.instance().logger.info(u"屏保设置按钮")
        res = self.screenSet.ctrlScreenSave("start")
        if(-1 == res):
           
            InfoHintDialog(u"打开屏保文件失败").exec_()
            return
        elif(-2 == res):
            
            InfoHintDialog(u"启用屏保失败").exec_()
            return
        else:
            
            InfoHintDialog(u"成功启用终端屏保").exec_()
            return
        return

    def on_radioButtonCancelScreen_clicked(self):
        LogRecord.instance().logger.info(u"屏保取消按钮")
        res = self.screenSet.ctrlScreenSave("off")
        if(-1 == res):
         
            InfoHintDialog(u"打开屏保文件失败").exec_()
            return
        elif(-2 == res):

            InfoHintDialog(u"关闭屏保失败").exec_()
            return
        else:

            InfoHintDialog(u"成功禁用终端屏保").exec_()
            return
        return

    #自动升级
    def on_radioButtonAutoUP_clicked(self):
        LogRecord.instance().logger.info(u"自动升级按钮")
        self.updateButton.setEnabled(False)
        content = "auto_upgrade"
        if(self.upgrade.setUpgradeMode(content)):
        
            InfoHintDialog(u"已成功设置为自动升级").exec_()
            return
        else:
          
            InfoHintDialog(u"设置失败").exec_()
            return
        return

    def on_radioButtonManualUp_clicked(self):
        LogRecord.instance().logger.info(u"手动升级设置")
        self.updateButton.setEnabled(True)
        content = "mamual_upgrade"
        self.upgrade.setUpgradeMode(content)
       
        InfoHintDialog(u"已成功设置为手动升级").exec_()
    #升级按钮
    def on_pushButtoUpdate_clicked(self):
        #QString ssl
        LogRecord.instance().logger.info(u"升级按钮点击")
        serverUrl = self.autoLog.getUserServer()
        if(serverUrl.isNull() or serverUrl.isEmpty()):
           
            InfoHintDialog(u"读取用户服务器信息失败，请检查平台设置").exec_()
            return
    
        #获取系统类型，确定是ｘ86还是ａｒｍ

        file_dir = self.upgrade.gethosttype()
        
        if( file_dir[0] != "arm" and file_dir[0] != "x86"):
           
            InfoHintDialog(u"没有与该系统匹配的升级包，请点击“ok“退出").exec_()
            return
    
        urlserver=serverUrl.split(":")[0]
        file_ = file_dir[1] + " update_index.xml"
    
        #下载升级说明文件
        if(not self.upgrade.getPacket(urlserver,"xml",file_)):

            InfoHintDialog(u"下载说明文件失败").exec_()
            return
    
        #查看本地是否有可比较的update_index.xml文件
        if(not QFile().exists(commondata.UPDATE_INDEX_OLD)):
            
            InfoHintDialog(u"本地无可比较版本信息文件").exec_()
            return
    
        #下载完后与本地文件比较，看是否需要升级
        i = self.upgrade.compareXmlWithBefore()
        if( -1 == i):
        
            InfoHintDialog(u"当前已是最新版本").exec_()
            return
        elif(-2 == i):
       
            InfoHintDialog(u"服务器端下载的版本文件异常").exec_()
            return
        elif( 1 == i ):
            #说明存在新版本，可以升级
          
            if (MessageBox(u"检测到有可用更新，是否立即升级？(提示：升级完成后需重启云终端)").exec_() == QDialog.Accepted):
                filezip = file_dir + "upgrade.zip"
                if(not self.upgrade.getPacket(urlserver,"zip",filezip)):
                    
                    InfoHintDialog(u"下载升级包失败").exec_()
                    self.upgrade.rmPacket("rmxml")
                    return
                filemd5 = file_dir + "md5.text"
                if(not self.upgrade.getPacket(urlserver,"md5",filemd5)):
                   
                    InfoHintDialog(u"下载md5校验文件失败").exec_()
                    self.upgrade.rmPacket("rmzip")
                    return
                #ｍｄ5校验
                if( not Upgrade.instance().md5Check() ):
              
                    InfoHintDialog(u"md5校验失败").exec_()
                    self.upgrade.rmPacket("rmall")
                    return
                #替换文件等
                if( not self.upgrade.replaceFile() ):
                    
                    InfoHintDialog(u"替换当前文件失败").exec_()
                    self.upgrade.rmPacket("rmall")
                    return
                #删除下载的临时文件
                self.upgrade.rmPacket("rmall")
                #重启终端
                os.system("reboot")
                self.close()
            return
    #双平异显
    def on_radioButtonEnableMulti_clicked(self):
        # if (not self.isResolutionSame()):
        #     InfoHintDialog(u"各个屏幕必须设置成相同的分辨率!").exec_()
        #     return
        
        LogRecord.instance().logger.info(u"多屏幕设置")
        result = self.multiMonitor.enableMultiMonitor()
        if(result == -1):
     
            InfoHintDialog(u"没有检测到多个显示器").exec_()
        elif(result == -2):

            InfoHintDialog(u"获取显示器失败").exec_()
        elif(result == -3):
      
            InfoHintDialog(u"获取当前分辨率失败").exec_()
        else:
            
            InfoHintDialog(u"启动双屏异显成功!").exec_()
            self.emit(SIGNAL("setscreenover"))

    #禁用多显示器(双屏同显)
    def on_radioButtonDisableMulti_clicked(self):
        # if (not self.isResolutionSame()):
        #     InfoHintDialog(u"各个屏幕必须设置成相同的分辨率!").exec_()
        #     return
        #
        LogRecord.instance().logger.info(u"取消多屏幕")
        result = self.multiMonitor.enableSameDoubleMonitor()
        if(result == -1):
  
            InfoHintDialog(u"没有检测到多个显示器").exec_()
        elif(result == -2):
   
            InfoHintDialog(u"获取显示器失败").exec_()
            
        else:
            
            InfoHintDialog(u"启动双屏同显成功!").exec_()
            self.emit(SIGNAL("setscreenover"))
    def on_radioButtonOpenAutoAdjust_clicked(self):
        LogRecord.instance().logger.info(u"分辨率自适应设置按钮")
        res = self.screenSet.ctrlResolutionAutoAdjust("open")
        if(-1 == res):
        
            InfoHintDialog(u"打开分辨率自适应文件失败").exec_()
        elif(-2 == res):
       
            InfoHintDialog(u"设置环境变量SMEP_SEND_MONITOR_CONFIG失败").exec_()
        else:
 
            InfoHintDialog(u"成功启用分辨率自适应").exec_()
            
        return

    def on_radioButtonCloseAutoAdjust_clicked(self):
        LogRecord.instance().logger.info(u"取消分辨率自适应按钮")
        res = self.screenSet.ctrlResolutionAutoAdjust("close")
        if(-1 == res):
           
            InfoHintDialog(u"打开分辨率自适应文件失败").exec_()
        else:
           
            InfoHintDialog(u"成功关闭分辨率自适应").exec_()
    
        return
    
    def on_comboBoxScreenName_activated(self,index):
        LogRecord.instance().logger.info(u"分辨率combo")
        variant = self.screenComboBox.itemData(index, Qt.UserRole + 1)
        if (variant.isValid()):
            self.ratioComboBox.clear()
            reList = variant.toStringList()
            count = len(reList)
         
            for i in range(count):
                self.ratioComboBox.addItem(reList[i])
    
        #显示当前屏幕的分辨率
        screenName = self.screenComboBox.itemText(index)
        curscr =self.screenSet.getCurScreen(screenName)
        j = self.ratioComboBox.count()
    
        for i in range(j):
            if(curscr == self.ratioComboBox.itemText(i)):
                self.ratioComboBox.setCurrentIndex(i)
    
    
    #双屏组合显
    def on_radioButtonMulConnect_clicked(self):        
        result = self.multiMonitor.enableMultiMonitor()
        if(result == -1):
       
            InfoHintDialog(u"没有检测到多个显示器").exec_()
            return
        if(result == -2):
           
            InfoHintDialog(u"获取显示器失败").exec_()
            return
        if(result == -3):
           
            InfoHintDialog(u"获取当前分辨率失败").exec_()
            return
    
        if (not self.isResolutionSame()):

            InfoHintDialog(u"各个屏幕必须设置成相同的分辨率!").exec_()
            return
        
        screenName = self.screenComboBox.itemText(0)
        firstScreenCursor =self.screenSet.getCurScreen(screenName)
    
        #获得多屏的分辨率
        width = int(firstScreenCursor.split("x")[0]) * 2
        height = firstScreenCursor.split("x")[1]
        ssize = QString.number(width) + "x" + height
    
        #把支持多屏连接的分辨率写入文件
        self.multiMonitor.setMultiMonitorStatus("enable", ssize)
    
       
        InfoHintDialog(u"启用多屏拼接成功!").exec_()
        self.emit(SIGNAL("setscreenover"))
        return
    
    #判断各个屏幕的分辨率是否相同
    def isResolutionSame(self):
    
        #获取屏幕名称及对应当前的分辨率

        resolutionMap = {}
      
        for i in range(self.screenComboBox.count()):
        
            screenName = self.screenComboBox.itemText(i)
            curscr =self.screenSet.getCurScreen(screenName)
            if (i == 0):
                firstScreenCursor = curscr
                
            resolutionMap[screenName] = curscr
        
    
        #比较各个屏幕的当前分辨率是否相同
   
            
        for item in resolutionMap:
            if resolutionMap[item] != firstScreenCursor:
                return False
        return True
    

if __name__ == "__main__":
    import sys
    from PyQt4.QtGui import QApplication
    from PyQt4.QtCore import QTextCodec
    app = QApplication(sys.argv)
    QTextCodec.setCodecForCStrings(QTextCodec.codecForName("utf-8"))
    win = SystemSetting()
    win.show()
    app.exec_()
