diff options
author | B Stack <bgstack15@gmail.com> | 2020-03-16 13:28:19 -0400 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2020-03-16 13:28:19 -0400 |
commit | 835a7930af8e77cf702d1f0070b1c7262106f4c2 (patch) | |
tree | fb5fc6a8d05f77adeb47e350624a0a98b9e3815e | |
parent | updates list every time you change search string (diff) | |
download | mime_types_editor-835a7930af8e77cf702d1f0070b1c7262106f4c2.tar.gz mime_types_editor-835a7930af8e77cf702d1f0070b1c7262106f4c2.tar.bz2 mime_types_editor-835a7930af8e77cf702d1f0070b1c7262106f4c2.zip |
add working searchbox to app view
-rw-r--r-- | src/app_mode/mime_editor_app_mode.py | 31 | ||||
-rw-r--r-- | src/app_mode/ui_app_mode.glade | 21 | ||||
-rw-r--r-- | 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 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.18.3 --> +<!-- Generated with glade 3.22.2 --> <interface> <requires lib="gtk+" version="3.12"/> <object class="GtkDialog" id="add_app_dialog"> <property name="can_focus">False</property> <property name="type_hint">dialog</property> + <child type="titlebar"> + <placeholder/> + </child> <child internal-child="vbox"> <object class="GtkBox" id="dialog-vbox2"> <property name="can_focus">False</property> @@ -135,6 +138,9 @@ <object class="GtkDialog" id="add_mime_type_dialog"> <property name="can_focus">False</property> <property name="type_hint">dialog</property> + <child type="titlebar"> + <placeholder/> + </child> <child internal-child="vbox"> <object class="GtkBox" id="add_mime_type_dialog_vbox"> <property name="can_focus">False</property> @@ -332,7 +338,18 @@ <property name="can_focus">False</property> <property name="orientation">vertical</property> <child> - <placeholder/> + <object class="GtkSearchEntry" id="searchbox"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="primary_icon_name">edit-find-symbolic</property> + <property name="primary_icon_activatable">False</property> + <property name="primary_icon_sensitive">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> </child> <child> <object class="GtkPaned" id="paned1"> 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): |