Beispiel #1
0
    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.

                options = [((True, False), "*original (pipes and dots)", ""),
                           ((False, True), "*classical (pipes and spaces)",
                                           ""),
                           ((True, True), "or *both versions", "")]
                m_org, m_cls = ui.get_choice("Do you want to get", options,
                                             oneline=True)

                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:
                    # Will also raise an exception if data is None.
                    txt = postalbarcode.cypher(txt, m_org=m_org, m_cls=m_cls,
                                               o_stght=o_stght, o_rev=o_rev)
                    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:
                if len(txt) > 1:
                    txt = "\n    " + "\n    ".join(txt)
                else:
                    txt, = txt
                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
Beispiel #2
0
    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)
Beispiel #3
0
    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)