示例#1
0
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.'
示例#2
0
    def __init__(self):

        # self.state = CasterState()

        # self.clipboard = {}
        self.sticky = []

        # self.history = RecognitionHistoryForWSR(20)
        # if not settings.WSR:
        #     self.history = RecognitionHistory(20)
        # self.history.register()
        # self.history = RecognitionHistory(20)
        # self.history.register()
        # self.state.set_stack_history(self.history)
        self.preserved = None

        # self.timer = TimerForWSR(0.025)
        # if not settings.WSR:
        # from dragonfly.timer import _Timer
        # self.timer = _Timer(0.025)
        # from dragonfly.timer import _Timer
        # self.timer = _Timer(0.025)

        # self.comm = Communicator()
        # self.intermediary = StatusIntermediary(self.comm, self.timer)

        # self.dep = DependencyMan()

        self.macros_grammar = Grammar("recorded_macros")

        # self.merger = CCRMerger(real_merger_config)
        self.merger = CCRMerger()
示例#3
0
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.'
示例#4
0
def load():
    """Register grammar."""
    global GRAMMAR
    GRAMMAR = Grammar('command_line_interface')
    GRAMMAR.add_rule(PasswordRule())
    GRAMMAR.load()

    print 'password grammar: Loaded.'
示例#5
0
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.'
示例#6
0
 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)
示例#7
0
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
示例#8
0
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
    IntegerRef,
    Key,
    MappingRule,
    ProxyAppContext,
    Text,
    Pause,
    Function
)


nixContext = aenea.AeneaContext(
    ProxyAppContext(match='regex', title='community edition'),
    (AppContext(title="intell") | AppContext(title="pycharm"))
)

terminator_grammar = Grammar("jidea")


class jideaRule(MappingRule):
    mapping = aenea.configuration.make_grammar_commands('jidea', {

        "all actions": Key("cs-a"),
        # Code execution.
        "run app": Key("s-f10"),
        "re-run app": Key("c-f5"),
        "run test": Key("cs-f10"),
        "stop running": Key("c-f2"),

        # Code navigation.
        "navigate to class <text>": Key("c-n") + Pause("30") + Function(format.pascal_case_text) + Pause("30") + Key(
            "enter"),
示例#10
0
        "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
示例#11
0
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()
示例#12
0
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'
            )


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)
示例#13
0
            "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" + " -*")
示例#14
0
        # 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
示例#15
0
    RuleRef,
    Repetition,
    CompoundRule,
    DictListRef,
    AppContext,
)

from dragonfly.actions.keyboard import keyboard
from dragonfly.actions.typeables import typeables
if 'semicolon' not in typeables:
    typeables["semicolon"] = keyboard.get_typeable(char=';')

MULTIEDIT_TAGS = ['multiedit', 'multiedit.count']
aenea.vocabulary.inhibit_global_dynamic_vocabulary('multiedit', MULTIEDIT_TAGS)

grammar = Grammar("multiedit")


