# -*- coding: utf-8 -*-  
from PyQt4.QtGui import *  
from PyQt4.QtCore import *  
import sys ,os 
  
QTextCodec.setCodecForTr(QTextCodec.codecForName("utf8"))  
  
class MessageBoxDlg(QDialog):  
    def __init__(self,parent=None):  
        super(MessageBoxDlg,self).__init__(parent)  
        self.setWindowTitle(u"图灵管家")
        self.resize(1000,90)
        self.label=QLabel(u"欢迎使用图灵机器人")  
        questionButton=QPushButton(u"音乐")  
        informationButton=QPushButton(u"电影")  
        warningButton=QPushButton(u"语音聊天")  
        criticalButton=QPushButton(u"人脸检测")  
        aboutButton=QPushButton(u"天气预报")  
        aboutqtButton=QPushButton(u"邮件推送")  
        customButton=QPushButton(u"环境检测")
        dongButton=QPushButton(u"机器动作")
        renlianButton=QPushButton(u"人脸识别")
        xinwenButton=QPushButton(u"新闻热点")
        qianButton=QPushButton(u"前进")  #控制
        houButton=QPushButton(u"后退")
        zuoButton=QPushButton(u"左转")
        youButton=QPushButton(u"右转")
        tingButton=QPushButton(u"停")
  
        gridLayout=QGridLayout(self)  
        gridLayout.addWidget(self.label,0,2,1,3)
        gridLayout.addWidget(questionButton,1,0)  
        gridLayout.addWidget(informationButton,1,1)  
        gridLayout.addWidget(warningButton,2,0)  
        gridLayout.addWidget(criticalButton,2,1)  
        gridLayout.addWidget(aboutButton,3,0)  
        gridLayout.addWidget(aboutqtButton,3,1)  
        gridLayout.addWidget(customButton,4,0)
        gridLayout.addWidget(dongButton,4,1)
        gridLayout.addWidget(renlianButton,4,2)
        gridLayout.addWidget(xinwenButton,4,4)
        
        gridLayout.addWidget(qianButton,1,3)   #控制
        gridLayout.addWidget(houButton,3,3)
        gridLayout.addWidget(zuoButton,2,2)
        gridLayout.addWidget(youButton,2,4)
        gridLayout.addWidget(tingButton,2,3)
        
 
        self.connect(questionButton,SIGNAL("clicked()"),self.slotQuestion)  
        self.connect(informationButton,SIGNAL("clicked()"),self.slotInformation)  
        self.connect(warningButton,SIGNAL("clicked()"),self.slotWarning)  
        self.connect(criticalButton,SIGNAL("clicked()"),self.slotCritical)  
        self.connect(aboutButton,SIGNAL("clicked()"),self.slotAbout)  
        self.connect(aboutqtButton,SIGNAL("clicked()"),self.slotAbout1)  
        self.connect(customButton,SIGNAL("clicked()"),self.slotCustom)
        self.connect(dongButton,SIGNAL("clicked()"),self.dong)
        self.connect(renlianButton,SIGNAL("clicked()"),self.renlian)
        self.connect(renlianButton,SIGNAL("clicked()"),self.xinwen)
        self.connect(qianButton,SIGNAL("clicked()"),self.qian)#控制
        self.connect(houButton,SIGNAL("clicked()"),self.hou)
        self.connect(zuoButton,SIGNAL("clicked()"),self.zuo)
        self.connect(youButton,SIGNAL("clicked()"),self.you)
        self.connect(tingButton,SIGNAL("clicked()"),self.ting)
  
    def slotQuestion(self):  
        button=QMessageBox.question(self,u"音乐播放器",  
                                    self.tr(u"是否打开音乐播放器"),  
                                    QMessageBox.Ok|QMessageBox.Cancel,  
                                    QMessageBox.Ok)  
 
        if button==QMessageBox.Ok:  
            self.label.setText(u"我不想忘记你---（郭静）")
            print "正在播放音乐"
            os.system(" omxplayer /home/pi/music/我不想忘记你---郭静.mp3")
            #print os.system('ps -e|grep omxplayer')
        elif button==QMessageBox.Cancel:  
            self.label.setText(u"已经关闭音乐播放器")
            #print os.system('ps -e|grep omxplayer')
        else:  
            return  
  
    def slotInformation(self):  
        button=QMessageBox.information(self,u"电影播放器",  
                                self.tr(u"是否打开电影播放器"),
                                QMessageBox.Ok|QMessageBox.Cancel,  
                                    QMessageBox.Ok)  
        if button==QMessageBox.Ok:  
            self.label.setText(u"我不想忘记你---（郭静）")
            print "正在播放电影"
        elif button==QMessageBox.Cancel:  
            self.label.setText(u"已经关闭音乐播放器")
            print "已经关闭电影播放器"
        else:  
            return    
  
    def slotWarning(self):  
        button=QMessageBox.warning(self,u"语音聊天",  
                                   self.tr(u"是否进入语音聊天?"),  
                                   QMessageBox.Ok|QMessageBox.Cancel,  
                                   QMessageBox.Ok)  
        if button==QMessageBox.Ok:  
            self.label.setText(u"正在聊天")  
        elif button==QMessageBox.Cancel:  
            self.label.setText(u"退出聊天")  
       
        else:  
            return  
  
    def slotCritical(self):  
        QMessageBox.critical(self,u"人脸检测",  
                             self.tr(u"请将你的脸对准摄像头"))  
        self.label.setText(u"正在人脸采集")
        os.system('python /home/pi/xiangmu/renlianshibie/renlian1.py')

    def renlian(self):  
        QMessageBox.critical(self,u"人脸识别",  
                             self.tr(u"请将你的脸对准摄像头"))  
        self.label.setText(u"正在人脸识别")
        os.system('sudo python /home/pi/webcam/face-recognition/prepare-data/shibie.py')
    def slotAbout(self):  
        QMessageBox.about(self,u"天气预报",self.tr(u"正在查询"))
        os.system("python /home/pi/xiangmu/tianqi/tianqi.py")
        f=open("/home/pi/xiangmu/tianqi/tianqi.txt","r")
        s=f.readline()
        f.close()
        s=unicode(s,'utf-8')
        self.label.setText(s)  
  
    def slotAbout1(self):  
        QMessageBox.about(self,u"邮件推送",self.tr(u"正在发送"))
        s=raw_input("输入邮件内容:")
        zong=open('/home/pi/xiangmu/youjian/youjian.txt','w')
        zong.write(s)
        zong.close()
 
        os.system("python /home/pi/xiangmu/youjian/youjian.py")
        s=unicode(s,'utf-8')
        self.label.setText(s+u"发送成功")
    def slotCustom(self):  
        QMessageBox.about(self,u"环境检测",self.tr(u"获取环境.."))
        os.system("python /home/pi/xiangmu/shuju/cpuneicunwendu.py")
        f=open('/home/pi/xiangmu/shuju/zongshuju.txt',"r")
        s=f.read()
        f.close()
        s=unicode(s,'utf-8')
        self.label.setText(s)
    def dong(self):  
        QMessageBox.about(self,u"图灵芭蕾",self.tr(u"请欣赏舞蹈"))
        self.label.setText(u"正在跳舞")
        print(u"正在跳舞")
    def xinwen(self):  
        QMessageBox.about(self,u"新闻热点",self.tr(u"正在搜索头条"))
        self.label.setText(u"搜索成功")
        print(u"正在跳舞")

        #控制
    def qian(self):  
        self.label.setText(u"正在前进")
        os.system('sudo python /home/pi/xiangmu/chuankou.py w')
        print(u"正在前进")
    def hou(self):  
        self.label.setText(u"正在后退")
        os.system('sudo python /home/pi/xiangmu/chuankou.py s')
        print(u"正在后退")
    def zuo(self):  
        self.label.setText(u"正在左转")
        os.system('sudo python /home/pi/xiangmu/chuankou.py a')
        print(u"正在左转")
    def you(self):  
        self.label.setText(u"正在右转")
        os.system('sudo python /home/pi/xiangmu/chuankou.py d')
        print(u"正在右转")
    def ting(self):  
        self.label.setText(u"已经停止")
        os.system("sudo python /home/pi/xiangmu/chuankou.py 0")
        print(u"停止")
    
app=QApplication(sys.argv)  
MessageBox=MessageBoxDlg()  
MessageBox.show()  
app.exec_()  
