本文整理汇总了Python中kiwi.ui.widgets.combo.ProxyComboBox类的典型用法代码示例。如果您正苦于以下问题:Python ProxyComboBox类的具体用法?Python ProxyComboBox怎么用?Python ProxyComboBox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProxyComboBox类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_combo
def add_combo(self, data=None):
"""Add a combo for selecting an option"""
combo = ProxyComboBox()
self.pack_start(combo, False, False, 0)
if data:
combo.prefill(data)
return combo
示例2: __init__
def __init__(self, label='', values=None):
"""
Create a new ComboSearchFilter object.
:param label: label of the search filter
:param values: items to put in the combo, see
:class:`kiwi.ui.widgets.combo.ProxyComboBox.prefill`
"""
self._block_updates = False
SearchFilter.__init__(self, label=label)
label = gtk.Label(label)
self.pack_start(label, False, False)
label.show()
self.title_label = label
# We create the mode, but it will only be added to this box when
# enable_advanced is called
self.mode = ProxyComboBox()
self.mode.connect('content-changed', self._on_mode__content_changed)
for option in (ComboEquals, ComboDifferent):
self.add_option(option)
self.mode.select_item_by_position(0)
self.combo = ProxyComboBox()
if values:
self.update_values(values)
self.combo.connect('content-changed', self._on_combo__content_changed)
self.pack_start(self.combo, False, False, 6)
self.combo.show()
示例3: _add_options
def _add_options(self, attr, pos):
combo = ProxyComboBox()
label = gtk.Label(attr.attribute.description)
# This dictionary is populated with the purpose of tests
self._widgets[attr.attribute.description] = combo
self.attr_table.attach(label, 0, 1, pos, pos + 1, 0, 0, 0, 0)
self.attr_table.attach(combo, 1, 2, pos, pos + 1, 0, gtk.EXPAND | gtk.FILL, 0, 0)
self.attr_table.show_all()
self._fill_options(combo, attr)
combo.connect('changed', self._on_combo_selection__changed)
示例4: ComboSearchFilter
class ComboSearchFilter(SearchFilter):
"""
- a label
- a combo with a set of predefined item to select from
"""
__gtype_name__ = 'ComboSearchFilter'
def __init__(self, label='', values=None):
"""
Create a new ComboSearchFilter object.
@param name: name of the search filter
@param values: items to put in the combo, see
L{kiwi.ui.widgets.combo.ProxyComboBox.prefill}
"""
SearchFilter.__init__(self, label=label)
label = gtk.Label(label)
self.pack_start(label, False, False)
label.show()
self.title_label = label
self.combo = ProxyComboBox()
if values:
self.combo.prefill(values)
self.combo.connect('content-changed', self._on_combo__content_changed)
self.pack_start(self.combo, False, False, 6)
self.combo.show()
#
# SearchFilter
#
def get_state(self):
return NumberQueryState(filter=self,
value=self.combo.get_selected_data())
def get_title_label(self):
return self.title_label
def get_mode_combo(self):
return self.combo
#
# Public API
#
def select(self, data):
"""
selects an item in the combo
@param data: what to select
"""
self.combo.select(data)
#
# Callbacks
#
def _on_combo__content_changed(self, mode):
self.emit('changed')
示例5: test_prefill_attr_none
def test_prefill_attr_none(self):
model = Settable(attr=None)
proxy = Proxy(FakeView(), model)
combo = ProxyComboBox()
combo.data_type = int
combo.model_attribute = 'attr'
combo.prefill([('foo', 10), ('bar', 20)])
proxy.add_widget('attr', combo)
# Even though attr is None, the combo doesn't allow something
# not prefilled in it to be selected. In this case, it will select
# the first item (prefill actually does that) instead.
self.assertEqual(model.attr, 10)
示例6: _setup_work_orders_widgets
def _setup_work_orders_widgets(self):
self._work_orders_hbox = gtk.HBox(spacing=6)
self.item_vbox.pack_start(self._work_orders_hbox, False, True, 6)
self.item_vbox.reorder_child(self._work_orders_hbox, 0)
self._work_orders_hbox.show()
label = gtk.Label(_("Work order:"))
self._work_orders_hbox.pack_start(label, False, True)
data = []
for wo in self.wizard.workorders:
# The work order might be already approved if we are editing a sale
if wo.can_approve():
wo.approve()
self.setup_work_order(wo)
data.append([wo.description, wo])
if len(data) <= _MAX_WORK_ORDERS_FOR_RADIO:
self.work_orders_combo = None
for desc, wo in data:
self._add_work_order_radio(desc, wo)
else:
self.work_orders_combo = ProxyComboBox()
self.work_orders_combo.prefill(data)
self._selected_workorder = self.work_orders_combo.get_selected()
self._work_orders_hbox.pack_start(self.work_orders_combo,
False, False)
self._work_orders_hbox.show_all()
示例7: _update_account_type
def _update_account_type(self, account_type):
if not self.account_type.get_sensitive():
return
if account_type != Account.TYPE_BANK:
self._remove_bank_widgets()
self._remove_bank_option_widgets()
self.code.set_sensitive(True)
return
self.code.set_sensitive(False)
self.bank_type = ProxyComboBox()
self._add_widget(api.escape(_("Bank:")), self.bank_type)
self.bank_type.connect('content-changed',
self._on_bank_type__content_changed)
self.bank_type.show()
banks = [(_('Generic'), None)]
banks.extend([(b.description,
b.bank_number) for b in get_all_banks()])
self.bank_type.prefill(banks)
if self.model.bank:
try:
self.bank_type.select(self.model.bank.bank_number)
except KeyError:
self.bank_type.select(None)
self._update_bank_type()
示例8: __init__
def __init__(self, label, chars=0):
"""
Create a new StringSearchFilter object.
@param label: label of the search filter
@param chars: maximum number of chars used by the search entry
"""
SearchFilter.__init__(self, label=label)
self.title_label = gtk.Label(label)
self.pack_start(self.title_label, False, False)
self.title_label.show()
self._options = {}
self.mode = ProxyComboBox()
self.mode.connect('content-changed', self._on_mode__content_changed)
self.pack_start(self.mode, False, False, 6)
self.entry = gtk.Entry()
self.entry.connect('activate', self._on_entry__activate)
if chars:
self.entry.set_width_chars(chars)
self.pack_start(self.entry, False, False, 6)
self.entry.show()
for option in (Contains, DoesNotContain):
self._add_option(option)
self.mode.select_item_by_position(0)
示例9: __init__
def __init__(self):
self._js_data = None
self._js_options = None
self._current = None
gtk.Window.__init__(self)
self.set_size_request(800, 480)
self.vbox = gtk.VBox()
self.add(self.vbox)
self.vbox.show()
hbox = gtk.HBox()
self.vbox.pack_start(hbox, False, False, 6)
hbox.show()
label = gtk.Label('Period:')
hbox.pack_start(label, False, False, 6)
label.show()
self.chart_type = ProxyComboBox()
self.chart_type.connect(
'content-changed',
self._on_chart_type__content_changed)
hbox.pack_start(self.chart_type, False, False, 6)
self.chart_type.show()
self.period_values = ProxyComboBox()
self.period_values.connect(
'content-changed',
self._on_period_values__content_changed)
hbox.pack_start(self.period_values, False, False, 6)
self.period_values.show()
self._view = WebView()
self._view.get_view().connect(
'load-finished',
self._on_view__document_load_finished)
self.vbox.pack_start(self._view, True, True)
self.results = ObjectList()
self.results.connect(
'row-activated',
self._on_results__row_activated)
self.vbox.pack_start(self.results, True, True)
self._setup_daemon()
示例10: _setup_options_combo_slave
def _setup_options_combo_slave(self):
widget = ProxyComboBox()
widget.props.sensitive = self.sensitive
widget.model_attribute = "field_value"
widget.data_type = unicode
data = [(value, unicode(key)) for key, value in self.detail.options.items()]
widget.prefill(data)
self.proxy.add_widget("field_value", widget)
self.container.add(widget)
widget.show()
示例11: __init__
def __init__(self, store, field, other_fields):
"""
:param store: a storm store if its needed
:param field: the field that is being edited
:param other_fields: other fields available for math operations
"""
assert len(self.operations)
self._store = store
self._other_fields = other_fields
self._oper = None
self._field = field
super(Editor, self).__init__(spacing=6)
self.operations_combo = ProxyComboBox()
self.pack_start(self.operations_combo, True, True, 0)
self.operations_combo.connect('changed', self._on_operation_changed)
for oper in self.operations:
self.operations_combo.append_item(oper.label, oper)
self.operations_combo.select(self.operations[0])
self.show_all()
示例12: __init__
def __init__(self, label='', values=None):
"""
Create a new ComboSearchFilter object.
:param label: label of the search filter
:param values: items to put in the combo, see
:class:`kiwi.ui.widgets.combo.ProxyComboBox.prefill`
"""
self._block_updates = False
SearchFilter.__init__(self, label=label)
label = gtk.Label(label)
self.pack_start(label, False, False)
label.show()
self.title_label = label
self.combo = ProxyComboBox()
if values:
self.update_values(values)
self.combo.connect('content-changed', self._on_combo__content_changed)
self.pack_start(self.combo, False, False, 6)
self.combo.show()
示例13: __init__
def __init__(self, label, chars=0, container=None):
"""
Create a new StringSearchFilter object.
:param label: label of the search filter
:param chars: maximum number of chars used by the search entry
"""
self._container = container
SearchFilter.__init__(self, label=label)
self.title_label = Gtk.Label(label=label)
self.pack_start(self.title_label, False, False, 0)
self.title_label.show()
self._options = {}
self.mode = ProxyComboBox()
self.mode.connect('content-changed', self._on_mode__content_changed)
self.pack_start(self.mode, False, False, 6)
self.entry = Gtk.Entry()
self.entry.set_placeholder_text(_("Search"))
self.entry.props.secondary_icon_sensitive = False
self.entry.set_icon_from_icon_name(Gtk.EntryIconPosition.PRIMARY,
'fa-filter-symbolic')
self.entry.set_icon_tooltip_text(Gtk.EntryIconPosition.PRIMARY,
_("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)
示例14: Editor
class Editor(Gtk.HBox):
"""Base class for field editors
Subclasses must define a list of operations and a datatype
"""
operations = []
data_type = None
def __init__(self, store, field, other_fields):
"""
:param store: a storm store if its needed
:param field: the field that is being edited
:param other_fields: other fields available for math operations
"""
assert len(self.operations)
self._store = store
self._other_fields = other_fields
self._oper = None
self._field = field
super(Editor, self).__init__(spacing=6)
self.operations_combo = ProxyComboBox()
self.pack_start(self.operations_combo, True, True, 0)
self.operations_combo.connect('changed', self._on_operation_changed)
for oper in self.operations:
self.operations_combo.append_item(oper.label, oper)
self.operations_combo.select(self.operations[0])
self.show_all()
def set_field(self, field):
assert field.data_type == self.data_type
self._field = field
self._oper.set_field(field)
def _on_operation_changed(self, combo):
if self._oper is not None:
# Remove previous operation
self.remove(self._oper)
self._oper = combo.get_selected()(self._store, self._field,
self._other_fields)
self.pack_start(self._oper, True, True, 0)
def apply_operation(self, item):
return self._oper.apply_operation(item)
示例15: TestComboBox
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()), [])