class _KeystrokeRule(MappingRule):
    exported = False
    mapping = {
        # motions
        "up": "up",
        "down": "down",
        "right": "right",
        "left": "left",
        "page up": "pgup",
        "page down": "pgdown",
        "home": "home",
        "end": "end",
        "scape": "escape",
示例#16
0
    "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

示例#17
0
        # 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
示例#18
0
import string
import aenea.config
import aenea.misc
import aenea.vocabulary

from aenea import (Grammar, MappingRule, CompoundRule, RuleRef, Alternative,
                   Choice, Repetition, IntegerRef, AppContext, Dictation)
#from dragonfly_grammars.common import (
#from dragonfly import AppContext
from common import (_, extract_values, Text, Key, sum_actions)

from aenea.proxy_contexts import ProxyAppContext
general_context = aenea.wrappers.AeneaContext(
    ProxyAppContext(match='regex', title='(?i).*LibreOffice.*'),
    AppContext(title='LibreOffice Writer'))
grammar = Grammar('general', context=general_context)


class Symbol(MappingRule):
    """Symbols, brackets, whitespace and interpunction."""

    exported = False

    def __init__(self, *args, **kwargs):
        self.mapping = {
            _('(left|open) angle [bracket]'): Key('langle'),
            _('(left|open) [curly] brace'): Key('lbrace'),
            _('(left|open) [square] bracket'): Key('lbracket'),
            _('(left|open) paren'): Key('lparen'),
            _('(right|close) angle [bracket]'): Key('rangle'),
            _('(right|close) [curly] brace'): Key('rbrace'),
示例#19
0
INVISIBLEWINDOW_SERVER_ADDRESS = 'http://192.168.56.1:8001'

mouseServer = xmlrpclib.ServerProxy(MOUSE_SERVER_ADDRESS)
windowServer = xmlrpclib.ServerProxy(INVISIBLEWINDOW_SERVER_ADDRESS)

try:
    import aenea.communications
    #import aenea.config
except ImportError:
    print 'Unable to import Aenea client-side modules.'
    raise

from mousegridutils import mouseActions
from mousegridutils import mostNumbers

grammar = Grammar('aenea mouse start grammar')


class CenterMouseRule(CompoundRule):
    spec = "center [<mouseAction>]"
    extras = [
        Choice("mouseAction", mouseActions),
    ]
    defaults = {
        # Set the default to -1 if you want "center" to just move the cursor,
        # or set it to 1 if you want "center" to perform a left mouse click by default.
        "mouseAction": 1,
    }

    def _process_recognition(self, node, extras):
        mouseAction = extras["mouseAction"]
示例#20
0
    AppContext,
    Dictation,
    Grammar,
    IntegerRef,
    Key,
    MappingRule,
    ProxyAppContext,
    Text
    )

chromium_context = aenea.AeneaContext(
    ProxyAppContext(cls_name='chromium', cls='chromium'),
    (AppContext(executable='chrome') | AppContext(executable='chromium'))
    )

chromium_grammar = Grammar('chromium', context=chromium_context)


class ChromiumRule(MappingRule):
    mapping = aenea.configuration.make_grammar_commands('chromium', {
        'close [<n>] ( frame | frames )':    Key('c-w:%(n)d'),
        'open frame':                        Key('c-t'),
        'open window':                       Key('c-n'),
        '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'),
示例#21
0
    Function,
    Playback,
)

from aenea import (AeneaContext, AppContext, Grammar, IntegerRef, Key, Literal,
                   ProxyAppContext, MappingRule, NeverContext, Repetition,
                   Repeat, RuleRef, Sequence, Text)

from magneto.mergerule import MergeRule
from magneto.settings import ModuleDictionary

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),
    }
示例#22
0
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.'
示例#23
0
from aenea import Choice, Grammar, MappingRule, Function

# Languages
from ruby import get_ruby_grammar
from javascript import get_javascript_grammar

generic_grammar = Grammar('generic')

language_map = {
    "ruby": get_ruby_grammar(),
    "javascript": get_javascript_grammar()
}


def clear_mode():
    for _, grammar in language_map.iteritems():
        grammar.disable()


def switch_mode(language):
    clear_mode()
    language.enable()


basics_mapping = {
    'lang <language>': Function(switch_mode),
    'clear lang': Function(clear_mode),
}


class Basics(MappingRule):
    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
示例#25
0
    Section,
    Item,
    IntegerRef,
    Alternative,
    RuleRef,
    Repetition,
    CompoundRule,
    AppContext,
)

from dragonfly.actions.keyboard import keyboard
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")
示例#26
0
def get_ruby_grammar():
    grammar = Grammar('ruby')
    grammar.add_rule(RubyNewLineRule())
    grammar.add_rule(RubyRuleAppend())
    return grammar
示例#27
0
print('loading copypaste rules')

try:
    import aenea.communications
except ImportError:
    print 'Unable to import Aenea client-side modules.'
    raise


bash_context = AeneaContext(
    ProxyAppContext(cls_name='Terminal', cls='Terminal'),
    AppContext(executable='Terminal')
    )

bash_grammar = Grammar('bash', context=bash_context)



dictionary = ModuleDictionary("apps\\bash")

def paste(t,n):
    if n != 0:
        t=n
    if t=="default":
        Key("cs-v").execute()
    else:
        global CLIPBOARD
        key = str(t)
        if key in CLIPBOARD.dictionary:
            previous = aenea.communications.server.paste(CLIPBOARD.dictionary[key])
示例#28
0
    # Run our aenea plugin script that shows the mouse grid fullscreen in Linux.
    #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
示例#29
0
def get_javascript_grammar():
    grammar = Grammar('Javascript')
    grammar.add_rule(JavascriptNewLineRule())
    grammar.add_rule(JavascriptRuleAppend())
    return grammar
示例#30
0
# published by the Free Software Foundation.
#
# 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()
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)
示例#32
0
        "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