在UI原型设计和Python脚本实现UI原型两个blog中已经跟大家介绍了整个智能魔镜端的交互UI的设计原型和实现的Python脚本及方式,这里将进一步教大家如何实现整个UI交互的逻辑控制程序,根据智能魔镜整体设计文章中的设计方案,智能魔镜交互主要是依托摄像头、超声波和显示屏与用户进行交互,智能魔镜依托超声波模块实时的监控镜子前面的人体动态,在有人靠近的时候启动摄像头,然后通过图像识别来处理和识别当前的用户身份,*后根据用户身份启动显示模块控制显示,将指定的用户消息推送显示在当前使用镜子的用户面前。
以上就是在智能魔镜中的显示控制逻辑设计中需要完成的内容,在具体实现的过程中,对于显示逻辑控制这一块,主要是通过构建了一个magic_mirroWindows.py文件来实现,在这里实现了对魔镜的交互UI类的实例化,同时创建了一个magic_mirroWindows类来实现魔镜UI控制的各个逻辑控制功能,其中主逻辑是通过实例化该类来启动魔镜的UI交互程序,在UI交互程序控制中,首先会通过函数调用刷新页面的公共显示信息,然后调用定时器对执行过程进行控制,定时的检测当前镜子前面的情况,然后根据定时检测的结果来执行相应的刷新程序,具体的代码设计如下:
class magic_mirroWindows
self.new.setupUi
#save user video Info
self.push_video_userID=[]
self.videoPathList=[]
#self.viedoMsg.setWindowFlags
self.tp.setColor
self.movie=QtGui.QMovie
#set html view is black
self.new.webMessageText.setHtml
self.new.webMemorandum.setHtml
self.new.webZhishu.setHtml
self.manager = QtNetwork.QNetworkAccessManager
#self.weather=getWeatherInfo
self.weather_updateOK=0
self.new.helloWelcome.setText
self.Reply=self.manager.get
self.Reply.finished.connect
forecast_date_list.append
forecast_date_list.append
forecast_date_list.append
forecast_date_list.append
forecast_date_list.append
forecast_temp_list.append
forecast_temp_list.append
forecast_temp_list.append
forecast_temp_list.append
forecast_temp_list.append
forecast_type_list.append
forecast_type_list.append
forecast_type_list.append
forecast_type_list.append
forecast_type_list.append
#定时刷新
self.TImer=QtCore.QTImer
#self.count=0
self.timer.timeout.connect
# test button
self.new.closeButton.setStyleSheet
time = QtCore.QDateTime.currentDateTime
self.new.date.setPalette
self.new.date.setText
palette1 = QtGui.QPalette
palette1.setColor
self.setPalette
self.setWindowTitle
self.setWindowFlags
def paintEvent
#painter.drawPixmap
qbyte = self.Reply.readAll
pbyte = bytes
str
weatherInfo = bytes.decode
self.updateUIdata
def updateUIdata
forecast_date_list[i].setText
forecast_temp_list[i].setPalette
forecast_temp_list[i].setText
forecast_type_list[i].setPalette
forecast_type_list[i].setPixmap
self.new.city.setPalette
self.new.city.setText
self.new.temp.setPalette
self.new.temp.setText
self.new.fengli.setPalette
self.new.fengli.setText
self.new.fengxiang.setPalette
self.new.fengxiang.setText
self.new.shidu.setPalette
self.new.shidu.setText
self.new.label_3.setPalette
self.new.label_3.setText
self.updateZhishu
def updateZhishu
format="
%s:
%s
"values=
result= format % values
self.new.webZhishu.setHtml
self.zhishuUpdateTime=5
else:
self.zhishuUpdateTime=self.zhishuUpdateTime-1
# start Personalized Display by userID when system detect someone in front of the magic mirror
def startPersonalizedDisplay
#display user video msg
def detectPeople
#get System Status
#statusName peopeleInfront
#statusValue{0,1,2},0 no people in front,1 have people in front of mirror but no detect people ID
#2 have people in front of mirror and detect people ID return ID
result=MMDB.getSystemStatusValue
if result[0]==1:
return 0
elif result[0]==2:
return result[1] #return userID
else:
return -1
def timerControl
# test have people
detectResult=self.detectPeople
if detectResult==-1:
self.hide
elif detectResult==0:
self.showNormalInfo
self.show
else:
self.show
if self.current_userID!=detectResult:
self.startPersonalizedDisplay
self.current_userID=detectResult
else:
return
def showNormalInfo
self.new.webMemorandum.setHtml
self.new.helloWelcome.setText
def showPushInfo
#update welcome info by userID
userName=MMDB.getUserName
format="
Hello %s Welcome...
"values=
result=format % values
self.new.helloWelcome.setText
#update pushInfo
#infoID,pushID,infoSubject,infoContent,pushTime
msgList=MMDB.getTextMessageList
i=0
pushName=""
msg_info=""
pushTime=""
msgStr=""
selfMsgStr=""
if msgList!=None:
for msg in msgList:
pushName=MMDB.getUserName
msg_info=msg[3]
pushTime=msg[4]
if msg[1]!=userID:
msgStr+=
else:
selfMsgStr+=
self.new.webMessageText.setHtml
self.new.webMemorandum.setHtml
#show message end get video message info
if videoMsgList!=None:
i=0
for videoMsg in videoMsgList:
if i%2==0:
self.push_video_userID.append
else:
self.videoPathList.append
i=i+1
videocmd="mplayer -vo x11 -playlist "
for video in self.videoPathList:
videocmd=videocmd+' '+video
os.system
*后,只需要将主函数写入该文件中,启动该类进行实例化即可完成整个交互逻辑控制程序的启动,也就是整个UI交互程序的启动,具体的主函数代码如下:
if __name__=="__main__":
import sys
import os
app=QtWidgets.QApplication
pixmap = QtGui.QPixmap
myshow.show
sys.exit
在这种设计中,我们将整个魔镜的UI设计和数据设计进行了分离,*终在整合的过程中,只需要在启动超声波、摄像头监控程序和数据库程序,然后启动UI交互程序即可完成整个智能魔镜��模的整合。