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


from logger.logrecord import LogRecord


class AppIcon(QtGui.QLabel):
    def __init__(self,parent=None,icon_='default-app.png'):
        QtGui.QLabel.__init__(self,parent)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
#         self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
#         sideLength=parent.geometry().width()*3//4
#         print parent.geometry()
#         leftMargin=sideLength//6
#         self.setGeometry(leftMargin,0,sideLength,sideLength)
        icon_path=getenv("MCOS_APP_ICON_PATH")
        if not os.path.exists('%s/%s'%(icon_path,icon_)):
            LogRecord.instance().logger.warn('找不到应用图标：%s'%icon_)
            icon_='default-app.png'
        #iconStyle='''QLabel{border-image: url(images/%s);background:transparent;}'''%icon_
        # iconStyle='''QLabel{border-image: url(VirtApp/images/%s);background:transparent;}'''%icon_
        # print 'icon_path:'+icon_path+" icon_:"+icon_
        iconStyle='''QLabel{border-image: url(%s/%s);background:transparent;}'''%(icon_path,icon_)
        self.setStyleSheet(iconStyle)
