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

from AppLabel import AppLabel
from AppUser import AppUser
from AppApplication import AppApplication
from AppObject import AppObject
from NotifyWidget import NotifyWedget
from AppTool import AppTool
from AppActivWidget import AppActivWidget
from logger.logrecord import LogRecord
from uiWindow.WaitingDialog import WaitingDialog


class AppPannel(QtGui.QLabel):
    """
    展示应用的面板
    """
    #打开应用的错误码
    startAppErrNo={
        '1':u"找不到应用ID!",
        '2':u"找不到应用!",
        '3':u"连接RDP会话失败!",
        '4':u"断开连接失败,连接rdp会话失败",
        '5':u"连接RDP会话失败!",
        '6':u"发送打开应用命令失败!"
    }
    def __init__(self,parent=None,appUser=None):
        QtGui.QLabel.__init__(self,parent)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.pannelWidth=parent.geometry().width()
        self.parentHeight=parent.geometry().height()
        self.singleWdith=164
        self.singleHeight=167
        self.columnCount=self.pannelWidth//self.singleWdith
        self.desktopWidth=QtGui.QApplication.desktop().screenGeometry().width()
        # self.total=0
        self.setStyleSheet('QLabel{border-image: url();background:transparent;}')

        self.Waiting=WaitingDialog()
        self.waiteTimer=QtCore.QTimer()
        self.__timeout=30000
        self.closeWaitingSignal=QtCore.pyqtSignal()
        self.connect(self.waiteTimer,QtCore.SIGNAL("timeout()"),self,QtCore.SLOT("waiteTimeout()"))
        self.connect(self,QtCore.SIGNAL("closeWaitingSignal()"),self,QtCore.SLOT("waiteTimeout()"))

        self.user=appUser
        if self.user == None:
            self.user=AppUser(r'www10.com\wang')
            self.user.setPassword('Pass1234')
            self.user.setAgentIP('192.168.102.36')
            self.user.setAgentPort('3389')
            self.user.setRdpState('disconnected')
            self.user.setLoginState('ready')
            #初始化应用
            appObj=AppObject('计算器','100')
            appObj.setAppPosition(0)
            appObj.setAppIcon('2.png')
            appObj.setAppCommand('C:\\Windows\\system32\\calc.exe')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            appObj=AppObject('记事本','99')
            appObj.setAppPosition(1)
            appObj.setAppIcon('1.png')
            appObj.setAppCommand('C:\\Windows\\system32\\notepad.exe')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            appObj=AppObject('画图','101')
            appObj.setAppPosition(2)
            appObj.setAppIcon('3.png')
            appObj.setAppCommand('C:\\Windows\\system32\\mspaint.exe')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            appObj=AppObject('Windows Media Player','102')
            appObj.setAppPosition(3)
            appObj.setAppIcon('4.png')
            appObj.setAppCommand(r'C:\Program Files (x86)\Windows Media Player\wmplayer.exe')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            appObj=AppObject('iexplore','103')
            appObj.setAppPosition(4)
            appObj.setAppIcon('27.png')
            appObj.setAppCommand(r'C:\Program Files (x86)\Internet Explorer\iexplore.exe')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            appObj=AppObject('Microsoft Excel 2010','104')
            appObj.setAppPosition(5)
            appObj.setAppIcon('320.png')#Adobe Reader 9
            appObj.setAppCommand(r'C:\Program Files\Microsoft Office\Office14\EXCEL.EXE')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            appObj=AppObject('Adobe Reader 9','105')
            appObj.setAppPosition(6)
            appObj.setAppIcon('18.png')
            appObj.setAppCommand(r'C:\Program Files (x86)\Adobe\Reader 9.0\Reader\AcroRd32.exe')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            appObj=AppObject('Microsoft Word 2010','106')
            appObj.setAppPosition(7)
            appObj.setAppIcon('137.png')
            appObj.setAppCommand(r'C:\Program Files\Microsoft Office\Office14\WINWORD.EXE')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            #Microsoft PowerPoint 2010
            appObj=AppObject('Microsoft PowerPoint 2010','107')
            appObj.setAppPosition(8)
            appObj.setAppIcon('102.png')
            appObj.setAppCommand(r'C:\Program Files\Microsoft Office\Office14\POWERPNT.EXE')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            #Microsoft Access 2010
            appObj=AppObject('Microsoft Access 2010','108')
            appObj.setAppPosition(9)
            appObj.setAppIcon('133.png')
            appObj.setAppCommand(r'C:\Program Files\Microsoft Office\Office14\MSACCESS.EXE')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            #Microsoft InfoPath Designer 2010
            appObj=AppObject('Microsoft InfoPath Designer 2010','109')
            appObj.setAppPosition(10)
            appObj.setAppIcon('321.png')
            appObj.setAppCommand(r'C:\Program Files\Microsoft Office\Office14\INFOPATH.EXE')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            #Microsoft Office Picture Manager
            appObj=AppObject('Microsoft Office Picture Manager','110')
            appObj.setAppPosition(11)
            appObj.setAppIcon('96.png')
            appObj.setAppCommand(r'C:\Program Files\Microsoft Office\Office14\OIS.EXE')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            #Microsoft OneNote 2010
            appObj=AppObject('Microsoft OneNote 2010','111')
            appObj.setAppPosition(12)
            appObj.setAppIcon('319.png')
            appObj.setAppCommand(r'C:\Program Files\Microsoft Office\Office14\ONENOTE.EXE')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            #Microsoft Outlook 2010
            appObj=AppObject('Microsoft Outlook 2010','112')
            appObj.setAppPosition(13)
            appObj.setAppIcon('176.png')
            appObj.setAppCommand(r'C:\Program Files\Microsoft Office\Office14\OUTLOOK.EXE')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            #Microsoft Publisher 2010
            appObj=AppObject('Microsoft Publisher 2010','113')
            appObj.setAppPosition(14)
            appObj.setAppIcon('317.png')
            appObj.setAppCommand(r'C:\Program Files\Microsoft Office\Office14\MSPUB.EXE')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            #Microsoft SharePoint Workspace 2010
            appObj=AppObject('Microsoft SharePoint Workspace 2010','114')
            appObj.setAppPosition(15)
            appObj.setAppIcon('315.png')
            appObj.setAppCommand(r'C:\Program Files\Microsoft Office\Office14\GROOVE.EXE')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            #Microsoft 剪辑管理器
            appObj=AppObject('Microsoft 剪辑管理器','115')
            appObj.setAppPosition(16)
            appObj.setAppIcon('112.png')
            appObj.setAppCommand(r'C:\Program Files\Microsoft Office\Office14\MSTORE.EXE')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            #WPS文字
            appObj=AppObject('WPS文字','116')
            appObj.setAppPosition(17)
            appObj.setAppIcon('8.png')
            appObj.setAppCommand(r'E:\programs\WPS Office\10.1.0.5603\office6\wps.exe')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            #WPS演示
            appObj=AppObject('WPS演示','117')
            appObj.setAppPosition(18)
            appObj.setAppIcon('9.png')
            appObj.setAppCommand(r'E:\programs\WPS Office\10.1.0.5603\office6\wpp.exe')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            #WPS表格
            appObj=AppObject('WPS表格','118')
            appObj.setAppPosition(19)
            appObj.setAppIcon('10.png')
            appObj.setAppCommand(r'E:\programs\WPS Office\10.1.0.5603\office6\et.exe')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            # #WPS云文档
            # appObj=AppObject('WPS云文档','119')
            # appObj.setAppPosition(20)
            # appObj.setAppIcon('11.png')
            # appObj.setAppCommand(r'E:\programs\WPS Office\ksolaunch.exe /qingbangong /showui adType=drive')
            # appObj.setAppEnable(True)
            # self.user.updateAppDictionary(appObj)
            #Google Chrome
            appObj=AppObject('Google Chrome','119')
            appObj.setAppPosition(20)
            appObj.setAppIcon('36.png')
            appObj.setAppCommand(r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            #Mozilla Firefox
            appObj=AppObject('Mozilla Firefox','120')
            appObj.setAppPosition(21)
            appObj.setAppIcon('37.png')
            appObj.setAppCommand(r'E:\programs\firefox\firefox.exe')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            #好压
            appObj=AppObject('好压','121')
            appObj.setAppPosition(22)
            appObj.setAppIcon('78.png')
            appObj.setAppCommand(r'C:\Program Files\2345Soft\HaoZip\HaoZip.exe')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            #WinRAR
            appObj=AppObject('WinRAR','122')
            appObj.setAppPosition(23)
            appObj.setAppIcon('79.png')
            appObj.setAppCommand(r'C:\Program Files\WinRAR\WinRAR.exe')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            #暴风影音5
            appObj=AppObject('暴风影音5','123')
            appObj.setAppPosition(24)
            appObj.setAppIcon('80.png')
            appObj.setAppCommand(r'C:\Windows\explorer.exe E:\programs\storm\StormPlayer.exe')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
            #360安全浏览器7
            appObj=AppObject('360安全浏览器7','124')
            appObj.setAppPosition(25)
            appObj.setAppIcon('81.png')
            appObj.setAppCommand(r'E:\programs\360\360se6\Application\360se.exe')
            appObj.setAppEnable(True)
            self.user.updateAppDictionary(appObj)
        self.application=AppApplication(self.user,self.eventFromApplication)
        # self.application.appRDP.setFullScreen(True)
        self.refreshApp()
        self.activitiesDic={}
        self.activities=AppActivWidget(pannel_=self)
        # self.activities.setParentWnd(self.winId())
        self.tool=AppTool(rdpWidth_=self.desktopWidth,pannel_=self)
        # self.connect(self,QtCore.SIGNAL('showUpSignal()'),self.tool,QtCore.SLOT('showUp()'))
        # self.connect(self,QtCore.SIGNAL('showDownSignal()'),self.tool,QtCore.SLOT('showDown()'))
        self.notifyWidget=NotifyWedget(parent)
        self.notifyWidget.hide()

        self.isFetchActivs=False

        self.enableFloatSignal=QtCore.pyqtSignal(bool)
        self.connect(self,QtCore.SIGNAL('enableFloatSignal'),parent,QtCore.SIGNAL('enableFloatSignal'))
        self.notifySignal=QtCore.pyqtSignal(str)
        self.connect(self,QtCore.SIGNAL('notifySignal'),self.notifyWidget.showMessage)
        self.showActivs=QtCore.pyqtSignal()
        self.connect(self,QtCore.SIGNAL('showActivs'),self.activities.showActivities)
        self.hideActivs=QtCore.pyqtSignal()
        self.connect(self,QtCore.SIGNAL('hideActivs'),self.activities.hideActivities)
        self.hideFloatLabel=QtCore.pyqtSignal()
        self.connect(self,QtCore.SIGNAL('hideFloatLabel'),parent.hideFloatLabel)
        self.showFloatLabel=QtCore.pyqtSignal()
        self.connect(self,QtCore.SIGNAL('showFloatLabel'),parent.showFloatLabel)
        self.toolUp=QtCore.pyqtSignal()
        self.connect(self,QtCore.SIGNAL('toolUp'),self.tool.showUp)
        self.toolDown=QtCore.pyqtSignal()
        self.connect(self,QtCore.SIGNAL('toolDown'),self.tool.showDown)
        self.backInfoSignal=QtCore.pyqtSignal()
        self.connect(self,QtCore.SIGNAL('backInfoSignal'),parent,QtCore.SIGNAL('backInfoSignal'))
        self.showRDPSignal=QtCore.pyqtSignal()
        self.hideRDPSignal=QtCore.pyqtSignal()
        self.connect(self,QtCore.SIGNAL('showRDPSignal'),self.showRDP)
        self.connect(self,QtCore.SIGNAL('hideRDPSignal'),self.hideRDP)
        self.displayRDPSignal=QtCore.pyqtSignal()
        self.connect(self,QtCore.SIGNAL('displayRDPSignal'),self.displayRDP)
        self.hungToolSignal=QtCore.pyqtSignal()
        self.connect(self,QtCore.SIGNAL('hungToolSignal'),self.hungTool)
        self.connectFailedMsgSignal=QtCore.pyqtSignal()
        self.connect(self,QtCore.SIGNAL('connectFailedMsgSignal'),self.connectFailedMsg)

        self.isFetching=False

    def refreshApp(self):
        """
        刷新应用界面
        """
        self.total=0
        self.gridLayout=QtGui.QGridLayout(self)
        # self.gridLayout.setSpacing(20)
#         self.gridLayout.setMargin(40)
#         self.gridLayout.setContentsMargins(10, 20, 30, 40)
        dic=self.user.getAppDictionary()
        # print dic
        # for kkk in range(2):
        for appID in dic:
            appObj=self.user.findAppObjectFromDic(appID)
            label=AppLabel(self,appObj)
            label.setMinimumSize(164, 167)
            label.setAlignment(QtCore.Qt.AlignCenter)
            # i=appObj.getAppPosition()
            # self.gridLayout.addWidget(label,i//self.columnCount,i%self.columnCount)
            self.total+=1
            self.gridLayout.addWidget(label,(self.total-1)//self.columnCount,(self.total-1)%self.columnCount)


        if self.total%self.columnCount == 0:
            self.rowCount=self.total//self.columnCount
        else:
            self.rowCount=self.total//self.columnCount+1
        # self.pannelHeight=self.pannelWidth//self.columnCount*(self.rowCount)
        self.pannelHeight=self.singleHeight*self.rowCount
        # if self.pannelHeight < self.parentHeight:
        #     self.pannelHeight=self.parentHeight
        self.left=0
        self.top=0
        if self.total<=self.columnCount:
            # self.left=(self.pannelWidth*(1.0-self.total/self.columnCount))//2
            # self.top=(self.parentHeight-self.pannelHeight)//2
            # self.width_=self.pannelWidth*self.total//self.columnCount
            self.width_=self.singleWdith*self.total
            self.left=(self.pannelWidth-self.width_)//2
            self.top=(self.parentHeight-self.pannelHeight)//2-QtGui.QApplication.desktop().height()//12
            # self.top=320-76
            # print self.pannelHeight
        else:
            self.width_=self.pannelWidth-self.pannelWidth%164
            self.left=(self.pannelWidth-self.width_)//2
        # print 'left: '+str(self.left)+' top: '+str(self.top)
        self.setGeometry(self.left,self.top,self.width_,self.pannelHeight)
        # print(self.geometry())
    @QtCore.pyqtSlot()
    def waiteTimeout(self):
        self.Waiting.showMsg("")
        self.waiteTimer.stop()
        self.Waiting.close()
        self.emit(QtCore.SIGNAL('displayRDPSignal'))
        
    def startApp(self,appNo):
#         print 'AppPannel startApp start!'
        self.isFetchActivs=False
        self.waiteTimer.start(self.__timeout)
        self.Waiting.refresh()
        self.Waiting.showMsg(u" 正在打开应用 ... ")
        # #添加延迟
        # QtCore.QTimer.singleShot(1000,self.Waiting,QtCore.SLOT("close()"))
        # self.Waiting.exec_()

        self.Waiting.show()

        appThread=threading.Thread(target=self.application.startApp,args=(appNo,))
        appThread.setDaemon(True)
        appThread.start()
#         time.sleep(30)
#         self.application.startApp(appNo)
    def disconnectRDP(self):
        try:
            self.application.appRDP.disconnectRDP()
        except Exception,err:
            LogRecord.instance().logger.exception("关闭应用面板，释放RDP连接失败！")

    def showRDP(self):
        if self.user.getRdpState() == 'connected':
            self.application.showRDP()

    def displayRDP(self):
        if self.user.getRdpState() == 'connected':
            if not self.isFetchActivs:
                self.application.displayRDP()

    def hideRDP(self):
        if self.user.getRdpState() == 'connected':
            self.application.hideRDP()

    # @QtCore.pyqtSlot()
    def backHome(self):
        homeThread=threading.Thread(target=self.application.backHome)
        homeThread.setDaemon(True)
        homeThread.start()
        self.emit(QtCore.SIGNAL('toolUp'))
        self.emit(QtCore.SIGNAL('hideActivs'))
        self.emit(QtCore.SIGNAL('hideFloatLabel'))
        # self.activities.setParentWnd(self.winId())

    # [taskbarAll::]
    def fetchActivities(self,caller='float'):
        # if self.user.getRdpState() != 'connected':
        #     LogRecord.instance().logger.debug("rdp会话连接未建立，不能获取活动的应用窗口！")
        #     return False
        if self.isFetching:
            return True
        self.isFetching=True

        self.activShower=caller
        self.isFetchActivs=True
        activitiesThread=threading.Thread(target=self.application.fetchActivities)
        activitiesThread.setDaemon(True)
        activitiesThread.start()
        try:
            self.emit(QtCore.SIGNAL('hideActivs'))
            self.emit(QtCore.SIGNAL('hideFloatLabel'))
        except Exception,err:
            LogRecord.instance().logger.exception("应用面板已经被删除！不能向应用面板发送信号！")
        return True

    #
    def alterActivity(self,id,type):
        """
        切换或关闭应用窗口
        :param id:应用窗口
        :param type:切换或关闭
        :return:
        """
        self.isFetchActivs=False
        alterThread=threading.Thread(target=self.application.alterActivities,args=(id,type,))
        alterThread.setDaemon(True)
        alterThread.start()
        self.emit(QtCore.SIGNAL('toolUp'))
        self.emit(QtCore.SIGNAL('hideActivs'))
        self.emit(QtCore.SIGNAL('hideFloatLabel'))

    def hungTool(self,hwnd):
        try:
            self.tool.setParentWnd(hwnd)
            self.activities.setParentWnd(hwnd)
        except Exception,err:
            LogRecord.instance().logger.exception("向rdp窗口挂载工具栏失败！")

    def connectFailedMsg(self,msg):
        self.Waiting.showMsg(msg)
        self.waiteTimer.stop()
        self.waiteTimer.start(2000)

    def eventFromApplication(self,event):
        if event == '':
            LogRecord.instance().logger.debug("返回自RDP的信息为空！")
            return 
        elif event.startswith('refresh::'):
            self.refreshApp()
            return
        elif event.startswith('backInfo::'):
            msg=event[10:]
            try:
                self.emit(QtCore.SIGNAL("closeWaitingSignal()"))
            except Exception,err:
                LogRecord.instance().logger.exception("closeWaitingSignal()")

            try:
                code,description=msg.split('||',1)
                self.emit(QtCore.SIGNAL('backInfoSignal'),code,description)
            except Exception ,err:
                LogRecord.instance().logger.exception("返回的信息解析错误！")
            # self.NotifyShow(msg)
            return
        elif event.startswith('appFailed::'):
            self.isFetchActivs=True
            try:
                self.emit(QtCore.SIGNAL("closeWaitingSignal()"))
            except Exception,err:
                LogRecord.instance().logger.exception("closeWaitingSignal()")
            try:
                self.emit(QtCore.SIGNAL('backInfoSignal'),40100,'打开应用失败！')
            except Exception ,err:
                LogRecord.instance().logger.exception("打开应用失败！")
        elif event.startswith('hwnd::'):
            window=event[6:]
            hwnd=int(window)
            self.emit(QtCore.SIGNAL('hungToolSignal'),hwnd)
            # self.tool.setParentWnd(hwnd)
            # self.activities.setParentWnd(hwnd)
            return
        elif event.startswith('toolDown::'):
            try:
                self.emit(QtCore.SIGNAL('toolDown'))
            except Exception,err:
                LogRecord.instance().logger.exception("toolDown::")
            # self.tool.showDown()
#             self.tool.showUp()
            return
        elif event.startswith('toolUp::'):
            # self.tool.showUp()
            try:
                self.emit(QtCore.SIGNAL('toolUp'))
                self.emit(QtCore.SIGNAL('hideActivs'))
            except Exception,err:
                LogRecord.instance().logger.exception("toolUp::")
            return
        elif event.startswith('noActivities::'):
            self.emit(QtCore.SIGNAL('enableFloatSignal'),False)
            self.user.setHasActs(False)
            return
        elif event.startswith('aliveActivities::'):
            try:
                self.emit(QtCore.SIGNAL("closeWaitingSignal()"))
            except Exception,err:
                LogRecord.instance().logger.exception("closeWaitingSignal()")

            self.emit(QtCore.SIGNAL('enableFloatSignal'),True)
            self.user.setHasActs(True)
            return
        elif event.startswith('activites::'):
            self.isFetching=False
            actString=event[13:]
            # print actString.decode('GBK')
            self.activitiesDic={}
            activities=actString.split('&&')
            for act in activities:
                if act.find('::') == -1:
                    continue
                pair=act.split('::')
                self.activitiesDic[pair[0]]=pair[1]

            if len(self.activitiesDic) == 0:
                # self.emit(QtCore.SIGNAL('enableFloatSignal'),False)
                return
            # self.activities.activDic=self.activitiesDic
            # self.emit(QtCore.SIGNAL('enableFloatSignal'),True)
            if self.activShower == 'tool':
                try:
                    self.emit(QtCore.SIGNAL('showActivs'),self.activitiesDic,self.desktopWidth//2,70)
                except Exception,err:
                    LogRecord.instance().logger.exception("showActivs")
            elif self.activShower == 'float':
                try:
                    self.emit(QtCore.SIGNAL('showFloatLabel'),self.activitiesDic)
                except Exception,err:
                    LogRecord.instance().logger.exception("showFloatLabel")
            return
        elif event.startswith("startError::"):
            try:
                errNo=event.split("::",2)[1]
                if errNo == "0":
                    # try:
                    #     self.emit(QtCore.SIGNAL("closeWaitingSignal()"))
                    # except Exception,err:
                    #     LogRecord.instance().logger.exception("closeWaitingSignal()")
                    return
                else:
                    msg=AppPannel.startAppErrNo[errNo]
                    self.emit(QtCore.SIGNAL('connectFailedMsgSignal'),msg)
                    # self.Waiting.showMsg(msg)
                    # self.waiteTimer.stop()
                    # self.waiteTimer.start(2000)
                    return
            except Exception,err:
                LogRecord.instance().logger.exception("解析打开应用的错误码异常！")
                self.emit(QtCore.SIGNAL('connectFailedMsgSignal'),u"连接代理失败，请联系管理员检查代理服务器状态或交付平台配置！")
                # self.Waiting.showMsg(u"未知错误！")
                # self.waiteTimer.stop()
                # self.waiteTimer.start(2000)
                return


    def NotifyShow(self,msg):
#         self.notifyWidget=NotifyWedget(self) 
#         self.notifyWidget.showMessage(msg)
        self.emit(QtCore.SIGNAL('notifySignal'),msg)

#         notify=QtCore.pyqtSignal(str)
#         self.connect(self, QtCore.SIGNAL('notify(const char*)'),self.notifyWidget,QtCore.SLOT('showMessage'))
#         self.emit(QtCore.SIGNAL('notify(const char*)'),msg)
#         self.notifyWidget.showMessage(msg)