def decypher(self, ui): """Interactive version of decypher().""" txt = "" ui.message("===== Decypher Mode =====") while 1: txt = ui.text_input("Please choose some Braille text") options = [((True, False), "*straight", ""), ((False, True), "*reversed", ""), ((True, True), "or *both orders", "")] o_stght, o_rev = ui.get_choice("Do you want to get", options, oneline=True) try: txt = postalbarcode.decypher(txt, o_stght=o_stght, o_rev=o_rev) if len(txt) > 1: txt = "\n " + "\n ".join(txt) else: txt, = txt ui.text_output("Text successfully decyphered", txt, "The decyphered text is") except Exception as e: ui.message(str(e), ui.ERROR) options = [("redo", "*decypher another data", ""), ("quit", "or go back to *menu", "")] answ = ui.get_choice("Do you want to", options, oneline=True) if answ == "quit": return
def decypher(self, ui): """Interactive version of decypher().""" txt = "" ui.message("===== Decypher Mode =====") while 1: txt = ui.text_input("Please choose some Braille text") options = [((True, False), "*straight", ""), ((False, True), "*reversed", ""), ((True, True), "or *both orders", "")] o_stght, o_rev = ui.get_choice("Do you want to get", options, oneline=True) try: txt = postalbarcode.decypher(txt, o_stght=o_stght, o_rev=o_rev) if len(txt) > 1: txt = "\n " + "\n ".join(txt) else: txt, = txt ui.text_output("Text successfully decyphered", txt, "The decyphered text is") except Exception as e: if utils.DEBUG: import traceback traceback.print_tb(sys.exc_info()[2]) ui.message(str(e), level=ui.ERROR) options = [("redo", "*decypher another data", ""), ("quit", "or go back to *menu", "")] answ = ui.get_choice("Do you want to", options, oneline=True) if answ == "quit": return
def demo(self, ui): ui.message("===== Demo Mode =====") ui.message("Running a small demo/testing!") ui.message("") ui.message("--- Cyphering ---") text = "3141592654" ui.message("Data to cypher: {}\n".format(text)) ui.message("Postal bar code cyphered data:\n" " org straight: {}\n org reversed: {}\n" " cls straight: {}\n cls reversed: {}" "".format(*postalbarcode.cypher(text, m_org=True, m_cls=True, o_stght=True, o_rev=True))) ui.message("") ui.message("--- Decyphering ---") htext = "⋅||⋅|| ||⋅⋅|| ⋅|⋅||| ||⋅|⋅| ⋅||⋅|| ||⋅|⋅| ⋅|⋅||| ||⋅|⋅| " \ "⋅||⋅|| ||⋅|⋅|" ui.message("Postal bar code text used as input: {}".format(htext)) ui.message("The decyphered data is:\n" " straight: {}\n reversed: {}" "".format(*postalbarcode.decypher(htext, o_stght=True, o_rev=True))) ui.message("") htext = " || || || || | ||| || | | || || || | | | ||| || | | " \ " || || || | |" ui.message("Postal bar code text used as input: {}".format(htext)) ui.message("The decyphered data is:\n" " straight: {}\n reversed: {}" "".format(*postalbarcode.decypher(htext, o_stght=True, o_rev=True))) ui.message("") ui.message("--- Won’t work ---") text = "3.141592654" ui.message("+ The input text to cypher must be digits only:") ui.message("Data to cypher: {}\n".format(text)) try: ui.message("Postal bar code cyphered data: {}" "".format(postalbarcode.cypher(text))) except Exception as e: ui.message(str(e), ui.ERROR) ui.message("") ui.message("+ The input text to decypher must be valid postal " "bar codes only:") htext = "⋅||⋅|| || || ⋅|⋅|⋅| ||⋅|⋅| ⋅||⋅|| || | | ⋅|⋅||| ||⋅|⋅| " \ "⋅||⋅|| ||⋅|⋅|" ui.message("Braille text used as input: {}".format(htext)) try: ui.message("The decyphered data is: {}" "".format(postalbarcode.decypher(htext))) except Exception as e: ui.message(str(e), 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 = "3141592654" ui.message("Data to cypher: {}\n".format(text)) ui.message( "Postal bar code cyphered data:\n" " org straight: {}\n org reversed: {}\n" " cls straight: {}\n cls reversed: {}" "".format(*postalbarcode.cypher( text, m_org=True, m_cls=True, o_stght=True, o_rev=True))) ui.message("") ui.message("--- Decyphering ---") htext = "⋅||⋅|| ||⋅⋅|| ⋅|⋅||| ||⋅|⋅| ⋅||⋅|| ||⋅|⋅| ⋅|⋅||| ||⋅|⋅| " \ "⋅||⋅|| ||⋅|⋅|" ui.message("Postal bar code text used as input: {}".format(htext)) ui.message( "The decyphered data is:\n" " straight: {}\n reversed: {}" "".format( *postalbarcode.decypher(htext, o_stght=True, o_rev=True))) ui.message("") htext = " || || || || | ||| || | | || || || | | | ||| || | | " \ " || || || | |" ui.message("Postal bar code text used as input: {}".format(htext)) ui.message( "The decyphered data is:\n" " straight: {}\n reversed: {}" "".format( *postalbarcode.decypher(htext, o_stght=True, o_rev=True))) ui.message("") ui.message("--- Won’t work ---") text = "3.141592654" ui.message("+ The input text to cypher must be digits only:") ui.message("Data to cypher: {}\n".format(text)) try: ui.message("Postal bar code cyphered data: {}" "".format(postalbarcode.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 postal " "bar codes only:") htext = "⋅||⋅|| || || ⋅|⋅|⋅| ||⋅|⋅| ⋅||⋅|| || | | ⋅|⋅||| ||⋅|⋅| " \ "⋅||⋅|| ||⋅|⋅|" ui.message("Braille text used as input: {}".format(htext)) try: ui.message("The decyphered data is: {}" "".format(postalbarcode.decypher(htext))) except Exception as e: ui.message(str(e), level=ui.ERROR) ui.message("") ui.get_choice("", [("", "Go back to $menu", "")], oneline=True)