当我单击 ON 按钮直到 guvcview 打开时,我需要显示文本“请稍候.....”,然后显示“guvcview 正在运行”。当我关闭 guvcview 时,同样的事情?在下面的 python代码,我试图显示“请稍候.....”,但我做不到。有人说需要重新加载页面。这只是示例,在我的代码中,我对页面登录和注销进行了身份验证。我需要最简单的方法,谢谢。
import cherrypy
import os.path
import struct
import time
import subprocess
import commands
class Server(object):
led_on=1
led_off=1
def index(self, on='', off=''):
html = """
<html>
<body>
<br>
<p>{htmlText}
<p>
<a href="?on=1"><img src="images/on.png"></a>
<a href="?off=1"><img src="images/off.png"></a>
</body>
</html>
"""
myText = ''
if on:
self.led_on = int(on)
myText = "Please wait ....."
html.format(htmlText=myText)
subprocess.call(['guvcview &'], shell=True)
time.sleep(2)
output = commands.getoutput('ps -A')
if 'guvcview' in output:
myText = "guvcview is running"
if off:
self.led_off = int(off)
myText = "Please wait ....."
html.format(htmlText=myText)
subprocess.call(['sudo pkill guvcview'], shell=True)
time.sleep(2)
output = commands.getoutput('ps -A')
if 'guvcview' in output:
myText = "Please wait ....."
else:
myText = "guvcview closed"
return html.format(htmlText=myText)
index.exposed = True
conf = {
'global' : {
'server.socket_host': '0.0.0.0',
'server.socket_port': 8085
},
'/images': {
'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.abspath('images')
}
}
cherrypy.quickstart(Server(), config=conf)