diff options
author | B Stack <bgstack15@gmail.com> | 2020-03-16 10:28:26 -0400 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2020-03-16 10:28:26 -0400 |
commit | 5be18b3f108cfe89a7ea8f14bfad1a85455bda24 (patch) | |
tree | fa1b988058a1bae334d37a4e6031594fc4b17752 | |
parent | WIP: add search widget (diff) | |
download | mime_types_editor-5be18b3f108cfe89a7ea8f14bfad1a85455bda24.tar.gz mime_types_editor-5be18b3f108cfe89a7ea8f14bfad1a85455bda24.tar.bz2 mime_types_editor-5be18b3f108cfe89a7ea8f14bfad1a85455bda24.zip |
WIP: search works raw
search filter works for category view, but does not auto-update
like the "show only associated types" checkbox yet.
-rw-r--r-- | src/cat_mode/mime_editor_cat_mode.py | 7 | ||||
-rw-r--r-- | src/common/data_filter.py | 20 | ||||
-rw-r--r-- | src/common/mime_view.py | 24 |
3 files changed, 39 insertions, 12 deletions
diff --git a/src/cat_mode/mime_editor_cat_mode.py b/src/cat_mode/mime_editor_cat_mode.py index 7b216d7..d50c8bc 100644 --- a/src/cat_mode/mime_editor_cat_mode.py +++ b/src/cat_mode/mime_editor_cat_mode.py @@ -51,8 +51,6 @@ class CategoriesView(gtk_common.CategoriesWidget): #register callback tree_selection = self.categories_view.get_selection() tree_selection.connect("changed", self.on_selection_changes) - self.searchbox = builder.get_object("searchbox") - self.searchbox.connect("search-changed", self.on_searchbox_changed) def _fill_list_store(self): categories = sorted((_(name), cat ,id_) @@ -79,11 +77,6 @@ class CategoriesView(gtk_common.CategoriesWidget): self.on_category_changed(cat_ids) - def on_searchbox_changed(self, search_widget): - print("INSIDE on_searchbox_changed, value ", '"' + search_widget.get_text() + '"' ) - print(self) - #self.mime_view.filter_category(category_id[0]) - class AddAppDialog: def __init__(self, builder, parent_window, on_add_dialog_apply): self.builder = builder diff --git a/src/common/data_filter.py b/src/common/data_filter.py index e97f018..b3de1af 100644 --- a/src/common/data_filter.py +++ b/src/common/data_filter.py @@ -7,6 +7,7 @@ Created on Fri Nov 25 07:18:57 2016 """ import mime_categories +import re class DataFilter: def __init__(self, enabled = True): @@ -29,7 +30,26 @@ class GeneralFilter(DataFilter): value = model.get_value(iter_, self.column) return self.value_condition_fn(value) +class RegexFilter(DataFilter): + def __init__(self, matchstring): + self._new_regex(matchstring) + def _new_regex(self, matchstring): + self.matchstring = matchstring + if matchstring == "": + self.matchregex = ".*" + else: + self.matchregex = ".*" + matchstring + ".*" + self.pattern = re.compile(self.matchregex, re.IGNORECASE) + print("Setting RegexFilter to:",self.matchregex) + + def process_row(self, model, iter_, data): + if self.matchstring != data: + self._new_regex(data) + instring=model.get_value(iter_,2) + result = self.pattern.match(instring) + #print("ROW ",'"' + instring + '"', " test against regex", self.matchstring, "is", result, "data=",data) + return result != None class CategoryFilter(DataFilter): def __init__(self, category_column, current_category_id): diff --git a/src/common/mime_view.py b/src/common/mime_view.py index 6470ebd..0abf2b2 100644 --- a/src/common/mime_view.py +++ b/src/common/mime_view.py @@ -23,6 +23,8 @@ class MimeView: UI_VIEW_ID = None UI_CONTEXT_MENU_ID = None + SEARCH_STRING = "" + #model columns MIME_TYPE = 0 MIME_CATEGORY = 1 @@ -39,6 +41,8 @@ class MimeView: #callbacks self.mtypes_view.connect("button-press-event", self.on_mouse_clicked) self.mtypes_view.connect("key-press-event", self.on_key_pressed) + self.searchbox = builder.get_object("searchbox") + self.searchbox.connect("search-changed", self.on_searchbox_changed) #allow multiple selection self.tree_selection = self.mtypes_view.get_selection() @@ -51,6 +55,11 @@ class MimeView: self._init_columns() self._init_context_menu() + def on_searchbox_changed(self, search_widget): + #print("INSIDE on_searchbox_changed, value ", '"' + search_widget.get_text() + '"' ) + self.SEARCH_STRING = search_widget.get_text() + self.set_search_filter(self.SEARCH_STRING) + def _init_mappings(self): #mappings self.context_menu_items = {} # dictionary of item_id: item_action pairs @@ -60,7 +69,6 @@ class MimeView: def _init_filters(self): self.ordered_data_filters = [] #order may be matter self.data_filters = {} # save reference by name - self.search_filters = {} #add category filter category_filter = data_filter.CategoryFilter(self.MIME_CATEGORY, @@ -72,9 +80,12 @@ class MimeView: self.ordered_data_filters.append(data_filter) self.data_filters[filter_name] = data_filter - def _set_search_filter(self, filter_name, data_filter): - self.data_filters[filter_name].set_params(**kwargs) - self.filter_model.refilter() + def set_search_filter(self, search_string): + search_filter = data_filter.RegexFilter(search_string) + if "search_filter" in self.data_filters: + self.data_filters["search_filter"] = search_filter + else: + self._add_filter_to_cascade("search_filter", search_filter) def _init_model(self): """liststore -> filter -> sort -> view""" @@ -135,7 +146,10 @@ class MimeView: def cascade_filter_func(self, model, iter_, data): # return True if all conditions are satisfied for filter_ in self.ordered_data_filters: - if not filter_.process_row(model, iter_, data): + outdata = data + if isinstance(filter_, data_filter.RegexFilter): + outdata = self.SEARCH_STRING + if not filter_.process_row(model, iter_, outdata): return False return True |