本文整理汇总了Python中kiwi.ui.widgets.combo.ProxyComboBox.get_model方法的典型用法代码示例。如果您正苦于以下问题:Python ProxyComboBox.get_model方法的具体用法?Python ProxyComboBox.get_model怎么用?Python ProxyComboBox.get_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kiwi.ui.widgets.combo.ProxyComboBox
的用法示例。
在下文中一共展示了ProxyComboBox.get_model方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestComboBox
# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import get_model [as 别名]
class TestComboBox(unittest.TestCase):
def setUp(self):
self.combo = ProxyComboBox()
def _prefill(self):
self.combo.prefill((('Johan', 1981),
('Lorenzo', 1979),
('Christian', 1976)))
def testPrefill(self):
self.combo.prefill(('foo', 'bar'))
model = self.combo.get_model()
self.assertEqual(tuple(model[0]), ('foo', None))
self.assertEqual(tuple(model[1]), ('bar', None))
def testPrefillWithData(self):
self.combo.prefill((('foo', 42), ('bar', 138)))
model = self.combo.get_model()
self.assertEqual(tuple(model[0]), ('foo', 42))
self.assertEqual(tuple(model[1]), ('bar', 138))
self.combo.prefill([])
self.assertEqual(len(self.combo.get_model()), 0)
self.assertEqual(len(model), 0)
self.assertEqual(len(self.combo), 0)
def testSelectItemByPosition(self):
self._prefill()
self.combo.select_item_by_position(1)
model = self.combo.get_model()
iter = self.combo.get_active_iter()
self.assertEqual(model.get_value(iter, 0), 'Lorenzo')
self.assertEqual(model.get_value(iter, 1), 1979)
self.assertRaises(KeyError, self.combo.select_item_by_label, 4)
def testSelectItemByLabel(self):
self._prefill()
self.combo.select_item_by_label('Christian')
model = self.combo.get_model()
iter = self.combo.get_active_iter()
rowNo = model.get_path(iter)[0]
self.assertEqual(rowNo, 2)
self.assertRaises(KeyError, self.combo.select_item_by_label, 'Salgado')
def testSelectByData(self):
self._prefill()
self.combo.select_item_by_data(1976)
model = self.combo.get_model()
iter = self.combo.get_active_iter()
rowNo = model.get_path(iter)[0]
self.assertEqual(rowNo, 2)
self.assertEqual(model.get_value(iter, 0), 'Christian')
self.assertEqual(model.get_value(iter, 1), 1976)
self.assertRaises(KeyError, self.combo.select_item_by_data, 1980)
def testGetSelectedData(self):
self._prefill()
self.combo.select_item_by_position(0)
self.assertEqual(self.combo.get_selected_data(), 1981)
self.assertRaises(TypeError,
self.combo.select_item_by_position, 'foobar')
def testGetSelectedLabel(self):
self._prefill()
def testClear(self):
self._prefill()
self.combo.clear()
self.assertEqual(map(list, self.combo.get_model()), [])