本文整理汇总了Python中plover.translation.Translator.remove_listener方法的典型用法代码示例。如果您正苦于以下问题:Python Translator.remove_listener方法的具体用法?Python Translator.remove_listener怎么用?Python Translator.remove_listener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plover.translation.Translator
的用法示例。
在下文中一共展示了Translator.remove_listener方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_listeners
# 需要导入模块: from plover.translation import Translator [as 别名]
# 或者: from plover.translation.Translator import remove_listener [as 别名]
def test_listeners():
output1 = []
def listener1(undo, do, prev):
output1.append((undo, do, prev))
output2 = []
def listener2(undo, do, prev):
output2.append((undo, do, prev))
t = Translator()
s = stroke('S')
tr = Translation([s], None)
expected_output = [([], [tr], [tr])]
t.translate(s)
t.add_listener(listener1)
t.translate(s)
assert output1 == expected_output
del output1[:]
t.add_listener(listener2)
t.translate(s)
assert output1 == expected_output
assert output2 == expected_output
del output1[:]
del output2[:]
t.add_listener(listener2)
t.translate(s)
assert output1 == expected_output
assert output2 == expected_output
del output1[:]
del output2[:]
t.remove_listener(listener1)
t.translate(s)
assert output1 == []
assert output2 == expected_output
del output1[:]
del output2[:]
t.remove_listener(listener2)
t.translate(s)
assert output1 == []
assert output2 == []
示例2: test_listeners
# 需要导入模块: from plover.translation import Translator [as 别名]
# 或者: from plover.translation.Translator import remove_listener [as 别名]
def test_listeners(self):
output1 = []
def listener1(undo, do, prev):
output1.append((undo, do, prev))
output2 = []
def listener2(undo, do, prev):
output2.append((undo, do, prev))
t = Translator()
s = stroke('S')
tr = Translation([s], None)
expected_output = [([], [tr], [tr])]
t.translate(s)
t.add_listener(listener1)
t.translate(s)
self.assertEqual(output1, expected_output)
del output1[:]
t.add_listener(listener2)
t.translate(s)
self.assertEqual(output1, expected_output)
self.assertEqual(output2, expected_output)
del output1[:]
del output2[:]
t.add_listener(listener2)
t.translate(s)
self.assertEqual(output1, expected_output)
self.assertEqual(output2, expected_output)
del output1[:]
del output2[:]
t.remove_listener(listener1)
t.translate(s)
self.assertEqual(output1, [])
self.assertEqual(output2, expected_output)
del output1[:]
del output2[:]
t.remove_listener(listener2)
t.translate(s)
self.assertEqual(output1, [])
self.assertEqual(output2, [])
示例3: test_translator
# 需要导入模块: from plover.translation import Translator [as 别名]
# 或者: from plover.translation.Translator import remove_listener [as 别名]
#.........这里部分代码省略.........
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'
t.translate(stroke('*'))
assert out.get() == 't4'
t.translate(stroke('*'))
assert out.get() == 't3'
t.translate(stroke('*'))
assert out.get() == 't1'
t.translate(stroke('*'))
assert out.get() == ''
d.clear()
s = stroke('S')
t.translate(s)
t.translate(s)
t.translate(s)
t.translate(s)
s = stroke('*')
t.translate(s)
t.translate(s)
t.translate(s)
t.translate(s)
# Not enough undo to clear output.
assert out.get() == 'S ' + BACK_STRING
out.clear()
t.remove_listener(out.write)
t.translate(stroke('S'))
assert out.get() == ''