Beispiel #1
0
    def refresh(self, *args):
        '''args: spec, list of lists of strings'''

        # get mapping
        recorded_macros = utilities.load_toml_file(
            settings.SETTINGS["paths"]["RECORDED_MACROS_PATH"])
        if len(args) > 0:
            recorded_macros[args[0]] = args[1]
            utilities.save_toml_file(
                recorded_macros,
                settings.SETTINGS["paths"]["RECORDED_MACROS_PATH"])
        mapping = {}
        for spec in recorded_macros:
            # Create a copy of the string without Unicode characters.
            ascii_str = str(spec)
            sequences = recorded_macros[spec]
            delay = settings.SETTINGS["miscellaneous"][
                "history_playback_delay_secs"]
            # It appears that the associative string (ascii_str) must be ascii, but the sequences within Playback must be Unicode.
            mapping[ascii_str] = R(
                Playback([(sequence, delay) for sequence in sequences]),
                rdescript="Recorded Macro: " + ascii_str) * Repeat(extra="n")
        mapping["record from history"] = R(Function(self.record_from_history),
                                           rdescript="Record From History")
        mapping["delete recorded macros"] = R(
            Function(self.delete_recorded_macros),
            rdescript="Delete Recorded Macros")
        # reload with new mapping
        self.reset(mapping)
Beispiel #2
0
    def refresh(self, *args):
        '''args: spec, list of lists of strings'''

        # get mapping
        recorded_macros = utilities.load_toml_file(
            settings.SETTINGS["paths"]["RECORDED_MACROS_PATH"])
        if len(args) > 0:
            recorded_macros[args[0]] = args[1]
            utilities.save_toml_file(
                recorded_macros,
                settings.SETTINGS["paths"]["RECORDED_MACROS_PATH"])
        mapping = {}
        for spec in recorded_macros:
            sequences = recorded_macros[spec]
            delay = settings.SETTINGS["miscellaneous"][
                "history_playback_delay_secs"]
            play = Playback([(sequence, delay) for sequence in sequences])
            command = play * Repeat(
                extra="n") if spec.endswith("[times <n>]") else play
            mapping[spec] = R(command, rdescript="Recorded Macro: " + spec)
        mapping["record from history"] = R(Function(self.record_from_history),
                                           rdescript="Record From History")
        mapping["delete recorded macros"] = R(
            Function(self.delete_recorded_macros),
            rdescript="Delete Recorded Macros")
        # reload with new mapping
        self.reset(mapping)
Beispiel #3
0
 def _deserialize(self):
     mapping = {}
     recorded_macros = self._config.get_copy()
     for spec in recorded_macros:
         sequences = recorded_macros[spec]
         delay = settings.settings(["miscellaneous", "history_playback_delay_secs"])
         # The associative string (ascii_str) must be ascii, but the sequences within Playback must be Unicode.
         mapping[spec] = R(
             Playback([(sequence, delay) for sequence in sequences]),
             rdescript="Recorded Macro: " + spec) * Repeat(extra="n")
     mapping["record from history"] = R(
         Function(lambda: self._record_from_history()), rdescript="Record From History")
     mapping["delete recorded macros"] = R(
         Function(lambda: self._delete_recorded_macros()), rdescript="Delete Recorded Macros")
     self._smr_mapping = mapping
Beispiel #4
0
 def refresh(self, *args):
     '''args: spec, list of lists of strings'''
     
     # get mapping
     recorded_macros = utilities.load_json_file(settings.SETTINGS["paths"]["RECORDED_MACROS_PATH"])
     if len(args)>0:
         recorded_macros[args[0]] = args[1]
         utilities.save_json_file(recorded_macros, settings.SETTINGS["paths"]["RECORDED_MACROS_PATH"])
     mapping = {}
     for spec in recorded_macros:
         sequences = recorded_macros[spec]
         mapping[spec] = R(Playback([(sequence, 0.0) for sequence in sequences])*Repeat(extra="n"), rdescript="Recorded Macro: "+spec)
     mapping["record from history"] = R(Function(self.record_from_history), rdescript="Record From History")
     mapping["delete recorded macros"] = R(Function(self.delete_recorded_macros), rdescript="Delete Recorded Macros")
     # reload with new mapping
     self.reset(mapping)
