def load(): """Register grammar.""" global GRAMMAR GRAMMAR = Grammar('command_line_interface') GRAMMAR.add_rule(PasswordRule()) GRAMMAR.load() print 'password grammar: Loaded.'
def load(): """Register grammar.""" global GRAMMAR GRAMMAR = Grammar('i3', context=linux()) GRAMMAR.add_rule(OpenProcessRule()) GRAMMAR.add_rule(WorkspaceRules()) GRAMMAR.load() print 'i3 grammar: Loaded.'
def load(): """Register grammar.""" global TRUE_VIM_NORMAL_GRAMMAR TRUE_VIM_NORMAL_GRAMMAR = Grammar('true_vim_normal_mode', context=vim_normal_mode()) TRUE_VIM_NORMAL_GRAMMAR.add_rule(TrueVimNormalRepetitionRule()) TRUE_VIM_NORMAL_GRAMMAR.load() print 'vim grammars: Loaded.'
def _add_grammar(self, rule, ccr=False, context=None): name = str(rule) grammar = Grammar(name, context=context) self._grammars.append(grammar) if ccr: repeater = self._create_repeat_rule(rule) grammar.add_rule(repeater) else: grammar.add_rule(rule)
def load(): """Register grammar.""" global GRAMMAR GRAMMAR = Grammar('global') GRAMMAR.add_rule(BasicKeyboardRule()) GRAMMAR.add_rule(SpellingRule()) GRAMMAR.add_rule(PressRule()) GRAMMAR.add_rule(DictationRule(exported=True)) GRAMMAR.load() print 'global grammar: Loaded.'
def load(): """Register grammar.""" global GRAMMAR GRAMMAR = Grammar('command_line_interface', context=terminal_not_vim()) GRAMMAR.add_rule(SshRule()) GRAMMAR.add_rule(SimpleCommand()) GRAMMAR.add_rule(SudoRule()) GRAMMAR.load() print 'cli grammar: Loaded.'
class StartMouseGridRule(MappingRule): mapping = { # Commands for starting the mouse grid. The grid might only cover part of a large screen, # or you might have multiple screens, so we have commands to show grids in multiple locations. "sink": Function(showMouseGridY0), # Slide down or up "glide": Function(showMouseGridX0), # Slide left or right "sled": Function(showMouseGridX0), # Slide to the left screen "sliddle": Function(showMouseGridX1), # Slide to the inner screen "slight": Function(showMouseGridX2), # Slide to the right screen "grid": Function(showMouseGridG0), # 2D grid "beam": Function(clickMouseGridG0), # 2D grid + left mouse click "ladder": Function(showMouseGridX0Y0 ), # Show a sequence of 2 grids moving in a single direction } grammar.add_rule(StartMouseGridRule()) grammar.add_rule(CenterMouseRule()) grammar.add_rule(NudgeMouseRule()) grammar.load() def unload(): global grammar if grammar: grammar.unload() grammar = None
"(refactor|re-factor) copy": Key("f5"), "(refactor|re-factor) safe delete": Key("a-del"), "(refactor|re-factor) extract variable": Key("ca-v"), "(refactor|re-factor) extract constant": Key("ca-c"), "(refactor|re-factor) extract field": Key("ca-f"), "(refactor|re-factor) extract parameter": Key("ca-p"), "(refactor|re-factor) extract method": Key("ca-m"), "(refactor|re-factor) (in line|inline)": Key("ca-n"), # Custom key mappings. "(run SSH session|run SSH console|run remote terminal|run remote console)": Key("a-f11/25, enter"), #debug }) extras = [ Dictation("text"), IntegerRef("n", 1, 50000) ] terminator_grammar.add_rule(jideaRule()) terminator_grammar.load() # Unload function which will be called by natlink at unload time. def unload(): global terminator_grammar if terminator_grammar: terminator_grammar.unload() terminator_grammar = None
"n2": 1, } class NormalModeRule(MappingRule): mapping = normal_mode_mapping extras = extras defaults = defaults def _process_recognition(self, value, extras): # press escape before all normal mode commands _esc() MappingRule._process_recognition(self, value, extras) class GeneralRule(MappingRule): mapping = general_mapping extras = extras defaults = defaults grammar = Grammar('vim') grammar.add_rule(GeneralRule()) grammar.add_rule(NormalModeRule()) grammar.load() def unload(): global grammar if grammar: grammar.unload() grammar = None
from aenea import Grammar, MappingRule, Integer, Key, Text grammar = Grammar('tmux') LEADER = 'c-b' class Command(MappingRule): mapping = {'switch win [<n>]': Key(LEADER + ', ' + '%(n)s')} extras = [ Integer("n", 0, 10), ] defaults = { "n": 1, } grammar.add_rule(Command()) grammar.load() def unload(): global grammar if grammar: grammar.unload() grammar = None
extras = [ sequence, # Sequence of actions defined above. my_format_rule ] def _process_recognition(self, node, extras): # @UnusedVariable sequence = extras["sequence"] # A sequence of actions. for action in sequence: action.execute() if "my_format_rule" in extras: extras["my_format_rule"].execute() my_chaining_rule = MyChainingRule(name="my_chaining_rule") grammar.add_rule(my_chaining_rule) grammar.add_rule(my_literal_rule) class MyMimicRule(MappingRule): mapping = { "snore": Mimic("go to sleep") + aenea.proxy_actions.ProxyNotification("Microphone off"), } grammar.add_rule(MyMimicRule()) grammar.load() # Load the grammar.
class RepeatRule(CompoundRule): # Here we define this rule's spoken-form and special elements. spec = "<sequence> [[[and] repeat [that]] <n> times]" extras = [ sequence, # Sequence of actions defined above. IntegerRef("n", 1, 100), # Times to repeat the sequence. ] defaults = { "n": 1, # Default repeat count. } def _process_recognition(self, node, extras): # @UnusedVariable sequence = extras["sequence"] # A sequence of actions. count = extras["n"] # An integer repeat count. for i in range(count): # @UnusedVariable for action in sequence: action.execute() release.execute() grammar = Grammar("Generic edit") grammar.add_rule(RepeatRule()) # Add the top-level rule. grammar.load() # Load the grammar. def unload(): """Unload function which will be called at unload time.""" global grammar if grammar: grammar.unload() grammar = None
# my launcher 'my launcher': Key('a-dot'), # system macros 'record actions': Key('c-9'), 'play actions': Key('c-0'), # call my Google voice recognition script 'say russian': Key('a-comma') + Function(mute_microphone), # 'say english': Key('a-dot'), } extras = [IntegerRef('windowNumber', 1, 10), Dictation('text')] defaults = { 'windowNumber': 1, 'text': '' } grammar = Grammar('window_manager') grammar.add_rule(MappingWindowManager()) grammar.load() def unload(): global grammar if grammar: grammar.unload() grammar = None
"enable": True, "disable": False }), # Choice("volume_mode", # {"mute": "mute", "up":"up", "down":"down" # }), generate_ccr_choices.__func__(NEXUS), # generate_sm_ccr_choices.__func__(NEXUS), ] defaults = { # "n": 1, "nnv": 1, # "text": "", "volume_mode": "setsysvolume", "enable": -1 } grammar = Grammar('general') grammar.add_rule(MainRule()) # grammar.add_rule(Again(NEXUS)) # grammar.add_rule(VanillaAlias(name="vanilla alias")) grammar.load() NEXUS.merger.update_config() NEXUS.merger.merge(Inf.BOOT) # if settings.MAGNETO["miscellaneous"]["status_window_enabled"]: # print("\nWARNING: Status Window is an experimental feature, and there is a known freezing glitch with it.\n") # utilities.launch_status() print("*- Starting " + "magneto" + " -*")
'reopen [<n>] ( frame | frames )': Key('cs-t:%(n)d'), '[ go to ] frame [<n>]': Key('c-%(n)d'), 'frame left [<n>]': Key('cs-tab:%(n)d'), 'frame right [<n>]': Key('c-tab:%(n)d'), 'search [<text>]': Key('c-k') + Text('%(text)s'), 'find [<text>]': Key('c-f') + Text('%(text)s'), 'history': Key('c-h'), 'reload': Key('c-r'), 'next [<n>]': Key('c-g:%(n)d'), 'previous [<n>]': Key('cs-g:%(n)d'), 'back [<n>]': Key('a-left:%(n)d'), 'forward [<n>]': Key('a-right:%(n)d'), }) extras = [IntegerRef('n', 1, 10), Dictation('text')] defaults = { 'n': 1, 'text': '' } chromium_grammar.add_rule(ChromiumRule()) chromium_grammar.load() def unload(): global chromium_grammar if chromium_grammar: chromium_grammar.unload() chromium_grammar = None
"X D O tool": Text("xdotool "), "X M L lint": Text("xmllint "), "X M L lint <text>": Text("xmllint %(text)s"), "X M L lint format": Text("xmllint -format "), "X M L lint format <text>": Text("xmllint -format %(text)s"), "X M L lint schema": Text("xmllint -schema "), "X M L lint schema <text>": Text("xmllint -schema %(text)s"), "X prop": Text("xprop "), "X win info": Text("xwininfo "), }, extras=[IntegerRef('n', 1, 10), Dictation('text')] ) context = aenea.AeneaContext( ProxyAppContext(match='regex', title='fish'), (AppContext(executable='python')) ) terminator_grammar = Grammar("Terminator general", context=context) terminator_grammar.add_rule(rules) terminator_grammar.load() def unload(): global terminator_grammar if terminator_grammar: terminator_grammar.unload() grammar = None
from aenea import Grammar, Mouse, MappingRule, Integer grammar = Grammar('mouse') class MouseClickRule(MappingRule): mapping = { 'vee box': Mouse('<1829, 304>, left'), #temporary 'host': Mouse('<0, 304>, left'), #temporary 'tick': Mouse('left'), 'tick ra': Mouse('right'), } extras = [ Integer("n", 0, 9999), ] grammar.add_rule(MouseClickRule()) def unload(): global grammar if grammar: grammar.unload() grammar = None grammar.load()
if isinstance(proxy_disable_setting, dict): d = {} for k, v in proxy_disable_setting.iteritems(): d[str(k)] = str(v) proxy_disable_context = ProxyAppContext(**d) else: proxy_disable_context = ProxyAppContext( title=str(proxy_disable_setting), match='substring' ) context = AeneaContext(proxy_disable_context, local_disable_context) grammar = Grammar('multiedit', context=~context) grammar.add_rule(RepeatRule(extras=extras + [format_rule, Alternative(finishes, name='finish')], name='a')) grammar.add_rule(LiteralRule()) grammar.load() # Unload function which will be called at unload time. def unload(): global grammar aenea.vocabulary.uninhibit_global_dynamic_vocabulary( 'multiedit', MULTIEDIT_TAGS ) for tag in MULTIEDIT_TAGS: aenea.vocabulary.unregister_dynamic_vocabulary(tag) if grammar:
sublime_context = AeneaContext( ProxyAppContext(cls_name='Sublime', cls='Sublime'), AppContext(executable='Sublime')) sublime_grammar = Grammar('sublime', context=sublime_context) dictionary = ModuleDictionary("apps\\sublime") def go_to_line(n1000): Key("c-g").execute() Text(str(n1000)).execute() Key("enter").execute() class Sublime(MergeRule): mapping = { "line <n1000>": Function(go_to_line), } extras = [ IntegerRef("n1000", 1, 1000), ] defaults = {} sublime_grammar.add_rule(Sublime())
mapping = { 'open terminal': Key('control:down, alt:down, t, control:up, alt:up'), 'cancel': Key('c-c'), # fzf 'get command [<text>]': Key('c-r') + Pause('200') + Text('%(text)s'), 'get file': Key('c-t'), 'get folder': Key('a-c'), # copy/paste terminal 'copy raw': Key('cs-c'), 'plop raw': Key('cs-v'), } extras = [IntegerRef('n', 1, 10), Dictation('text')] defaults = {'n': 1, 'text': ''} chromium_context = aenea.AeneaContext( ProxyAppContext(match='regex', title='(?i).*terminal.*'), AppContext(title='chrome')) grammar = Grammar('terminal') grammar.add_rule(MappingTerminal()) grammar.load() def unload(): global grammar if grammar: grammar.unload() grammar = None
def switch_mode(language): clear_mode() language.enable() basics_mapping = { 'lang <language>': Function(switch_mode), 'clear lang': Function(clear_mode), } class Basics(MappingRule): mapping = basics_mapping extras = [Choice("language", language_map)] generic_grammar.add_rule(Basics()) generic_grammar.load() # Start with no modes active for _, grammar in language_map.iteritems(): grammar.load() grammar.disable() def unload(): generic_grammar.unload() for _, grammar in language_map.iteritems(): grammar.unload()
def get_ruby_grammar(): grammar = Grammar('ruby') grammar.add_rule(RubyNewLineRule()) grammar.add_rule(RubyRuleAppend()) return grammar
from dragonfly.actions.typeables import typeables if 'semicolon' not in typeables: typeables["semicolon"] = keyboard.get_typeable(char=';') grammar = Grammar('hello world aenea') print 'monkeys: Loaded.' class TestRule(MappingRule): mapping = { 'test hello world remote grammar': Text('woot yeah'), } grammar.add_rule(TestRule()) grammar.load() release = Key("shift:up, ctrl:up, alt:up") def cancel_and_sleep(text=None, text2=None): """Used to cancel an ongoing dictation and puts microphone to sleep. This method notifies the user that the dictation was in fact canceled, a message in the Natlink feedback window. Then the the microphone is put to sleep. Example: "'random mumbling go to sleep'" => Microphone sleep. """ print("* Dictation canceled. Going to sleep. *") setMicState("sleeping")
#aenea.communications.server.showMouseGrid("cancel") print "Sending Escape to cancel the mouse grid" action = Key("escape") action.execute() class MouseCancelRule(MappingRule): mapping = { "cancel": Function(cancelMouseGrid), } contextMini = ProxyAppContext(title="InvisibleWindow - Mini") grammarMini = Grammar('extra symbols mini grammar', context=contextMini) grammarMini.add_rule(ExtraSymbolsMiniGridRule()) grammarMini.add_rule(MouseCancelRule()) grammarMini.add_rule(MouseActionGridRule()) grammarMini.load() contextFull = ProxyAppContext(title="InvisibleWindow - Full") grammarFull = Grammar('extra symbols full grammar', context=contextFull) grammarFull.add_rule(ExtraSymbolsFullGridRule()) grammarFull.add_rule(MouseCancelRule()) grammarFull.add_rule(MouseActionGridRule()) grammarFull.load() def unload(): global grammarMini if grammarMini:
mapping = { "pseudo-": Text("sudo "), "change": Text("cd "), "list": Key("l,s,enter"), "sublime": Text("subl "), "home": Text("~/"), "pie": Text("py"), "copy": Key("cs-c"), "copy <t>": Function(copy), "paste": Key("cs-v"), "paste <t>": Function(paste), "make directory": Text("mkdir "), ".Thought": Text(".."), "parent": Text("../"), "remote <ssh_server>": Text('ssh %(ssh_server)s'), "dropbox": Text("cd ~/Dropbox/"), "reset": Key("c-c,c-c,up,enter") } extras = [ Choice('ssh_server', {}), Dictation("t"), ] defaults = { "t": 'default', } bash_grammar.add_rule(Bash())
# Aenea is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public # License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with Aenea. If not, see <http://www.gnu.org/licenses/>. # # Copyright (2014) Alex Roper # Alex Roper <*****@*****.**> from aenea import Grammar, MappingRule, Text grammar = Grammar('hello world aenea') print 'Aenea hello world grammar: Loaded.' class TestRule(MappingRule): mapping = { 'test hello world remote grammar': Text('Aenea remote setup operational'), } grammar.add_rule(TestRule()) grammar.load() def unload(): global grammar if grammar: grammar.unload() grammar = None
def get_javascript_grammar(): grammar = Grammar('Javascript') grammar.add_rule(JavascriptNewLineRule()) grammar.add_rule(JavascriptRuleAppend()) return grammar
# zoom 'zoom in [<n>]': Key('c-plus:%(n)d'), 'zoom out [<n>]': Key('c-minus:%(n)d'), # scroll slow 'slide': Key('c-0'), }) extras = [IntegerRef('n', 1, 100), Dictation('text')] defaults = { 'n': 1, 'text': '' } chromium_context = aenea.AeneaContext( ProxyAppContext(match='regex', title='(?i).*chrome.*'), AppContext(title='chrome') ) chromium_grammar = Grammar('chromium', context=chromium_context) chromium_grammar.add_rule(ChromiumRule()) chromium_grammar.load() def unload(): global chromium_grammar if chromium_grammar: chromium_grammar.unload() chromium_grammar = None
proxy_disable_setting = conf.get('proxy_disable_context', None) proxy_disable_context = NeverContext() if proxy_disable_setting is not None: if isinstance(proxy_disable_setting, dict): d = {} for k, v in proxy_disable_setting.iteritems(): d[str(k)] = str(v) proxy_disable_context = ProxyAppContext(**d) else: proxy_disable_context = ProxyAppContext( title=str(proxy_disable_setting), match='substring' ) grammar = Grammar('aenea_emacs', context=emacs_context) grammar.add_rule(RepeatRule(extras=extras + [format_rule, Alternative(finishes, name='finish')], name='a')) grammar.add_rule(LiteralRule()) grammar.load() # Unload function which will be called at unload time. def unload(): global grammar aenea.vocabulary.uninhibit_global_dynamic_vocabulary( 'aenea_emacs', MULTIEDIT_TAGS ) for tag in MULTIEDIT_TAGS: aenea.vocabulary.unregister_dynamic_vocabulary(tag) if grammar:
"n": 1, "text": "", } class FormatRule(EscapeInsertRule): mapping = {# Format dictated words "snake [<text>]": Function(snake_case_text), "since [<text>]": Function(sentence), "upper [<text>]": Function(uppercase_text), "dashy [<text>]": Function(dash), "camel [<text>]": Function(camel_case_text), "dotty [<text>]": Function(dot), "low [<text>]": Function(lowercase_text) } defaults = { "n": 1, "text": "", } extras = [Dictation("text")] grammar = Grammar("Generic edit") grammar.add_rule(KeystrokeRule()) # Add the top-level rule. grammar.add_rule(FormatRule()) # Add the top-level rule. grammar.load() # Load the grammar. def unload(): global grammar if grammar: grammar.unload() grammar = None