当前位置: 首页>>代码示例>>Python>>正文


Python Translator.set_min_undo_length方法代码示例

本文整理汇总了Python中plover.translation.Translator.set_min_undo_length方法的典型用法代码示例。如果您正苦于以下问题:Python Translator.set_min_undo_length方法的具体用法?Python Translator.set_min_undo_length怎么用?Python Translator.set_min_undo_length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在plover.translation.Translator的用法示例。


在下文中一共展示了Translator.set_min_undo_length方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TranslatorStateSizeTestCase

# 需要导入模块: from plover.translation import Translator [as 别名]
# 或者: from plover.translation.Translator import set_min_undo_length [as 别名]
class TranslatorStateSizeTestCase(unittest.TestCase):
    class FakeState(_State):
        def __init__(self):
            _State.__init__(self)
            self.restrict_calls = []
        def restrict_size(self, n):
            self.restrict_calls.append(n)

    def assert_size_call(self, size):
        self.assertEqual(self.s.restrict_calls[-1], size)

    def assert_no_size_call(self):
        self.assertEqual(self.s.restrict_calls, [])

    def clear(self):
        self.s.restrict_calls = []

    def setUp(self):
        self.t = Translator()
        self.s = type(self).FakeState()
        self.t._state = self.s
        self.d = StenoDictionary()
        self.dc = StenoDictionaryCollection()
        self.dc.set_dicts([self.d])
        self.t.set_dictionary(self.dc)

    def test_dictionary_update_grows_size1(self):
        self.d[('S',)] = '1'
        self.assert_size_call(1)

    def test_dictionary_update_grows_size4(self):
        self.d[('S', 'PT', '-Z', 'TOP')] = 'hi'
        self.assert_size_call(4)

    def test_dictionary_update_no_grow(self):
        self.t.set_min_undo_length(4)
        self.assert_size_call(4)
        self.clear()
        self.d[('S', 'T')] = 'nothing'
        self.assert_size_call(4)

    def test_dictionary_update_shrink(self):
        self.d[('S', 'T', 'P', '-Z', '-D')] = '1'
        self.assert_size_call(5)
        self.clear()
        self.d[('A', 'P')] = '2'
        self.assert_no_size_call()
        del self.d[('S', 'T', 'P', '-Z', '-D')]
        self.assert_size_call(2)

    def test_dictionary_update_no_shrink(self):
        self.t.set_min_undo_length(7)
        self.d[('S', 'T', 'P', '-Z', '-D')] = '1'
        del self.d[('S', 'T', 'P', '-Z', '-D')]
        self.assert_size_call(7)

    def test_translation_calls_restrict(self):
        self.t.translate(stroke('S'))
        self.assert_size_call(0)
开发者ID:Slotkenov,项目名称:plover,代码行数:61,代码来源:test_translation.py

示例2: __init__

# 需要导入模块: from plover.translation import Translator [as 别名]
# 或者: from plover.translation.Translator import set_min_undo_length [as 别名]
class Steno:

    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)

    def flush(self):
        self._output.flush()
        self.reset()

    def stroke(self, stroke):
        self._log.debug('stroke(%s)' % stroke.rtfcre)
        self._output.stroke_start()
        self._translator.translate(stroke)
        self._output.stroke_end()

    def reset(self, full=False, output=True):
        self._log.debug('reset steno state (full=%s)' % full)
        state = _State()
        state.tail = self._translator.get_state().last()
        if full or state.tail is None:
            state.tail = Translation([Stroke('*')], None)
            state.tail.formatting = [_Action(attach=True)]
        self._translator.set_state(state)
        if output:
            self._output.reset()

    def translate_keycode_to_steno(self, keycode):
        return self._mapping.get(keycode, None)
开发者ID:KarlHegbloom,项目名称:ibus-plover,代码行数:52,代码来源:engine.py

示例3: BlackboxTester

# 需要导入模块: from plover.translation import Translator [as 别名]
# 或者: from plover.translation.Translator import set_min_undo_length [as 别名]
class BlackboxTester(object):

    @classmethod
    def setup_class(cls):
        for name in dir(cls):
            if name.startswith('test_'):
                setattr(cls, name, replay_doc(getattr(cls, name)))

    def setup_method(self):
        self.output = CaptureOutput()
        self.formatter = Formatter()
        self.formatter.set_output(self.output)
        self.translator = Translator()
        self.translator.set_min_undo_length(100)
        self.translator.add_listener(self.formatter.format)
        self.dictionary = self.translator.get_dictionary()
        self.dictionary.set_dicts([StenoDictionary()])
