本文整理汇总了Python中kiwi.ui.widgets.combo.ProxyComboBox.select_item_by_data方法的典型用法代码示例。如果您正苦于以下问题:Python ProxyComboBox.select_item_by_data方法的具体用法?Python ProxyComboBox.select_item_by_data怎么用?Python ProxyComboBox.select_item_by_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kiwi.ui.widgets.combo.ProxyComboBox
的用法示例。
在下文中一共展示了ProxyComboBox.select_item_by_data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestComboBox
# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import select_item_by_data [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()), [])
示例2: StringSearchFilter
# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import select_item_by_data [as 别名]
#.........这里部分代码省略.........
_("Add a filter"))
self.entry.set_icon_from_icon_name(Gtk.EntryIconPosition.SECONDARY,
'edit-clear-symbolic')
self.entry.set_icon_tooltip_text(Gtk.EntryIconPosition.SECONDARY,
_("Clear the search"))
self.entry.connect("icon-release", self._on_entry__icon_release)
self.entry.connect('activate', self._on_entry__activate)
self.entry.connect('changed', self._on_entry__changed)
if chars:
self.entry.set_width_chars(chars)
self.pack_start(self.entry, False, False, 6)
self.entry.show()
# Default filter will be only contains all. When advanced filter is enabled it will add
# other options
self._add_option(ContainsAll)
self.mode.select_item_by_position(0)
def _add_option(self, option_type):
option = option_type()
self.mode.append_item(option.name, option_type)
self._options[option_type] = option
#
# Callbacks
#
def _on_mode__content_changed(self, combo):
self.emit('changed')
def _on_entry__activate(self, entry):
self.emit('changed')
def _on_entry__changed(self, entry):
entry.props.secondary_icon_sensitive = bool(entry.get_text())
def _position_filter_menu(self, data):
window = self.entry.get_icon_window(Gtk.EntryIconPosition.PRIMARY)
x, y = window.get_origin()
y += window.get_size()[1]
border = self.entry.style_get_property('progress-border')
if border is not None:
y += border.bottom
return (x, y, True)
def _on_entry__icon_release(self, entry, icon_pos, event):
if icon_pos == Gtk.EntryIconPosition.SECONDARY:
entry.set_text("")
entry.grab_focus()
self.emit('changed')
elif icon_pos == Gtk.EntryIconPosition.PRIMARY:
# We don't need create popup filters if haven't search columns.
if (not self._container or not hasattr(self._container, 'menu') or
not self._container.menu):
return
self._container.menu.popup(None, None, None,
self._position_filter_menu, 0, event.time)
#
# SearchFilter
#
def get_state(self):
option = self.mode.get_selected_data()
return StringQueryState(filter=self,
text=str(self.entry.get_text()),
mode=option and option.mode)
def set_state(self, text, mode=None):
self.entry.set_text(text)
for i in self.mode.get_model_items().values():
if i.mode == mode:
self.mode.select_item_by_data(i)
break
def get_title_label(self):
return self.title_label
def get_mode_combo(self):
return self.mode
def get_description(self):
desc = self.entry.get_text()
if desc:
mode = self.mode.get_selected_label()
return '%s %s "%s"' % (self.title_label.get_text(), mode, desc,)
#
# Public API
#
def enable_advanced(self):
# Do not show the funnel icon if its an advanced filter
self.entry.set_icon_from_pixbuf(Gtk.EntryIconPosition.PRIMARY, None)
for option in [ContainsExactly, IdenticalTo, DoesNotContain]:
self._add_option(option)
self.mode.show()
def set_label(self, label):
self.title_label.set_text(label)