本文整理汇总了Python中plover.steno_dictionary.StenoDictionaryCollection.get方法的典型用法代码示例。如果您正苦于以下问题:Python StenoDictionaryCollection.get方法的具体用法?Python StenoDictionaryCollection.get怎么用?Python StenoDictionaryCollection.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plover.steno_dictionary.StenoDictionaryCollection
的用法示例。
在下文中一共展示了StenoDictionaryCollection.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dictionary_collection
# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import get [as 别名]
def test_dictionary_collection(self):
dc = StenoDictionaryCollection()
d1 = StenoDictionary()
d1[('S',)] = 'a'
d1[('T',)] = 'b'
d1.path = 'd1'
d2 = StenoDictionary()
d2[('S',)] = 'c'
d2[('W',)] = 'd'
d2.path = 'd2'
dc.set_dicts([d2, d1])
self.assertEqual(dc.lookup(('S',)), 'c')
self.assertEqual(dc.lookup(('W',)), 'd')
self.assertEqual(dc.lookup(('T',)), 'b')
f = lambda k, v: v == 'c'
dc.add_filter(f)
self.assertIsNone(dc.lookup(('S',)))
self.assertEqual(dc.raw_lookup(('S',)), 'c')
self.assertEqual(dc.lookup(('W',)), 'd')
self.assertEqual(dc.lookup(('T',)), 'b')
self.assertEqual(dc.reverse_lookup('c'), [('S',)])
dc.remove_filter(f)
self.assertEqual(dc.lookup(('S',)), 'c')
self.assertEqual(dc.lookup(('W',)), 'd')
self.assertEqual(dc.lookup(('T',)), 'b')
self.assertEqual(dc.reverse_lookup('c'), [('S',)])
dc.set(('S',), 'e')
self.assertEqual(dc.lookup(('S',)), 'e')
self.assertEqual(d2[('S',)], 'e')
dc.set(('S',), 'f', path='d1')
self.assertEqual(dc.lookup(('S',)), 'e')
self.assertEqual(d1[('S',)], 'f')
self.assertEqual(d2[('S',)], 'e')
# Iterating on a StenoDictionaryCollection is
# the same as iterating on its dictionaries' paths.
self.assertEqual(list(dc), ['d2', 'd1'])
# Test get and [].
self.assertEqual(dc.get('d1'), d1)
self.assertEqual(dc['d1'], d1)
self.assertEqual(dc.get('invalid'), None)
with self.assertRaises(KeyError):
dc['invalid']
示例2: test_dictionary_collection
# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import get [as 别名]
def test_dictionary_collection():
d1 = StenoDictionary()
d1[('S',)] = 'a'
d1[('T',)] = 'b'
d1.path = 'd1'
d2 = StenoDictionary()
d2[('S',)] = 'c'
d2[('W',)] = 'd'
d2.path = 'd2'
dc = StenoDictionaryCollection([d2, d1])
assert dc.lookup(('S',)) == 'c'
assert dc.lookup(('W',)) == 'd'
assert dc.lookup(('T',)) == 'b'
f = lambda k, v: v == 'c'
dc.add_filter(f)
assert dc.lookup(('S',)) is None
assert dc.raw_lookup(('S',)) == 'c'
assert dc.lookup(('W',)) == 'd'
assert dc.lookup(('T',)) == 'b'
assert dc.reverse_lookup('c') == [('S',)]
dc.remove_filter(f)
assert dc.lookup(('S',)) == 'c'
assert dc.lookup(('W',)) == 'd'
assert dc.lookup(('T',)) == 'b'
assert dc.reverse_lookup('c') == [('S',)]
dc.set(('S',), 'e')
assert dc.lookup(('S',)) == 'e'
assert d2[('S',)] == 'e'
dc.set(('S',), 'f', path='d1')
assert dc.lookup(('S',)) == 'e'
assert d1[('S',)] == 'f'
assert d2[('S',)] == 'e'
# Iterating on a StenoDictionaryCollection is
# the same as iterating on its dictionaries' paths.
assert list(dc) == ['d2', 'd1']
# Test get and [].
assert dc.get('d1') == d1
assert dc['d1'] == d1
assert dc.get('invalid') is None
with pytest.raises(KeyError):
dc['invalid']
示例3: StenoEngine
# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import get [as 别名]
class StenoEngine(object):
HOOKS = '''
stroked
translated
machine_state_changed
output_changed
config_changed
dictionaries_loaded
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._keyboard_emulation = keyboard_emulation
self._hooks = { hook: [] for hook in self.HOOKS }
self._running_extensions = {}
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):
self._stop_extensions(self._running_extensions.keys())
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 _set_dictionaries(self, dictionaries):
def dictionaries_changed(l1, l2):
if len(l1) != len(l2):
return True
for d1, d2 in zip(l1, l2):
if d1 is not d2:
return True
return False
if not dictionaries_changed(dictionaries, self._dictionaries.dicts):
# No change.
return
self._dictionaries = StenoDictionaryCollection(dictionaries)
self._translator.set_dictionary(self._dictionaries)
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.
#.........这里部分代码省略.........