示例#1
0
    def __init__(self, entities):
        """TODO: to be defined. """

        self._entities = DictList('bring_me_base')

        if isinstance(entities, dict):
            self._entities.set(entities)

        self.mapping = {
            "bring me <entity>":
                Function(self.bring_me),
            "<entity_type> to bring me as <entity_name>":
                Function(self.bring_me_as),
            "remove <entity_name> from bring me":
                Function(self.bring_me_remove)
        }

        self.extras = [
            DictListRef("entity", self._entities),
            Literal(self.type, "entity_type"),
            Dictation("entity_name").apply(lambda key:
                                           re.sub(r'[^A-Za-z\'\s]+', '', key)
                                           .lower())
        ]

        self._subscribers = []

        super().__init__()
示例#2
0
class GoToFolderRule(CompoundRule):
    spec = config.lang.go_to_folder
    extras = [DictListRef('folder', grammar.folders)]
    def _process_recognition(self, node, extras):
        folder = extras['folder']
        explorer = self.grammar.get_active_explorer()
        if not explorer: return
        explorer.SelectFolder(folder)
示例#3
0
class VocabRule(MappingRule):
    mapping = {
        'new vocab <text>': Function(add_clipboard_contents_to_vocabulary),
        '(Dell|delete) vocab <text>': Function(del_from_vocabulary),
        'clear vocab': Function(clear_vocabulary),
        'recall <vocab>': Text('%(vocab)s'),
        'list vocab': Function(type_out_vocabulary)
    }
    extras = [Dictation('text'), DictListRef('vocab', vocab_dict)]
示例#4
0
class MoveToFolderRule(CompoundRule):
    """Move selected messages to folder"""
    spec = config.lang.move_to_folder
    extras = [DictListRef('folder', grammar.folders)]
    def _process_recognition(self, node, extras):
        folder = extras['folder']
        explorer = self.grammar.get_active_explorer()
        if not explorer: return
        for item in collection_iter(explorer.Selection):
            self._log.debug('%s: moving item %r to folder %r.'
                            % (self, item.Subject, folder.Name))
            item.Move(folder)
示例#5
0
class EditModuleRule(CompoundRule):

    spec = config.lang.edit_module
    extras = [DictListRef("module", config_map)]

    def _process_recognition(self, node, extras):
        module_instance = extras["module"]
        path = module_instance.module_path
        if not os.path.isfile(path):
            print("I can't find the module file you want to edit!!")

        subprocess.Popen([r"C:\Program Files\Notepad++\notepad++.exe", path])
示例#6
0
class StyleRule(CompoundRule):

    spec   = config.lang.set_style
    styles = DictList("styles")
    extras = [DictListRef("style", styles)]

    def _process_recognition(self, node, extras):
        try:
            document = self.grammar.application.ActiveDocument
            document.ActiveWindow.Selection.Style = extras["style"]
        except com_error, e:
            if self._log_proc: self._log_proc.warning("Rule %s:"
                    " failed to set style: %s." % (self, e))
示例#7
0
class EditConfigRule(CompoundRule):

    spec = config.lang.edit_config
    extras = [DictListRef("config", config_map)]

    def _process_recognition(self, node, extras):
        config_instance = extras["config"]
        path = config_instance.config_path
        if not os.path.isfile(path):
            try:
                config_instance.generate_config_file(path)
            except Exception, e:
                self._log.warning("Failed to create new config file %r: %s" %
                                  (path, e))
                return
        os.startfile(path)
示例#8
0
class EditConfigRule(CompoundRule):

    spec = config.lang.edit_config
    extras = [DictListRef("config", config_map)]

    def _process_recognition(self, node, extras):
        config_instance = extras["config"]
        path = config_instance.config_path
        if not os.path.isfile(path):
            try:
                config_instance.generate_config_file(path)
            except Exception, e:
                self._log.warning("Failed to create new config file %r: %s" %
                                  (path, e))
                return
        #os.startfile(path) # this seems to open the config file in notepad++, but it crashes Dragon 15 altogether on Windows 7 and Windows 10 both 64-bit and the rest of the stack of dragonfly NatLink python and pywin32 are all 32-bit
        #print(path)
        subprocess.Popen([r"C:\Program Files\Notepad++\notepad++.exe", path])
示例#9
0
        'plus equal': Text('+= '),
        'minus equal': Text('-= '),
        'times equal': Text('*= '),
        'divided equal': Text('/= '),
        'mod equal': Text('%%= '),
    }


ruleArithmeticInsertion = RuleRef(ArithmeticInsertion(),
                                  name='ArithmeticInsertion')

