Esempio n. 1
0
def update_engine(engine, old, new):
    """Modify a StenoEngine using a before and after config object.
    
    Using the before and after allows this function to not make unnecessary 
    changes.
    """
    machine_type = new.get_machine_type()
    machine_options = new.get_machine_specific_options(machine_type)
    if (old.get_machine_type() != machine_type or 
        old.get_machine_specific_options(machine_type) != machine_options):
        try:
            machine_class = machine_registry.get(machine_type)
        except NoSuchMachineException as e:
            raise InvalidConfigurationError(unicode(e))
        engine.set_machine(machine_class(machine_options))

    dictionary_file_names = new.get_dictionary_file_names()
    if old.get_dictionary_file_names() != dictionary_file_names:
        try:
            dicts = dict_manager.load(dictionary_file_names)
        except DictionaryLoaderException as e:
            raise InvalidConfigurationError(unicode(e))
        engine.get_dictionary().set_dicts(dicts)

    log_file_name = new.get_log_file_name()
    if old.get_log_file_name() != log_file_name:
        engine.set_log_file_name(log_file_name)

    enable_stroke_logging = new.get_enable_stroke_logging()
    if old.get_enable_stroke_logging() != enable_stroke_logging:
        engine.enable_stroke_logging(enable_stroke_logging)

    enable_translation_logging = new.get_enable_translation_logging()
    if old.get_enable_translation_logging() != enable_translation_logging:
        engine.enable_translation_logging(enable_translation_logging)
Esempio n. 2
0
def update_engine(engine, old, new):
    """Modify a StenoEngine using a before and after config object.
    
    Using the before and after allows this function to not make unnecessary 
    changes.
    """
    machine_type = new.get_machine_type()
    machine_options = new.get_machine_specific_options(machine_type)
    if (old.get_machine_type() != machine_type or
            old.get_machine_specific_options(machine_type) != machine_options):
        try:
            machine_class = machine_registry.get(machine_type)
        except NoSuchMachineException as e:
            raise InvalidConfigurationError(unicode(e))
        engine.set_machine(machine_class(machine_options))

    dictionary_file_names = new.get_dictionary_file_names()
    if old.get_dictionary_file_names() != dictionary_file_names:
        try:
            dicts = dict_manager.load(dictionary_file_names)
        except DictionaryLoaderException as e:
            raise InvalidConfigurationError(unicode(e))
        engine.get_dictionary().set_dicts(dicts)

    log_file_name = new.get_log_file_name()
    if old.get_log_file_name() != log_file_name:
        engine.set_log_file_name(log_file_name)

    enable_stroke_logging = new.get_enable_stroke_logging()
    if old.get_enable_stroke_logging() != enable_stroke_logging:
        engine.enable_stroke_logging(enable_stroke_logging)

    enable_translation_logging = new.get_enable_translation_logging()
    if old.get_enable_translation_logging() != enable_translation_logging:
        engine.enable_translation_logging(enable_translation_logging)
Esempio n. 3
0
def get_dicts(config):
    """Initialize a StenoEngine from a config object."""
    dictionary_file_names = config.get_dictionary_file_names()
    try:
        dicts = dict_manager.load(dictionary_file_names)
    except DictionaryLoaderException as e:
        raise InvalidConfigurationError(unicode(e))
    return dicts
Esempio n. 4
0
def get_dicts(config):
    """Initialize a StenoEngine from a config object."""
    dictionary_file_names = config.get_dictionary_file_names()
    try:
        dicts = dict_manager.load(dictionary_file_names)
    except DictionaryLoaderException as e:
        raise InvalidConfigurationError(unicode(e))
    return dicts
Esempio n. 5
0
def init_engine(engine, config):
    """Initialize a StenoEngine from a config object."""
    reset_machine(engine, config)
    
    dictionary_file_names = config.get_dictionary_file_names()
    try:
        dicts = dict_manager.load(dictionary_file_names)
    except DictionaryLoaderException as e:
        raise InvalidConfigurationError(unicode(e))
    engine.get_dictionary().set_dicts(dicts)

    engine.set_log_file_name(config)
    engine.enable_stroke_logging(config.get_enable_stroke_logging())
    engine.enable_translation_logging(config.get_enable_translation_logging())
    engine.set_space_placement(config.get_space_placement())
    
    engine.set_is_running(config.get_auto_start())
Esempio n. 6
0
def init_engine(engine, config):
    """Initialize a StenoEngine from a config object."""
    reset_machine(engine, config)

    dictionary_file_names = config.get_dictionary_file_names()
    try:
        dicts = dict_manager.load(dictionary_file_names)
    except DictionaryLoaderException as e:
        raise InvalidConfigurationError(unicode(e))
    engine.get_dictionary().set_dicts(dicts)

    engine.set_log_file_name(config)
    engine.enable_stroke_logging(config.get_enable_stroke_logging())
    engine.enable_translation_logging(config.get_enable_translation_logging())
    engine.set_space_placement(config.get_space_placement())

    engine.set_is_running(config.get_auto_start())
Esempio n. 7
0
    def __init__(self, output, log):

        self._log = log
        self._output = output
        self._config = plover.config.Config()
        with open(plover.config.CONFIG_FILE) as f:
            self._config.load(f)
        keymap = self._config.get_machine_specific_options('NKRO Keyboard')['keymap']
        self._mapping = {}
        for steno_key, key_names in keymap.get().items():
            for key in key_names:
                key = key.lower()
                if not key in PSEUDOKEY_TO_KEYCODE:
                    continue
                keycode = PSEUDOKEY_TO_KEYCODE[key]
                self._mapping[keycode] = steno_key
        self._dicts = DictionaryManager.load(self._config.get_dictionary_file_names())
        self._formatter = Formatter()
        self._formatter.set_output(self._output)
        self._translator = Translator()
        self._translator.add_listener(self._formatter.format)
        self._translator.get_dictionary().set_dicts(self._dicts)
        self._translator.set_min_undo_length(NB_PREDIT_STROKES)
        self.reset(full=True, output=False)
Esempio n. 8
0
 def set_dictionaries(self, file_names):
     dictionary = self.translator.get_dictionary()
     dicts = dict_manager.load(file_names)
     dictionary.set_dicts(dicts)
Esempio n. 9
0
 def set_dictionaries(self, file_names):
     dictionary = self.translator.get_dictionary()
     if tuple(file_names) == tuple(d.get_path() for d in dictionary.dicts):
         return
     dicts = dict_manager.load(file_names)
     dictionary.set_dicts(dicts)
Esempio n. 10
0
 def set_dictionaries(self, file_names):
     dictionary = self.translator.get_dictionary()
     dicts = dict_manager.load(file_names)
     dictionary.set_dicts(dicts)
     self.suggestions = Suggestions(dictionary)
Esempio n. 11
0
File: app.py Progetto: buribu/plover
 def set_dictionaries(self, file_names):
     dictionary = self.translator.get_dictionary()
     if tuple(file_names) == tuple(d.get_path() for d in dictionary.dicts):
         return
     dicts = dict_manager.load(file_names)
     dictionary.set_dicts(dicts)