class CustomPunctuation(MergeRule):
    pronunciation = "custom punctuation"
    mapping = {

        # my custom overrides
        "double quotes":
        R(Key("dquote"), rdescript="Quotation Marks"),
        "Quach it":
        R(Key("apostrophe"), rdescript="Thin Quotation Marks"),
        "equals | equal to":
        R(Text("="), rdescript="Equals"),
        "equeft":
        R(Text(" = "), rdescript="Equals"),
        "Schrock it | shrocket":
        R(Text(" => "), rdescript="Equals"),
        "not equals | not equal to":
        R(Text(" != "), rdescript="Not Equal To"),
        "is equal to":
        R(Text(" == "), rdescript="Not Equal To"),
        "[is] greater than":
        R(Text(" > "), rdescript="> Comparison"),
        "[is] less than":
        R(Text(" < "), rdescript="< Comparison"),
        "[is] greater [than] [or] equal [to]":
        R(Text(" >= "), rdescript=">= Comparison"),
        "[is] less [than] [or] equal [to]":
        R(Text(" <= "), rdescript="<= Comparison"),
        "deplush":
        R(Text(" + "), rdescript="Plus with padding"),
        "plus":
        R(Text("+"), rdescript="Plus"),
        "pluqual | Luke while":
        R(Text(" += "), rdescript="Plus Equals"),
        "deminus":
        R(Text(" - "), rdescript="Minus with padding"),
        "minus":
        R(Text("-"), rdescript="Minus"),
        "minqual | min call":
        R(Text(" -= "), rdescript="Minus Equals"),
        "min twice | mintwice":
        R(Text("--"), rdescript="Minus Twice"),

        # this is same as the default punctuation
        "sinker":
        R(Key("semicolon"), rdescript="Semicolon"),
        "prekris":
        R(Key("lparen"), rdescript="Parentheses"),
        "prekorp":
        R(Key("lparen"), rdescript="Parentheses"),
        "prekos":
        R(Key("rparen"), rdescript="Parentheses"),
        "brax":
        R(Key("lbracket"), rdescript="Square Brackets"),
        "brackorp":
        R(Key("lbracket"), rdescript="Left Square Bracket"),
        "brackos":
        R(Key("rbracket"), rdescript="Right Square Bracket"),
        "curly":
        R(Key("lbrace"), rdescript="Curly Braces"),
        "kirksorp":
        R(Key("lbrace"), rdescript="Left Curly Brace"),
        "kirkos":
        R(Key("rbrace"), rdescript="Right Curly Brace"),
        "angle":
        R(Key("langle"), rdescript="Left Angle Bracket"),
        "wrangle":
        R(Key("rangle"), rdescript="Right Angle Bracket"),
        "(pipe | pipes) (sim | symbol)":
        R(Text("|"), rdescript="Pipe Symbol"),
        "pipes and":
        R(Text("|"), rdescript="Pipe Symbol"),
        'skoosh [<npunc>]':
        R(Key("space"), rdescript="Space") * Repeat(extra="npunc"),
        "clamor":
        R(Text("!"), rdescript="Exclamation Mark"),
        "deckle":
        R(Text(":"), rdescript="Colon"),
        "starling":
        R(Key("asterisk"), rdescript="Asterisk"),
        "questo":
        R(Text("?"), rdescript="Question Mark"),
        "comma":
        R(Text(","), rdescript="Comma"),
        "carrot":
        R(Text("^"), rdescript="Carat"),
        "(period | dot)":
        R(Text("."), rdescript="Dot"),
        "at sign":
        R(Text("@"), rdescript="At Sign"),
        "hash tag | pound sign | pounder":
        R(Text("#"), rdescript="Hash Tag"),
        "apostrophe":
        R(Text("'"), rdescript="Apostrophe"),
        "tinker":
        R(Text("`"), rdescript='back tick'),
        "crunder":
        R(Text("_"), rdescript="Underscore"),
        "shawls":
        R(Text("\\"), rdescript="Back Slash"),
        "slash":
        R(Text("/"), rdescript="Forward Slash"),
        "Dolly":
        R(Text("$"), rdescript="Dollar Sign"),
        "Percy":
        R(Key("percent"), rdescript="Percent Sign"),
        'tarp [<npunc>]':
        R(Key("tab"), rdescript="Tab") * Repeat(extra="npunc"),
        'tarsh [<npunc>]':
        R(Key("s-tab"), rdescript="Tab") * Repeat(extra="npunc"),
        'shaber [<npunc>]':
        R(Key("c-rbracket"), rdescript="Tab") * Repeat(extra="npunc"),
        'shable [<npunc>]':
        R(Key("c-lbracket"), rdescript="Tab") * Repeat(extra="npunc"),
        "swipe":
        R(Text(", "), rdescript="Comma + Space"),
    }

    extras = [
        IntegerRefST("npunc", 0, 10),
    ]
    defaults = {
        "npunc": 1,
    }
