Add the possibility of case sensitive/insensitive search

See https://gramps.discourse.group/t/help-with-regex-to-create-gramps-case-sensitive-filter/2536
This commit is contained in:
SNoiraud 2022-07-03 15:42:28 +02:00 committed by Nick Hall
parent e7e1b74aae
commit 8b64b9f145
15 changed files with 121 additions and 51 deletions

View File

@ -142,9 +142,9 @@ class FilterList:
file.write(' comment="%s"' % self.fix(comment)) file.write(' comment="%s"' % self.fix(comment))
file.write('>\n') file.write('>\n')
for rule in the_filter.get_rules(): for rule in the_filter.get_rules():
file.write(' <rule class="%s" use_regex="%s">' file.write(' <rule class="%s" use_regex="%s" use_case="%s">'
'\n' % (rule.__class__.__name__, '\n' % (rule.__class__.__name__,
rule.use_regex)) rule.use_regex, rule.use_case))
for value in list(rule.values()): for value in list(rule.values()):
file.write(' <arg value="%s"/>' file.write(' <arg value="%s"/>'
'\n' % self.fix(value)) '\n' % self.fix(value))

View File

@ -52,6 +52,7 @@ class FilterParser(handler.ContentHandler):
self.cname = None self.cname = None
self.namespace = 'Person' self.namespace = 'Person'
self.use_regex = False self.use_regex = False
self.use_case = False
def setDocumentLocator(self, locator): def setDocumentLocator(self, locator):
self.locator = locator self.locator = locator
@ -87,6 +88,10 @@ class FilterParser(handler.ContentHandler):
self.use_regex = attrs['use_regex'] == 'True' self.use_regex = attrs['use_regex'] == 'True'
else: else:
self.use_regex = False 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'] save_name = attrs['class']
if save_name in old_names_2_class: if save_name in old_names_2_class:
self.r = old_names_2_class[save_name] self.r = old_names_2_class[save_name]
@ -120,7 +125,7 @@ class FilterParser(handler.ContentHandler):
"Trying to load with subset of arguments.") %\ "Trying to load with subset of arguments.") %\
self.f.get_name()) self.f.get_name())
nargs = len(self.r.labels) 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) self.f.add_rule(rule)
else: else:
if len(self.r.labels) > len(self.a): if len(self.r.labels) > len(self.a):
@ -129,7 +134,7 @@ class FilterParser(handler.ContentHandler):
"will be upgraded.") %\ "will be upgraded.") %\
self.f.get_name()) self.f.get_name())
try: try:
rule = self.r(self.a, self.use_regex) rule = self.r(self.a, self.use_regex, self.use_case)
except AssertionError as msg: except AssertionError as msg:
print(msg) print(msg)
print(_("ERROR: filter %s could not be correctly loaded. " print(_("ERROR: filter %s could not be correctly loaded. "

View File

@ -48,13 +48,13 @@ class HasNoteBase(Rule):
description = "Matches objects that have a certain number of notes" description = "Matches objects that have a certain number of notes"
category = _('General filters') 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 # Upgrade from pre 3.1 HasNote filter, use defaults that correspond
# Previous filter had 0 arguments # Previous filter had 0 arguments
if len(arg) == 0: if len(arg) == 0:
Rule.__init__(self, ["0", 'greater than'], use_regex) Rule.__init__(self, ["0", 'greater than'], use_regex, use_case)
else: else:
Rule.__init__(self, arg, use_regex) Rule.__init__(self, arg, use_regex, use_case)
def prepare(self, db, user): def prepare(self, db, user):
# things we want to do just once, not for every handle # things we want to do just once, not for every handle

View File

@ -56,12 +56,13 @@ class Rule:
description = _('No description') description = _('No description')
allow_regex = False allow_regex = False
def __init__(self, arg, use_regex=False): def __init__(self, arg, use_regex=False, use_case=False):
self.list = [] self.list = []
self.regex = [] self.regex = []
self.match_substring = self.__match_substring self.match_substring = self.__match_substring
self.set_list(arg) self.set_list(arg)
self.use_regex = use_regex self.use_regex = use_regex
self.use_case = use_case
self.nrprepare = 0 self.nrprepare = 0
def is_empty(self): def is_empty(self):
@ -84,6 +85,9 @@ class Rule:
for index, label in enumerate(self.labels): for index, label in enumerate(self.labels):
if self.list[index]: if self.list[index]:
try: try:
if self.use_case:
self.regex[index] = re.compile(self.list[index])
else:
self.regex[index] = re.compile(self.list[index], re.I) self.regex[index] = re.compile(self.list[index], re.I)
except re.error: except re.error:
self.regex[index] = re.compile('') self.regex[index] = re.compile('')

View File

@ -609,6 +609,7 @@ class EditRule(ManagedWindow):
pos += 1 pos += 1
use_regex = None use_regex = None
use_case = None
if class_obj.allow_regex: if class_obj.allow_regex:
use_regex = Gtk.CheckButton(label=_('Use regular expressions')) use_regex = Gtk.CheckButton(label=_('Use regular expressions'))
tip = _('Interpret the contents of string fields as regular ' tip = _('Interpret the contents of string fields as regular '
@ -625,7 +626,13 @@ class EditRule(ManagedWindow):
use_regex.set_tooltip_text(tip) use_regex.set_tooltip_text(tip)
grid.attach(use_regex, 1, pos, 1, 1) 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: # put the grid into a scrollable area:
scrolled_win = Gtk.ScrolledWindow() scrolled_win = Gtk.ScrolledWindow()
@ -684,12 +691,14 @@ class EditRule(ManagedWindow):
page = self.class2page[self.active_rule.__class__] page = self.class2page[self.active_rule.__class__]
self.notebook.set_current_page(page) self.notebook.set_current_page(page)
self.display_values(self.active_rule.__class__) 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()) r = list(self.active_rule.values())
for i in range(0, min(len(tlist), len(r))): for i in range(0, min(len(tlist), len(r))):
tlist[i].set_text(r[i]) tlist[i].set_text(r[i])
if class_obj.allow_regex: if class_obj.allow_regex:
use_regex.set_active(self.active_rule.use_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.selection.connect('changed', self.on_node_selected)
self.rname.connect('button-press-event', self._button_press) self.rname.connect('button-press-event', self._button_press)
@ -706,6 +715,14 @@ class EditRule(ManagedWindow):
self.rname.restore_column_size() self.rname.restore_column_size()
self.show() 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): def select_iter(self, data):
""" """
Workaround to get self.selection to move to iter row. Workaround to get self.selection to move to iter row.
@ -787,10 +804,10 @@ class EditRule(ManagedWindow):
try: try:
page = self.notebook.get_current_page() 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] value_list = [str(sclass.get_text()) for sclass in tlist]
if class_obj.allow_regex: 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: else:
new_rule = class_obj(value_list) new_rule = class_obj(value_list)

View File

@ -74,6 +74,7 @@ class CitationSidebarFilter(SidebarFilter):
self.filter_note = Gtk.Entry() self.filter_note = Gtk.Entry()
self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))
self.sensitive_regex = Gtk.CheckButton(label=_('Case sensitive'))
self.tag = Gtk.ComboBox() self.tag = Gtk.ComboBox()
self.generic = Gtk.ComboBox() self.generic = Gtk.ComboBox()
@ -116,6 +117,9 @@ class CitationSidebarFilter(SidebarFilter):
self.add_entry(_('Tag'), self.tag) self.add_entry(_('Tag'), self.tag)
self.add_filter_entry(_('Custom filter'), self.generic) self.add_filter_entry(_('Custom filter'), self.generic)
self.add_entry(None, self.filter_regex) 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): def clear(self, obj):
self.filter_src_id.set_text('') self.filter_src_id.set_text('')
@ -145,6 +149,7 @@ class CitationSidebarFilter(SidebarFilter):
conf = str(self.filter_conf.get_active()) conf = str(self.filter_conf.get_active())
note = str(self.filter_note.get_text()).strip() note = str(self.filter_note.get_text()).strip()
regex = self.filter_regex.get_active() regex = self.filter_regex.get_active()
usecase = self.sensitive_regex.get_active()
tag = self.tag.get_active() > 0 tag = self.tag.get_active() > 0
gen = self.generic.get_active() > 0 gen = self.generic.get_active() > 0
@ -156,26 +161,26 @@ class CitationSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericCitationFilter() generic_filter = GenericCitationFilter()
if gid: if gid:
rule = RegExpIdOf([gid], use_regex=regex) rule = RegExpIdOf([gid], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) 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) generic_filter.add_rule(rule)
if src_id: 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) generic_filter.add_rule(rule)
rule = HasSource([src_title, src_author, src_abbr, src_pub], rule = HasSource([src_title, src_author, src_abbr, src_pub],
use_regex=regex) use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if note: if note:
rule = HasNoteRegexp([note], use_regex=regex) rule = HasNoteRegexp([note], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if src_note: 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) generic_filter.add_rule(rule)
# check the Tag # check the Tag

View File

@ -78,6 +78,7 @@ class EventSidebarFilter(SidebarFilter):
self.filter_note = widgets.BasicEntry() self.filter_note = widgets.BasicEntry()
self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))
self.sensitive_regex = Gtk.CheckButton(label=_('Case sensitive'))
self.tag = Gtk.ComboBox() self.tag = Gtk.ComboBox()
self.generic = Gtk.ComboBox() self.generic = Gtk.ComboBox()
@ -110,6 +111,7 @@ class EventSidebarFilter(SidebarFilter):
self.add_entry(_('Tag'), self.tag) self.add_entry(_('Tag'), self.tag)
self.add_filter_entry(_('Custom filter'), self.generic) self.add_filter_entry(_('Custom filter'), self.generic)
self.add_regex_entry(self.filter_regex) self.add_regex_entry(self.filter_regex)
self.add_regex_case(self.sensitive_regex)
def clear(self, obj): def clear(self, obj):
self.filter_id.set_text('') self.filter_id.set_text('')
@ -130,6 +132,7 @@ class EventSidebarFilter(SidebarFilter):
place = str(self.filter_place.get_text()).strip() place = str(self.filter_place.get_text()).strip()
note = str(self.filter_note.get_text()).strip() note = str(self.filter_note.get_text()).strip()
regex = self.filter_regex.get_active() regex = self.filter_regex.get_active()
usecase = self.sensitive_regex.get_active()
tag = self.tag.get_active() > 0 tag = self.tag.get_active() > 0
generic = self.generic.get_active() > 0 generic = self.generic.get_active() > 0
etype = self.filter_event.get_type().xml_str() etype = self.filter_event.get_type().xml_str()
@ -141,15 +144,15 @@ class EventSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericEventFilter() generic_filter = GenericEventFilter()
if gid: if gid:
rule = RegExpIdOf([gid], use_regex=regex) rule = RegExpIdOf([gid], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
rule = HasEvent([etype, date, place, desc, mainparts], rule = HasEvent([etype, date, place, desc, mainparts],
use_regex=regex) use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if note: if note:
rule = HasNoteRegexp([note], use_regex=regex) rule = HasNoteRegexp([note], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the Tag # check the Tag

View File

@ -95,6 +95,7 @@ class FamilySidebarFilter(SidebarFilter):
self.filter_note = widgets.BasicEntry() self.filter_note = widgets.BasicEntry()
self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))
self.sensitive_regex = Gtk.CheckButton(label=_('Case sensitive'))
self.tag = Gtk.ComboBox() self.tag = Gtk.ComboBox()
self.generic = Gtk.ComboBox() self.generic = Gtk.ComboBox()
@ -128,6 +129,7 @@ class FamilySidebarFilter(SidebarFilter):
self.add_entry(_('Tag'), self.tag) self.add_entry(_('Tag'), self.tag)
self.add_filter_entry(_('Custom filter'), self.generic) self.add_filter_entry(_('Custom filter'), self.generic)
self.add_regex_entry(self.filter_regex) self.add_regex_entry(self.filter_regex)
self.add_regex_case(self.sensitive_regex)
def clear(self, obj): def clear(self, obj):
self.filter_id.set_text('') self.filter_id.set_text('')
@ -149,6 +151,7 @@ class FamilySidebarFilter(SidebarFilter):
etype = self.filter_event.get_type().xml_str() etype = self.filter_event.get_type().xml_str()
rtype = self.filter_family.get_relationship().xml_str() rtype = self.filter_family.get_relationship().xml_str()
regex = self.filter_regex.get_active() regex = self.filter_regex.get_active()
usecase = self.sensitive_regex.get_active()
tag = self.tag.get_active() > 0 tag = self.tag.get_active() > 0
generic = self.generic.get_active() > 0 generic = self.generic.get_active() > 0
@ -159,7 +162,7 @@ class FamilySidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericFamilyFilter() generic_filter = GenericFamilyFilter()
if gid: if gid:
rule = RegExpIdOf([gid], use_regex=regex) rule = RegExpIdOf([gid], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if father: if father:
@ -169,10 +172,10 @@ class FamilySidebarFilter(SidebarFilter):
if not regex: if not regex:
name_parts = father.split(sep=" ") name_parts = father.split(sep=" ")
for name_part in name_parts: 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) generic_filter.add_rule(rule)
else: else:
rule = RegExpFatherName([father], use_regex=regex) rule = RegExpFatherName([father], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if mother: if mother:
@ -182,10 +185,10 @@ class FamilySidebarFilter(SidebarFilter):
if not regex: if not regex:
name_parts = mother.split(sep=" ") name_parts = mother.split(sep=" ")
for name_part in name_parts: 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) generic_filter.add_rule(rule)
else: else:
rule = RegExpMotherName([mother], use_regex=regex) rule = RegExpMotherName([mother], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if child: if child:
@ -195,22 +198,22 @@ class FamilySidebarFilter(SidebarFilter):
if not regex: if not regex:
name_parts = child.split(sep=" ") name_parts = child.split(sep=" ")
for name_part in name_parts: 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) generic_filter.add_rule(rule)
else: else:
rule = RegExpChildName([child], use_regex=regex) rule = RegExpChildName([child], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if etype: if etype:
rule = HasEvent([etype, '', '', '', ''], use_regex=regex) rule = HasEvent([etype, '', '', '', ''], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if rtype: if rtype:
rule = HasRelType([rtype], use_regex=regex) rule = HasRelType([rtype], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if note: if note:
rule = HasNoteRegexp([note], use_regex=regex) rule = HasNoteRegexp([note], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the Tag # check the Tag

View File

@ -64,6 +64,7 @@ class MediaSidebarFilter(SidebarFilter):
self.filter_note = widgets.BasicEntry() self.filter_note = widgets.BasicEntry()
self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))
self.sensitive_regex = Gtk.CheckButton(label=_('Case sensitive'))
self.tag = Gtk.ComboBox() self.tag = Gtk.ComboBox()
self.generic = Gtk.ComboBox() self.generic = Gtk.ComboBox()
@ -93,6 +94,7 @@ class MediaSidebarFilter(SidebarFilter):
self.add_entry(_('Tag'), self.tag) self.add_entry(_('Tag'), self.tag)
self.add_filter_entry(_('Custom filter'), self.generic) self.add_filter_entry(_('Custom filter'), self.generic)
self.add_regex_entry(self.filter_regex) self.add_regex_entry(self.filter_regex)
self.add_regex_case(self.sensitive_regex)
def clear(self, obj): def clear(self, obj):
self.filter_id.set_text('') self.filter_id.set_text('')
@ -112,6 +114,7 @@ class MediaSidebarFilter(SidebarFilter):
date = str(self.filter_date.get_text()).strip() date = str(self.filter_date.get_text()).strip()
note = str(self.filter_note.get_text()).strip() note = str(self.filter_note.get_text()).strip()
regex = self.filter_regex.get_active() regex = self.filter_regex.get_active()
usecase = self.sensitive_regex.get_active()
tag = self.tag.get_active() > 0 tag = self.tag.get_active() > 0
gen = self.generic.get_active() > 0 gen = self.generic.get_active() > 0
@ -122,14 +125,14 @@ class MediaSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericMediaFilter() generic_filter = GenericMediaFilter()
if gid: if gid:
rule = RegExpIdOf([gid], use_regex=regex) rule = RegExpIdOf([gid], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) 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) generic_filter.add_rule(rule)
if note: if note:
rule = HasNoteRegexp([note], use_regex=regex) rule = HasNoteRegexp([note], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the Tag # check the Tag

View File

@ -75,6 +75,7 @@ class NoteSidebarFilter(SidebarFilter):
self.custom_types) self.custom_types)
self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))
self.sensitive_regex = Gtk.CheckButton(label=_('Case sensitive'))
self.tag = Gtk.ComboBox() self.tag = Gtk.ComboBox()
self.generic = Gtk.ComboBox() self.generic = Gtk.ComboBox()
@ -103,6 +104,7 @@ class NoteSidebarFilter(SidebarFilter):
self.add_entry(_('Tag'), self.tag) self.add_entry(_('Tag'), self.tag)
self.add_filter_entry(_('Custom filter'), self.generic) self.add_filter_entry(_('Custom filter'), self.generic)
self.add_regex_entry(self.filter_regex) self.add_regex_entry(self.filter_regex)
self.add_regex_case(self.sensitive_regex)
def clear(self, obj): def clear(self, obj):
self.filter_id.set_text('') self.filter_id.set_text('')
@ -116,6 +118,7 @@ class NoteSidebarFilter(SidebarFilter):
text = str(self.filter_text.get_text()).strip() text = str(self.filter_text.get_text()).strip()
ntype = self.note.get_type().xml_str() ntype = self.note.get_type().xml_str()
regex = self.filter_regex.get_active() regex = self.filter_regex.get_active()
usecase = self.sensitive_regex.get_active()
tag = self.tag.get_active() > 0 tag = self.tag.get_active() > 0
gen = self.generic.get_active() > 0 gen = self.generic.get_active() > 0
@ -125,10 +128,10 @@ class NoteSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericNoteFilter() generic_filter = GenericNoteFilter()
if gid: if gid:
rule = RegExpIdOf([gid], use_regex=regex) rule = RegExpIdOf([gid], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) 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) generic_filter.add_rule(rule)
# check the Tag # check the Tag