开发者ID:ohAitch,项目名称:plover,代码行数:19,代码来源:testing.py

示例4: StenoEngine

# 需要导入模块: from plover.translation import Translator [as 别名]
# 或者: from plover.translation.Translator import set_min_undo_length [as 别名]

#.........这里部分代码省略.........
        self._trigger_hook('dictionaries_loaded', self._dictionaries)

    def _update(self, config_update=None, full=False, reset_machine=False):
        original_config = self._config.as_dict()
        # Update configuration.
        if config_update is not None:
            self._config.update(**config_update)
            config = self._config.as_dict()
        else:
            config = original_config
        # Create configuration update.
        if full:
            config_update = config
        else:
            config_update = {
                option: value
                for option, value in config.items()
                if value != original_config[option]
            }
            if 'machine_type' in config_update:
                for opt in (
                    'machine_specific_options',
                    'system_keymap',
                ):
                    config_update[opt] = config[opt]
        # Update logging.
        log.set_stroke_filename(config['log_file_name'])
        log.enable_stroke_logging(config['enable_stroke_logging'])
        log.enable_translation_logging(config['enable_translation_logging'])
        # Update output.
        self._formatter.set_space_placement(config['space_placement'])
        self._formatter.start_attached = config['start_attached']
        self._formatter.start_capitalized = config['start_capitalized']
        self._translator.set_min_undo_length(config['undo_levels'])
        # Update system.
        system_name = config['system_name']
        if system.NAME != system_name:
            log.info('loading system: %s', system_name)
            system.setup(system_name)
        # Update machine.
        update_keymap = False
        start_machine = False
        machine_params = MachineParams(config['machine_type'],
                                       config['machine_specific_options'],
                                       config['system_keymap'])
        # Do not reset if only the keymap changed.
        if self._machine_params is None or \
           self._machine_params.type != machine_params.type or \
           self._machine_params.options != machine_params.options:
            reset_machine = True
        if reset_machine:
            if self._machine is not None:
                self._machine.stop_capture()
                self._machine = None
            machine_type = config['machine_type']
            machine_options = config['machine_specific_options']
            try:
                machine_class = registry.get_plugin('machine', machine_type).obj
            except Exception as e:
                raise InvalidConfigurationError(str(e))
            log.info('setting machine: %s', machine_type)
            self._machine = machine_class(machine_options)
            self._machine.set_suppression(self._is_running)
            self._machine.add_state_callback(self._machine_state_callback)
            self._machine.add_stroke_callback(self._machine_stroke_callback)
            self._machine_params = machine_params
开发者ID:ohAitch,项目名称:plover,代码行数:70,代码来源:engine.py

示例5: namedtuple

