本文整理汇总了Python中kiwi.ui.widgets.combo.ProxyComboBox.connect方法的典型用法代码示例。如果您正苦于以下问题:Python ProxyComboBox.connect方法的具体用法?Python ProxyComboBox.connect怎么用?Python ProxyComboBox.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kiwi.ui.widgets.combo.ProxyComboBox
的用法示例。
在下文中一共展示了ProxyComboBox.connect方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ComboSearchFilter
# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import connect [as 别名]
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')
示例2: _add_options
# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import connect [as 别名]
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)
示例3: Editor
# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import connect [as 别名]
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)
示例4: ChartDialog
# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import connect [as 别名]
class ChartDialog(gtk.Window):
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()
@api.async
def _setup_daemon(self):
daemon = yield start_daemon()
self._daemon_uri = daemon.base_uri
proxy = daemon.get_client()
yield proxy.callRemote('start_webservice')
self.chart_type.prefill([
('Year', 'YearlyPayments'),
('Month', 'MonthlyPayments'),
('Day', 'DailyPayments'),
])
@api.async
def _invoke_chart(self, chart_type_name, **report_kwargs):
def _get_chart_url(**kwargs):
params = []
for key, value in kwargs.items():
params.append(key + '=' + str(value))
return '%s/web/chart.json?%s' % (
self._daemon_uri, '&'.join(params))
url = _get_chart_url(type=chart_type_name, **report_kwargs)
page = yield getPage(url)
data = json.loads(page)
api.asyncReturn(data)
def _render_chart(self, chart_class, response):
self._render_javascript(chart_class, response)
self._render_objectlist(chart_class, response)
def _render_javascript(self, chart_class, response):
ticks = [item['short_title'] for item in response['items']]
self._js_data = response['data']
options = {}
options['description'] = response['description']
options['series'] = [dict(label=c['title']) for c in chart_class.columns][1:]
options['xaxis_ticks'] = ticks
self._js_options = options
self._view.load_uri('%s/web/static/chart.html' % (
self._daemon_uri,))
def _render_objectlist(self, chart_class, response):
columns = []
for kwargs in chart_class.columns:
kwargs = kwargs.copy()
name = kwargs.pop('name')
#.........这里部分代码省略.........
示例5: MassEditorWidget
# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import connect [as 别名]
class MassEditorWidget(Gtk.HBox):
_editors = {
currency: DecimalEditor,
Decimal: DecimalEditor,
str: UnicodeEditor,
datetime.date: DateEditor,
object: ObjectEditor,
}
def __init__(self, store, fields, results):
self._store = store
self._editor = None
self._fields = fields
self._results = results
super(MassEditorWidget, self).__init__(spacing=6)
self._setup_widgets()
def _filter_fields(self, data_type):
return [f for f in self._fields if f.data_type == data_type]
def _setup_editor(self, field):
# Reuse editor if its possible (not when data_type is an object, since
# that requires changing the reference values)
if (self._editor and field.data_type is not object and
self._editor.data_type == field.data_type):
self._editor.set_field(field)
return
if self._editor:
self.editor_placeholder.remove(self._editor)
other_fields = self._filter_fields(field.data_type)
klass = self._editors[field.data_type]
self._editor = klass(self._store, field, other_fields)
self.editor_placeholder.add(self._editor)
def _setup_widgets(self):
label = Gtk.Label(label=_('Update'))
self.pack_start(label, False, False, 0)
self.field_combo = ProxyComboBox()
self.field_combo.connect('changed', self._on_field_combo__changed)
self.pack_start(self.field_combo, False, False, 0)
self.editor_placeholder = Gtk.EventBox()
self.pack_start(self.editor_placeholder, False, False, 0)
self.apply_button = Gtk.Button(stock=Gtk.STOCK_APPLY)
self.apply_button.connect('clicked', self._on_apply_button__clicked)
self.pack_start(self.apply_button, False, False, 0)
for field in self._fields:
# Don't let the user edit unique fields for now
if field.unique or field.read_only:
continue
self.field_combo.append_item(field.label, field)
self.field_combo.select_item_by_position(0)
def _apply(self):
marker('Updating values')
for i in self._results:
self._editor.apply_operation(i)
self._results.refresh(i)
marker('Done updating values')
#
# Public API
#
def get_changed_objects(self):
"""Returns a set of all the changed objects"""
objs = set()
for field in self._fields:
objs.update(field.new_values.keys())
return objs
#
# BaseEditorSlave
#
def confirm(self, dialog):
marker('Saving data')
objs = self.get_changed_objects()
total = len(objs)
for i, obj in enumerate(objs):
for field in self._fields:
field.save_value(obj)
yield i, total
# Flush soon, so that any errors triggered by database constraints
# pop up.
self._store.flush()
marker('Done saving data')
#
# Callbacks
#
def _on_field_combo__changed(self, combo):
self._setup_editor(combo.get_selected())
def _on_apply_button__clicked(self, button):
#.........这里部分代码省略.........
示例6: NumberSearchFilter
# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import connect [as 别名]
class NumberSearchFilter(SearchFilter):
"""
A filter which helps you to search by a number interval.
"""
__gtype_name__ = 'NumberSearchFilter'
def __init__(self, label=''):
"""
Create a new NumberSearchFilter object.
@param label: name of the search filter
"""
self._options = {}
SearchFilter.__init__(self, label=label)
self.title_label = gtk.Label(label)
self.title_label.set_alignment(1.0, 0.5)
self.pack_start(self.title_label, False, False)
self.title_label.show()
self.mode = ProxyComboBox()
self.mode.connect('content-changed', self._on_mode__content_changed)
self.pack_start(self.mode, False, False, 6)
self.mode.show()
self.start = gtk.SpinButton(climb_rate=1.0)
self.start.get_adjustment().step_increment = 1.0
self.start.set_range(-sys.maxint-1, sys.maxint)
self.pack_start(self.start, False, False, 6)
self.start.show()
self.start.connect_after('activate', self._on_entry__activate)
self.and_label = gtk.Label(_("And"))
self.pack_start(self.and_label, False, False)
self.and_label.show()
self.end = gtk.SpinButton(climb_rate=1.0)
self.end.get_adjustment().step_increment = 1.0
self.end.set_range(-sys.maxint-1, sys.maxint)
self.pack_start(self.end, False, False, 6)
self.end.show()
self.end.connect_after('activate', self._on_entry__activate)
for option in (LowerThan, EqualsTo, GreaterThan, Between):
self.add_option(option)
self.mode.select_item_by_position(0)
def set_digits(self, digits):
"""
Number of decimal place to be displayed
@param digits: number of decimal places
"""
self.start.set_digits(digits)
self.end.set_digits(digits)
#
# Private
#
def _update_visibility(self):
option = self.mode.get_selected_data()
numbers = option.numbers
if numbers == 0:
self.start.hide()
self.and_label.hide()
self.end.hide()
elif numbers == 1:
self.start.show()
self.and_label.hide()
self.end.hide()
elif numbers == 2:
self.start.show()
self.and_label.show()
self.end.show()
#
# Callbacks
#
def _on_entry__activate(self, entry):
self.emit('changed')
def _on_mode__content_changed(self, combo):
self._update_visibility()
self.emit('changed')
#
# SearchFilter
#
def get_state(self):
# Using Decimals for better precision.
start_value = Decimal("%.2f" % self.start.get_value())
end_value = Decimal("%.2f" % self.end.get_value())
option = self.mode.get_selected_data()
start, end = option().get_interval(start_value, end_value)
return NumberIntervalQueryState(filter=self, start=start, end=end)
#.........这里部分代码省略.........
示例7: StringSearchFilter
# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import connect [as 别名]
class StringSearchFilter(SearchFilter):
"""
- a label
- an entry
@ivar entry: the entry
@ivar label: the label
"""
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)
def _add_option(self, option_type, position=-2):
option = option_type()
num = len(self.mode) + position
self.mode.insert_item(num, 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')
#
# SearchFilter
#
def get_state(self):
option = self.mode.get_selected_data()
return StringQueryState(filter=self,
text=self.entry.get_text(),
mode=option.mode)
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_advaced(self):
self.mode.show()
def set_label(self, label):
self.title_label.set_text(label)
示例8: DateSearchFilter
# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import connect [as 别名]
class DateSearchFilter(SearchFilter):
"""
A filter which helps you to search by a date interval.
Can be customized through add_option.
"""
__gtype_name__ = 'DateSearchFilter'
class Type(enum):
(USER_DAY,
USER_INTERVAL) = range(100, 102)
def __init__(self, label=''):
"""
Create a new DateSearchFilter object.
@param label: name of the search filter
"""
self._options = {}
SearchFilter.__init__(self, label=label)
self.title_label = gtk.Label(label)
self.pack_start(self.title_label, False, False)
self.title_label.show()
self.mode = ProxyComboBox()
self.mode.connect(
'content-changed',
self._on_mode__content_changed)
self.pack_start(self.mode, False, False, 6)
self.mode.show()
self.from_label = gtk.Label(_("From:"))
self.pack_start(self.from_label, False, False)
self.from_label.show()
self.start_date = ProxyDateEntry()
self._start_changed_id = self.start_date.connect(
'content-changed', self._on_start_date__changed)
self.pack_start(self.start_date, False, False, 6)
self.start_date.show()
self.to_label = gtk.Label(_("To:"))
self.pack_start(self.to_label, False, False)
self.to_label.show()
self.end_date = ProxyDateEntry()
self._end_changed_id = self.end_date.connect(
'content-changed', self._on_end_date__changed)
self.pack_start(self.end_date, False, False, 6)
self.end_date.show()
self.add_custom_options()
for option in (Any, Today, Yesterday, LastWeek, LastMonth):
self.add_option(option)
self.mode.select_item_by_position(0)
#
# SearchFilter
#
def get_state(self):
start = self.start_date.get_date()
end = self.end_date.get_date()
if start == end:
return DateQueryState(filter=self, date=start)
return DateIntervalQueryState(filter=self, start=start, end=end)
def get_title_label(self):
return self.title_label
def get_mode_combo(self):
return self.mode
def get_description(self):
desc = ''
start_date = self.start_date.get_date()
end_date = self.end_date.get_date()
if start_date:
if end_date and start_date != end_date:
desc += ' %s %s %s %s' % (_(u'from'), start_date.strftime('%x'),
_(u'to'), end_date.strftime('%x'),)
else:
desc += start_date.strftime('%x')
if desc:
return '%s %s' % (self.get_title_label().get_text(), desc,)
#
# Public API
#
def clear_options(self):
"""
Removes all previously added options
"""
self._options = {}
self.mode.clear()
def add_option(self, option_type, position=-2):
"""
Adds a date option
#.........这里部分代码省略.........
示例9: AccountEditor
# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import connect [as 别名]
class AccountEditor(BaseEditor):
""" Account Editor """
gladefile = "AccountEditor"
proxy_widgets = ['description', 'code']
model_type = Account
model_name = _('Account')
def __init__(self, store, model=None, parent_account=None):
self._last_account_type = None
self._bank_number = -1
self._bank_widgets = []
self._bank_option_widgets = []
self._option_fields = {}
self._test_button = None
self.existing = model is not None
self.parent_account = parent_account
self.bank_model = _TemporaryBankAccount()
BaseEditor.__init__(self, store, model)
action_area = self.main_dialog.action_area
action_area.set_layout(gtk.BUTTONBOX_END)
action_area.pack_start(self._test_button, expand=False, fill=False)
action_area.set_child_secondary(self._test_button, True)
self._test_button.show()
#
# BaseEditor hooks
#
def create_model(self, store):
return Account(description=u"",
account_type=Account.TYPE_CASH,
store=store)
def _setup_widgets(self):
self._test_button = gtk.Button(_("Print a test bill"))
self._test_button.connect('clicked',
self._on_test_button__clicked)
self.parent_accounts = AccountTree(with_code=False, create_mode=True)
self.parent_accounts.connect('selection-changed',
self._on_parent_accounts__selection_changed)
self.tree_box.pack_start(self.parent_accounts)
self.tree_box.reorder_child(self.parent_accounts, 0)
if self.model == sysparam(self.store).IMBALANCE_ACCOUNT:
self.account_type.set_sensitive(False)
self.account_type.prefill(Account.account_type_descriptions)
account_type = self.model.account_type
self.parent_accounts.insert_initial(self.store,
edited_account=self.model)
if self.parent_account:
account = self.parent_accounts.get_account_by_id(
self.parent_account.id)
self.parent_accounts.select(account)
if not self.existing:
account_type = account.account_type
self.account_type.select(account_type)
self.parent_accounts.show()
def setup_proxies(self):
self._setup_widgets()
self.add_proxy(self.model, AccountEditor.proxy_widgets)
def validate_confirm(self):
if not self.model.description:
return False
account = self.parent_accounts.get_selected()
if not account:
return True
return account.selectable
def on_confirm(self):
new_parent = self.parent_accounts.get_selected()
if new_parent:
new_parent = new_parent.account
if new_parent != self.model:
self.model.parent = new_parent
self.model.account_type = self.account_type.get_selected()
self._save_bank()
def refresh_ok(self, value):
BaseEditor.refresh_ok(self, value)
account_type = self.account_type.get_selected()
if account_type != Account.TYPE_BANK:
value = False
self._test_button.set_sensitive(value)
# Private
def _save_bank(self):
bank_account = self.model.bank
if not bank_account:
bank_account = BankAccount(account=self.model,
store=self.store)
# FIXME: Who sets this to a str?
bank_account.bank_account = unicode(self.bank_model.bank_account)
bank_account.bank_branch = unicode(self.bank_model.bank_branch)
#.........这里部分代码省略.........
示例10: StringSearchFilter
# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import connect [as 别名]
class StringSearchFilter(SearchFilter):
"""
Contains:
- a label
- an entry
:ivar entry: the entry
:ivar label: the label
"""
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)
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 = HintedEntry()
self.entry.set_hint(_("Search"))
self.entry.show_hint()
self.entry.props.secondary_icon_sensitive = False
data = environ.get_resource_string('stoq', 'pixmaps',
'stoq-funnel-16x16.png')
image = pixbuf_from_string(data)
self.entry.set_icon_from_pixbuf(gtk.ENTRY_ICON_PRIMARY,
image)
self.entry.set_icon_tooltip_text(gtk.ENTRY_ICON_PRIMARY,
_("Add a filter"))
self.entry.set_icon_from_stock(gtk.ENTRY_ICON_SECONDARY,
gtk.STOCK_CLEAR)
self.entry.set_icon_tooltip_text(gtk.ENTRY_ICON_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()
for option in (ContainsAll, ContainsExactly, DoesNotContain):
self._add_option(option)
self.mode.select_item_by_position(0)
def _add_option(self, option_type, position=-2):
option = option_type()
num = abs(position)
self.mode.insert_item(num, 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.ENTRY_ICON_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.ENTRY_ICON_SECONDARY:
entry.set_text("")
entry.grab_focus()
self.emit('changed')
elif icon_pos == gtk.ENTRY_ICON_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,
self._position_filter_menu, 0, event.time)
#
# SearchFilter
#
def get_state(self):
#.........这里部分代码省略.........
示例11: ComboSearchFilter
# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import connect [as 别名]
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 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()
#
# SearchFilter
#
def get_state(self):
value = self.combo.get_selected_data()
mode = self.mode.get_selected_data()
state = NumberQueryState(filter=self, value=value, mode=mode.mode)
if hasattr(value, 'id'):
state.value_id = value.id
return state
def set_state(self, value, value_id=None, mode=None):
if mode is None:
mode = NumberQueryState.EQUALS
if value_id is not None:
for item in self.combo.get_model_items().values():
if item is None:
continue
if item.id == value_id:
value = item
break
self.select(value)
def update_values(self, values):
self._block_updates = True
self.combo.prefill(values)
self._block_updates = False
def get_title_label(self):
return self.title_label
def get_mode_combo(self):
return self.combo
def get_description(self):
desc = ''
data = self.combo.get_selected_data()
if data is not None:
desc += self.combo.get_selected_label()
return '%s %s' % (self.title_label.get_text(), desc,)
#
# Public API
#
def add_option(self, option_type, position=0):
"""
Adds an option
:param option_type: option to add
:type option_type: a :class:`ComboSearchOption` subclass
"""
option = option_type()
num = len(self.mode) + position
self.mode.insert_item(num, option.name, option_type)
def select(self, data):
"""
selects an item in the combo
:param data: what to select
"""
self.combo.select(data)
def enable_advanced(self):
#.........这里部分代码省略.........
示例12: ComboSearchFilter
# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import connect [as 别名]
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 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()
#
# SearchFilter
#
def get_state(self):
value = self.combo.get_selected_data()
state = NumberQueryState(filter=self,
value=value)
if hasattr(value, 'id'):
state.value_id = value.id
return state
def set_state(self, value, value_id=None):
if value_id is not None:
for item in self.combo.get_model_items().values():
if item is None:
continue
if item.id == value_id:
value = item
break
self.select(value)
def update_values(self, values):
self._block_updates = True
self.combo.prefill(values)
self._block_updates = False
def get_title_label(self):
return self.title_label
def get_mode_combo(self):
return self.combo
def get_description(self):
desc = ''
data = self.combo.get_selected_data()
if data is not None:
desc += self.combo.get_selected_label()
return '%s %s' % (self.title_label.get_text(), desc,)
#
# 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):
if not self._block_updates:
self.emit('changed')
示例13: StringSearchFilter
# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import connect [as 别名]
class StringSearchFilter(SearchFilter):
"""
Contains:
- a label
- an entry
:ivar entry: the entry
:ivar label: the label
"""
__gtype_name__ = 'StringSearchFilter'
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)
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()
#.........这里部分代码省略.........
示例14: NumberSearchFilter
# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import connect [as 别名]
class NumberSearchFilter(SearchFilter):
"""
A filter which helps you to search by a number interval.
"""
__gtype_name__ = 'NumberSearchFilter'
def __init__(self, label=''):
"""
@param label: name of the search filter
"""
self._options = {}
SearchFilter.__init__(self, label=label)
self.title_label = gtk.Label(label)
self.title_label.set_alignment(1.0, 0.5)
self.pack_start(self.title_label, False, False)
self.title_label.show()
self.mode = ProxyComboBox()
self.mode.connect('content-changed', self._on_mode__content_changed)
self.pack_start(self.mode, False, False, 6)
self.mode.show()
self.start = gtk.SpinButton(climb_rate=1.0)
self.start.get_adjustment().step_increment = 1.0
self.start.set_range(-sys.maxint-1, sys.maxint)
self.pack_start(self.start, False, False, 6)
self.start.show()
self.and_label = gtk.Label(_("And"))
self.pack_start(self.and_label, False, False)
self.and_label.show()
self.end = gtk.SpinButton(climb_rate=1.0)
self.end.get_adjustment().step_increment = 1.0
self.end.set_range(-sys.maxint-1, sys.maxint)
self.pack_start(self.end, False, False, 6)
self.end.show()
for option in (LowerThan, EqualsTo, GreaterThan, Between):
self.add_option(option)
self.mode.select_item_by_position(0)
#
# Private
#
def _update_visibility(self):
option = self.mode.get_selected_data()
numbers = option.numbers
if numbers == 0:
self.start.hide()
self.and_label.hide()
self.end.hide()
elif numbers == 1:
self.start.show()
self.and_label.hide()
self.end.hide()
elif numbers == 2:
self.start.show()
self.and_label.show()
self.end.show()
#
# Callbacks
#
def _on_mode__content_changed(self, combo):
self._update_visibility()
#
# SearchFilter
#
def get_state(self):
start_value = self.start.get_value_as_int()
end_value = self.end.get_value_as_int()
option = self.mode.get_selected_data()
start, end = option().get_interval(start_value, end_value)
return NumberIntervalQueryState(filter=self, start=start, end=end)
def get_title_label(self):
return self.title_label
def get_mode_combo(self):
return self.mode
#
# Public API
#
def add_option(self, option_type, position=-2):
"""
Adds a date option
@param option_type: option to add
#.........这里部分代码省略.........