本文整理汇总了Python中stoqlib.gui.search.searchslave.SearchSlave.add_filter方法的典型用法代码示例。如果您正苦于以下问题:Python SearchSlave.add_filter方法的具体用法?Python SearchSlave.add_filter怎么用?Python SearchSlave.add_filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stoqlib.gui.search.searchslave.SearchSlave
的用法示例。
在下文中一共展示了SearchSlave.add_filter方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SearchDialog
# 需要导入模块: from stoqlib.gui.search.searchslave import SearchSlave [as 别名]
# 或者: from stoqlib.gui.search.searchslave.SearchSlave import add_filter [as 别名]
#.........这里部分代码省略.........
def cancel(self, *args):
self.retval = []
self.search.save_columns()
# FIXME: This should chain up so the "cancel" signal gets emitted
self.close()
# FIXME: -> remove/use
# TODO: Check if we can remove
def set_searchbar_label(self, label):
search_filter = self.search.get_primary_filter()
search_filter.set_label(label)
def set_searchbar_search_string(self, string):
if string == self.get_searchbar_search_string():
return
search_filter = self.search.get_primary_filter()
search_filter.entry.set_text(string)
def get_searchbar_search_string(self):
search_filter = self.search.get_primary_filter()
return search_filter.get_state().text
def set_text_field_columns(self, columns):
"""See :class:`SearchSlave.set_text_field_columns`
"""
self.search.set_text_field_columns(columns)
def disable_search_entry(self):
"""See :class:`SearchSlave.disable_search_entry`
"""
self.search.disable_search_entry()
def add_filter(self, search_filter, position=SearchFilterPosition.BOTTOM,
columns=None, callback=None):
"""See :class:`SearchSlave.add_filter`
"""
self.search.add_filter(search_filter, position, columns, callback)
def row_activate(self, obj):
"""This is called when an item in the results list is double clicked.
:param obj: the item that was double clicked.
"""
if self.double_click_confirm:
# But only if its also confirmable with ok_button
if self.ok_button.props.sensitive:
self.confirm()
#
# Filters
#
def create_branch_filter(self, label=None):
from stoqlib.domain.person import Branch
branches = Branch.get_active_branches(self.store)
items = [(b.person.name, b.id) for b in branches]
# if not items:
# raise ValueError('You should have at least one branch at '
# 'this point')
items.insert(0, (_("Any"), None))
if not label:
label = _('Branch:')
branch_filter = ComboSearchFilter(label, items)
current = api.get_current_branch(self.store)
示例2: TransactionPage
# 需要导入模块: from stoqlib.gui.search.searchslave import SearchSlave [as 别名]
# 或者: from stoqlib.gui.search.searchslave.SearchSlave import add_filter [as 别名]
class TransactionPage(object):
# shows either a list of:
# - transactions
# - payments
def __init__(self, model, app, parent):
self.model = model
self.app = app
self.parent_window = parent
self._block = False
self._create_search()
self._add_date_filter()
self._setup_search()
self.refresh()
def get_toplevel(self):
return self.parent_window
def _create_search(self):
self.search = SearchSlave(self._get_columns(self.model.kind),
store=self.app.store)
self.search.connect('result-item-activated',
self._on_search__item_activated)
self.search.enable_advanced_search()
self.search.set_result_view(FinancialSearchResults)
self.result_view = self.search.result_view
self.result_view.page = self
tree_view = self.search.result_view.get_treeview()
tree_view.set_rules_hint(True)
tree_view.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_BOTH)
def _add_date_filter(self):
self.date_filter = DateSearchFilter(_('Date:'))
self.date_filter.clear_options()
self.date_filter.add_option(Any, 0)
year = datetime.datetime.today().year
month_names = get_month_names()
for i, month in enumerate(month_names):
name = month_names[i]
option = type(name + 'Option', (MonthOption, ),
{'name': _(name),
'month': i + 1,
'year': year})
self.date_filter.add_option(option, i + 1)
self.date_filter.add_custom_options()
self.date_filter.mode.select_item_by_position(0)
self.search.add_filter(self.date_filter)
def _append_date_query(self, field):
date = self.date_filter.get_state()
queries = []
if isinstance(date, DateQueryState) and date.date is not None:
queries.append(Date(field) == date.date)
elif isinstance(date, DateIntervalQueryState):
queries.append(Date(field) >= date.start)
queries.append(Date(field) <= date.end)
return queries
def _payment_query(self, store):
executer = self.search.get_query_executer()
search_spec = executer.search_spec
queries = self._append_date_query(search_spec.due_date)
if queries:
return store.find(search_spec, And(*queries))
return store.find(search_spec)
def _transaction_query(self, store):
queries = [Or(self.model.id == AccountTransaction.account_id,
self.model.id == AccountTransaction.source_account_id)]
queries.extend(self._append_date_query(AccountTransaction.date))
return store.find(AccountTransactionView, And(*queries))
def show(self):
self.search.show()
def _setup_search(self):
if self.model.kind == 'account':
self.search.set_search_spec(AccountTransactionView)
self.search.set_text_field_columns(['description'])
self.search.set_query(self._transaction_query)
elif self.model.kind == 'payable':
self.search.set_text_field_columns(['description', 'supplier_name'])
self.search.set_search_spec(OutPaymentView)
self.search.set_query(self._payment_query)
elif self.model.kind == 'receivable':
self.search.set_text_field_columns(['description', 'drawee'])
self.search.set_search_spec(InPaymentView)
self.search.set_query(self._payment_query)
else:
raise TypeError("unknown model kind: %r" % (self.model.kind, ))
def refresh(self):
self.search.result_view.clear()
if self.model.kind == 'account':
transactions = AccountTransactionView.get_for_account(self.model, self.app.store)
self.append_transactions(transactions)
elif self.model.kind == 'payable':
#.........这里部分代码省略.........
示例3: SearchDialog
# 需要导入模块: from stoqlib.gui.search.searchslave import SearchSlave [as 别名]
# 或者: from stoqlib.gui.search.searchslave.SearchSlave import add_filter [as 别名]
#.........这里部分代码省略.........
elif isinstance(state, DateIntervalQueryState):
if state.start and state.end:
return Individual.get_birthday_query(state.start, state.end)
else:
raise AssertionError
# FIXME: -> remove/use
# TODO: Check if we can remove
def set_searchbar_label(self, label):
search_filter = self.search.get_primary_filter()
search_filter.set_label(label)
def set_searchbar_search_string(self, string):
if string == self.get_searchbar_search_string():
return
search_filter = self.search.get_primary_filter()
search_filter.entry.set_text(string)
def get_searchbar_search_string(self):
search_filter = self.search.get_primary_filter()
return search_filter.get_state().text
def set_text_field_columns(self, columns):
"""See :class:`SearchSlave.set_text_field_columns`
"""
self.search.set_text_field_columns(columns)
def disable_search_entry(self):
"""See :class:`SearchSlave.disable_search_entry`
"""
self.search.disable_search_entry()
def add_filter(self, search_filter, position=SearchFilterPosition.BOTTOM,
columns=None, callback=None):
"""See :class:`SearchSlave.add_filter`
"""
self.search.add_filter(search_filter, position, columns, callback)
def row_activate(self, obj):
"""This is called when an item in the results list is double clicked.
:param obj: the item that was double clicked.
"""
if self.double_click_confirm:
# But only if its also confirmable with ok_button
if self.ok_button.props.sensitive:
self.confirm()
def add_extension(self, extension):
"""Adds the extention to this search.
See :class:`stoqlib.gui.search.searchextention.SearchExtention for more
information
"""
extension.attach(self)
def add_columns(self, columns):
"""Add some columns to the default ones.
Note that this method must be called during the setup of this search,
which right now is only possible for those who capture the
`<stoqlib.gui.events.SearchDialogSetupSearchEvent>`
"""
self.columns.extend(columns)
示例4: QuoteGroupSelectionStep
# 需要导入模块: from stoqlib.gui.search.searchslave import SearchSlave [as 别名]
# 或者: from stoqlib.gui.search.searchslave.SearchSlave import add_filter [as 别名]
class QuoteGroupSelectionStep(BaseWizardStep):
gladefile = 'QuoteGroupSelectionStep'
def __init__(self, wizard, store):
self._next_step = None
BaseWizardStep.__init__(self, store, wizard)
self._setup_slaves()
def _setup_slaves(self):
self.search = SearchSlave(self._get_columns(),
restore_name=self.__class__.__name__,
search_spec=QuotationView,
store=self.store)
self.attach_slave('search_group_holder', self.search)
self.search.set_text_field_columns(['supplier_name', 'identifier_str'])
filter = self.search.get_primary_filter()
filter.set_label(_(u'Supplier:'))
self.search.focus_search_entry()
self.search.results.connect('selection-changed',
self._on_searchlist__selection_changed)
self.search.results.connect('row-activated',
self._on_searchlist__row_activated)
date_filter = DateSearchFilter(_('Date:'))
self.search.add_filter(date_filter, columns=['open_date', 'deadline'])
self.edit_button.set_sensitive(False)
self.remove_button.set_sensitive(False)
def _get_columns(self):
return [IdentifierColumn('identifier', title=_("Quote #"), sorted=True),
IdentifierColumn('group_identifier', title=_('Group #')),
Column('supplier_name', title=_('Supplier'), data_type=str,
width=300),
Column('open_date', title=_('Open date'),
data_type=datetime.date),
Column('deadline', title=_('Deadline'),
data_type=datetime.date)]
def _can_purchase(self, item):
return item.cost > currency(0) and item.quantity > Decimal(0)
def _can_order(self, quotation):
if quotation is None:
return False
for item in quotation.purchase.get_items():
if not self._can_purchase(item):
return False
return True
def _update_view(self):
selected = self.search.results.get_selected()
has_selected = selected is not None
self.edit_button.set_sensitive(has_selected)
self.remove_button.set_sensitive(has_selected)
self.wizard.refresh_next(self._can_order(selected))
def _run_quote_editor(self):
store = api.new_store()
selected = store.fetch(self.search.results.get_selected().purchase)
retval = run_dialog(QuoteFillingDialog, self.wizard, selected, store)
store.confirm(retval)
store.close()
self._update_view()
def _remove_quote(self):
q = self.search.results.get_selected().quotation
msg = _('Are you sure you want to remove "%s" ?') % q.get_description()
if not yesno(msg, gtk.RESPONSE_NO,
_("Remove quote"), _("Don't remove")):
return
store = api.new_store()
group = store.fetch(q.group)
quote = store.fetch(q)
group.remove_item(quote)
# there is no reason to keep the group if there's no more quotes
if group.get_items().count() == 0:
store.remove(group)
store.confirm(True)
store.close()
self.search.refresh()
#
# WizardStep hooks
#
def next_step(self):
self.search.save_columns()
selected = self.search.results.get_selected()
if selected is None:
return
return QuoteGroupItemsSelectionStep(self.wizard, self.store,
selected.group, self)
#
# Callbacks
#.........这里部分代码省略.........
示例5: ShellApp
# 需要导入模块: from stoqlib.gui.search.searchslave import SearchSlave [as 别名]
# 或者: from stoqlib.gui.search.searchslave.SearchSlave import add_filter [as 别名]
#.........这里部分代码省略.........
insensitive.
:param widgets: a list of widgets
:param validation_func: a function for validation. It should
return either ``True`` or ``False``.
:param args: args that will be passed to *validation_func*
"""
assert callable(validation_func)
for widget in widgets:
validators = self._sensitive_group.setdefault(widget, set())
validators.add((validation_func, args))
def run_dialog(self, dialog_class, *args, **kwargs):
""" Encapsuled method for running dialogs. """
return run_dialog(dialog_class, self, *args, **kwargs)
@cached_function()
def has_open_inventory(self):
return Inventory.has_open(self.store,
api.get_current_branch(self.store))
def check_open_inventory(self):
"""Checks if there is an open inventory.
In the case there is one, will call set_open_inventory (subclasses
should implement it).
Returns True if there is an open inventory. False otherwise
"""
inventory_bar = getattr(self, 'inventory_bar', None)
if self.has_open_inventory():
if inventory_bar:
inventory_bar.show()
else:
self._display_open_inventory_message()
self.set_open_inventory()
return True
elif inventory_bar:
inventory_bar.hide()
return False
# FIXME: Most of these should be removed and access the search API
# directly, eg, self.search.clear() etc
def add_filter(self, search_filter, position=SearchFilterPosition.BOTTOM,
columns=None, callback=None):
"""
See :class:`SearchSlave.add_filter`
"""
self.search.add_filter(search_filter, position, columns, callback)
def set_text_field_columns(self, columns):
"""
See :class:`SearchSlave.set_text_field_columns`
"""
self.search.set_text_field_columns(columns)
def refresh(self, rollback=True):
"""
See :class:`stoqlib.gui.search.searchslave.SearchSlave.refresh`
"""
# Since the store here is actually a transaction and the items
# on it can be changed from another station, do a rollback so
# the items get reloaded, avoiding cache problems
# Note that this gets mocked on tests to not do the rollback
if rollback:
self.store.rollback(close=False)
self.search.refresh()
def clear(self):
"""
See :class:`stoqlib.gui.search.searchslave.SearchSlave.clear`
"""
self.search.clear()
def select_result(self, result):
"""Select the object in the result list
If the object is not in the list (filtered out, for instance), no error
is thrown and nothing is selected
"""
try:
self.results.select(result)
except ValueError:
pass
#
# Callbacks
#
def on_search__search_completed(self, search, results, states):
self.search_completed(results, states)
has_results = len(results)
for widget in [self.window.Print,
self.window.ExportSpreadSheet]:
widget.set_sensitive(has_results)
self.search.save_filter_settings('app-ui', self.app_name)