Beispiel #6
0
class Punctuation(MergeRule):
    pronunciation = CCRMerger.CORE[3]

    mapping = {
        "semper":
        R(Key("semicolon"), rdescript="Semicolon"),
        "quotes":
        R(Key("dquote,dquote,left"), rdescript="Quotation Marks"),
        "thin quotes":
        R(Key("apostrophe,apostrophe,left"), rdescript="Thin Quotation Marks"),
        "[is] greater than":
        R(Key("rangle"), rdescript="> Comparison"),
        "[is] less than":
        R(Key("langle"), rdescript="< Comparison"),
        "[is] greater [than] [or] equal [to]":
        R(Key("rangle, equals"), rdescript=">= Comparison"),
        "[is] less [than] [or] equal [to]":
        R(Key("langle, equals"), rdescript="<= Comparison"),
        "[is] equal to":
        R(Key("equals,equals"), rdescript="Equality"),
        "equals":
        R(Key("equals"), rdescript="Equals Sign"),
        "prekris":
        R(Key("lparen, rparen, left"), rdescript="Parentheses"),
        "brax":
        R(Key("lbracket, rbracket, left"), rdescript="Square Brackets"),
        "curly":
        R(Key("lbrace, rbrace, left"), rdescript="Curly Braces"),
        "angle":
        R(Key("langle, rangle, left"), rdescript="Angle Brackets"),
        "plus":
        R(Text("+"), rdescript="Plus Sign"),
        "minus":
        R(Text("-"), rdescript="Dash"),
        "pipe (sim | symbol)":
        R(Text("|"), rdescript="Pipe Symbol"),
        'ace [<npunc>]':
        R(Key("space"), rdescript="Space") * Repeat(extra="npunc"),
        "clamor":
        R(Text("!"), rdescript="Exclamation Mark"),
        "deckle":
        R(Text(":"), rdescript="Colon"),
        "starling":
        R(Key("asterisk"), rdescript="Asterisk"),
        "questo":
        R(Text("?"), rdescript="Question Mark"),
        "comma":
        R(Text(","), rdescript="Comma"),
        "carrot":
        R(Text("^"), rdescript="Carat"),
        "(period | dot)":
        R(Text("."), rdescript="Dot"),
        "at sign":
        R(Text("@"), rdescript="At Sign"),
        "hash tag":
        R(Text("#"), rdescript="Hash Tag"),
        "apostrophe":
        R(Text("'"), rdescript="Apostrophe"),
        "underscore":
        R(Text("_"), rdescript="Underscore"),
        "backslash":
        R(Text("\\"), rdescript="Back Slash"),
        "slash":
        R(Text("/"), rdescript="Forward Slash"),
        "Dolly":
        R(Text("$"), rdescript="Dollar Sign"),
        "modulo":
        R(Key("percent"), rdescript="Percent Sign"),
        'tabby [<npunc>]':
        R(Key("tab"), rdescript="Tab") * Repeat(extra="npunc"),
        "boom":
        R(Text(", "), rdescript="Comma + Space"),
        "ampersand":
        R(Key("ampersand"), rdescript="Ampersand"),
        "leap":
        R(Text("("), rdescript="Left Paren"),
        "reap":
        R(Text(")"), rdescript="Right Paren"),
        "lake":
        R(Text("{"), rdescript="Left Curly"),
        "rake":
        R(Text("}"), rdescript="Right Curly"),
        "lobe":
        R(Text("["), rdescript="Left Bracket"),
        "robe":
        R(Text("]"), rdescript="Right Bracket"),
        "backtick":
        R(Text("`"), rdescript="Backtick"),
    }

    extras = [
        IntegerRefST("npunc", 0, 10),
    ]
    defaults = {
        "npunc": 1,
    }
Beispiel #7
0
    def test_repeat(self):
        """ Test handling of Repeat elements """

        r1 = Repeat("n")
        self.assertEqual(r1.factor({"n": 3}), 3)
        r2 = Repeat("n", 3)
        self.assertEqual(r2.factor({"n": 3}), 6)
        r3 = Repeat(3)
        self.assertEqual(r3.factor(), 3)
        r4 = Repeat(3, "n")
        self.assertEqual(r4.factor({"n": 3}), 6)