# 需要导入模块: from plover.translation import Translator [as 别名]
# 或者: from plover.translation.Translator import set_min_undo_length [as 别名]
class TestTranslateStroke:

    class CaptureOutput:
        output = namedtuple('output', 'undo do prev')

        def __init__(self):
            self.output = []

        def __call__(self, undo, new, prev):
            prev = list(prev) if prev else None
            self.output = type(self).output(undo, new, prev)

    def t(self, strokes):
        """A quick way to make a translation."""
        strokes = [stroke(x) for x in strokes.split('/')]
        key = tuple(s.rtfcre for s in strokes)
        translation = self.dc.lookup(key)
        return Translation(strokes, translation)

    def lt(self, translations):
        """A quick way to make a list of translations."""
        return [self.t(x) for x in translations.split()]

    def define(self, key, value):
        key = normalize_steno(key)
        self.d[key] = value

    def translate(self, steno):
        self.tlor.translate(stroke(steno))

    def _check_translations(self, expected):
        # Hide from traceback on assertions (reduce output size for failed tests).
        __tracebackhide__ = operator.methodcaller('errisinstance', AssertionError)
        msg = '''
        translations:
            results: %s
            expected: %s
        ''' % (self.s.translations, expected)
        assert self.s.translations == expected, msg

    def _check_output(self, undo, do, prev):
        # Hide from traceback on assertions (reduce output size for failed tests).
        __tracebackhide__ = operator.methodcaller('errisinstance', AssertionError)
        msg = '''
        output:
            results: -%s
                     +%s
                     [%s]
            expected: -%s
                      +%s
                      [%s]
        ''' % (self.o.output + (undo, do, prev))
        assert self.o.output == (undo, do, prev), msg

    def setup_method(self):
        self.d = StenoDictionary()
        self.dc = StenoDictionaryCollection([self.d])
        self.s = _State()
        self.o = self.CaptureOutput()
        self.tlor = Translator()
        self.tlor.set_dictionary(self.dc)
        self.tlor.add_listener(self.o)
        self.tlor.set_state(self.s)

    def test_first_stroke(self):
        self.translate('-B')
        self._check_translations(self.lt('-B'))
        self._check_output([], self.lt('-B'), None)

    def test_second_stroke(self):
        self.define('S/P', 'spiders')
        self.s.translations = self.lt('S')
        self.translate('-T')
        self._check_translations(self.lt('S -T'))
        self._check_output([], self.lt('-T'), self.lt('S'))

    def test_second_stroke_tail(self):
        self.s.tail = self.t('T/A/EU/L')
        self.translate('-E')
        self._check_translations(self.lt('E'))
        self._check_output([], self.lt('E'), self.lt('T/A/EU/L'))

    def test_with_translation_1(self):
        self.define('S', 'is')
        self.define('-T', 'that')
        self.s.translations = self.lt('S')
        self.tlor.set_min_undo_length(2)
        self.translate('-T')
        self._check_translations(self.lt('S -T'))
        self._check_output([], self.lt('-T'), self.lt('S'))
        assert self.o.output.do[0].english == 'that'

    def test_with_translation_2(self):
        self.define('S', 'is')
        self.define('-T', 'that')
        self.s.translations = self.lt('S')
        self.tlor.set_min_undo_length(1)
        self.translate('-T')
        self._check_translations(self.lt('-T'))
        self._check_output([], self.lt('-T'), self.lt('S'))
#.........这里部分代码省略.........
开发者ID:DanLanglois,项目名称:plover,代码行数:103,代码来源:test_translation.py

示例6: test_translator

# 需要导入模块: from plover.translation import Translator [as 别名]
# 或者: from plover.translation.Translator import set_min_undo_length [as 别名]
def test_translator():

    # It's not clear that this test is needed anymore. There are separate
    # tests for _translate_stroke and test_translate_calls_translate_stroke
    # makes sure that translate calls it properly. But since I already wrote
    # this test I'm going to keep it.

    class Output:
        def __init__(self):
            self._output = []

        def write(self, undo, do, prev):
            for t in undo:
                self._output.pop()
            for t in do:
                if t.english:
                    self._output.append(t.english)
                else:
                    self._output.append('/'.join(t.rtfcre))

        def get(self):
            return ' '.join(self._output)

        def clear(self):
            del self._output[:]

    d = StenoDictionary()
    out = Output()
    t = Translator()
    dc = StenoDictionaryCollection([d])
    t.set_dictionary(dc)
    t.add_listener(out.write)

    t.translate(stroke('S'))
    assert out.get() == 'S'
    t.translate(stroke('T'))
    assert out.get() == 'S T'
    t.translate(stroke('*'))
    assert out.get() == 'S'
    t.translate(stroke('*'))
    # Undo buffer ran out
    assert out.get() == 'S ' + BACK_STRING

    t.set_min_undo_length(3)
    out.clear()
    t.translate(stroke('S'))
    assert out.get() == 'S'
    t.translate(stroke('T'))
    assert out.get() == 'S T'
    t.translate(stroke('*'))
    assert out.get() == 'S'
    t.translate(stroke('*'))
    assert out.get() == ''

    out.clear()
    d[('S',)] = 't1'
    d[('T',)] = 't2'
    d[('S', 'T')] = 't3'

    t.translate(stroke('S'))
    assert out.get() == 't1'
    t.translate(stroke('T'))
    assert out.get() == 't3'
    t.translate(stroke('T'))
    assert out.get() == 't3 t2'
    t.translate(stroke('S'))
    assert out.get() == 't3 t2 t1'
    t.translate(stroke('*'))
    assert out.get() == 't3 t2'
    t.translate(stroke('*'))
    assert out.get() == 't3'
    t.translate(stroke('*'))
    assert out.get() == 't1'
    t.translate(stroke('*'))
    assert out.get() == ''

    t.translate(stroke('S'))
    assert out.get() == 't1'
    t.translate(stroke('T'))
    assert out.get() == 't3'
    t.translate(stroke('T'))
    assert out.get() == 't3 t2'

    d[('S', 'T', 'T')] = 't4'
    d[('S', 'T', 'T', 'S')] = 't5'

    t.translate(stroke('S'))
    assert out.get() == 't5'
    t.translate(stroke('*'))
    assert out.get() == 't3 t2'
    t.translate(stroke('*'))
    assert out.get() == 't3'
    t.translate(stroke('T'))
    assert out.get() == 't4'
    t.translate(stroke('S'))
    assert out.get() == 't5'
    t.translate(stroke('S'))
    assert out.get() == 't5 t1'
    t.translate(stroke('*'))
    assert out.get() == 't5'