View File

@ -96,6 +96,7 @@ class PersonSidebarFilter(SidebarFilter):
self.filter_gender.set_active(0) self.filter_gender.set_active(0)
self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))
self.sensitive_regex = Gtk.CheckButton(label=_('Case sensitive'))
self.tag = Gtk.ComboBox() self.tag = Gtk.ComboBox()
self.generic = Gtk.ComboBox() self.generic = Gtk.ComboBox()
@ -141,6 +142,7 @@ class PersonSidebarFilter(SidebarFilter):
self.add_entry(_('Tag'), self.tag) self.add_entry(_('Tag'), self.tag)
self.add_filter_entry(_('Custom filter'), self.generic) self.add_filter_entry(_('Custom filter'), self.generic)
self.add_regex_entry(self.filter_regex) self.add_regex_entry(self.filter_regex)
self.add_regex_case(self.sensitive_regex)
def clear(self, obj): def clear(self, obj):
self.filter_name.set_text('') self.filter_name.set_text('')
@ -170,6 +172,7 @@ class PersonSidebarFilter(SidebarFilter):
etype = self.filter_event.get_type().xml_str() etype = self.filter_event.get_type().xml_str()
gender = self.filter_gender.get_active() gender = self.filter_gender.get_active()
regex = self.filter_regex.get_active() regex = self.filter_regex.get_active()
usecase = self.sensitive_regex.get_active()
tag = self.tag.get_active() > 0 tag = self.tag.get_active() > 0
generic = self.generic.get_active() > 0 generic = self.generic.get_active() > 0
@ -191,16 +194,16 @@ class PersonSidebarFilter(SidebarFilter):
if not regex: if not regex:
name_parts = name.split(sep=" ") name_parts = name.split(sep=" ")
for name_part in name_parts: 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) generic_filter.add_rule(rule)
else: else:
rule = RegExpName([name], use_regex=regex) rule = RegExpName([name], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# if the id is not empty, choose either the regular expression # if the id is not empty, choose either the regular expression
# version or the normal text match # version or the normal text match
if gid: if gid:
rule = RegExpIdOf([gid], use_regex=regex) rule = RegExpIdOf([gid], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the gender, and select the right rule based on gender # check the gender, and select the right rule based on gender
@ -216,7 +219,7 @@ class PersonSidebarFilter(SidebarFilter):
# Build an event filter if needed # Build an event filter if needed
if etype: if etype:
rule = HasEvent([etype, '', '', '', '', '1'], use_regex=regex) rule = HasEvent([etype, '', '', '', '', '1'], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# Build birth event filter if needed # Build birth event filter if needed
@ -234,7 +237,7 @@ class PersonSidebarFilter(SidebarFilter):
# Build note filter if needed # Build note filter if needed
if note: if note:
rule = HasNoteRegexp([note], use_regex=regex) rule = HasNoteRegexp([note], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the Tag # check the Tag

View File

@ -85,6 +85,7 @@ class PlaceSidebarFilter(SidebarFilter):
self.filter_within = widgets.PlaceWithin(dbstate, uistate, []) self.filter_within = widgets.PlaceWithin(dbstate, uistate, [])
self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))
self.sensitive_regex = Gtk.CheckButton(label=_('Case sensitive'))
self.tag = Gtk.ComboBox() self.tag = Gtk.ComboBox()
self.generic = Gtk.ComboBox() self.generic = Gtk.ComboBox()
@ -114,6 +115,7 @@ class PlaceSidebarFilter(SidebarFilter):
self.add_entry(_('Tag'), self.tag) self.add_entry(_('Tag'), self.tag)
self.add_filter_entry(_('Custom filter'), self.generic) self.add_filter_entry(_('Custom filter'), self.generic)
self.add_regex_entry(self.filter_regex) self.add_regex_entry(self.filter_regex)
self.add_regex_case(self.sensitive_regex)
def clear(self, obj): def clear(self, obj):
self.filter_id.set_text('') self.filter_id.set_text('')
@ -135,6 +137,7 @@ class PlaceSidebarFilter(SidebarFilter):
note = str(self.filter_note.get_text()).strip() note = str(self.filter_note.get_text()).strip()
within = self.filter_within.get_value() within = self.filter_within.get_value()
regex = self.filter_regex.get_active() regex = self.filter_regex.get_active()
usecase = self.sensitive_regex.get_active()
tag = self.tag.get_active() > 0 tag = self.tag.get_active() > 0
gen = self.generic.get_active() > 0 gen = self.generic.get_active() > 0
@ -145,18 +148,18 @@ class PlaceSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericPlaceFilter() generic_filter = GenericPlaceFilter()
if gid: if gid:
rule = RegExpIdOf([gid], use_regex=regex) rule = RegExpIdOf([gid], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if enclosed: if enclosed:
rule = IsEnclosedBy([enclosed, '0']) rule = IsEnclosedBy([enclosed, '0'])
generic_filter.add_rule(rule) 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) generic_filter.add_rule(rule)
if note: if note:
rule = HasNoteRegexp([note], use_regex=regex) rule = HasNoteRegexp([note], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if within and within[0] > 0 and self.dbstate.is_open(): if within and within[0] > 0 and self.dbstate.is_open():

View File

@ -78,6 +78,7 @@ class RepoSidebarFilter(SidebarFilter):
self.filter_note = widgets.BasicEntry() self.filter_note = widgets.BasicEntry()
self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))
self.sensitive_regex = Gtk.CheckButton(label=_('Case sensitive'))
self.tag = Gtk.ComboBox() self.tag = Gtk.ComboBox()
self.generic = Gtk.ComboBox() self.generic = Gtk.ComboBox()
@ -109,6 +110,7 @@ class RepoSidebarFilter(SidebarFilter):
self.add_entry(_('Tag'), self.tag) self.add_entry(_('Tag'), self.tag)
self.add_filter_entry(_('Custom filter'), self.generic) self.add_filter_entry(_('Custom filter'), self.generic)
self.add_regex_entry(self.filter_regex) self.add_regex_entry(self.filter_regex)
self.add_regex_case(self.sensitive_regex)
def clear(self, obj): def clear(self, obj):
self.filter_id.set_text('') self.filter_id.set_text('')
@ -128,6 +130,7 @@ class RepoSidebarFilter(SidebarFilter):
rtype = self.repo.get_type().xml_str() rtype = self.repo.get_type().xml_str()
note = str(self.filter_note.get_text()).strip() note = str(self.filter_note.get_text()).strip()
regex = self.filter_regex.get_active() regex = self.filter_regex.get_active()
usecase = self.sensitive_regex.get_active()
tag = self.tag.get_active() > 0 tag = self.tag.get_active() > 0
gen = self.generic.get_active() > 0 gen = self.generic.get_active() > 0
@ -138,14 +141,14 @@ class RepoSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericRepoFilter() generic_filter = GenericRepoFilter()
if gid: if gid:
rule = RegExpIdOf([gid], use_regex=regex) rule = RegExpIdOf([gid], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) 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) generic_filter.add_rule(rule)
if note: if note:
rule = HasNoteRegexp([note], use_regex=regex) rule = HasNoteRegexp([note], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the Tag # check the Tag

View File

@ -124,8 +124,23 @@ class SidebarFilter(DbGUIElement):
def add_regex_entry(self, widget): def add_regex_entry(self, widget):
hbox = Gtk.Box() hbox = Gtk.Box()
hbox.pack_start(widget, False, False, 12) hbox.pack_start(widget, False, False, 12)
widget.connect('toggled', self.regex_selection)
self.vbox.pack_start(hbox, False, False, 0) 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): def add_text_entry(self, name, widget, tooltip=None):
self.add_entry(name, widget) self.add_entry(name, widget)
widget.connect('key-press-event', self.key_press) widget.connect('key-press-event', self.key_press)

