def __init__(self, entry, store, initial_value=None, parent=None, run_editor=None, edit_button=None, info_button=None, search_clause=None): """ :param entry: The entry that we should modify :param store: The store that will be used for database queries :param initial_value: Initial value for the entry :param parent: The parent that should be respected when running other dialogs """ super(QueryEntryGadget, self).__init__() self._parent = parent self._on_run_editor = run_editor self._can_edit = False self._search_clause = search_clause self.entry = entry self.entry.set_mode(ENTRY_MODE_DATA) self.edit_button = edit_button self.info_button = info_button self.store = store # The filter that will be used. This is not really in the interface. # We will just use it to perform the search. self._filter = StringSearchFilter('') self._executer = QueryExecuter(self.store) self._executer.set_search_spec(self.search_spec) self._executer.set_filter_columns(self._filter, self.search_columns) self._last_operation = None self._source_id = None self._setup() self.set_value(initial_value, force=True)
def __init__(self, entry, store, initial_value=None, parent=None, run_editor=None): """ :param entry: The entry that we should modify :param store: The store that will be used for database queries :param initial_value: Initial value for the entry :param parent: The parent that should be respected when running other dialogs """ super(QueryEntryGadget, self).__init__() self._current_obj = None self._parent = parent self._on_run_editor = run_editor self.entry = entry self.entry.set_mode(ENTRY_MODE_DATA) self.store = store # The filter that will be used. This is not really in the interface. # We will just use it to perform the search. self._filter = StringSearchFilter('') self._executer = QueryExecuter(self.store) self._executer.set_search_spec(self.SEARCH_SPEC) self._executer.set_filter_columns(self._filter, self.SEARCH_COLUMNS) self._last_operation = None self._source_id = None self._is_person = issubclass(self.ITEM_EDITOR, BasePersonRoleEditor) self._setup() self.set_value(initial_value, force=True)
def add_filter_by_attribute(self, attr, title, data_type, valid_values=None, callback=None, use_having=False): """Add a filter accordingly to the attributes specified :param attr: attribute that will be filtered. This can be either the name of the attribute or the attribute itself. :param title: the title of the filter that will be visible in the interface :param data_type: the attribute type (str, bool, decimal, etc) :param callback: the callback function that will be triggered :param use_having: use having expression in the query """ if data_type is not bool: title += ':' if data_type == datetime.date: filter = DateSearchFilter(title) if valid_values: filter.clear_options() filter.add_custom_options() for opt in valid_values: filter.add_option(opt) filter.select(valid_values[0]) elif (data_type == decimal.Decimal or data_type == int or data_type == currency): filter = NumberSearchFilter(title) if data_type != int: filter.set_digits(2) elif data_type == str: if valid_values: filter = ComboSearchFilter(title, valid_values) else: filter = StringSearchFilter(title) filter.enable_advanced() elif data_type == bool: filter = BoolSearchFilter(title) else: raise NotImplementedError(title, data_type) filter.set_removable() self.add_filter(filter, columns=[attr], callback=callback, use_having=use_having) if data_type is not bool: label = filter.get_title_label() label.set_alignment(1.0, 0.5) self.label_group.add_widget(label) combo = filter.get_mode_combo() if combo: self.combo_group.add_widget(combo) return filter
def _setup_widgets(self): self._replace_widget() # Add the two buttons self.find_button = self._create_button(gtk.STOCK_FIND) self.edit_button = self._create_button(gtk.STOCK_NEW) can_edit = self._entry.get_editable() and self._entry.get_sensitive() self.find_button.set_sensitive(can_edit) self.find_button.set_tooltip_text(self.find_tooltip) self.edit_button.set_tooltip_text(self.new_tooltip) # the entry needs a completion to work in MODE_DATA self._completion = gtk.EntryCompletion() self._entry.set_completion(self._completion) self._entry.set_mode(ENTRY_MODE_DATA) initial_value = getattr(self._model, self._model_property) self.set_value(initial_value) # The filter that will be used. This is not really in the interface. We # will just use it to perform the search. self._filter = StringSearchFilter('') self._executer = QueryExecuter(self.store) self._executer.set_search_spec(self._search_class.search_spec) self._executer.set_filter_columns(self._filter, self._search_columns)
def __init__(self, columns=None, tree=False, restore_name=None, chars=25, store=None, search_spec=None, fast_iter=False, result_view_class=None): """ Create a new SearchContainer object. :param columns: a list of :class:`kiwi.ui.objectlist.Column` :param tree: if we should list the results as a tree :param restore_name: :param chars: maximum number of chars used by the search entry :param store: a database store :param search_spec: a search spec for store to find on """ if tree: self.result_view_class = SearchResultTreeView if result_view_class: self.result_view_class = result_view_class self._auto_search = True self._lazy_search = False self._last_results = None self._model = None self._query_executer = None self._restore_name = restore_name self._search_filters = [] self._selected_item = None self._summary_label = None self._search_spec = search_spec self._fast_iter = fast_iter self.store = store self.menu = None self.result_view = None self._settings_key = 'search-columns-%s' % (api.get_current_user( self.store).username, ) self.columns = self.restore_columns(columns) self.vbox = gtk.VBox() SlaveDelegate.__init__(self, toplevel=self.vbox) self.vbox.show() search_filter = StringSearchFilter(_('Search:'), chars=chars, container=self) search_filter.connect('changed', self._on_search_filter__changed) self._search_filters.append(search_filter) self._primary_filter = search_filter self._create_ui() self.focus_search_entry()
def add_filter_by_column(self, column): """Add a filter accordingly to the column specification :param column: a SearchColumn instance """ title = column.get_search_label() if column.data_type is not bool: title += ':' if column.data_type == datetime.date: filter = DateSearchFilter(title) if column.valid_values: filter.clear_options() filter.add_custom_options() for opt in column.valid_values: filter.add_option(opt) filter.select(column.valid_values[0]) elif (column.data_type == decimal.Decimal or column.data_type == int or column.data_type == currency): filter = NumberSearchFilter(title) if column.data_type != int: filter.set_digits(2) elif column.data_type == str: if column.valid_values: filter = ComboSearchFilter(title, column.valid_values) else: filter = StringSearchFilter(title) filter.enable_advanced() elif column.data_type == bool: filter = BoolSearchFilter(title) else: raise NotImplementedError(title, column.data_type) filter.set_removable() attr = column.search_attribute or column.attribute self.add_filter(filter, columns=[attr], callback=column.search_func, use_having=column.use_having) if column.data_type is not bool: label = filter.get_title_label() label.set_alignment(1.0, 0.5) self.label_group.add_widget(label) combo = filter.get_mode_combo() if combo: self.combo_group.add_widget(combo) return filter