本文整理汇总了Python中program.Program.view方法的典型用法代码示例。如果您正苦于以下问题:Python Program.view方法的具体用法?Python Program.view怎么用?Python Program.view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类program.Program
的用法示例。
在下文中一共展示了Program.view方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GushPiBot
# 需要导入模块: from program import Program [as 别名]
# 或者: from program.Program import view [as 别名]
#.........这里部分代码省略.........
self.add_component("Audio", self.audio)
def create_echo(self):
self.echo = Echo(self.display)
self.echo.stop_handler.add(self.wheels.stop)
self.add_component("Echo", self.echo)
def create_keyboard(self):
self.keyboard = Keyboard(self.display.stdscr)
self.keyboard.handlers["UP"].add(self.wheels.forwards)
self.keyboard.handlers["DOWN"].add(self.wheels.backwards)
self.keyboard.handlers["LEFT"].add(self.wheels.left)
self.keyboard.handlers["RIGHT"].add(self.wheels.right)
self.keyboard.handlers["."].add(self.wheels.stop)
self.keyboard.handlers["{"].add(self.wheels.slow_left)
self.keyboard.handlers["}"].add(self.wheels.slow_right)
self.keyboard.handlers["CTRL+X"].add(self.pi_shutdown)
self.keyboard.handlers["PAGEDOWN"].add(self.menu.next)
self.keyboard.handlers["PAGEUP"].add(self.menu.prev)
self.keyboard.handlers["RETURN"].add(self.menu.select)
self.keyboard.handlers["ESC"].add(self.exit)
try:
self.keyboard.handlers["#"].add(self.webcam.take_photo)
except AttributeError:
pass
self.add_component("Keyboard", self.keyboard)
def create_webserver(self):
self.webserver = Webserver()
self.webserver.post_handlers["up"] = self.wheels.forwards
self.webserver.post_handlers["down"] = self.wheels.backwards
self.webserver.post_handlers["left"] = self.wheels.left
self.webserver.post_handlers["right"] = self.wheels.right
self.webserver.post_handlers["stop"] = self.wheels.stop
self.webserver.post_handlers["menu_next"] = self.menu.next
self.webserver.post_handlers["menu_prev"] = self.menu.prev
self.webserver.post_handlers["menu_select"] = self.menu.select
self.webserver.post_handlers["menu_text"] = self.menu.text
try:
self.webserver.post_handlers["photo"] = self.webcam.take_photo
except AttributeError:
pass
self.webserver.serve()
self.add_component("Webserver", self.webserver)
def create_menu(self):
self.display.display("GushPiBot...\nCreating menu")
self.menu = Menu(self.display)
def update_menu(self):
for item in self.components:
item.update_menu(self.menu)
menu = self.menu.add_folder("System")
self.menu.add_function("Exit", self.exit, menu)
self.menu.add_function("Shutdown RasPi", self.pi_shutdown, menu)
self.menu.add_function("IP Address", self.display_ip, menu)
try:
self.menu.speech = self.speech
except AttributeError:
pass
def run(self, program=None):
if program:
self.display.display("GushPiBot...\nRunning...")
self.program.set(program)
self.program.view()
self.program.run()
else:
self.display.display("GushPiBot...\nListening...")
while self.loop_cycle():
time.sleep(0.1)
def display_ip(self):
p = Popen("hostname -I", shell=True, stdout=PIPE)
output = p.communicate()[0].split("\n")[0]
self.display.display_at(1, 0, output.ljust(16))
def exit(self):
self.display.display("GushPiBot...\nExiting...")
self.active = False
def loop_cycle(self):
for item in self.components:
item.check()
return self.active
def cleanup(self):
for item in self.components:
try:
item.cleanup()
except:
pass
def pi_shutdown(self):
self.display.display("Pi Shutdown")
try:
self.speech.speak("Shutting down Raspberry Pi")
except AttributeError:
pass
call('halt', shell=False)