本文整理汇总了Python中stoqlib.gui.search.searchslave.SearchSlave.enable_advanced_search方法的典型用法代码示例。如果您正苦于以下问题:Python SearchSlave.enable_advanced_search方法的具体用法?Python SearchSlave.enable_advanced_search怎么用?Python SearchSlave.enable_advanced_search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stoqlib.gui.search.searchslave.SearchSlave
的用法示例。
在下文中一共展示了SearchSlave.enable_advanced_search方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SearchDialog
# 需要导入模块: from stoqlib.gui.search.searchslave import SearchSlave [as 别名]
# 或者: from stoqlib.gui.search.searchslave.SearchSlave import enable_advanced_search [as 别名]
#.........这里部分代码省略.........
size=self.size)
self.enable_window_controls()
self.disable_ok()
self.set_ok_label(_('Se_lect Items'))
self._setup_search()
self._setup_details_slave()
self.create_filters()
self.setup_widgets()
if self.search_label:
self.set_searchbar_label(self.search_label)
def _setup_selection_mode(self, selection_mode):
# For consistency do not allow none or single, in other words,
# only allowed values are browse and multiple so we always will
# be able to use both the keyboard and the mouse to select items
# in the search list.
selection_mode = selection_mode or self.selection_mode
if (selection_mode != gtk.SELECTION_BROWSE and
selection_mode != gtk.SELECTION_MULTIPLE):
raise ValueError('Invalid selection mode %r' % selection_mode)
return selection_mode
def _setup_search(self):
self.search = SearchSlave(
self.get_columns(),
tree=self.tree,
restore_name=self.__class__.__name__,
store=self.store,
search_spec=self.search_spec,
)
if self.advanced_search:
self.search.enable_advanced_search()
self.attach_slave('main', self.search)
self.header.hide()
self.results = self.search.result_view
self.results.set_selection_mode(self.selection_mode)
self.results.connect('cell-edited', self._on_results__cell_edited)
self.results.connect('selection-changed',
self._on_results__selection_changed)
self.results.connect('row-activated', self._on_results__row_activated)
def _setup_details_slave(self):
# FIXME: Gross hack
has_details_btn = hasattr(self, 'on_details_button_clicked')
has_print_btn = hasattr(self, 'on_print_button_clicked')
if not (has_details_btn or has_print_btn):
self._details_slave = None
return
self._details_slave = _SearchDialogDetailsSlave()
self.attach_slave('details_holder', self._details_slave)
if has_details_btn:
self._details_slave.connect("details",
self.on_details_button_clicked)
else:
self._details_slave.details_button.hide()
if has_print_btn:
self._details_slave.connect("print", self.on_print_button_clicked)
self.set_print_button_sensitive(False)
self.results.connect('has-rows', self._has_rows)
else:
self._details_slave.print_button.hide()
#
示例2: PurchaseSelectionStep
# 需要导入模块: from stoqlib.gui.search.searchslave import SearchSlave [as 别名]
# 或者: from stoqlib.gui.search.searchslave.SearchSlave import enable_advanced_search [as 别名]
class PurchaseSelectionStep(BaseWizardStep):
gladefile = 'PurchaseSelectionStep'
def __init__(self, wizard, store):
self._next_step = None
BaseWizardStep.__init__(self, store, wizard)
self.setup_slaves()
def _create_search(self):
self.search = SearchSlave(self._get_columns(),
restore_name=self.__class__.__name__,
store=self.store,
search_spec=PurchaseOrderView)
self.search.enable_advanced_search()
self.attach_slave('searchbar_holder', self.search)
executer = self.search.get_query_executer()
executer.add_query_callback(self.get_extra_query)
self._create_filters()
self.search.result_view.set_selection_mode(gtk.SELECTION_MULTIPLE)
self.search.result_view.connect('selection-changed',
self._on_results__selection_changed)
self.search.result_view.connect('row-activated',
self._on_results__row_activated)
self.search.focus_search_entry()
def _create_filters(self):
self.search.set_text_field_columns(['supplier_name', 'identifier_str'])
def get_extra_query(self, states):
query = PurchaseOrderView.status == PurchaseOrder.ORDER_CONFIRMED
# Dont let the user receive purchases from other branches when working
# in synchronized mode
if api.sysparam.get_bool('SYNCHRONIZED_MODE'):
branch = api.get_current_branch(self.store)
query = And(query,
PurchaseOrderView.branch_id == branch.id)
return query
def _get_columns(self):
return [IdentifierColumn('identifier', sorted=True),
SearchColumn('open_date', title=_('Date Started'),
data_type=datetime.date, width=100),
SearchColumn('expected_receival_date', data_type=datetime.date,
title=_('Expected Receival'), visible=False),
SearchColumn('supplier_name', title=_('Supplier'),
data_type=str, searchable=True, width=130,
expand=True),
SearchColumn('ordered_quantity', title=_('Qty Ordered'),
data_type=Decimal, width=110,
format_func=format_quantity),
SearchColumn('received_quantity', title=_('Qty Received'),
data_type=Decimal, width=145,
format_func=format_quantity),
SearchColumn('total', title=_('Order Total'),
data_type=currency, width=120)]
def _update_view(self):
selected_rows = self.search.result_view.get_selected_rows()
can_continue = len(set((v.supplier_id, v.branch_id) for v in selected_rows)) == 1
self.wizard.refresh_next(can_continue)
self.details_button.set_sensitive(len(selected_rows) == 1)
#
# WizardStep hooks
#
def post_init(self):
self._update_view()
self.force_validation()
def next_step(self):
self.search.save_columns()
selected_rows = self.search.result_view.get_selected_rows()
return ReceivingOrderItemStep(self.store, self.wizard, self,
selected_rows)
def has_previous_step(self):
return False
def setup_slaves(self):
self._create_search()
#
# Kiwi callbacks
#
def _on_results__selection_changed(self, results, purchase_order_view):
self.force_validation()
self._update_view()
def _on_results__row_activated(self, results, purchase_order_view):
run_dialog(PurchaseDetailsDialog, self.wizard, self.store,
model=purchase_order_view.purchase)
def on_details_button__clicked(self, *args):
selected = self.search.results.get_selected_rows()[0]
if not selected:
raise ValueError('You should have one order selected '
#.........这里部分代码省略.........
示例3: TransactionPage
# 需要导入模块: from stoqlib.gui.search.searchslave import SearchSlave [as 别名]
# 或者: from stoqlib.gui.search.searchslave.SearchSlave import enable_advanced_search [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':
#.........这里部分代码省略.........
示例4: LoanSelectionStep
# 需要导入模块: from stoqlib.gui.search.searchslave import SearchSlave [as 别名]
# 或者: from stoqlib.gui.search.searchslave.SearchSlave import enable_advanced_search [as 别名]
class LoanSelectionStep(BaseWizardStep):
gladefile = 'HolderTemplate'
def __init__(self, wizard, store):
BaseWizardStep.__init__(self, store, wizard)
self.setup_slaves()
def _create_filters(self):
self.search.set_text_field_columns(['client_name', 'identifier_str'])
def _get_columns(self):
return [IdentifierColumn('identifier', sorted=True),
SearchColumn('responsible_name', title=_(u'Responsible'),
data_type=str, expand=True),
SearchColumn('client_name', title=_(u'Client'),
data_type=str, expand=True),
SearchColumn('open_date', title=_(u'Opened'),
data_type=datetime.date),
SearchColumn('expire_date', title=_(u'Expire'),
data_type=datetime.date),
Column('loaned', title=_(u'Loaned'),
data_type=Decimal),
]
def _refresh_next(self, value=None):
can_continue = False
selected_rows = self.search.results.get_selected_rows()
if selected_rows:
client = selected_rows[0].client_id
branch = selected_rows[0].branch_id
# Only loans that belong to the same client and are from the same
# branch can be closed together
can_continue = all(v.client_id == client and v.branch_id == branch
for v in selected_rows)
self.wizard.refresh_next(can_continue)
def get_extra_query(self, states):
return LoanView.status == Loan.STATUS_OPEN
def setup_slaves(self):
self.search = SearchSlave(self._get_columns(),
restore_name=self.__class__.__name__,
store=self.store,
search_spec=LoanView)
self.search.enable_advanced_search()
self.attach_slave('place_holder', self.search)
executer = self.search.get_query_executer()
executer.add_query_callback(self.get_extra_query)
self._create_filters()
self.search.results.connect('selection-changed',
self._on_results_selection_changed)
self.search.results.set_selection_mode(gtk.SELECTION_MULTIPLE)
self.search.focus_search_entry()
#
# WizardStep
#
def has_previous_step(self):
return False
def post_init(self):
self.register_validate_function(self._refresh_next)
self.force_validation()
def next_step(self):
# FIXME: For some reason, the loan isn't in self.store
views = self.search.results.get_selected_rows()
self.wizard.models = [self.store.fetch(v.loan) for v in views]
return LoanItemSelectionStep(self.wizard, self, self.store,
self.wizard.models)
#
# Callbacks
#
def _on_results_selection_changed(self, widget, selection):
self._refresh_next()
示例5: SearchDialog
# 需要导入模块: from stoqlib.gui.search.searchslave import SearchSlave [as 别名]
# 或者: from stoqlib.gui.search.searchslave.SearchSlave import enable_advanced_search [as 别名]
#.........这里部分代码省略.........
if self.search_label:
self.set_searchbar_label(self.search_label)
if self.initial_string:
search_filter = self.search.get_primary_filter()
search_filter.set_state(self.initial_string)
self.search.refresh()
search_filter.entry.grab_focus()
def _setup_selection_mode(self, selection_mode):
# For consistency do not allow none or single, in other words,
# only allowed values are browse and multiple so we always will
# be able to use both the keyboard and the mouse to select items
# in the search list.
selection_mode = selection_mode or self.selection_mode
if (selection_mode != gtk.SELECTION_BROWSE and
selection_mode != gtk.SELECTION_MULTIPLE):
raise ValueError('Invalid selection mode %r' % selection_mode)
return selection_mode
def _setup_search(self):
self.columns = self.get_columns()
SearchDialogSetupSearchEvent.emit(self)
self.search = SearchSlave(
self.columns,
tree=self.tree,
restore_name=self.__class__.__name__,
store=self.store,
search_spec=self.search_spec,
fast_iter=self.fast_iter,
result_view_class=self.result_view_class
)
if self.advanced_search:
self.search.enable_advanced_search()
self.attach_slave('main', self.search)
self.header.hide()
self.results = self.search.result_view
self.results.set_selection_mode(self.selection_mode)
self.results.connect('cell-edited', self._on_results__cell_edited)
self.results.connect('selection-changed',
self._on_results__selection_changed)
self.results.connect('row-activated', self._on_results__row_activated)
def _setup_details_slave(self):
# FIXME: Gross hack
has_details_btn = hasattr(self, 'on_details_button_clicked')
has_print_btn = self.report_class is not None
self.results.connect('has-rows', self._has_rows)
if not (has_details_btn or has_print_btn):
self._details_slave = None
return
self._details_slave = _SearchDialogDetailsSlave()
self.attach_slave('details_holder', self._details_slave)
if has_details_btn:
self._details_slave.connect("details",
self.on_details_button_clicked)
else:
self._details_slave.details_button.hide()
if has_print_btn:
self._details_slave.connect("print", self._on_print_button__clicked)
self.set_print_button_sensitive(False)
else:
self._details_slave.print_button.hide()
def _create_default_filters(self):
示例6: ShellApp
# 需要导入模块: from stoqlib.gui.search.searchslave import SearchSlave [as 别名]
# 或者: from stoqlib.gui.search.searchslave.SearchSlave import enable_advanced_search [as 别名]
class ShellApp(GladeDelegate):
"""Base class for shell applications.
The main use is to interact with a shell window and reduce
duplication between other applications.
"""
#: This attribute is used when generating titles for applications.
#: It's also useful if we get a list of available applications with
#: the application names translated. This list is going to be used when
#: creating new user profiles.
app_title = None
#: name of the application, 'pos', 'payable', etc
app_name = None
#: If this application has a search like interface
search = None
#: This dictionary holds information about required permissions to access
#: certain actions. Keys should be the name of the action (for instance
#: SearchEmployess), and the value should be a tuple with the permission key
#: (domain object or action identifier) and the required permission. In this
#: case: ('Employee', perm.PERM_SEARCH). See <stoqlib.lib.permissions>
action_permissions = {}
#: The spec for store.find() to perform the search on
search_spec = None
#: Label left of the search entry
search_label = _('Search:')
#: the report class for printing the object list embedded on app.
report_table = None
def __init__(self, window, store=None):
if store is None:
store = api.get_default_store()
self.store = store
self.window = window
self._sensitive_group = dict()
self.help_ui = None
self.uimanager = self.window.uimanager
# FIXME: These two should probably post-__init__, but
# that breaks date_label in the calender app
self._create_search()
self.create_actions()
GladeDelegate.__init__(self,
gladefile=self.gladefile,
toplevel_name=self.toplevel_name)
self._attach_search()
self.create_ui()
def _create_search(self):
if self.search_spec is None:
return
self.columns = self.get_columns()
ApplicationSetupSearchEvent.emit(self)
self.search = SearchSlave(self.columns,
store=self.store,
restore_name=self.__class__.__name__,
search_spec=self.search_spec)
def _attach_search(self):
if self.search_spec is None:
return
self.search.enable_advanced_search()
self.attach_slave('search_holder', self.search)
search_filter = self.search.get_primary_filter()
search_filter.set_label(self.search_label)
self.create_filters()
self.search.restore_filter_settings('app-ui', self.app_name)
self.search.focus_search_entry()
# FIXME: Remove and use search directly instead of the result view
self.results = self.search.result_view
def _display_open_inventory_message(self):
msg = _(u'There is an inventory process open at the moment.\n'
'While that inventory is open, you will be unable to do '
'operations that modify your stock.')
self.inventory_bar = self.window.add_info_bar(gtk.MESSAGE_WARNING, msg)
#
# Overridables
#
def create_actions(self):
"""This is called before the BaseWindow constructor, so we
can create actions that can be autoconnected.
The widgets and actions loaded from builder files are not set
yet"""
def create_ui(self):
"""This is called when the UI such as GtkWidgets should be
created. Glade widgets are now created and can be accessed
in the instance.
"""
#.........这里部分代码省略.........
示例7: ReceivingSelectionStep
# 需要导入模块: from stoqlib.gui.search.searchslave import SearchSlave [as 别名]
# 或者: from stoqlib.gui.search.searchslave.SearchSlave import enable_advanced_search [as 别名]
class ReceivingSelectionStep(BaseWizardStep):
gladefile = 'PurchaseSelectionStep'
def __init__(self, wizard, store):
self._next_step = None
BaseWizardStep.__init__(self, store, wizard)
self.setup_slaves()
def _create_search(self):
self.search = SearchSlave(self._get_columns(),
restore_name=self.__class__.__name__,
store=self.store,
search_spec=PurchaseReceivingView)
self.search.enable_advanced_search()
self.attach_slave('searchbar_holder', self.search)
executer = self.search.get_query_executer()
executer.add_query_callback(self.get_extra_query)
self._create_filters()
self.search.result_view.set_selection_mode(Gtk.SelectionMode.MULTIPLE)
self.search.result_view.connect('selection-changed',
self._on_results__selection_changed)
self.search.result_view.connect('row-activated',
self._on_results__row_activated)
self.search.focus_search_entry()
def _create_filters(self):
self.search.set_text_field_columns(['supplier_name', 'purchase_identifier'])
def get_extra_query(self, states):
query = And(Eq(PurchaseReceivingView.purchase_group, None),
Eq(PurchaseReceivingView.receiving_invoice, None))
# Dont let the user receive purchases from other branches when working
# in synchronized mode
if (api.sysparam.get_bool('SYNCHRONIZED_MODE') and not
api.can_see_all_branches()):
branch = api.get_current_branch(self.store)
query = And(query, PurchaseReceivingView.branch_id == branch.id)
return query
def _get_columns(self):
return [IdentifierColumn('identifier', _('Receiving #'), width=140),
IdentifierColumn('purchase_identifier', _('Purchase #'), width=110),
SearchColumn('packing_number', title=_('Packing Number'),
data_type=str, visible=False),
SearchColumn('receival_date', _('Receival date'), expand=True,
data_type=datetime.date, sorted=True, width=110),
SearchColumn('supplier_name', _('Supplier'), data_type=str,
expand=True),
SearchColumn('responsible_name', _('Responsible'),
data_type=str, visible=False, expand=True),
SearchColumn('purchase_responsible_name', _('Purchaser'),
data_type=str, visible=False, expand=True),
SearchColumn('invoice_number', _('Invoice #'), data_type=int,
width=80),
Column('subtotal', title=_('Products total'),
data_type=currency, width=150)]
def _update_view(self):
selected_rows = self.search.result_view.get_selected_rows()
can_continue = len(set((v.supplier_id, v.branch_id) for v in selected_rows)) == 1
self.wizard.refresh_next(can_continue)
self.details_button.set_sensitive(len(selected_rows) == 1)
#
# WizardStep hooks
#
def post_init(self):
self._update_view()
self.force_validation()
def next_step(self):
self.search.save_columns()
selected_rows = self.search.result_view.get_selected_rows()
return ProductsCostCheckStep(self.wizard, self, self.store, selected_rows)
def has_previous_step(self):
return False
def setup_slaves(self):
self._create_search()
#
# Kiwi callbacks
#
def _on_results__selection_changed(self, results, purchase_order_view):
self.force_validation()
self._update_view()
def _on_results__row_activated(self, results, receiving_order_view):
run_dialog(ReceivingOrderDetailsDialog, self.wizard, self.store,
model=receiving_order_view.order)
def on_details_button__clicked(self, *args):
selected = self.search.results.get_selected_rows()[0]
if not selected:
raise ValueError('You should have one order selected '
#.........这里部分代码省略.........
示例8: PurchaseSelectionStep
# 需要导入模块: from stoqlib.gui.search.searchslave import SearchSlave [as 别名]
# 或者: from stoqlib.gui.search.searchslave.SearchSlave import enable_advanced_search [as 别名]
class PurchaseSelectionStep(BaseWizardStep):
gladefile = 'PurchaseSelectionStep'
def __init__(self, wizard, store):
self._next_step = None
BaseWizardStep.__init__(self, store, wizard)
self.setup_slaves()
def _refresh_next(self, validation_value):
has_selection = self.search.results.get_selected() is not None
self.wizard.refresh_next(has_selection)
def _create_search(self):
self.search = SearchSlave(self._get_columns(),
restore_name=self.__class__.__name__,
store=self.store,
search_spec=PurchaseOrderView)
self.search.enable_advanced_search()
self.attach_slave('searchbar_holder', self.search)
executer = self.search.get_query_executer()
executer.add_query_callback(self.get_extra_query)
self._create_filters()
self.search.results.connect('selection-changed',
self._on_results__selection_changed)
self.search.results.connect('row-activated',
self._on_results__row_activated)
self.search.focus_search_entry()
def _create_filters(self):
self.search.set_text_field_columns(['supplier_name', 'identifier_str'])
def get_extra_query(self, states):
query = PurchaseOrderView.status == PurchaseOrder.ORDER_CONFIRMED
# Dont let the user receive purchases from other branches when working
# in synchronized mode
if api.sysparam.get_bool('SYNCHRONIZED_MODE'):
branch = api.get_current_branch(self.store)
query = And(query,
PurchaseOrderView.branch_id == branch.id)
return query
def _get_columns(self):
return [IdentifierColumn('identifier', sorted=True),
SearchColumn('open_date', title=_('Date Started'),
data_type=datetime.date, width=100),
SearchColumn('expected_receival_date', data_type=datetime.date,
title=_('Expected Receival'), visible=False),
SearchColumn('supplier_name', title=_('Supplier'),
data_type=str, searchable=True, width=130,
expand=True),
SearchColumn('ordered_quantity', title=_('Qty Ordered'),
data_type=Decimal, width=110,
format_func=format_quantity),
SearchColumn('received_quantity', title=_('Qty Received'),
data_type=Decimal, width=145,
format_func=format_quantity),
SearchColumn('total', title=_('Order Total'),
data_type=currency, width=120)]
def _update_view(self):
has_selection = self.search.results.get_selected() is not None
self.details_button.set_sensitive(has_selection)
#
# WizardStep hooks
#
def post_init(self):
self._update_view()
self.register_validate_function(self._refresh_next)
self.force_validation()
def next_step(self):
self.search.save_columns()
selected = self.search.results.get_selected()
purchase = selected.purchase
# We cannot create the model in the wizard since we haven't
# selected a PurchaseOrder yet which ReceivingOrder depends on
# Create the order here since this is the first place where we
# actually have a purchase selected
if not self.wizard.model:
self.wizard.model = self.model = ReceivingOrder(
responsible=api.get_current_user(self.store),
supplier=purchase.supplier, invoice_number=None,
branch=purchase.branch, purchase=purchase,
store=self.store)
# Remove all the items added previously, used if we hit back
# at any point in the wizard.
if self.model.purchase != purchase:
self.model.remove_items()
# This forces ReceivingOrderProductStep to create a new model
self._next_step = None
if selected:
self.model.purchase = purchase
self.model.branch = purchase.branch
self.model.supplier = purchase.supplier
#.........这里部分代码省略.........