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


Python StenoDictionaryCollection.first_writable方法代码示例

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


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

示例1: test_dictionary_collection_writeable

# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import first_writable [as 别名]
 def test_dictionary_collection_writeable(self):
     d1 = StenoDictionary()
     d1[('S',)] = 'a'
     d1[('T',)] = 'b'
     d2 = StenoDictionary()
     d2[('S',)] = 'c'
     d2[('W',)] = 'd'
     d2.readonly = True
     dc = StenoDictionaryCollection([d2, d1])
     self.assertEqual(dc.first_writable(), d1)
     dc.set(('S',), 'A')
     self.assertEqual(d1[('S',)], 'A')
     self.assertEqual(d2[('S',)], 'c')
开发者ID:MartyGentillon,项目名称:plover,代码行数:15,代码来源:test_steno_dictionary.py

示例2: test_dictionary_collection_writeable

# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import first_writable [as 别名]
def test_dictionary_collection_writeable():
    d1 = StenoDictionary()
    d1[('S',)] = 'a'
    d1[('T',)] = 'b'
    d2 = StenoDictionary()
    d2[('S',)] = 'c'
    d2[('W',)] = 'd'
    d2.readonly = True
    dc = StenoDictionaryCollection([d2, d1])
    assert dc.first_writable() == d1
    dc.set(('S',), 'A')
    assert d1[('S',)] == 'A'
    assert d2[('S',)] == 'c'
开发者ID:DanLanglois,项目名称:plover,代码行数:15,代码来源:test_steno_dictionary.py

示例3: StenoEngine

# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import first_writable [as 别名]

#.........这里部分代码省略.........
    def join(self):
        return self.code

    @with_lock
    def machine_specific_options(self, machine_type):
        return self._config.get_machine_specific_options(machine_type)

    @with_lock
    def system_keymap(self, machine_type, system_name):
        return self._config.get_system_keymap(machine_type, system_name)

    @with_lock
    def lookup(self, translation):
        return self._dictionaries.lookup(translation)

    @with_lock
    def raw_lookup(self, translation):
        return self._dictionaries.raw_lookup(translation)

    @with_lock
    def reverse_lookup(self, translation):
        matches = self._dictionaries.reverse_lookup(translation)
        return [] if matches is None else matches

    @with_lock
    def casereverse_lookup(self, translation):
        matches = self._dictionaries.casereverse_lookup(translation)
        return set() if matches is None else matches

    @with_lock
    def add_dictionary_filter(self, dictionary_filter):
        self._dictionaries.add_filter(dictionary_filter)

    @with_lock
    def remove_dictionary_filter(self, dictionary_filter):
        self._dictionaries.remove_filter(dictionary_filter)

    @with_lock
    def get_suggestions(self, translation):
        return Suggestions(self._dictionaries).find(translation)

    @property
    @with_lock
    def translator_state(self):
        return self._translator.get_state()

    @translator_state.setter
    @with_lock
    def translator_state(self, state):
        self._translator.set_state(state)

    @with_lock
    def clear_translator_state(self, undo=False):
        if undo:
            state = self._translator.get_state()
            self._formatter.format(state.translations, (), None)
        self._translator.clear_state()

    @property
    @with_lock
    def starting_stroke_state(self):
        return StartingStrokeState(self._formatter.start_attached,
                                   self._formatter.start_capitalized)

    @starting_stroke_state.setter
    @with_lock
    def starting_stroke_state(self, state):
        self._formatter.start_attached = state.attach
        self._formatter.start_capitalized = state.capitalize

    @with_lock
    def add_translation(self, strokes, translation, dictionary_path=None):
        if dictionary_path is None:
            dictionary_path = self._dictionaries.first_writable().path
        self._dictionaries.set(strokes, translation, path=dictionary_path)
        self._dictionaries.save(path_list=(dictionary_path,))

    @property
    @with_lock
    def dictionaries(self):
        return self._dictionaries

    # Hooks.

    def _trigger_hook(self, hook, *args, **kwargs):
        for callback in self._hooks[hook]:
            try:
                callback(*args, **kwargs)
            except Exception:
                log.error('hook %r callback %r failed',
                          hook, callback,
                          exc_info=True)

    @with_lock
    def hook_connect(self, hook, callback):
        self._hooks[hook].append(callback)

    @with_lock
    def hook_disconnect(self, hook, callback):
        self._hooks[hook].remove(callback)
开发者ID:ohAitch,项目名称:plover,代码行数:104,代码来源:engine.py


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