#coding:utf-8
from PyQt4 import QtCore
from PyQt4 import QtGui
from AppActivLabel import AppActivLabel
from logger.logrecord import LogRecord
class AppActivWidget(QtGui.QX11EmbedWidget):
    """
    """
    def __init__(self,parent=None,pannel_=None):
        QtGui.QX11EmbedWidget.__init__(self,parent)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.setWindowFlags(QtCore.Qt.Dialog and QtCore.Qt.CustomizeWindowHint and QtCore.Qt.FramelessWindowHint)
        self.pannel=pannel_
        self.width_=300
        self.stripHeight=67
        self.setGeometry(0,0,self.width_,30)
        self.activDic={}
        self.activLabel=AppActivLabel(self)
        self.hide()
        self.alterSignal=QtCore.pyqtSignal()
        self.connect(self,QtCore.SIGNAL('alterSignal'),self.alterActivity)

    def setParentWnd(self,parentWnd=0):
        try:
            self.embedInto(parentWnd)
        except Exception,err:
            LogRecord.instance().logger.exception("挂载应用列表窗口失败！")

    @QtCore.pyqtSlot()
    def showActivities(self,activitiesDic={},left=0,top=0):
        self.activDic=activitiesDic
        print self.activDic
        self.left=left
        self.top=top
        # self.activLabel=AppActivLabel(self)
        self.activLabel.refresh(self.activDic)
        self.setGeometry(left,top,self.width_,self.activLabel.geometry().height())
        #设置圆角
        rect=QtCore.QRectF(0,0,self.geometry().width(),self.geometry().height())
        path=QtGui.QPainterPath()
        path.addRoundRect(rect,10)
        polygon= path.toFillPolygon().toPolygon()
        region=QtGui.QRegion(polygon)
        self.setMask(region)

        self.show()

    @QtCore.pyqtSlot()
    def hideActivities(self):
        self.hide()

    @QtCore.pyqtSlot()
    def alterActivity(self,id,type):
        try:
            self.pannel.alterActivity(id,type)
        except Exception,err:
            LogRecord.instance().logger.exception("应用面板已经被删除！不能调用应用面板方法！")


