def demo(self, ui): ui.message("===== Demo Mode =====") ui.message("Running a small demo/testing!") ui.message("") ui.message("--- Cyphering ---") text = "Hello Wolrd !" ui.message("Data to cypher: {}\n".format(text)) ui.message("Braille cyphered data: {}" "".format(braille.cypher(text))) ui.message("") ui.message("--- Decyphering ---") htext = "13457 24 14 15 2345 15 234 2345 6 24 234 1345 3457 2345 " \ "24 2345 168 1456" ui.message("Braille text used as input: {}".format(htext)) ui.message("The decyphered data is: {}" "".format(braille.decypher(htext))) ui.message("") ui.message("--- Won’t work ---") text = "Japanese : 日本の" ui.message("+ The input text to cypher must be cp1252 (Windows " "8bit occidental charset) chars only:") ui.message("Data to cypher: {}\n".format(text)) try: ui.message("Braille cyphered data: {}" "".format(braille.cypher(text))) except Exception as e: ui.message(str(e), level=ui.ERROR) ui.message("") ui.message("+ The input text to decypher must be valid Braille " "us-437 codes only:") htext = "13447 24 14 15 2345 15 234 2345 6 24 234 1345 3457 2345 " \ "24 2345 1778 1456" ui.message("Braille text used as input: {}".format(htext)) try: ui.message("The decyphered data is: {}" "".format(braille.decypher(htext))) except Exception as e: ui.message(str(e), level=ui.ERROR) ui.message("") ui.get_choice("", [("", "Go back to $menu", "")], oneline=True)
def demo(self, ui): ui.message("===== Demo Mode =====") ui.message("Running a small demo/testing!") ui.message("") ui.message("--- Cyphering ---") text = "Hello Wolrd !" ui.message("Data to cypher: {}\n".format(text)) ui.message("Braille cyphered data: {}" "".format(braille.cypher(text))) ui.message("") ui.message("--- Decyphering ---") htext = "13457 24 14 15 2345 15 234 2345 6 24 234 1345 3457 2345 " \ "24 2345 168 1456" ui.message("Braille text used as input: {}".format(htext)) ui.message("The decyphered data is: {}" "".format(braille.decypher(htext))) ui.message("") ui.message("--- Won’t work ---") text = "Japanese : 日本の" ui.message("+ The input text to cypher must be cp1252 (Windows " "8bit occidental charset) chars only:") ui.message("Data to cypher: {}\n".format(text)) try: ui.message("Braille cyphered data: {}" "".format(braille.cypher(text))) except Exception as e: ui.message(str(e), ui.ERROR) ui.message("") ui.message("+ The input text to decypher must be valid Braille " "us-437 codes only:") htext = "13447 24 14 15 2345 15 234 2345 6 24 234 1345 3457 2345 " \ "24 2345 1778 1456" ui.message("Braille text used as input: {}".format(htext)) try: ui.message("The decyphered data is: {}" "".format(braille.decypher(htext))) except Exception as e: ui.message(str(e), ui.ERROR) ui.message("") ui.get_choice("", [("", "Go back to *menu", "")], oneline=True)
def cypher(self, ui): """Interactive version of cypher().""" txt = "" ui.message("===== Cypher Mode =====") while 1: done = False while 1: txt = ui.text_input("Text to cypher to Braille") if txt is None: break # Go back to main Cypher menu. try: # Will also raise an exception if data is None. txt = braille.cypher(txt) done = True # Out of those loops, output result. break except Exception as e: if utils.DEBUG: import traceback traceback.print_tb(sys.exc_info()[2]) ui.message(str(e), level=ui.ERROR) options = [("retry", "*try again", ""), ("menu", "or go back to *menu", "")] answ = ui.get_choice( "Could not convert that data into " "Braille, please", options, oneline=True) if answ in {None, "menu"}: return # Go back to main Sema menu. # Else, retry with another data to hide. if done: ui.text_output("Text successfully converted", txt, "Braille version of text") options = [("redo", "*cypher another text", ""), ("quit", "or go back to *menu", "")] answ = ui.get_choice("Do you want to", options, oneline=True) if answ in {None, "quit"}: return
def cypher(self, ui): """Interactive version of cypher().""" txt = "" ui.message("===== Cypher Mode =====") while 1: done = False while 1: txt = ui.text_input("Text to cypher to Braille") if txt is None: break # Go back to main Cypher menu. try: # Will also raise an exception if data is None. txt = braille.cypher(txt) done = True # Out of those loops, output result. break except Exception as e: if utils.DEBUG: import traceback traceback.print_tb(sys.exc_info()[2]) ui.message(str(e), level=ui.ERROR) options = [("retry", "*try again", ""), ("menu", "or go back to *menu", "")] answ = ui.get_choice("Could not convert that data into " "Braille, please", options, oneline=True) if answ in {None, "menu"}: return # Go back to main Sema menu. # Else, retry with another data to hide. if done: ui.text_output("Text successfully converted", txt, "Braille version of text") options = [("redo", "*cypher another text", ""), ("quit", "or go back to *menu", "")] answ = ui.get_choice("Do you want to", options, oneline=True) if answ in {None, "quit"}: return