View File

@ -63,6 +63,7 @@ class SourceSidebarFilter(SidebarFilter):
self.filter_note = widgets.BasicEntry() self.filter_note = widgets.BasicEntry()
self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))
self.sensitive_regex = Gtk.CheckButton(label=_('Case sensitive'))
self.tag = Gtk.ComboBox() self.tag = Gtk.ComboBox()
self.generic = Gtk.ComboBox() self.generic = Gtk.ComboBox()
@ -92,6 +93,7 @@ class SourceSidebarFilter(SidebarFilter):
self.add_entry(_('Tag'), self.tag) self.add_entry(_('Tag'), self.tag)
self.add_filter_entry(_('Custom filter'), self.generic) self.add_filter_entry(_('Custom filter'), self.generic)
self.add_regex_entry(self.filter_regex) self.add_regex_entry(self.filter_regex)
self.add_regex_case(self.sensitive_regex)
def clear(self, obj): def clear(self, obj):
self.filter_id.set_text('') self.filter_id.set_text('')
@ -111,6 +113,7 @@ class SourceSidebarFilter(SidebarFilter):
pub = str(self.filter_pub.get_text()).strip() pub = str(self.filter_pub.get_text()).strip()
note = str(self.filter_note.get_text()).strip() note = str(self.filter_note.get_text()).strip()
regex = self.filter_regex.get_active() regex = self.filter_regex.get_active()
usecase = self.sensitive_regex.get_active()
tag = self.tag.get_active() > 0 tag = self.tag.get_active() > 0
gen = self.generic.get_active() > 0 gen = self.generic.get_active() > 0
@ -121,14 +124,14 @@ class SourceSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericSourceFilter() generic_filter = GenericSourceFilter()
if gid: if gid:
rule = RegExpIdOf([gid], use_regex=regex) rule = RegExpIdOf([gid], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) 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) generic_filter.add_rule(rule)
if note: if note:
rule = HasNoteRegexp([note], use_regex=regex) rule = HasNoteRegexp([note], use_regex=regex, use_case=usecase)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the Tag # check the Tag