#.........这里部分代码省略.........
开发者ID:DanLanglois,项目名称:plover,代码行数:103,代码来源:test_translation.py

示例7: StenoEngine

# 需要导入模块: from plover.translation import Translator [as 别名]
# 或者: from plover.translation.Translator import set_min_undo_length [as 别名]
class StenoEngine(object):

    HOOKS = """
    stroked
    translated
    machine_state_changed
    output_changed
    config_changed
    send_string
    send_backspaces
    send_key_combination
    add_translation
    focus
    configure
    lookup
    quit
    """.split()

    def __init__(self, config, keyboard_emulation):
        self._config = config
        self._is_running = False
        self._queue = Queue()
        self._lock = threading.RLock()
        self._machine = None
        self._machine_state = None
        self._machine_params = MachineParams(None, None, None)
        self._formatter = Formatter()
        self._formatter.set_output(self)
        self._formatter.add_listener(self._on_translated)
        self._translator = Translator()
        self._translator.add_listener(log.translation)
        self._translator.add_listener(self._formatter.format)
        self._dictionaries = self._translator.get_dictionary()
        self._dictionaries_manager = DictionaryLoadingManager()
        self._running_state = self._translator.get_state()
        self._suggestions = Suggestions(self._dictionaries)
        self._keyboard_emulation = keyboard_emulation
        self._hooks = {hook: [] for hook in self.HOOKS}

    def __enter__(self):
        self._lock.__enter__()
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        self._lock.__exit__(exc_type, exc_value, traceback)

    def _in_engine_thread(self):
        raise NotImplementedError()

    def _same_thread_hook(self, func, *args, **kwargs):
        if self._in_engine_thread():
            func(*args, **kwargs)
        else:
            self._queue.put((func, args, kwargs))

    def run(self):
        while True:
            func, args, kwargs = self._queue.get()
            try:
                with self._lock:
                    if func(*args, **kwargs):
                        break
            except Exception:
                log.error("engine %s failed", func.__name__[1:], exc_info=True)

    def _stop(self):
        if self._machine is not None:
            self._machine.stop_capture()
            self._machine = None

    def _start(self):
        self._set_output(self._config.get_auto_start())
        self._update(full=True)

    def _update(self, config_update=None, full=False, reset_machine=False):
        original_config = self._config.as_dict()
        # Update configuration.
        if config_update is not None:
            self._config.update(**config_update)
            config = self._config.as_dict()
        else:
            config = original_config
        # Create configuration update.
        if full:
            config_update = config
        else:
            config_update = {option: value for option, value in config.items() if value != original_config[option]}
            if "machine_type" in config_update:
                for opt in ("machine_specific_options", "system_keymap"):
                    config_update[opt] = config[opt]
        # Update logging.
        log.set_stroke_filename(config["log_file_name"])
        log.enable_stroke_logging(config["enable_stroke_logging"])
        log.enable_translation_logging(config["enable_translation_logging"])
        # Update output.
        self._formatter.set_space_placement(config["space_placement"])
        self._formatter.start_attached = config["start_attached"]
        self._formatter.start_capitalized = config["start_capitalized"]
        self._translator.set_min_undo_length(config["undo_levels"])
        # Update system.
#.........这里部分代码省略.........
开发者ID:openstenoproject,项目名称:plover,代码行数:103,代码来源:engine.py

