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

from PyQt4.QtGui import QWidget
from PyQt4.QtCore import SIGNAL,pyqtSlot, QString, Qt

from externDevice import ExternDevice   # 外部设备透传
from networkCheck import NetworkCheck   # 网络诊断
from muiltScreen import MuiltScreen     # 多平设置模块

from ui_qss.winDebugQss import WinDebugQss
from terminal.usblist import UsbList
from terminal.tools import NetWidget

class WinDebug (WinDebugQss):

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

        self.__externDevice = UsbList()     #ExternDevice() # 实例化 外部设备透传设置窗口
        self.__networkCheck = NetWidget()   #NetworkCheck() # 实例化 网络诊断设置窗口
        self.__muiltScreen  = MuiltScreen()  # 实例化 多屏显示设置窗口

        self.gridLayout_externDevice.addWidget(self.__externDevice)
        self.gridLayout_networkdset.addWidget(self.__networkCheck)
        self.gridLayout_muitScreen.addWidget(self.__muiltScreen)

        self.connect(self.btn_close,SIGNAL("clicked()"),self.close)
        self.connect(self.btn_cancle,SIGNAL("clicked()"),self.close)
        self.connect(self.btn_ok,SIGNAL("clicked()"),self.btn_ok_solt)    # 确定
        self.connect(self.btn_yes,SIGNAL("clicked()"),self.btn_yes_slolt) # 应用
        self.connect(self.muiltScreen, SIGNAL("clicked()"), self.__layout_band_muiltScreen)
        self.connect(self.networkCheck, SIGNAL("clicked()"), self.__layout_band_networkCheck)
        self.connect(self.externDevice, SIGNAL("clicked()"), self.__layout_band_externDevice)
        self.connect(self.pushButton_usb_set, SIGNAL("clicked()"), self.__layout_band_pushButton_usb_set)
        self.mousePressed = False
        self.stackedWidget.setCurrentIndex(0)
        self.update_current_pushbutton_style()
        self.btn_ok.setFocusPolicy(Qt.NoFocus)
        self.btn_cancle.setFocusPolicy(Qt.NoFocus)
        self.btn_yes.setFocusPolicy(Qt.NoFocus)

        self._update_usb_used_status()


    def _update_usb_used_status(self):
        """add by pbc for update usb used status"""
        from common import common_run
        ret = common_run.get_usb_set_statu()
        if ret == "" or ret == "22":
            self.radioButton_auto_usb.setChecked(True)
        elif ret == "00":
            self.radioButton_virt_usb.setChecked(True)
        elif ret == "11":
            self.radioButton_network_usb.setChecked(True)

    def set_usb_used_status(self):
        """add by pbc for set usb used status"""
        from common import common_run
        if self.radioButton_auto_usb.isChecked():
            common_run.set_usb_set_statu("22")
        elif self.radioButton_virt_usb.isChecked():
            common_run.set_usb_set_statu("00")
        elif self.radioButton_network_usb.isChecked():
            common_run.set_usb_set_statu("11")


    def btn_ok_solt(self): # 确定
        self.btn_yes_slolt()
        self.close()

    def btn_yes_slolt(self): # 应用
        self.set_usb_used_status()
        self.__muiltScreen.setMuiltScreen()

    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()

    def __del__(self):
        del self.__externDevice
        del self.__networkCheck
        del self.__muiltScreen

    @pyqtSlot()
    def __layout_band_pushButton_usb_set(self):
        self.stackedWidget.setCurrentIndex(3)
        self.update_current_pushbutton_style()

    @pyqtSlot()
    def __layout_band_muiltScreen(self):
        self.stackedWidget.setCurrentIndex(2)
        self.update_current_pushbutton_style()

    @pyqtSlot()
    def __layout_band_networkCheck(self):
        self.stackedWidget.setCurrentIndex(1)
        self.update_current_pushbutton_style()

    @pyqtSlot()
    def __layout_band_externDevice(self):
        self.stackedWidget.setCurrentIndex(0)
        self.update_current_pushbutton_style()



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