From 835a7930af8e77cf702d1f0070b1c7262106f4c2 Mon Sep 17 00:00:00 2001 From: B Stack Date: Mon, 16 Mar 2020 13:28:19 -0400 Subject: add working searchbox to app view --- src/app_mode/mime_editor_app_mode.py | 31 +++++++++++++++++++++++++++++-- src/app_mode/ui_app_mode.glade | 21 +++++++++++++++++++-- src/common/data_filter.py | 11 +++++++---- 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/app_mode/mime_editor_app_mode.py b/src/app_mode/mime_editor_app_mode.py index d6210ab..87a6d88 100644 --- a/src/app_mode/mime_editor_app_mode.py +++ b/src/app_mode/mime_editor_app_mode.py @@ -5,7 +5,7 @@ Created on Fri Nov 25 07:54:51 2016 @author: pavel """ -import os +import os, re DIR = os.path.dirname(os.path.realpath(__file__)) import sys @@ -56,6 +56,8 @@ class AppsView: def __init__(self, builder, on_app_changed): self.builder = builder self.on_app_changed = on_app_changed + self.SEARCH_STRING = "" + self.pattern = re.compile(".*") self.apps_view = self.builder.get_object("treeview_applications") @@ -67,8 +69,24 @@ class AppsView: tree_selection = self.apps_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 on_searchbox_changed(self, search_widget): + #print("INSIDE on_searchbox_changed, value ", '"' + search_widget.get_text() + '"' ) + self._new_regex(search_widget.get_text()) + self.cascade_filter.refilter() + + def _new_regex(self, matchstring): + self.SEARCH_STRING = matchstring + if matchstring == "": + self.matchregex = ".*" + else: + self.matchregex = ".*" + matchstring + ".*" + self.pattern = re.compile(self.matchregex, re.IGNORECASE) + #print("Setting app mode matchregex to:",self.matchregex) + def _add_columns(self): column = gtk_common.ImageTextColumn(_("Application"), self.APP_IMG, self.APP_NAME) column.set_sort_column_id(self.APP_NAME) @@ -103,7 +121,8 @@ class AppsView: def _cascade_filter_func(self, *args, **kwargs): return self._visible_only_filter_func(*args, **kwargs) and \ - self._with_file_support_only_filter_func(*args, **kwargs) + self._with_file_support_only_filter_func(*args, **kwargs) and \ + self._matches_search_regex(*args, **kwargs) def _visible_only_filter_func(self, model, iter, data): return self.show_invisible or model[iter][self.APP_VISIBLE] @@ -111,6 +130,14 @@ class AppsView: def _with_file_support_only_filter_func(self, model, iter, data): return self.show_without_file_support or model[iter][self.APP_SUPPORT_FILES] + def _matches_search_regex(self, model, iter, data): + instring=model.get_value(iter,1) + in_column1 = self.pattern.match(instring) + instring = model.get_value(iter,0).get_string("Exec") + in_column0 = self.pattern.match(instring) + #print("ROW ",'"' + instring + '"', "test against regex", self.SEARCH_STRING, "is", in_column0) + return in_column1 != None or in_column0 != None + def filter_visible(self, show_invisible = False): self.show_invisible = show_invisible self.cascade_filter.refilter() diff --git a/src/app_mode/ui_app_mode.glade b/src/app_mode/ui_app_mode.glade index 7a1c0f0..c672753 100644 --- a/src/app_mode/ui_app_mode.glade +++ b/src/app_mode/ui_app_mode.glade @@ -1,10 +1,13 @@ - + False dialog + + + False @@ -135,6 +138,9 @@ False dialog + + + False @@ -332,7 +338,18 @@ False vertical - + + True + True + edit-find-symbolic + False + False + + + False + True + 0 + diff --git a/src/common/data_filter.py b/src/common/data_filter.py index b3de1af..1c0b7ba 100644 --- a/src/common/data_filter.py +++ b/src/common/data_filter.py @@ -41,15 +41,18 @@ class RegexFilter(DataFilter): else: self.matchregex = ".*" + matchstring + ".*" self.pattern = re.compile(self.matchregex, re.IGNORECASE) - print("Setting RegexFilter to:",self.matchregex) + #print("Setting RegexFilter to:",self.matchregex) def process_row(self, model, iter_, data): if self.matchstring != data: self._new_regex(data) + # columns from MimeView class in mime_view.py 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 + in_column2 = self.pattern.match(instring) + instring=model.get_value(iter_,0) + in_column0 = self.pattern.match(instring) + #print("ROW ",'"' + instring + '"', " test against regex", self.matchstring, "is", in_column2, "data=",data) + return in_column2 != None or in_column0 != None class CategoryFilter(DataFilter): def __init__(self, category_column, current_category_id): -- cgit