本文整理匯總了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)