def input_string(msg=[], pattern="^[a-zA-Z0-9]$", default="", spell=True): voice.menu(msg) s = default while True: e = pygame.event.poll() if e.type == QUIT: sys.exit() elif e.type == KEYDOWN: pygame.event.clear() if e.key in [K_LSHIFT, K_RSHIFT]: continue if e.key in (K_RETURN, K_KP_ENTER): voice.item([s]) return s elif e.key == K_ESCAPE: return None elif e.key == K_BACKSPACE: s = s[:-1] voice.item(string_to_msg(s, spell)) elif re.match(pattern, e.unicode) != None: try: c = e.unicode.encode("ascii") # telnetlib doesn't like unicode s += c voice.item(string_to_msg(c) + [9999] + string_to_msg(s, spell)) except: warning("error reading character from keyboard") voice.item([1003, 9999] + string_to_msg(s, spell)) else: voice.item([1003, 9999] + string_to_msg(s, spell)) elif e.type == USEREVENT: voice.update() voice.update() # XXX useful for SAPI
def run(self): if self.title: voice.menu(self.title) else: voice.menu([4007]) self._get_choice_from_static_menu() self._execute_choice()
def run(self): if self.title: voice.menu(self.title) else: voice.menu(mp.MAKE_A_SELECTION2) self._get_choice_from_static_menu() self._execute_choice()
def post_run(self): # alert the server of the exit from the game interface if self.interface.forced_quit: self.main_server.write_line("abort_game") else: self.main_server.write_line("quit_game") self.say_score() # say score only after quit_game to avoid blocking the main server voice.menu([4010, 4030]) # "menu" "please make a selection" (long enough to allow history navigation)
def update_menu(self, menu): old_title = self.title old_choices = self.choices try: old_choice = self.choices[self.choice_index] except (IndexError, TypeError): old_choice = None self.title, self.choices = menu.title, menu.choices if self.title and self.title != old_title: voice.menu(self.title) if self.choices != old_choices: self.choice_index = None if old_choice in self.choices: self.choice_index = self.choices.index(old_choice)
def post_run(self): self.main_server.write_line("quit_game") # say score only after quit_game to avoid blocking the main server self.say_score() voice.menu(mp.MENU + mp.MAKE_A_SELECTION)