示例8: TranslateStrokeTestCase

# 需要导入模块: from plover.translation import Translator [as 别名]
# 或者: from plover.translation.Translator import set_min_undo_length [as 别名]
class TranslateStrokeTestCase(unittest.TestCase):

    class CaptureOutput(object):
        output = namedtuple('output', 'undo do prev')
        
        def __init__(self):
            self.output = []

        def __call__(self, undo, new, prev):
            prev = list(prev) if prev else None
            self.output = type(self).output(undo, new, prev)

    def t(self, strokes):
        """A quick way to make a translation."""
        strokes = [stroke(x) for x in strokes.split('/')]
        key = tuple(s.rtfcre for s in strokes)
        translation = self.dc.lookup(key)
        return Translation(strokes, translation)

    def lt(self, translations):
        """A quick way to make a list of translations."""
        return [self.t(x) for x in translations.split()]

    def define(self, key, value):
        key = normalize_steno(key)
        self.d[key] = value

    def translate(self, stroke):
        self.tlor.translate(stroke)

    def assertTranslations(self, expected):
        self.assertEqual(self.s.translations, expected)

    def assertOutput(self, undo, do, prev):
        self.assertEqual(self.o.output, (undo, do, prev))

    def setUp(self):
        self.d = StenoDictionary()
        self.dc = StenoDictionaryCollection()
        self.dc.set_dicts([self.d])
        self.s = _State()
        self.o = self.CaptureOutput()
        self.tlor = Translator()
        self.tlor.set_dictionary(self.dc)
        self.tlor.add_listener(self.o)
        self.tlor.set_state(self.s)

    def test_first_stroke(self):
        self.translate(stroke('-B'))
        self.assertTranslations(self.lt('-B'))
        self.assertOutput([], self.lt('-B'), None)

    def test_second_stroke(self):
        self.define('S/P', 'spiders')
        self.s.translations = self.lt('S')
        self.translate(stroke('-T'))
        self.assertTranslations(self.lt('S -T'))
        self.assertOutput([], self.lt('-T'), self.lt('S'))

    def test_second_stroke_tail(self):
        self.s.tail = self.t('T/A/I/L')
        self.translate(stroke('-E'))
        self.assertTranslations(self.lt('E'))
        self.assertOutput([], self.lt('E'), self.lt('T/A/I/L'))

    def test_with_translation_1(self):
        self.define('S', 'is')
        self.define('-T', 'that')
        self.s.translations = self.lt('S')
        self.tlor.set_min_undo_length(2)
        self.translate(stroke('-T'))
        self.assertTranslations(self.lt('S -T'))
        self.assertOutput([], self.lt('-T'), self.lt('S'))
        self.assertEqual(self.o.output.do[0].english, 'that')

    def test_with_translation_2(self):
        self.define('S', 'is')
        self.define('-T', 'that')
        self.s.translations = self.lt('S')
        self.tlor.set_min_undo_length(1)
        self.translate(stroke('-T'))
        self.assertTranslations(self.lt('-T'))
        self.assertOutput([], self.lt('-T'), self.lt('S'))
        self.assertEqual(self.o.output.do[0].english, 'that')

    def test_finish_two_translation(self):
        self.define('S/T', 'hello')
        self.s.translations = self.lt('S')
        self.translate(stroke('T'))
        self.assertTranslations(self.lt('S/T'))
        self.assertOutput(self.lt('S'), self.lt('S/T'), None)
        self.assertEqual(self.o.output.do[0].english, 'hello')
        self.assertEqual(self.o.output.do[0].replaced, self.lt('S'))

    def test_finish_three_translation(self):
        self.define('S/T/-B', 'bye')
        self.s.translations = self.lt('S T')
        self.translate(stroke('-B'))
        self.assertTranslations(self.lt('S/T/-B'))
        self.assertOutput(self.lt('S T'), self.lt('S/T/-B'), None)
#.........这里部分代码省略.........
开发者ID:Slotkenov,项目名称:plover,代码行数:103,代码来源:test_translation.py

示例9: BlackboxTest

