From 8b64b9f145c034bfca89c0efe7000562c8d84599 Mon Sep 17 00:00:00 2001 From: SNoiraud Date: Sun, 3 Jul 2022 15:42:28 +0200 Subject: [PATCH] Add the possibility of case sensitive/insensitive search See https://gramps.discourse.group/t/help-with-regex-to-create-gramps-case-sensitive-filter/2536 --- gramps/gen/filters/_filterlist.py | 4 +-- gramps/gen/filters/_filterparser.py | 9 +++++-- gramps/gen/filters/rules/_hasnotebase.py | 6 ++--- gramps/gen/filters/rules/_rule.py | 8 ++++-- gramps/gui/editors/filtereditor.py | 25 ++++++++++++++++--- .../filters/sidebar/_citationsidebarfilter.py | 17 ++++++++----- .../filters/sidebar/_eventsidebarfilter.py | 9 ++++--- .../filters/sidebar/_familysidebarfilter.py | 23 +++++++++-------- .../filters/sidebar/_mediasidebarfilter.py | 9 ++++--- .../gui/filters/sidebar/_notesidebarfilter.py | 7 ++++-- .../filters/sidebar/_personsidebarfilter.py | 13 ++++++---- .../filters/sidebar/_placesidebarfilter.py | 9 ++++--- .../gui/filters/sidebar/_reposidebarfilter.py | 9 ++++--- gramps/gui/filters/sidebar/_sidebarfilter.py | 15 +++++++++++ .../filters/sidebar/_sourcesidebarfilter.py | 9 ++++--- 15 files changed, 121 insertions(+), 51 deletions(-) diff --git a/gramps/gen/filters/_filterlist.py b/gramps/gen/filters/_filterlist.py index 39a4da301..881b18bf2 100644 --- a/gramps/gen/filters/_filterlist.py +++ b/gramps/gen/filters/_filterlist.py @@ -142,9 +142,9 @@ class FilterList: file.write(' comment="%s"' % self.fix(comment)) file.write('>\n') for rule in the_filter.get_rules(): - file.write(' ' + file.write(' ' '\n' % (rule.__class__.__name__, - rule.use_regex)) + rule.use_regex, rule.use_case)) for value in list(rule.values()): file.write(' ' '\n' % self.fix(value)) diff --git a/gramps/gen/filters/_filterparser.py b/gramps/gen/filters/_filterparser.py index 830b36a44..bd4d0cc50 100644 --- a/gramps/gen/filters/_filterparser.py +++ b/gramps/gen/filters/_filterparser.py @@ -52,6 +52,7 @@ class FilterParser(handler.ContentHandler): self.cname = None self.namespace = 'Person' self.use_regex = False + self.use_case = False def setDocumentLocator(self, locator): self.locator = locator @@ -87,6 +88,10 @@ class FilterParser(handler.ContentHandler): self.use_regex = attrs['use_regex'] == 'True' else: self.use_regex = False + if 'use_case' in attrs: + self.use_case = attrs['use_case'] == 'True' + else: + self.use_case = False save_name = attrs['class'] if save_name in old_names_2_class: self.r = old_names_2_class[save_name] @@ -120,7 +125,7 @@ class FilterParser(handler.ContentHandler): "Trying to load with subset of arguments.") %\ self.f.get_name()) nargs = len(self.r.labels) - rule = self.r(self.a[0:nargs], self.use_regex) + rule = self.r(self.a[0:nargs], self.use_regex, self.use_case) self.f.add_rule(rule) else: if len(self.r.labels) > len(self.a): @@ -129,7 +134,7 @@ class FilterParser(handler.ContentHandler): "will be upgraded.") %\ self.f.get_name()) try: - rule = self.r(self.a, self.use_regex) + rule = self.r(self.a, self.use_regex, self.use_case) except AssertionError as msg: print(msg) print(_("ERROR: filter %s could not be correctly loaded. " diff --git a/gramps/gen/filters/rules/_hasnotebase.py b/gramps/gen/filters/rules/_hasnotebase.py index 4118bf8df..8890facf1 100644 --- a/gramps/gen/filters/rules/_hasnotebase.py +++ b/gramps/gen/filters/rules/_hasnotebase.py @@ -48,13 +48,13 @@ class HasNoteBase(Rule): description = "Matches objects that have a certain number of notes" category = _('General filters') - def __init__(self, arg, use_regex=False): + def __init__(self, arg, use_regex=False, use_case=False): # Upgrade from pre 3.1 HasNote filter, use defaults that correspond # Previous filter had 0 arguments if len(arg) == 0: - Rule.__init__(self, ["0", 'greater than'], use_regex) + Rule.__init__(self, ["0", 'greater than'], use_regex, use_case) else: - Rule.__init__(self, arg, use_regex) + Rule.__init__(self, arg, use_regex, use_case) def prepare(self, db, user): # things we want to do just once, not for every handle diff --git a/gramps/gen/filters/rules/_rule.py b/gramps/gen/filters/rules/_rule.py index 59f71011d..34862c8a5 100644 --- a/gramps/gen/filters/rules/_rule.py +++ b/gramps/gen/filters/rules/_rule.py @@ -56,12 +56,13 @@ class Rule: description = _('No description') allow_regex = False - def __init__(self, arg, use_regex=False): + def __init__(self, arg, use_regex=False, use_case=False): self.list = [] self.regex = [] self.match_substring = self.__match_substring self.set_list(arg) self.use_regex = use_regex + self.use_case = use_case self.nrprepare = 0 def is_empty(self): @@ -84,7 +85,10 @@ class Rule: for index, label in enumerate(self.labels): if self.list[index]: try: - self.regex[index] = re.compile(self.list[index], re.I) + if self.use_case: + self.regex[index] = re.compile(self.list[index]) + else: + self.regex[index] = re.compile(self.list[index], re.I) except re.error: self.regex[index] = re.compile('') self.match_substring = self.match_regex diff --git a/gramps/gui/editors/filtereditor.py b/gramps/gui/editors/filtereditor.py index 8776a6854..237afcd1e 100644 --- a/gramps/gui/editors/filtereditor.py +++ b/gramps/gui/editors/filtereditor.py @@ -609,6 +609,7 @@ class EditRule(ManagedWindow): pos += 1 use_regex = None + use_case = None if class_obj.allow_regex: use_regex = Gtk.CheckButton(label=_('Use regular expressions')) tip = _('Interpret the contents of string fields as regular ' @@ -625,7 +626,13 @@ class EditRule(ManagedWindow): use_regex.set_tooltip_text(tip) grid.attach(use_regex, 1, pos, 1, 1) - self.page.append((class_obj, vallist, tlist, use_regex)) + pos += 1 + use_case = Gtk.CheckButton(label=_('Case sensitive')) + grid.attach(use_case, 1, pos, 1, 1) + use_regex.connect('toggled', self.regex_selection, use_case) + use_case.set_sensitive(False) + + self.page.append((class_obj, vallist, tlist, use_regex, use_case)) # put the grid into a scrollable area: scrolled_win = Gtk.ScrolledWindow() @@ -684,12 +691,14 @@ class EditRule(ManagedWindow): page = self.class2page[self.active_rule.__class__] self.notebook.set_current_page(page) self.display_values(self.active_rule.__class__) - (class_obj, vallist, tlist, use_regex) = self.page[page] + (class_obj, vallist, tlist, use_regex, use_case) = self.page[page] r = list(self.active_rule.values()) for i in range(0, min(len(tlist), len(r))): tlist[i].set_text(r[i]) if class_obj.allow_regex: use_regex.set_active(self.active_rule.use_regex) + use_case.set_active(self.active_rule.use_case) + self.regex_selection() self.selection.connect('changed', self.on_node_selected) self.rname.connect('button-press-event', self._button_press) @@ -706,6 +715,14 @@ class EditRule(ManagedWindow): self.rname.restore_column_size() self.show() + def regex_selection(self, widget=None, use_case=None): + if use_case: + if widget and widget.get_active(): + use_case.set_sensitive(True) + else: + use_case.set_active(False) + use_case.set_sensitive(False) + def select_iter(self, data): """ Workaround to get self.selection to move to iter row. @@ -787,10 +804,10 @@ class EditRule(ManagedWindow): try: page = self.notebook.get_current_page() - (class_obj, vallist, tlist, use_regex) = self.page[page] + (class_obj, vallist, tlist, use_regex, use_case) = self.page[page] value_list = [str(sclass.get_text()) for sclass in tlist] if class_obj.allow_regex: - new_rule = class_obj(value_list, use_regex.get_active()) + new_rule = class_obj(value_list, use_regex.get_active(), use_case.get_active()) else: new_rule = class_obj(value_list) diff --git a/gramps/gui/filters/sidebar/_citationsidebarfilter.py b/gramps/gui/filters/sidebar/_citationsidebarfilter.py index bac8610a8..25fb790a1 100644 --- a/gramps/gui/filters/sidebar/_citationsidebarfilter.py +++ b/gramps/gui/filters/sidebar/_citationsidebarfilter.py @@ -74,6 +74,7 @@ class CitationSidebarFilter(SidebarFilter): self.filter_note = Gtk.Entry() self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) + self.sensitive_regex = Gtk.CheckButton(label=_('Case sensitive')) self.tag = Gtk.ComboBox() self.generic = Gtk.ComboBox() @@ -116,6 +117,9 @@ class CitationSidebarFilter(SidebarFilter): self.add_entry(_('Tag'), self.tag) self.add_filter_entry(_('Custom filter'), self.generic) self.add_entry(None, self.filter_regex) + self.add_entry(None, self.sensitive_regex) + self.filter_regex.connect('toggled', self.regex_selection) + self.regex_selection() def clear(self, obj): self.filter_src_id.set_text('') @@ -145,6 +149,7 @@ class CitationSidebarFilter(SidebarFilter): conf = str(self.filter_conf.get_active()) note = str(self.filter_note.get_text()).strip() regex = self.filter_regex.get_active() + usecase = self.sensitive_regex.get_active() tag = self.tag.get_active() > 0 gen = self.generic.get_active() > 0 @@ -156,26 +161,26 @@ class CitationSidebarFilter(SidebarFilter): else: generic_filter = GenericCitationFilter() if gid: - rule = RegExpIdOf([gid], use_regex=regex) + rule = RegExpIdOf([gid], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) - rule = HasCitation([page, date, conf], use_regex=regex) + rule = HasCitation([page, date, conf], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) if src_id: - rule = RegExpSourceIdOf([src_id], use_regex=regex) + rule = RegExpSourceIdOf([src_id], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) rule = HasSource([src_title, src_author, src_abbr, src_pub], - use_regex=regex) + use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) if note: - rule = HasNoteRegexp([note], use_regex=regex) + rule = HasNoteRegexp([note], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) if src_note: - rule = HasSourceNoteRegexp([src_note], use_regex=regex) + rule = HasSourceNoteRegexp([src_note], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) # check the Tag diff --git a/gramps/gui/filters/sidebar/_eventsidebarfilter.py b/gramps/gui/filters/sidebar/_eventsidebarfilter.py index 28f427419..51ca5b9e4 100644 --- a/gramps/gui/filters/sidebar/_eventsidebarfilter.py +++ b/gramps/gui/filters/sidebar/_eventsidebarfilter.py @@ -78,6 +78,7 @@ class EventSidebarFilter(SidebarFilter): self.filter_note = widgets.BasicEntry() self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) + self.sensitive_regex = Gtk.CheckButton(label=_('Case sensitive')) self.tag = Gtk.ComboBox() self.generic = Gtk.ComboBox() @@ -110,6 +111,7 @@ class EventSidebarFilter(SidebarFilter): self.add_entry(_('Tag'), self.tag) self.add_filter_entry(_('Custom filter'), self.generic) self.add_regex_entry(self.filter_regex) + self.add_regex_case(self.sensitive_regex) def clear(self, obj): self.filter_id.set_text('') @@ -130,6 +132,7 @@ class EventSidebarFilter(SidebarFilter): place = str(self.filter_place.get_text()).strip() note = str(self.filter_note.get_text()).strip() regex = self.filter_regex.get_active() + usecase = self.sensitive_regex.get_active() tag = self.tag.get_active() > 0 generic = self.generic.get_active() > 0 etype = self.filter_event.get_type().xml_str() @@ -141,15 +144,15 @@ class EventSidebarFilter(SidebarFilter): else: generic_filter = GenericEventFilter() if gid: - rule = RegExpIdOf([gid], use_regex=regex) + rule = RegExpIdOf([gid], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) rule = HasEvent([etype, date, place, desc, mainparts], - use_regex=regex) + use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) if note: - rule = HasNoteRegexp([note], use_regex=regex) + rule = HasNoteRegexp([note], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) # check the Tag diff --git a/gramps/gui/filters/sidebar/_familysidebarfilter.py b/gramps/gui/filters/sidebar/_familysidebarfilter.py index 8ccdcc951..f4d4361bc 100644 --- a/gramps/gui/filters/sidebar/_familysidebarfilter.py +++ b/gramps/gui/filters/sidebar/_familysidebarfilter.py @@ -95,6 +95,7 @@ class FamilySidebarFilter(SidebarFilter): self.filter_note = widgets.BasicEntry() self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) + self.sensitive_regex = Gtk.CheckButton(label=_('Case sensitive')) self.tag = Gtk.ComboBox() self.generic = Gtk.ComboBox() @@ -128,6 +129,7 @@ class FamilySidebarFilter(SidebarFilter): self.add_entry(_('Tag'), self.tag) self.add_filter_entry(_('Custom filter'), self.generic) self.add_regex_entry(self.filter_regex) + self.add_regex_case(self.sensitive_regex) def clear(self, obj): self.filter_id.set_text('') @@ -149,6 +151,7 @@ class FamilySidebarFilter(SidebarFilter): etype = self.filter_event.get_type().xml_str() rtype = self.filter_family.get_relationship().xml_str() regex = self.filter_regex.get_active() + usecase = self.sensitive_regex.get_active() tag = self.tag.get_active() > 0 generic = self.generic.get_active() > 0 @@ -159,7 +162,7 @@ class FamilySidebarFilter(SidebarFilter): else: generic_filter = GenericFamilyFilter() if gid: - rule = RegExpIdOf([gid], use_regex=regex) + rule = RegExpIdOf([gid], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) if father: @@ -169,10 +172,10 @@ class FamilySidebarFilter(SidebarFilter): if not regex: name_parts = father.split(sep=" ") for name_part in name_parts: - rule = RegExpFatherName([name_part], use_regex=regex) + rule = RegExpFatherName([name_part], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) else: - rule = RegExpFatherName([father], use_regex=regex) + rule = RegExpFatherName([father], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) if mother: @@ -182,10 +185,10 @@ class FamilySidebarFilter(SidebarFilter): if not regex: name_parts = mother.split(sep=" ") for name_part in name_parts: - rule = RegExpMotherName([name_part], use_regex=regex) + rule = RegExpMotherName([name_part], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) else: - rule = RegExpMotherName([mother], use_regex=regex) + rule = RegExpMotherName([mother], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) if child: @@ -195,22 +198,22 @@ class FamilySidebarFilter(SidebarFilter): if not regex: name_parts = child.split(sep=" ") for name_part in name_parts: - rule = RegExpChildName([name_part], use_regex=regex) + rule = RegExpChildName([name_part], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) else: - rule = RegExpChildName([child], use_regex=regex) + rule = RegExpChildName([child], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) if etype: - rule = HasEvent([etype, '', '', '', ''], use_regex=regex) + rule = HasEvent([etype, '', '', '', ''], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) if rtype: - rule = HasRelType([rtype], use_regex=regex) + rule = HasRelType([rtype], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) if note: - rule = HasNoteRegexp([note], use_regex=regex) + rule = HasNoteRegexp([note], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) # check the Tag diff --git a/gramps/gui/filters/sidebar/_mediasidebarfilter.py b/gramps/gui/filters/sidebar/_mediasidebarfilter.py index 871bf9dab..355e086d0 100644 --- a/gramps/gui/filters/sidebar/_mediasidebarfilter.py +++ b/gramps/gui/filters/sidebar/_mediasidebarfilter.py @@ -64,6 +64,7 @@ class MediaSidebarFilter(SidebarFilter): self.filter_note = widgets.BasicEntry() self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) + self.sensitive_regex = Gtk.CheckButton(label=_('Case sensitive')) self.tag = Gtk.ComboBox() self.generic = Gtk.ComboBox() @@ -93,6 +94,7 @@ class MediaSidebarFilter(SidebarFilter): self.add_entry(_('Tag'), self.tag) self.add_filter_entry(_('Custom filter'), self.generic) self.add_regex_entry(self.filter_regex) + self.add_regex_case(self.sensitive_regex) def clear(self, obj): self.filter_id.set_text('') @@ -112,6 +114,7 @@ class MediaSidebarFilter(SidebarFilter): date = str(self.filter_date.get_text()).strip() note = str(self.filter_note.get_text()).strip() regex = self.filter_regex.get_active() + usecase = self.sensitive_regex.get_active() tag = self.tag.get_active() > 0 gen = self.generic.get_active() > 0 @@ -122,14 +125,14 @@ class MediaSidebarFilter(SidebarFilter): else: generic_filter = GenericMediaFilter() if gid: - rule = RegExpIdOf([gid], use_regex=regex) + rule = RegExpIdOf([gid], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) - rule = HasMedia([title, mime, path, date], use_regex=regex) + rule = HasMedia([title, mime, path, date], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) if note: - rule = HasNoteRegexp([note], use_regex=regex) + rule = HasNoteRegexp([note], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) # check the Tag diff --git a/gramps/gui/filters/sidebar/_notesidebarfilter.py b/gramps/gui/filters/sidebar/_notesidebarfilter.py index 3c63ce120..826d9596a 100644 --- a/gramps/gui/filters/sidebar/_notesidebarfilter.py +++ b/gramps/gui/filters/sidebar/_notesidebarfilter.py @@ -75,6 +75,7 @@ class NoteSidebarFilter(SidebarFilter): self.custom_types) self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) + self.sensitive_regex = Gtk.CheckButton(label=_('Case sensitive')) self.tag = Gtk.ComboBox() self.generic = Gtk.ComboBox() @@ -103,6 +104,7 @@ class NoteSidebarFilter(SidebarFilter): self.add_entry(_('Tag'), self.tag) self.add_filter_entry(_('Custom filter'), self.generic) self.add_regex_entry(self.filter_regex) + self.add_regex_case(self.sensitive_regex) def clear(self, obj): self.filter_id.set_text('') @@ -116,6 +118,7 @@ class NoteSidebarFilter(SidebarFilter): text = str(self.filter_text.get_text()).strip() ntype = self.note.get_type().xml_str() regex = self.filter_regex.get_active() + usecase = self.sensitive_regex.get_active() tag = self.tag.get_active() > 0 gen = self.generic.get_active() > 0 @@ -125,10 +128,10 @@ class NoteSidebarFilter(SidebarFilter): else: generic_filter = GenericNoteFilter() if gid: - rule = RegExpIdOf([gid], use_regex=regex) + rule = RegExpIdOf([gid], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) - rule = HasNote([text, ntype], use_regex=regex) + rule = HasNote([text, ntype], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) # check the Tag diff --git a/gramps/gui/filters/sidebar/_personsidebarfilter.py b/gramps/gui/filters/sidebar/_personsidebarfilter.py index 8b97b991a..4a92ef1f3 100644 --- a/gramps/gui/filters/sidebar/_personsidebarfilter.py +++ b/gramps/gui/filters/sidebar/_personsidebarfilter.py @@ -96,6 +96,7 @@ class PersonSidebarFilter(SidebarFilter): self.filter_gender.set_active(0) self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) + self.sensitive_regex = Gtk.CheckButton(label=_('Case sensitive')) self.tag = Gtk.ComboBox() self.generic = Gtk.ComboBox() @@ -141,6 +142,7 @@ class PersonSidebarFilter(SidebarFilter): self.add_entry(_('Tag'), self.tag) self.add_filter_entry(_('Custom filter'), self.generic) self.add_regex_entry(self.filter_regex) + self.add_regex_case(self.sensitive_regex) def clear(self, obj): self.filter_name.set_text('') @@ -170,6 +172,7 @@ class PersonSidebarFilter(SidebarFilter): etype = self.filter_event.get_type().xml_str() gender = self.filter_gender.get_active() regex = self.filter_regex.get_active() + usecase = self.sensitive_regex.get_active() tag = self.tag.get_active() > 0 generic = self.generic.get_active() > 0 @@ -191,16 +194,16 @@ class PersonSidebarFilter(SidebarFilter): if not regex: name_parts = name.split(sep=" ") for name_part in name_parts: - rule = RegExpName([name_part], use_regex=regex) + rule = RegExpName([name_part], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) else: - rule = RegExpName([name], use_regex=regex) + rule = RegExpName([name], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) # if the id is not empty, choose either the regular expression # version or the normal text match if gid: - rule = RegExpIdOf([gid], use_regex=regex) + rule = RegExpIdOf([gid], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) # check the gender, and select the right rule based on gender @@ -216,7 +219,7 @@ class PersonSidebarFilter(SidebarFilter): # Build an event filter if needed if etype: - rule = HasEvent([etype, '', '', '', '', '1'], use_regex=regex) + rule = HasEvent([etype, '', '', '', '', '1'], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) # Build birth event filter if needed @@ -234,7 +237,7 @@ class PersonSidebarFilter(SidebarFilter): # Build note filter if needed if note: - rule = HasNoteRegexp([note], use_regex=regex) + rule = HasNoteRegexp([note], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) # check the Tag diff --git a/gramps/gui/filters/sidebar/_placesidebarfilter.py b/gramps/gui/filters/sidebar/_placesidebarfilter.py index 1ac6fe0aa..0c5f5cb90 100644 --- a/gramps/gui/filters/sidebar/_placesidebarfilter.py +++ b/gramps/gui/filters/sidebar/_placesidebarfilter.py @@ -85,6 +85,7 @@ class PlaceSidebarFilter(SidebarFilter): self.filter_within = widgets.PlaceWithin(dbstate, uistate, []) self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) + self.sensitive_regex = Gtk.CheckButton(label=_('Case sensitive')) self.tag = Gtk.ComboBox() self.generic = Gtk.ComboBox() @@ -114,6 +115,7 @@ class PlaceSidebarFilter(SidebarFilter): self.add_entry(_('Tag'), self.tag) self.add_filter_entry(_('Custom filter'), self.generic) self.add_regex_entry(self.filter_regex) + self.add_regex_case(self.sensitive_regex) def clear(self, obj): self.filter_id.set_text('') @@ -135,6 +137,7 @@ class PlaceSidebarFilter(SidebarFilter): note = str(self.filter_note.get_text()).strip() within = self.filter_within.get_value() regex = self.filter_regex.get_active() + usecase = self.sensitive_regex.get_active() tag = self.tag.get_active() > 0 gen = self.generic.get_active() > 0 @@ -145,18 +148,18 @@ class PlaceSidebarFilter(SidebarFilter): else: generic_filter = GenericPlaceFilter() if gid: - rule = RegExpIdOf([gid], use_regex=regex) + rule = RegExpIdOf([gid], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) if enclosed: rule = IsEnclosedBy([enclosed, '0']) generic_filter.add_rule(rule) - rule = HasData([name, ptype, code], use_regex=regex) + rule = HasData([name, ptype, code], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) if note: - rule = HasNoteRegexp([note], use_regex=regex) + rule = HasNoteRegexp([note], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) if within and within[0] > 0 and self.dbstate.is_open(): diff --git a/gramps/gui/filters/sidebar/_reposidebarfilter.py b/gramps/gui/filters/sidebar/_reposidebarfilter.py index c6f58740c..9a56dccba 100644 --- a/gramps/gui/filters/sidebar/_reposidebarfilter.py +++ b/gramps/gui/filters/sidebar/_reposidebarfilter.py @@ -78,6 +78,7 @@ class RepoSidebarFilter(SidebarFilter): self.filter_note = widgets.BasicEntry() self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) + self.sensitive_regex = Gtk.CheckButton(label=_('Case sensitive')) self.tag = Gtk.ComboBox() self.generic = Gtk.ComboBox() @@ -109,6 +110,7 @@ class RepoSidebarFilter(SidebarFilter): self.add_entry(_('Tag'), self.tag) self.add_filter_entry(_('Custom filter'), self.generic) self.add_regex_entry(self.filter_regex) + self.add_regex_case(self.sensitive_regex) def clear(self, obj): self.filter_id.set_text('') @@ -128,6 +130,7 @@ class RepoSidebarFilter(SidebarFilter): rtype = self.repo.get_type().xml_str() note = str(self.filter_note.get_text()).strip() regex = self.filter_regex.get_active() + usecase = self.sensitive_regex.get_active() tag = self.tag.get_active() > 0 gen = self.generic.get_active() > 0 @@ -138,14 +141,14 @@ class RepoSidebarFilter(SidebarFilter): else: generic_filter = GenericRepoFilter() if gid: - rule = RegExpIdOf([gid], use_regex=regex) + rule = RegExpIdOf([gid], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) - rule = HasRepo([title, rtype, address, url], use_regex=regex) + rule = HasRepo([title, rtype, address, url], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) if note: - rule = HasNoteRegexp([note], use_regex=regex) + rule = HasNoteRegexp([note], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) # check the Tag diff --git a/gramps/gui/filters/sidebar/_sidebarfilter.py b/gramps/gui/filters/sidebar/_sidebarfilter.py index b8b140bc8..ea3998c4d 100644 --- a/gramps/gui/filters/sidebar/_sidebarfilter.py +++ b/gramps/gui/filters/sidebar/_sidebarfilter.py @@ -124,8 +124,23 @@ class SidebarFilter(DbGUIElement): def add_regex_entry(self, widget): hbox = Gtk.Box() hbox.pack_start(widget, False, False, 12) + widget.connect('toggled', self.regex_selection) self.vbox.pack_start(hbox, False, False, 0) + def add_regex_case(self, widget): + hbox = Gtk.Box() + hbox.pack_start(widget, False, False, 12) + self.vbox.pack_start(hbox, False, False, 0) + self.regex_selection() + + def regex_selection(self, widget=None): + if self.sensitive_regex: + if widget and widget.get_active(): + self.sensitive_regex.set_sensitive(True) + else: + self.sensitive_regex.set_active(False) + self.sensitive_regex.set_sensitive(False) + def add_text_entry(self, name, widget, tooltip=None): self.add_entry(name, widget) widget.connect('key-press-event', self.key_press) diff --git a/gramps/gui/filters/sidebar/_sourcesidebarfilter.py b/gramps/gui/filters/sidebar/_sourcesidebarfilter.py index 944dae4e4..08971cb9b 100644 --- a/gramps/gui/filters/sidebar/_sourcesidebarfilter.py +++ b/gramps/gui/filters/sidebar/_sourcesidebarfilter.py @@ -63,6 +63,7 @@ class SourceSidebarFilter(SidebarFilter): self.filter_note = widgets.BasicEntry() self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) + self.sensitive_regex = Gtk.CheckButton(label=_('Case sensitive')) self.tag = Gtk.ComboBox() self.generic = Gtk.ComboBox() @@ -92,6 +93,7 @@ class SourceSidebarFilter(SidebarFilter): self.add_entry(_('Tag'), self.tag) self.add_filter_entry(_('Custom filter'), self.generic) self.add_regex_entry(self.filter_regex) + self.add_regex_case(self.sensitive_regex) def clear(self, obj): self.filter_id.set_text('') @@ -111,6 +113,7 @@ class SourceSidebarFilter(SidebarFilter): pub = str(self.filter_pub.get_text()).strip() note = str(self.filter_note.get_text()).strip() regex = self.filter_regex.get_active() + usecase = self.sensitive_regex.get_active() tag = self.tag.get_active() > 0 gen = self.generic.get_active() > 0 @@ -121,14 +124,14 @@ class SourceSidebarFilter(SidebarFilter): else: generic_filter = GenericSourceFilter() if gid: - rule = RegExpIdOf([gid], use_regex=regex) + rule = RegExpIdOf([gid], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) - rule = HasSource([title, author, abbr, pub], use_regex=regex) + rule = HasSource([title, author, abbr, pub], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) if note: - rule = HasNoteRegexp([note], use_regex=regex) + rule = HasNoteRegexp([note], use_regex=regex, use_case=usecase) generic_filter.add_rule(rule) # check the Tag