Esempio n. 1
0
    def _buildRule(self):                
        mapping = {}
        for command in self.cmdWords:
            mapping[command] = None
        self.actionRule = makeHashedRule(self._actionRuleName, mapping, ruleType=RuleType.INDEPENDENT)
        pushEvent(RuleRegisterEvent(self.actionRule))

        mapping = {}
        extras = []
        for i in range(self.MAX_SUBWORDS):
            for j in range(i+1):
                phrase = []
                for k in range(j, self.MAX_SUBWORDS):
                    optional = (k != j)
                    refString = "<" + self._wordListRefName(i, k) + ">"
                    if optional:
                        refString = "[%s]" % refString
                    phrase.append(refString)
                    extras.append(ListRef(self._wordListName(i, k), self._wordListRefName(i, k), []))
                phrase = " ".join(phrase)
                mapping[phrase] = None                
        
        self.wordRule = makeHashedRule(self._wordRuleName, mapping, extras, ruleType=RuleType.INDEPENDENT)
        pushEvent(RuleRegisterEvent(self.wordRule))

        wordRulePart = "<%s>" % self._wordRuleRefName
        if self.allowNoChoice:
           wordRulePart = "[%s]" % wordRulePart 

        phrase = ("<%s>" % self._actionRuleRefName) + " " + wordRulePart
        mapping = {
            phrase : self._onSelection
        }
        extras = [
            RuleRef(self.actionRule, self._actionRuleRefName),
            RuleRef(self.wordRule, self._wordRuleRefName),
        ]

        self.rule = makeContextualRule(self._ruleName, mapping, extras, ruleType=self.ruleType)

        log.info("new crazy rule: [%s]" % self.rule.rule.rule.mapping)
        log.info("new crazy rule extras: [%s]" % self.rule.rule.rule.extras)
Esempio n. 2
0
    def _buildRule(self, requirements, keywords):
        listRule = makeKeywordListRule(self.name + "-list", keywords)
        pushEvent(RuleRegisterEvent(listRule))

        verbRule = "_".join([self.name, "mode_verb_rule"])
        kwRule = "_".join([self.name, "keyword"])

        mapping = {
            ("<%s> <%s>" % (verbRule, kwRule)) : KeywordCmd(keywords, verbRule, kwRule),
        }

        extras = [
            RuleRef(VerbRule, verbRule),
            RuleRef(listRule, kwRule),
        ]

        KeywordRule = makeContextualRule(self.name, mapping, extras)
        KeywordRule.context.addRequirement(IsEmacs)
        for r in self.requirements:
            KeywordRule.context.addRequirement(r)
        return KeywordRule
Esempio n. 3
0
        letter = BaseRules.lookup(extras)
        mark = AccentRule.rule.mapping[extras['accentrule']["words"]
                                       [0]] if 'accentrule' in extras else None
        mark = ("#x%x" % mark) if mark else "nil"
        return '(%s "%s" %s "%s")' % (self.data, letter, mark, color)


_mapping = {
    "<colorrule> <alpharule> [<accentrule>]":
    PickSymbol("md-hl-insert-symbol", 0),
    "jump <colorrule> <alpharule> [<accentrule>]":
    PickSymbol("md-hl-jump-symbol"),
}

_extras = emacsExtras + [
    RuleRef(AccentRule, "accentrule"),
    RuleRef(ColorRule, "colorrule"),
]

SymbolPickerRule = makeContextualRule("SymbolPicker", _mapping, _extras,
                                      emacsDefaults)
SymbolPickerRule.context.addRequirement(IsEmacs)
SymbolPickerRule.context.addRequirement(
    VarRequirement("md-symbol-picker-mode", "t"))

_mapping = {
    "toggle picker": Cmd("(md-toggle-symbol-picker-mode)"),
}
SymbolPickerToggleRule = makeContextualRule("SymbolPickerToggle", _mapping,
                                            _extras, emacsDefaults)
SymbolPickerToggleRule.context.addRequirement(IsEmacs)
Esempio n. 4
0
import rules.BaseRules as BaseRules

emacsExtras = [
    # Note that repetition counts have a minimum of 3
    # because if you want twice you can just say the
    # command followed by "rep".

    # Small repetition count
    Integer("i", 3, 8),

    # Big repetition count
    Integer("n", 3, 72),

    # generic integer argument, not used for repetitions
    Integer("j", 0, 20),
    Dictation("text"),
    Dictation("match"),
    Dictation("replace"),
    Integer("big", 0, 2**14),
    RuleRef(BaseRules.CharRule, "charrule"),
    RuleRef(BaseRules.AlphaRule, "alpharule"),
    Dictation("match"),
    Dictation("replace"),
]

emacsDefaults = {
    "n": 1,
    "i": 1,
    "text": "",
}
Esempio n. 5
0
    "pow"        : " ",
}

SymRule = makeHashedRule("SymRule", _mapping, ruleType=RuleType.INDEPENDENT)
pushEvent(RuleRegisterEvent(SymRule))

# TODO: another rule for all the keys that *don't*
# have a character, so you can request shift+pgdown
# and ctrl+enter

_mapping = {
    "(<alpharule> | num <digitrule> | <symrule>)" : ""
}

_charExtras = [
    RuleRef(AlphaRule, "alpharule"),
    RuleRef(DigitRule, "digitrule"),
    RuleRef(SymRule, "symrule"),
    ]

CharRule = makeHashedRule("CharRule", _mapping, _charExtras, ruleType=RuleType.INDEPENDENT)
pushEvent(RuleRegisterEvent(CharRule))

def lookup(charrule, keyNames=False):
    for e in _charExtras:
        if e.name in charrule:
            mapping = e.rule_ref.rule.mapping
            if e.name == "symrule" and not keyNames:
                mapping = _literalMapping
            return mapping[charrule[e.name]["words"][0]]
Esempio n. 6
0
    "[control] [alt] [sky] <charrule> [<i>]" : PressKey(),
    'scoot [<i>]'                            : Key("tab:%(i)d"),
    'cap scoot [<i>]'                        : Key("s-tab:%(i)d"),
    'greek alpha' : Text("alpha"),
    'greek alphas' : Text("alphas"),
    "click left" : click(1),
    "click middle" : click(2),
    "click right" : click(3)
}

_extras = [
    Integer("i", 3, 8),
    Integer("n", 3, 72),
    Integer("digit", 0, 10),
    Dictation("text"),
    RuleRef(AlphaRule, "alpharule"),
    RuleRef(CharRule, "charrule"),
]

_defaults = {
    "n": 1,
    "i": 1,
}

AlwaysRule = makeContextualRule("Always", _mapping, _extras, _defaults)
AlwaysRule.activate()

_extras = [
    Dictation("text")
]