primitive_insertions = [
    ruleKeyInsertion,
    ruleIdentifierInsertion,
    DictListRef(
        'dynamic vim.insertions.code',
        aenea.vocabulary.register_dynamic_vocabulary('vim.insertions.code')),
    DictListRef(
        'dynamic vim.insertions',
        aenea.vocabulary.register_dynamic_vocabulary('vim.insertions')),
    ruleArithmeticInsertion,
    ruleSpellingInsertion,
]

static_code_insertions = aenea.vocabulary.get_static_vocabulary(
    'vim.insertions.code')
static_insertions = aenea.vocabulary.get_static_vocabulary('vim.insertions')

if static_code_insertions:
    primitive_insertions.append(
        RuleRef(
示例#10
0
    "firefox", None)}, doc="Default window names.  Maps spoken-forms to (executable, title) pairs.")
# config.generate_config_file()
config.load()


# ===========================================================================
# Create this module's main grammar object.

winControlGrammar = Grammar("window control")


# ---------------------------------------------------------------------------
# Dictionary list of window and monitor names.

win_names = DictList("win_names")
win_names_ref = DictListRef("win_names", win_names)
mon_names = DictList("mon_names")
mon_names_ref = DictListRef("mon_names", mon_names)

# Populate monitor names.
for i, m in enumerate(monitors):
    mon_names[str(i+1)] = m


# ---------------------------------------------------------------------------
# Default window names handling.

default_names = config.settings.defaults

# Pre-populate the win_names mapping with the given default names.
for key in default_names.keys():
示例#11
0
    utils.text_map_to_action_map(symbol_map), key_action_map)
#-------------------------------------------------------------------------------

# Lists which will be populated later via RPC.
context_word_list = List("context_word_list", [])
prefix_list = List("prefix_list", prefixes)
suffix_list = List("suffix_list", suffixes)

# Simple element map corresponding to keystroke action maps from earlier.
keystroke_element_map = {
    "n": (IntegerRef(None, 1, 10), 1),
    "text":
    RuleWrap(None,
             Alternative([
                 Dictation(),
                 DictListRef(None, char_dict_list),
             ])),
    "char":
    DictListRef(None, char_dict_list),
    "custom_text":
    RuleWrap(
        None,
        Alternative([
            Dictation(),
            DictListRef(None, char_dict_list),
            ListRef(None, prefix_list),
            ListRef(None, suffix_list),
        ])),
}

#-------------------------------------------------------------------------------
示例#12
0

context = CommandContext("latex")
Breathe.add_commands(
    context=AppContext(title='.tex') | context,
    mapping={
        'new paragraph': Text('\n\n'),
        'emphasize <latex>': Text(r'\emph{}%(latex)s}\n'),
        'inline math': Text('$') + Function(start_inline),
        'begin align': Text('\\begin{align}\n') + Function(start_align),
        'begin math': Function(start_math),
        # 'stop math': Function(end_math),
        "<math_command>": Function(process_math_command),
    },
    extras=[
        DictListRef('math_command', math_commands),
        Dictation("latex", default="").lower().replace(" new paragraph ",
                                                       "\n\n"),
    ])

# fraction sin x ^2squared divided by 3 + x
#  \frac{\sin(x^2)}{3+x}
# Breathe.add_commands(
#     context=context,
#     mapping={
#        "<expr1> frac <expr2> over <expr3>":
#             Exec("expr1") + Text("\\frac{") + Exec("expr2") + Text("}{") + Exec("expr3") + Text("}"),
#        "<expr1> over <expr2>":
#            Text("\\frac{") + Exec("expr1") + Text("}{") + Exec("expr2") + Text("}"),
#        "<expr1> of <expr2>":
#            Exec("expr1") + Text("\\left(") + Exec("expr2") + Text("\\right)"),
}

char_map = dict(
    (k, v.strip()) for (k, v) in utils.combine_maps(letters_map).iteritems())

# Simple elements that may be referred to within a rule.
numbers_dict_list = DictList("numbers_dict_list", numbers_map)
letters_dict_list = DictList("letters_dict_list", letters_map)
char_dict_list = DictList("char_dict_list", char_map)
letters_map_dict_list = DictList("letters_map_dict_list", letters_map)

# A sequence of either short letters or long letters.
letters_element = RuleWrap(
    None,
    utils.JoinedRepetition("",
                           DictListRef(None, letters_dict_list),
                           min=1,
                           max=10))

# A sequence of numbers.
numbers_element = RuleWrap(
    None,
    utils.JoinedRepetition("",
                           DictListRef(None, numbers_dict_list),
                           min=0,
                           max=10))

# A sequence of characters.
chars_element = RuleWrap(
    None,
    utils.JoinedRepetition("",