本文整理汇总了Python中plover.translation.Translator.clear_state方法的典型用法代码示例。如果您正苦于以下问题:Python Translator.clear_state方法的具体用法?Python Translator.clear_state怎么用?Python Translator.clear_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plover.translation.Translator
的用法示例。
在下文中一共展示了Translator.clear_state方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_changing_state
# 需要导入模块: from plover.translation import Translator [as 别名]
# 或者: from plover.translation.Translator import clear_state [as 别名]
def test_changing_state(self):
output = []
def listener(undo, do, prev):
prev = list(prev) if prev else None
output.append((undo, do, prev))
d = StenoDictionary()
d[('S', 'P')] = 'hi'
dc = StenoDictionaryCollection()
dc.set_dicts([d])
t = Translator()
t.set_dictionary(dc)
t.translate(stroke('T'))
t.translate(stroke('S'))
s = copy.deepcopy(t.get_state())
t.add_listener(listener)
expected = [([Translation([stroke('S')], None)],
[Translation([stroke('S'), stroke('P')], 'hi')],
[Translation([stroke('T')], None)])]
t.translate(stroke('P'))
self.assertEqual(output, expected)
del output[:]
t.set_state(s)
t.translate(stroke('P'))
self.assertEqual(output, expected)
del output[:]
t.clear_state()
t.translate(stroke('P'))
self.assertEqual(output, [([], [Translation([stroke('P')], None)], None)])
del output[:]
t.set_state(s)
t.translate(stroke('P'))
self.assertEqual(output,
[([],
[Translation([stroke('P')], None)],
[Translation([stroke('S'), stroke('P')], 'hi')])])
示例2: StenoEngine
# 需要导入模块: from plover.translation import Translator [as 别名]
# 或者: from plover.translation.Translator import clear_state [as 别名]
#.........这里部分代码省略.........
for extension_name in extension_list:
log.info('starting `%s` extension', extension_name)
try:
extension = registry.get_plugin('extension', extension_name).obj(self)
extension.start()
except Exception:
log.error('initializing extension `%s` failed', extension_name, exc_info=True)
else:
self._running_extensions[extension_name] = extension
def _stop_extensions(self, extension_list):
for extension_name in list(extension_list):
log.info('stopping `%s` extension', extension_name)
extension = self._running_extensions.pop(extension_name)
extension.stop()
del extension
def _quit(self, code):
self._stop()
self.code = code
self._trigger_hook('quit')
return True
def _toggle_output(self):
self._set_output(not self._is_running)
def _set_output(self, enabled):
if enabled == self._is_running:
return
self._is_running = enabled
if enabled:
self._translator.set_state(self._running_state)
else:
self._translator.clear_state()
if self._machine is not None:
self._machine.set_suppression(enabled)
self._trigger_hook('output_changed', enabled)
def _machine_state_callback(self, machine_state):
self._same_thread_hook(self._on_machine_state_changed, machine_state)
def _machine_stroke_callback(self, steno_keys):
self._same_thread_hook(self._on_stroked, steno_keys)
@with_lock
def _on_machine_state_changed(self, machine_state):
assert machine_state is not None
self._machine_state = machine_state
machine_type = self._config.get_machine_type()
self._trigger_hook('machine_state_changed', machine_type, machine_state)
def _consume_engine_command(self, command):
# The first commands can be used whether plover has output enabled or not.
if command == 'RESUME':
self._set_output(True)
return True
elif command == 'TOGGLE':
self._toggle_output()
return True
elif command == 'QUIT':
self.quit()
return True
if not self._is_running:
return False
# These commands can only be run when plover has output enabled.
if command == 'SUSPEND':
示例3: StenoEngine
# 需要导入模块: from plover.translation import Translator [as 别名]
# 或者: from plover.translation.Translator import clear_state [as 别名]
#.........这里部分代码省略.........
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.
dictionaries_files = config["dictionary_file_names"]
copy_default_dictionaries(dictionaries_files)
dictionaries = self._dictionaries_manager.load(dictionaries_files)
self._dictionaries.set_dicts(dictionaries)
# Trigger `config_changed` hook.
if config_update:
self._trigger_hook("config_changed", config_update)
def _quit(self):
self._stop()
return True
def _toggle_output(self):
self._set_output(not self._is_running)
def _set_output(self, enabled):
if enabled == self._is_running:
return
self._is_running = enabled
if enabled:
self._translator.set_state(self._running_state)
else:
self._translator.clear_state()
if self._machine is not None:
self._machine.set_suppression(enabled)
self._trigger_hook("output_changed", enabled)
def _machine_state_callback(self, machine_state):
self._same_thread_hook(self._on_machine_state_changed, machine_state)
def _machine_stroke_callback(self, steno_keys):
self._same_thread_hook(self._on_stroked, steno_keys)
@with_lock
def _on_machine_state_changed(self, machine_state):
assert machine_state is not None
self._machine_state = machine_state
machine_type = self._config.get_machine_type()
self._trigger_hook("machine_state_changed", machine_type, machine_state)
def _consume_engine_command(self, command):
# The first commands can be used whether plover has output enabled or not.
if command == "RESUME":
self._set_output(True)
return True
elif command == "TOGGLE":
self._toggle_output()
return True
elif command == "QUIT":
self._trigger_hook("quit")
return True
if not self._is_running:
return False
# These commands can only be run when plover has output enabled.
if command == "SUSPEND":
示例4: StenoEngine
# 需要导入模块: from plover.translation import Translator [as 别名]
# 或者: from plover.translation.Translator import clear_state [as 别名]
#.........这里部分代码省略.........
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.
dictionaries_files = config['dictionary_file_names']
dictionaries = self._dictionaries_manager.load(dictionaries_files)
self._dictionaries.set_dicts(dictionaries)
# Trigger `config_changed` hook.
if config_update:
self._trigger_hook('config_changed', config_update)
def _quit(self):
self._stop()
return True
def _toggle_output(self):
self._set_output(not self._is_running)
def _set_output(self, enabled):
if enabled == self._is_running:
return
self._is_running = enabled
if enabled:
self._translator.set_state(self._running_state)
else:
self._translator.clear_state()
if self._machine is not None:
self._machine.set_suppression(enabled)
self._trigger_hook('output_changed', enabled)
def _machine_state_callback(self, machine_state):
self._same_thread_hook(self._on_machine_state_changed, machine_state)
def _machine_stroke_callback(self, steno_keys):
self._same_thread_hook(self._on_stroked, steno_keys)
@with_lock
def _on_machine_state_changed(self, machine_state):
assert machine_state is not None
self._machine_state = machine_state
machine_type = self._config.get_machine_type()
self._trigger_hook('machine_state_changed', machine_type, machine_state)
def _consume_engine_command(self, command):
# The first commands can be used whether plover has output enabled or not.
if command == 'RESUME':
self._set_output(True)
return True
elif command == 'TOGGLE':
self._toggle_output()
return True
elif command == 'QUIT':
self._trigger_hook('quit')
return True
if not self._is_running:
return False
# These commands can only be run when plover has output enabled.
if command == 'SUSPEND':