Ejemplo n.º 1
0
def register_dynamic_vocabulary(tag):
    '''Call this to register a dynamic vocabulary hook in your grammar that
       users can configure. It returns a DictList, which will always be
       kept up to date with user updates. You need to call unregister when
       the grammar is unloaded or your module won't successfully reload without
       restarting Dragon.'''
    global _lists
    _lists['dynamic'][str(tag)] = dragonfly.DictList('dynamic %s' % str(tag))
    refresh_vocabulary()
    _load_enabled_from_disk()
    _save_enabled_to_disk()
    return _lists['dynamic'][str(tag)]
Ejemplo n.º 2
0
class StaticRule(dragonfly.CompoundRule):
    spec = command_table['<static>']

    extras = [
        dragonfly.DictListRef(
            'static',
            dragonfly.DictList(
                'static global',
                aenea.vocabulary.get_static_vocabulary('global')))
    ]

    def _process_recognition(self, node, extras):
        extras['static'].execute(extras)
Ejemplo n.º 3
0
def register_global_dynamic_vocabulary():
    '''Returns a DictList of the global vocabulary. This is like all vocabs
       tagged 'global', EXCEPT grammars may inhibit a name from being here by
       calling inhibit_name_globally when a given context is active. This is
       intended to allow more complex editing grammars (eg, multiedit), which
       have their own custom hooks for vocabs which enable advanced features
       to avoid conflicting with the global grammar.

       Note that this is NOT the same as calling
       register_dynamic_vocabulary('global'); which will ignore inhibited
       vocabularies.'''
    global _global_list
    _global_list = dragonfly.DictList(name='global inhibited')
    refresh_vocabulary()
    return _global_list
Ejemplo n.º 4
0
        # Reload the top-level modules in macro_dir if natlinkmain is available.
        if natlinkmain:
            natlinkmain.findAndLoadFiles()
    except Exception as e:
        print "reloading failed: {}".format(e)
    else:
        print "finished reloading"


# Note that you do not need to turn mic off and then on after saying this.  This
# also unloads all modules and packages in the macro directory so that they will
# be reloaded the next time that they are imported.  It even reloads Aenea!
class ReloadGrammarsRule(dragonfly.MappingRule):
    mapping = {command_table['force natlink to reload all grammars']: dragonfly.Function(reload_code)}

server_list = dragonfly.DictList('aenea servers')
server_list_watcher = aenea.configuration.ConfigWatcher(
    ('grammar_config', 'aenea'))


class ChangeServer(dragonfly.CompoundRule):
    spec = command_table['set proxy server to <proxy>']
    extras = [dragonfly.DictListRef('proxy', server_list)]

    def _process_recognition(self, node, extras):
        aenea.communications.set_server_address((extras['proxy']['host'], extras['proxy']['port']))

    def _process_begin(self):
        if server_list_watcher.refresh():
            server_list.clear()
            for k, v in server_list_watcher.conf.get('servers', {}).iteritems():
Ejemplo n.º 5
0
    def _process_recognition(self, _node, _extras):
        aenea.config.disable_proxy()


class EnableRule(dragonfly.CompoundRule):

    """Enable remote."""

    def __init__(self, *args, **kwargs):
        self.spec = _('enable proxy server')
        dragonfly.CompoundRule.__init__(self, *args, **kwargs)

    def _process_recognition(self, _node, _extras):
        aenea.config.enable_proxy()

SERVER_LIST = dragonfly.DictList('aenea servers')
SERVER_LIST_WATCHER = aenea.configuration.ConfigWatcher(
    ('grammar_config', 'aenea'))

class ChangeServer(dragonfly.CompoundRule):

    """Change to different remote."""

    def __init__(self, *args, **kwargs):
        self.spec = _('set proxy server to <proxy>')
        self.extras = [dragonfly.DictListRef('proxy', SERVER_LIST)]
        dragonfly.CompoundRule.__init__(self, *args, **kwargs)

    def _process_recognition(self, _node, extras):
        aenea.communications.set_server_address((
            extras['proxy']['host'],
Ejemplo n.º 6
0
        if natlinkmain:
            natlinkmain.findAndLoadFiles()
    except Exception as e:
        print "reloading failed: {}".format(e)
    else:
        print "finished reloading"


# Note that you do not need to turn mic off and then on after saying this.  This
# also unloads all modules and packages in the macro directory so that they will
# be reloaded the next time that they are imported.  It even reloads Aenea!
class ReloadGrammarsRule(dragonfly.MappingRule):
    mapping = {command_table["forcefield"]: dragonfly.Function(reload_code)}


server_list = dragonfly.DictList("aenea servers")
server_list_watcher = aenea.configuration.ConfigWatcher(
    ("grammar_config", "aenea"))


class ChangeServer(dragonfly.CompoundRule):
    spec = command_table["set proxy server to <proxy>"]
    extras = [dragonfly.DictListRef("proxy", server_list)]

    def _process_recognition(self, node, extras):
        aenea.communications.set_server_address(
            (extras["proxy"]["host"], extras["proxy"]["port"]))

    def _process_begin(self):
        if server_list_watcher.refresh():
            server_list.clear()