# 需要导入模块: from plover.translation import Translator [as 别名]
# 或者: from plover.translation.Translator import set_min_undo_length [as 别名]
class BlackboxTest(unittest.TestCase):

    def setUp(self):
        self.output = CaptureOutput()
        self.formatter = Formatter()
        self.formatter.set_output(self.output)
        self.translator = Translator()
        self.translator.set_min_undo_length(100)
        self.translator.add_listener(self.formatter.format)
        self.dictionary = self.translator.get_dictionary()
        self.dictionary.set_dicts([StenoDictionary()])

    def test_translator_state_handling(self):
        # Check if the translator curtailing the list of last translations
        # according to its dictionary longest key does no affect things
        # like the restrospective repeate-last-stroke command.
        self.dictionary.set(('TEFT',), 'test')
        self.dictionary.set(('R*S',), '{*+}')
        # Note: the implementation of repeat-last-stroke looks at the last
        # stroke keys, so we can't use the same trick as for other tests.
        for keys in (
            ('T-', '-E', '-F', '-T'),
            ('R-', '*', '-S'),
        ):
            stroke = Stroke(keys)
            self.translator.translate(stroke)
        self.assertEqual(self.output.text, u' test test')

    def test_bug471(self):
        # Repeat-last-stroke after typing two numbers outputs the numbers
        # reversed for some combos.
        self.dictionary.set(('R*S',), '{*+}')
        # Note: the implementation of repeat-last-stroke looks at the last
        # stroke keys, so we can't use the same trick as for other tests.
        for keys in (
            ('#', 'S-', 'T-'), # 12
            ('R-', '*', '-S'),
        ):
            stroke = Stroke(keys)
            self.translator.translate(stroke)
        self.assertEqual(self.output.text, u' 1212')

    def test_bug535(self):
        # Currency formatting a number with a decimal fails by not erasing
        # the previous output.
        self.dictionary.set(('P-P',), '{^.^}')
        self.dictionary.set(('KR*UR',), '{*($c)}')
        for steno in (
            '1',
            'P-P',
            '2',
            'KR*UR',
        ):
            stroke = steno_to_stroke(steno)
            self.translator.translate(stroke)
        self.assertEqual(self.output.text, u' $1.20')

    @unittest.expectedFailure
    def test_bug557(self):
        # Using the asterisk key to delete letters in fingerspelled words
        # occasionally causes problems when the space placement is set to
        # "After Output".
        for steno, translation in (
            ('EU'      , 'I'      ),
            ('HRAOEUBG', 'like'   ),
            ('T*'      , '{>}{&t}'),
            ('A*'      , '{>}{&a}'),
            ('KR*'     , '{>}{&c}'),
            ('O*'      , '{>}{&o}'),
            ('S*'      , '{>}{&s}'),
        ):
            self.dictionary.set(normalize_steno(steno), translation)
        self.formatter.set_space_placement('After Output')
        for steno in (
            'EU',
            'HRAOEUBG',
            'T*', 'A*', 'KR*', 'O*', 'S*',
                          '*',  '*',  '*',
        ):
            stroke = steno_to_stroke(steno)
            self.translator.translate(stroke)
        self.assertEqual(self.output.text, u'I like ta ')

    def test_special_characters(self):
        self.dictionary.set(('R-R',), '{^}\n{^}')
        self.dictionary.set(('TAB',), '\t')
        for steno in (
            'R-R',
            'TAB',
        ):
            stroke = steno_to_stroke(steno)
            self.translator.translate(stroke)
        self.assertEqual(self.output.text, u'\n\t')
开发者ID:morinted,项目名称:plover,代码行数:95,代码来源:test_blackbox.py

示例10: StenoEngine

# 需要导入模块: from plover.translation import Translator [as 别名]
# 或者: from plover.translation.Translator import set_min_undo_length [as 别名]

#.........这里部分代码省略.........
        self._update(full=True)

    def _update(self, config_update=None, full=False, reset_machine=False):
        original_config = self._config.as_dict()
        # Update configuration.
        if config_update is not None:
            self._config.update(**config_update)
            config = self._config.as_dict()
        else:
            config = original_config
        # Create configuration update.
        if full:
            config_update = config
        else:
            config_update = {
                option: value
                for option, value in config.items()
                if value != original_config[option]
            }
            if 'machine_type' in config_update:
                for opt in (
                    'machine_specific_options',
                    'system_keymap',
                ):
                    config_update[opt] = config[opt]
        # Update logging.
        log.set_stroke_filename(config['log_file_name'])
        log.enable_stroke_logging(config['enable_stroke_logging'])
        log.enable_translation_logging(config['enable_translation_logging'])
        # Update output.
        self._formatter.set_space_placement(config['space_placement'])
        self._formatter.start_attached = config['start_attached']
        self._formatter.start_capitalized = config['start_capitalized']
        self._translator.set_min_undo_length(config['undo_levels'])
        # Update machine.
        update_keymap = False
        start_machine = False
        machine_params = MachineParams(config['machine_type'],
                                       config['machine_specific_options'],
                                       config['system_keymap'])
        if reset_machine or machine_params != self._machine_params:
            if self._machine is not None:
                self._machine.stop_capture()
                self._machine = None
            machine_type = config['machine_type']
            machine_options = config['machine_specific_options']
            try:
                machine_class = machine_registry.get(machine_type)
            except NoSuchMachineException as e:
                raise InvalidConfigurationError(str(e))
            self._machine = machine_class(machine_options)
            self._machine.set_suppression(self._is_running)
            self._machine.add_state_callback(self._machine_state_callback)
            self._machine.add_stroke_callback(self._machine_stroke_callback)
            self._machine_params = machine_params
            update_keymap = True
            start_machine = True
        elif self._machine is not None:
            update_keymap = 'system_keymap' in config_update
        if update_keymap:
            machine_keymap = config['system_keymap']
            if machine_keymap is not None:
                self._machine.set_keymap(machine_keymap)
        if start_machine:
            self._machine.start_capture()
        # Update dictionaries.
开发者ID:percidae,项目名称:plover,代码行数:70,代码来源:engine.py

示例11: BlackboxTest

# 需要导入模块: from plover.translation import Translator [as 别名]
# 或者: from plover.translation.Translator import set_min_undo_length [as 别名]
class BlackboxTest(unittest.TestCase):

    def setUp(self):
        self.output = CaptureOutput()
        self.formatter = Formatter()
        self.formatter.set_output(self.output)
        self.translator = Translator()
        self.translator.set_min_undo_length(100)
        self.translator.add_listener(self.formatter.format)
        self.dictionary = self.translator.get_dictionary()
        self.dictionary.set_dicts([StenoDictionary()])

    @simple_replay
    def test_translator_state_handling(self):
        # Check if the translator curtailing the list of last translations
        # according to its dictionary longest key does no affect things
        # like the restrospective repeate-last-stroke command.
        r'''
        "TEFT": "test",
        "R*S": "{*+}",

        TEFT/R*S

        " test test"
        '''

    @simple_replay
    def test_force_lowercase_title(self):
        r'''
        "T-LT": "{MODE:TITLE}",
        "TEFT": "{>}test",

        T-LT/TEFT

        " test"
        '''

    @simple_replay
    def test_bug471(self):
        # Repeat-last-stroke after typing two numbers outputs the numbers
        # reversed for some combos.
        r'''
        "R*S": "{*+}",

        12/R*S

        " 1212"
        '''

    @simple_replay
    def test_bug535(self):
        # Currency formatting a number with a decimal fails by not erasing
        # the previous output.
        r'''
        "P-P": "{^.^}",
        "KR*UR": "{*($c)}",

        1/P-P/2/KR*UR

        " $1.20"
        '''

    @simple_replay
    @spaces_after
    def test_bug606(self):
        r'''
        "KWEGS": "question",
        "-S": "{^s}",
        "TP-PL": "{.}",

        KWEGS/-S/TP-PL

        "questions. "
        '''

    @simple_replay
    @spaces_after
    def test_bug535_spaces_after(self):
        # Currency formatting a number with a decimal fails by not erasing
        # the previous output.
        r'''
        "P-P": "{^.^}",
        "KR*UR": "{*($c)}",

        1/P-P/2/KR*UR

        "$1.20 "
        '''

    @simple_replay
    @spaces_after
    def test_bug557(self):
        # Using the asterisk key to delete letters in fingerspelled words
        # occasionally causes problems when the space placement is set to
        # "After Output".
        r'''
        "EU": "I",
        "HRAOEUBG": "like",
        "T*": "{>}{&t}",
        "A*": "{>}{&a}",
#.........这里部分代码省略.........
开发者ID:MartyGentillon,项目名称:plover,代码行数:103,代码来源:test_blackbox.py


注:本文中的plover.translation.Translator.set_min_undo_length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。