基于dragonboard 410c的智能魔镜设计(9)——如何实现UI交互控制逻辑
forecast_type_list.append(self.new.forecast_0_type)
forecast_type_list.append(self.new.forecast_1_type)
forecast_type_list.append(self.new.forecast_2_type)
forecast_type_list.append(self.new.forecast_3_type)
forecast_type_list.append(self.new.forecast_4_type)
#定时刷新
self.TImer=QtCore.QTImer(self)
#self.count=0
self.timer.timeout.connect(self.timerControl)
# test button
self.new.closeButton.setStyleSheet("QPushButton {border-image:url(:/images/close);}QPushButton:hover{border-image:url(:/images/close_on);}QPushButton:hover:pressed{border-image:url(:/images/close);}")
time = QtCore.QDateTime.currentDateTime()
self.new.date.setPalette(self.tp)
self.new.date.setText(time.toString("yyyy-MM-dd"))
palette1 = QtGui.QPalette(self)
palette1.setColor(self.backgroundRole(),QtGui.QColor(0,0,0))
self.setPalette(palette1)
self.setWindowTitle('w')
self.setWindowFlags(Qt.FramelessWindowHint)
def paintEvent(self,QPaintEvent):
painter=QtGui.QPainter(self)
#painter.drawPixmap(0, 0, pixmap) #绘制UI
def replayFinished(self):
global weather
print("weather replayFinished")
qbyte = self.Reply.readAll()
pbyte = bytes(qbyte.data())
str(pbyte, encoding = "utf-8")
weatherInfo = bytes.decode(pbyte)
weather=getWeatherInfo(weatherInfo)
self.updateUIdata(weather)
def updateUIdata(self,weatherResult):
for i in range(0,5):
forecast_date_list[i].setPalette(self.tp)
forecast_date_list[i].setText(weatherResult.forecast_weather_info_date[i])
forecast_temp_list[i].setPalette(self.tp)
forecast_temp_list[i].setText(weatherResult.forecast_weather_info_low[i][3:6]+"~"+weatherResult.forecast_weather_info_high[i][3:6])
forecast_type_list[i].setPalette(self.tp)
forecast_type_list[i].setPixmap(QtGui.QPixmap(":/images/"+weatherResult.forecast_weather_info_dtype[i]))
self.new.city.setPalette(self.tp)
self.new.city.setText(weatherResult.weather_city)
self.new.temp.setPalette(self.tp)
self.new.temp.setText(weatherResult.weather_wendu+"℃")
self.new.fengli.setPalette(self.tp)
self.new.fengli.setText(weatherResult.weather_fengli)
self.new.fengxiang.setPalette(self.tp)
self.new.fengxiang.setText(weatherResult.weather_fengxiang)
self.new.shidu.setPalette(self.tp)
self.new.shidu.setText(weatherResult.weather_shidu)
self.new.label_3.setPalette(self.tp)
self.new.label_3.setText("湿度")
self.updateZhishu()
self.timer.start(1000)
def updateZhishu(self):
global weather
if self.zhishuUpdateTime == 0:
i=random.randint(0,5)
format="<body bgcolor=black><h3><FONT color = red> %s:</FONT></h3><p><FONT color = white> %s</p></FONT> <body>"
values=(weather.weather_zhishu_name[i],weather.weather_zhishu_data[i])
result= format % values
self.new.webZhishu.setHtml(result)
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(self,userID):
self.showPushInfo(userID)
#display user video msg
def detectPeople(self):
MMDB=MagicMirrorDB("./db.sqlite3")
#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("peopleInfront")
print("peopleInfront")
print(result)
if result[0]==1:
return 0
elif result[0]==2:
print("front people ID:")
print(result[1])
return result[1] #return userID
else:
return -1
def timerControl(self):
#self.updateZhishu()
# test have people
detectResult=self.detectPeople()
if detectResult==-1:
print("no people")
self.hide()
elif detectResult==0:
self.showNormalInfo()
self.show()
print("have people but no ID")
else:
self.show()
print(detectResult)
print("in front of magicmirror")
if self.current_userID!=detectResult:
self.startPersonalizedDisplay(detectResult)
self.current_userID=detectResult
else:
return
def showNormalInfo(self):
self.new.webMessageText.setHtml("<body bgcolor=black></body>")
self.new.webMemorandum.setHtml("<body bgcolor=black></body>")
self.new.helloWelcome.setText("<h3>hello,welcom2...</h3>")
def showPushInfo(self,userID):
MMDB=MMDB=MagicMirrorDB("db.sqlite3")
#update welcome info by userID
userName=MMDB.getUserName(userID)
format="<h3><FONT color = white> Hello %s Welcome...</FONT></h3>"
values=(userName)
result=format % values
self.new.helloWelcome.setText(result)
#update pushInfo
#infoID,pushID,infoSubject,infoContent,pushTime
msgList=MMDB.getTextMessageList(userID)
print("test0")
print(msgList)
print("hello")
i=0
pushName=""
msg_info=""
pushTime=""
msgStr=""
selfMsgStr=""
if msgList!=None:
for msg in msgList:
print(msg)
print("test1")
print(msg)
pushName=MMDB.getUserName(msg[1])
msg_info=msg[3]
pushTime=msg[4]
if msg[1]!=userID:
msgStr+=("<h3><FONT color=red>"+pushTime+"</FONT></h3>"+"<h3><FONT color=red>"+pushName+"to you:"+"</FONT></h3><p>"+msg_info+"</p>")
else:
selfMsgStr+=("<h3><FONT color=red>"+msg_info+"</FONT></h3>")
self.new.webMessageText.setHtml("<body bgcolor=black><marquee loop=-1 direction=up scrollamount=5 height=210 width=300 bgcolor=black><FONT color=white>"+msgStr+"</marquee></body>")
self.new.webMemorandum.setHtml("<body bgcolor=black><marquee loop=0 direction=up scrollamount=5 height=160 width=300 bgcolor=black><FONT color=white>"+selfMsgStr+"</marquee></body>")
videoMsgList=MMDB.getUserVideoMessageList(self.current_userID)
print("videoMsgList")
print(videoMsgList)
#show message end get video message info
if videoMsgList!=None:
print("start play video msg")
i=0
for videoMsg in videoMsgList:
if i%2==0:
print(videoMsg)
self.push_video_userID.append(videoMsg)
else:
print(videoMsg)
self.videoPathList.append(videoMsg)
i=i+1
videocmd="mplayer -vo x11 -playlist "
for video in self.videoPathList:
videocmd=videocmd+' '+video
os.system(videocmd)
最后,只需要将主函数写入该文件中,启动该类进行实例化即可完成整个交互逻辑控制程序的启动,也就是整个UI交互程序的启动,具体的主函数代码如下:
智能魔镜 DragonBoard 410c 相关文章: