#coding:utf-8
from PyQt4 import QtGui
from PyQt4 import QtCore

from AppActivTop import AppActivTop
from AppActivScrollArea import AppActivScrollArea
from AppActivBottom import AppActivBottom
from logger.logrecord import LogRecord


class AppActivLabel(QtGui.QLabel):
    """
    """
    def __init__(self,parent=None,activDic={}):
        QtGui.QLabel.__init__(self,parent)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.parent_=parent
        self.width_=parent.geometry().width()
        self.setGeometry(0,0,self.width_,parent.geometry().height())
        # self.setObjectName('activLabel')
        self.setStyleSheet("QLabel{background-color: rgb(9,26,35);}")
        self.activDic={}
        self.activTop=None
        self.activScrollArea=None
        self.activBottom=None
        # self.setStyleSheet("QLabel{border-image: url(VirtApp/images/floatItem1.png);}")
        # self.activDic=activDic
        # self.activTop=AppActivTop(self)
        # l=self.activTop.geometry().height()
        # self.activScrollArea=AppActivScrollArea(self,self.activDic,l)
        # l+=self.activScrollArea.geometry().height()
        # self.activBottom=AppActivBottom(self,l)
        # l+=self.activBottom.geometry().height()
        # self.setGeometry(0,0,self.width_,l)
        self.alterSignal=QtCore.pyqtSignal()
        self.connect(self,QtCore.SIGNAL('alterSignal'),parent,QtCore.SIGNAL('alterSignal'))

    def refresh(self,activDic={}):
        self.activDic=activDic
        if self.activTop != None:
            self.activTop.close()

        if self.activScrollArea != None:
            self.activScrollArea.close()

        if self.activBottom != None:
            self.activBottom.close()

        self.activTop=AppActivTop(self)
        l=self.activTop.geometry().height()
        self.activScrollArea=AppActivScrollArea(self,self.activDic,l)
        l+=self.activScrollArea.geometry().height()
        self.activBottom=AppActivBottom(self,l)
        l+=self.activBottom.geometry().height()
        self.setGeometry(0,0,self.width_,l)
        # self.alterSignal=QtCore.pyqtSignal()
        # self.connect(self,QtCore.SIGNAL('alterSignal'),self.parent_,QtCore.SIGNAL('alterSignal'))
    def closeAll(self):
        """
        关闭所有打开的应用窗口
        :return:
        """
        for k in self.activDic.keys():
            LogRecord.instance().logger.debug("关闭所有窗口")
            self.emit(QtCore.SIGNAL('alterSignal'),k,'close')


