예제 #1
0
    def set_search(self, search):
        """
        Change the search function that filters the data in the model.
        When this method is called, make sure:
        # you call self.rebuild_data() to recalculate what should be seen
          in the model
        # you reattach the model to the treeview so that the treeview updates
          with the new entries
        """
        if search:
            if search[0] == 1:  # Filter
                #following is None if no data given in filter sidebar
                self.search = search[1]
                if self.has_secondary:
                    self.search2 = search[1]
                    _LOG.debug("search2 filter %s %s" % (search[0], search[1]))
                self._build_data = self._rebuild_filter
            elif search[0] == 0:  # Search
                if search[1]:
                    # we have search[1] = (index, text_unicode, inversion)
                    col, text, inv = search[1]
                    func = lambda x: self._get_value(x, col, secondary=False
                                                     ) or ""
                    if self.has_secondary:
                        func2 = lambda x: self._get_value(
                            x, col, secondary=True) or ""
                    if search[2]:
                        self.search = ExactSearchFilter(func, text, inv)
                        if self.has_secondary:
                            self.search2 = ExactSearchFilter(func2, text, inv)
                    else:
                        self.search = SearchFilter(func, text, inv)
                        if self.has_secondary:
                            self.search2 = SearchFilter(func2, text, inv)
                else:
                    self.search = None
                    if self.has_secondary:
                        self.search2 = None
                        _LOG.debug("search2 search with no data")
                self._build_data = self._rebuild_search
            else:  # Fast filter
                self.search = search[1]
                if self.has_secondary:
                    self.search2 = search[2]
                    _LOG.debug("search2 fast filter")
                self._build_data = self._rebuild_search
        else:
            self.search = None
            if self.has_secondary:
                self.search2 = search[2]
                _LOG.debug("search2 no search parameter")
            self._build_data = self._rebuild_search

        self.current_filter = self.search
        if self.has_secondary:
            self.current_filter2 = self.search2
예제 #2
0
 def set_search(self, search):
     """
     Change the search function that filters the data in the model.
     When this method is called, make sure:
     # you call self.rebuild_data() to recalculate what should be seen
       in the model
     # you reattach the model to the treeview so that the treeview updates
       with the new entries
     """
     if search:
         if search[0]:
             #following is None if no data given in filter sidebar
             self.search = search[1]
             self.rebuild_data = self._rebuild_filter
         else:
             if search[1]:  # Search from topbar in columns
                 # we have search[1] = (index, text_unicode, inversion)
                 col = search[1][0]
                 text = search[1][1]
                 inv = search[1][2]
                 func = lambda x: self._get_value(x, col) or UEMPTY
                 if search[2]:
                     self.search = ExactSearchFilter(func, text, inv)
                 else:
                     self.search = SearchFilter(func, text, inv)
             else:
                 self.search = None
             self.rebuild_data = self._rebuild_search
     else:
         self.search = None
         self.rebuild_data = self._rebuild_search