From 21fd8f2cfbeff549fa22d7529a4643599f1632e1 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Fri, 30 Aug 2013 20:34:01 +0000 Subject: [PATCH] Fix regular expressions in sidebar filters svn: r22967 --- .../filters/sidebar/_citationsidebarfilter.py | 58 ++++++++++++------ .../filters/sidebar/_eventsidebarfilter.py | 58 ++++++++++++------ .../filters/sidebar/_familysidebarfilter.py | 35 +++-------- .../filters/sidebar/_mediasidebarfilter.py | 15 ++--- .../gui/filters/sidebar/_notesidebarfilter.py | 9 +-- .../filters/sidebar/_personsidebarfilter.py | 25 +++----- .../filters/sidebar/_placesidebarfilter.py | 47 +++++++++++---- .../gui/filters/sidebar/_reposidebarfilter.py | 58 ++++++++++++------ .../filters/sidebar/_sourcesidebarfilter.py | 60 +++++++++++++------ 9 files changed, 220 insertions(+), 145 deletions(-) diff --git a/gramps/gui/filters/sidebar/_citationsidebarfilter.py b/gramps/gui/filters/sidebar/_citationsidebarfilter.py index beb8b99d2..cd7cea680 100644 --- a/gramps/gui/filters/sidebar/_citationsidebarfilter.py +++ b/gramps/gui/filters/sidebar/_citationsidebarfilter.py @@ -47,9 +47,8 @@ from .. import build_filter_model from . import SidebarFilter from gramps.gen.constfunc import cuni from gramps.gen.filters import GenericFilterFactory, rules -from gramps.gen.filters.rules.citation import (RegExpIdOf, HasIdOf, HasCitation, - HasNoteMatchingSubstringOf, - HasNoteRegexp, MatchesFilter) +from gramps.gen.filters.rules.citation import (RegExpIdOf, HasCitation, HasTag, + HasNoteRegexp, MatchesFilter) from gramps.gen.utils.string import confidence GenericCitationFilter = GenericFilterFactory('Citation') #------------------------------------------------------------------------- @@ -76,6 +75,7 @@ class CitationSidebarFilter(SidebarFilter): self.filter_regex = Gtk.CheckButton(_('Use regular expressions')) + self.tag = Gtk.ComboBox() self.generic = Gtk.ComboBox() SidebarFilter.__init__(self, dbstate, uistate, "Citation") @@ -94,11 +94,18 @@ class CitationSidebarFilter(SidebarFilter): self.filter_conf.pack_start(cell, True) self.filter_conf.add_attribute(cell, 'text', 0) + cell = Gtk.CellRendererText() + cell.set_property('width', self._FILTER_WIDTH) + cell.set_property('ellipsize', self._FILTER_ELLIPSIZE) + self.tag.pack_start(cell, True) + self.tag.add_attribute(cell, 'text', 0) + self.add_text_entry(_('ID'), self.filter_id) self.add_text_entry(_('Volume/Page'), self.filter_page) self.add_text_entry(_('Date'), self.filter_date) self.add_entry(_('Minimum Confidence|Min. Conf.'), self.filter_conf) self.add_text_entry(_('Note'), self.filter_note) + self.add_entry(_('Tag'), self.tag) self.add_filter_entry(_('Custom filter'), self.generic) self.add_entry(None, self.filter_regex) @@ -108,6 +115,7 @@ class CitationSidebarFilter(SidebarFilter): self.filter_date.set_text('') self.filter_conf.set_active(2) self.filter_note.set_text('') + self.tag.set_active(0) self.generic.set_active(0) def get_filter(self): @@ -125,36 +133,39 @@ class CitationSidebarFilter(SidebarFilter): # conf = self.citn.get_confidence_level() note = cuni(self.filter_note.get_text()).strip() regex = self.filter_regex.get_active() + tag = self.tag.get_active() > 0 gen = self.generic.get_active() > 0 - empty = not (gid or page or date or conf or note or regex or gen) + empty = not (gid or page or date or conf or note or regex or tag or gen) if empty: generic_filter = None else: generic_filter = GenericCitationFilter() if gid: - if regex: - rule = RegExpIdOf([gid]) - else: - rule = HasIdOf([gid]) + rule = RegExpIdOf([gid], use_regex=regex) generic_filter.add_rule(rule) rule = HasCitation([page, date, conf], use_regex=regex) generic_filter.add_rule(rule) if note: - if regex: - rule = HasNoteRegexp([note]) - else: - rule = HasNoteMatchingSubstringOf([note]) + rule = HasNoteRegexp([note], use_regex=regex) generic_filter.add_rule(rule) - if self.generic.get_active() != 0: - model = self.generic.get_model() - node = self.generic.get_active_iter() - obj = cuni(model.get_value(node, 0)) - rule = MatchesFilter([obj]) - generic_filter.add_rule(rule) + # check the Tag + if tag: + model = self.tag.get_model() + node = self.tag.get_active_iter() + attr = model.get_value(node, 0) + rule = HasTag([attr]) + generic_filter.add_rule(rule) + + if self.generic.get_active() != 0: + model = self.generic.get_model() + node = self.generic.get_active_iter() + obj = cuni(model.get_value(node, 0)) + rule = MatchesFilter([obj]) + generic_filter.add_rule(rule) return generic_filter @@ -165,3 +176,14 @@ class CitationSidebarFilter(SidebarFilter): all_filter.add_rule(rules.citation.AllCitations([])) self.generic.set_model(build_filter_model('Citation', [all_filter])) self.generic.set_active(0) + + def on_tags_changed(self, tag_list): + """ + Update the list of tags in the tag filter. + """ + model = Gtk.ListStore(str) + model.append(('',)) + for tag_name in tag_list: + model.append((tag_name,)) + self.tag.set_model(model) + self.tag.set_active(0) diff --git a/gramps/gui/filters/sidebar/_eventsidebarfilter.py b/gramps/gui/filters/sidebar/_eventsidebarfilter.py index 222e58a51..7ec480d35 100644 --- a/gramps/gui/filters/sidebar/_eventsidebarfilter.py +++ b/gramps/gui/filters/sidebar/_eventsidebarfilter.py @@ -46,9 +46,8 @@ from .. import build_filter_model from . import SidebarFilter from gramps.gen.constfunc import cuni from gramps.gen.filters import GenericFilterFactory, rules -from gramps.gen.filters.rules.event import (RegExpIdOf, HasIdOf, HasNoteRegexp, - HasNoteMatchingSubstringOf, MatchesFilter, - HasEvent) +from gramps.gen.filters.rules.event import (RegExpIdOf, HasNoteRegexp, + MatchesFilter, HasEvent, HasTag) GenericEventFilter = GenericFilterFactory('Event') #------------------------------------------------------------------------- @@ -78,6 +77,7 @@ class EventSidebarFilter(SidebarFilter): self.filter_regex = Gtk.CheckButton(_('Use regular expressions')) + self.tag = Gtk.ComboBox() self.generic = Gtk.ComboBox() SidebarFilter.__init__(self, dbstate, uistate, "Event") @@ -90,6 +90,12 @@ class EventSidebarFilter(SidebarFilter): self.generic.add_attribute(cell, 'text', 0) self.on_filters_changed('Event') + cell = Gtk.CellRendererText() + cell.set_property('width', self._FILTER_WIDTH) + cell.set_property('ellipsize', self._FILTER_ELLIPSIZE) + self.tag.pack_start(cell, True) + self.tag.add_attribute(cell, 'text', 0) + self.etype.get_child().set_width_chars(5) self.add_text_entry(_('ID'), self.filter_id) @@ -99,6 +105,7 @@ class EventSidebarFilter(SidebarFilter): self.add_text_entry(_('Date'), self.filter_date) self.add_text_entry(_('Place'), self.filter_place) self.add_text_entry(_('Note'), self.filter_note) + self.add_entry(_('Tag'), self.tag) self.add_filter_entry(_('Custom filter'), self.generic) self.add_regex_entry(self.filter_regex) @@ -110,6 +117,7 @@ class EventSidebarFilter(SidebarFilter): self.filter_place.set_text('') self.filter_note.set_text('') self.etype.get_child().set_text('') + self.tag.set_active(0) self.generic.set_active(0) def get_filter(self): @@ -120,20 +128,18 @@ class EventSidebarFilter(SidebarFilter): place = cuni(self.filter_place.get_text()).strip() note = cuni(self.filter_note.get_text()).strip() regex = self.filter_regex.get_active() + tag = self.tag.get_active() > 0 generic = self.generic.get_active() > 0 etype = self.filter_event.get_type().xml_str() empty = not (gid or desc or mainparts or date or place or note - or etype or regex or generic) + or etype or regex or tag or generic) if empty: generic_filter = None else: generic_filter = GenericEventFilter() if gid: - if regex: - rule = RegExpIdOf([gid]) - else: - rule = HasIdOf([gid]) + rule = RegExpIdOf([gid], use_regex=regex) generic_filter.add_rule(rule) rule = HasEvent([etype, date, place, desc, mainparts], @@ -141,18 +147,23 @@ class EventSidebarFilter(SidebarFilter): generic_filter.add_rule(rule) if note: - if regex: - rule = HasNoteRegexp([note]) - else: - rule = HasNoteMatchingSubstringOf([note]) + rule = HasNoteRegexp([note], use_regex=regex) generic_filter.add_rule(rule) - if self.generic.get_active() != 0: - model = self.generic.get_model() - node = self.generic.get_active_iter() - obj = cuni(model.get_value(node, 0)) - rule = MatchesFilter([obj]) - generic_filter.add_rule(rule) + # check the Tag + if tag: + model = self.tag.get_model() + node = self.tag.get_active_iter() + attr = model.get_value(node, 0) + rule = HasTag([attr]) + generic_filter.add_rule(rule) + + if self.generic.get_active() != 0: + model = self.generic.get_model() + node = self.generic.get_active_iter() + obj = cuni(model.get_value(node, 0)) + rule = MatchesFilter([obj]) + generic_filter.add_rule(rule) return generic_filter @@ -163,3 +174,14 @@ class EventSidebarFilter(SidebarFilter): all_filter.add_rule(rules.event.AllEvents([])) self.generic.set_model(build_filter_model('Event', [all_filter])) self.generic.set_active(0) + + def on_tags_changed(self, tag_list): + """ + Update the list of tags in the tag filter. + """ + model = Gtk.ListStore(str) + model.append(('',)) + for tag_name in tag_list: + model.append((tag_name,)) + self.tag.set_model(model) + self.tag.set_active(0) diff --git a/gramps/gui/filters/sidebar/_familysidebarfilter.py b/gramps/gui/filters/sidebar/_familysidebarfilter.py index 9e6838c28..15951b3b9 100644 --- a/gramps/gui/filters/sidebar/_familysidebarfilter.py +++ b/gramps/gui/filters/sidebar/_familysidebarfilter.py @@ -47,12 +47,10 @@ from .. import build_filter_model from . import SidebarFilter from gramps.gen.constfunc import cuni from gramps.gen.filters import GenericFilterFactory, rules -from gramps.gen.filters.rules.family import (RegExpIdOf, HasIdOf, RegExpFatherName, - SearchFatherName, RegExpMotherName, - SearchMotherName, RegExpChildName, - SearchChildName, HasEvent, HasRelType, - HasTag, HasNoteRegexp, - HasNoteMatchingSubstringOf, MatchesFilter) +from gramps.gen.filters.rules.family import (RegExpIdOf, RegExpFatherName, + RegExpMotherName, RegExpChildName, + HasEvent, HasRelType, HasTag, + HasNoteRegexp, MatchesFilter) GenericFamilyFilter = GenericFilterFactory('Family') #------------------------------------------------------------------------- @@ -154,31 +152,19 @@ class FamilySidebarFilter(SidebarFilter): else: generic_filter = GenericFamilyFilter() if gid: - if regex: - rule = RegExpIdOf([gid]) - else: - rule = HasIdOf([gid]) + rule = RegExpIdOf([gid], use_regex=regex) generic_filter.add_rule(rule) if father: - if regex: - rule = RegExpFatherName([father]) - else: - rule = SearchFatherName([father]) + rule = RegExpFatherName([father], use_regex=regex) generic_filter.add_rule(rule) if mother: - if regex: - rule = RegExpMotherName([mother]) - else: - rule = SearchMotherName([mother]) + rule = RegExpMotherName([mother], use_regex=regex) generic_filter.add_rule(rule) if child: - if regex: - rule = RegExpChildName([child]) - else: - rule = SearchChildName([child]) + rule = RegExpChildName([child], use_regex=regex) generic_filter.add_rule(rule) if etype: @@ -190,10 +176,7 @@ class FamilySidebarFilter(SidebarFilter): generic_filter.add_rule(rule) if note: - if regex: - rule = HasNoteRegexp([note]) - else: - rule = HasNoteMatchingSubstringOf([note]) + rule = HasNoteRegexp([note], use_regex=regex) 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 a10717e2c..be6a6a7e9 100644 --- a/gramps/gui/filters/sidebar/_mediasidebarfilter.py +++ b/gramps/gui/filters/sidebar/_mediasidebarfilter.py @@ -46,9 +46,8 @@ from .. import build_filter_model from . import SidebarFilter from gramps.gen.constfunc import cuni from gramps.gen.filters import GenericFilterFactory, rules -from gramps.gen.filters.rules.media import (RegExpIdOf, HasIdOf, HasMedia, HasTag, - HasNoteRegexp, MatchesFilter, - HasNoteMatchingSubstringOf) +from gramps.gen.filters.rules.media import (RegExpIdOf, HasMedia, HasTag, + HasNoteRegexp, MatchesFilter) GenericMediaFilter = GenericFilterFactory('Media') #------------------------------------------------------------------------- @@ -126,20 +125,14 @@ class MediaSidebarFilter(SidebarFilter): else: generic_filter = GenericMediaFilter() if gid: - if regex: - rule = RegExpIdOf([gid]) - else: - rule = HasIdOf([gid]) + rule = RegExpIdOf([gid], use_regex=regex) generic_filter.add_rule(rule) rule = HasMedia([title, mime, path, date], use_regex=regex) generic_filter.add_rule(rule) if note: - if regex: - rule = HasNoteRegexp([note]) - else: - rule = HasNoteMatchingSubstringOf([note]) + rule = HasNoteRegexp([note], use_regex=regex) 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 83ba6698c..6b9420df4 100644 --- a/gramps/gui/filters/sidebar/_notesidebarfilter.py +++ b/gramps/gui/filters/sidebar/_notesidebarfilter.py @@ -47,8 +47,8 @@ from .. import build_filter_model from . import SidebarFilter from gramps.gen.constfunc import cuni from gramps.gen.filters import GenericFilterFactory, rules -from gramps.gen.filters.rules.note import (RegExpIdOf, HasIdOf, HasNote, - MatchesFilter, HasTag) +from gramps.gen.filters.rules.note import (RegExpIdOf, HasNote, MatchesFilter, + HasTag) GenericNoteFilter = GenericFilterFactory('Note') #------------------------------------------------------------------------- @@ -122,10 +122,7 @@ class NoteSidebarFilter(SidebarFilter): else: generic_filter = GenericNoteFilter() if gid: - if regex: - rule = RegExpIdOf([gid]) - else: - rule = HasIdOf([gid]) + rule = RegExpIdOf([gid], use_regex=regex) generic_filter.add_rule(rule) rule = HasNote([text, ntype], use_regex=regex) diff --git a/gramps/gui/filters/sidebar/_personsidebarfilter.py b/gramps/gui/filters/sidebar/_personsidebarfilter.py index 7d994e8ee..6850f7be1 100644 --- a/gramps/gui/filters/sidebar/_personsidebarfilter.py +++ b/gramps/gui/filters/sidebar/_personsidebarfilter.py @@ -48,11 +48,11 @@ from .. import build_filter_model from . import SidebarFilter from gramps.gen.constfunc import cuni from gramps.gen.filters import GenericFilter, rules -from gramps.gen.filters.rules.person import (RegExpName, SearchName, RegExpIdOf, - MatchIdOf, IsMale, IsFemale, - HasUnknownGender, HasEvent, HasTag, - HasBirth, HasDeath, HasNoteRegexp, - HasNoteMatchingSubstringOf, MatchesFilter) +from gramps.gen.filters.rules.person import (RegExpName, RegExpIdOf, IsMale, + IsFemale, HasUnknownGender, + HasEvent, HasTag, HasBirth, + HasDeath, HasNoteRegexp, + MatchesFilter) def extract_text(entry_widget): """ @@ -184,19 +184,13 @@ class PersonSidebarFilter(SidebarFilter): # if the name is not empty, choose either the regular expression # version or the normal text match if name: - if regex: - rule = RegExpName([name]) - else: - rule = SearchName([name]) + rule = RegExpName([name], use_regex=regex) generic_filter.add_rule(rule) # if the id is not empty, choose either the regular expression # version or the normal text match if gid: - if regex: - rule = RegExpIdOf([gid]) - else: - rule = MatchIdOf([gid]) + rule = RegExpIdOf([gid], use_regex=regex) generic_filter.add_rule(rule) # check the gender, and select the right rule based on gender @@ -228,10 +222,7 @@ class PersonSidebarFilter(SidebarFilter): # Build note filter if needed if note: - if regex: - rule = HasNoteRegexp([note]) - else: - rule = HasNoteMatchingSubstringOf([note]) + rule = HasNoteRegexp([note], use_regex=regex) 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 e26786bc0..5fe675972 100644 --- a/gramps/gui/filters/sidebar/_placesidebarfilter.py +++ b/gramps/gui/filters/sidebar/_placesidebarfilter.py @@ -47,9 +47,8 @@ from .. import build_filter_model from . import SidebarFilter from gramps.gen.constfunc import cuni from gramps.gen.filters import GenericFilterFactory, rules -from gramps.gen.filters.rules.place import (RegExpIdOf, HasIdOf, HasPlace, - HasNoteRegexp, HasNoteMatchingSubstringOf, - MatchesFilter) +from gramps.gen.filters.rules.place import (RegExpIdOf, HasPlace, HasTag, + HasNoteRegexp, MatchesFilter) GenericPlaceFilter = GenericFilterFactory('Place') #------------------------------------------------------------------------- @@ -75,6 +74,7 @@ class PlaceSidebarFilter(SidebarFilter): self.filter_note = widgets.BasicEntry() self.filter_regex = Gtk.CheckButton(_('Use regular expressions')) + self.tag = Gtk.ComboBox() self.generic = Gtk.ComboBox() SidebarFilter.__init__(self, dbstate, uistate, "Place") @@ -87,6 +87,12 @@ class PlaceSidebarFilter(SidebarFilter): self.generic.add_attribute(cell, 'text', 0) self.on_filters_changed('Place') + cell = Gtk.CellRendererText() + cell.set_property('width', self._FILTER_WIDTH) + cell.set_property('ellipsize', self._FILTER_ELLIPSIZE) + self.tag.pack_start(cell, True) + self.tag.add_attribute(cell, 'text', 0) + self.add_text_entry(_('ID'), self.filter_id) self.add_text_entry(_('Place Name'), self.filter_title) self.add_text_entry(_('Street'), self.filter_street) @@ -98,6 +104,7 @@ class PlaceSidebarFilter(SidebarFilter): self.add_text_entry(_('ZIP/Postal code'), self.filter_zip) self.add_text_entry(_('Church parish'), self.filter_parish) self.add_text_entry(_('Note'), self.filter_note) + self.add_entry(_('Tag'), self.tag) self.add_filter_entry(_('Custom filter'), self.generic) self.add_regex_entry(self.filter_regex) @@ -113,6 +120,7 @@ class PlaceSidebarFilter(SidebarFilter): self.filter_zip.set_text('') self.filter_parish.set_text('') self.filter_note.set_text('') + self.tag.set_active(0) self.generic.set_active(0) def get_filter(self): @@ -128,19 +136,18 @@ class PlaceSidebarFilter(SidebarFilter): parish = cuni(self.filter_parish.get_text()).strip() note = cuni(self.filter_note.get_text()).strip() regex = self.filter_regex.get_active() + tag = self.tag.get_active() > 0 gen = self.generic.get_active() > 0 empty = not (gid or title or street or locality or city or county or - state or country or zipc or parish or note or regex or gen) + state or country or zipc or parish or note or regex or tag + or gen) if empty: generic_filter = None else: generic_filter = GenericPlaceFilter() if gid: - if regex: - rule = RegExpIdOf([gid]) - else: - rule = HasIdOf([gid]) + rule = RegExpIdOf([gid], use_regex=regex) generic_filter.add_rule(rule) rule = HasPlace([title, street, locality, city, county, state, @@ -148,10 +155,15 @@ class PlaceSidebarFilter(SidebarFilter): generic_filter.add_rule(rule) if note: - if regex: - rule = HasNoteRegexp([note]) - else: - rule = HasNoteMatchingSubstringOf([note]) + rule = HasNoteRegexp([note], use_regex=regex) + generic_filter.add_rule(rule) + + # check the Tag + if tag: + model = self.tag.get_model() + node = self.tag.get_active_iter() + attr = model.get_value(node, 0) + rule = HasTag([attr]) generic_filter.add_rule(rule) if self.generic.get_active() != 0: @@ -170,3 +182,14 @@ class PlaceSidebarFilter(SidebarFilter): all_filter.add_rule(rules.place.AllPlaces([])) self.generic.set_model(build_filter_model('Place', [all_filter])) self.generic.set_active(0) + + def on_tags_changed(self, tag_list): + """ + Update the list of tags in the tag filter. + """ + model = Gtk.ListStore(str) + model.append(('',)) + for tag_name in tag_list: + model.append((tag_name,)) + self.tag.set_model(model) + self.tag.set_active(0) diff --git a/gramps/gui/filters/sidebar/_reposidebarfilter.py b/gramps/gui/filters/sidebar/_reposidebarfilter.py index 59da3deed..6c53d20ac 100644 --- a/gramps/gui/filters/sidebar/_reposidebarfilter.py +++ b/gramps/gui/filters/sidebar/_reposidebarfilter.py @@ -46,9 +46,8 @@ from .. import build_filter_model from . import SidebarFilter from gramps.gen.constfunc import cuni from gramps.gen.filters import GenericFilterFactory, rules -from gramps.gen.filters.rules.repository import (RegExpIdOf, HasIdOf, HasRepo, - HasNoteRegexp, MatchesFilter, - HasNoteMatchingSubstringOf) +from gramps.gen.filters.rules.repository import (RegExpIdOf, HasRepo, HasTag, + HasNoteRegexp, MatchesFilter) GenericRepoFilter = GenericFilterFactory('Repository') #------------------------------------------------------------------------- @@ -77,6 +76,7 @@ class RepoSidebarFilter(SidebarFilter): self.filter_regex = Gtk.CheckButton(_('Use regular expressions')) + self.tag = Gtk.ComboBox() self.generic = Gtk.ComboBox() SidebarFilter.__init__(self, dbstate, uistate, "Repository") @@ -89,6 +89,12 @@ class RepoSidebarFilter(SidebarFilter): self.generic.add_attribute(cell, 'text', 0) self.on_filters_changed('Repository') + cell = Gtk.CellRendererText() + cell.set_property('width', self._FILTER_WIDTH) + cell.set_property('ellipsize', self._FILTER_ELLIPSIZE) + self.tag.pack_start(cell, True) + self.tag.add_attribute(cell, 'text', 0) + self.rtype.get_child().set_width_chars(5) self.add_text_entry(_('ID'), self.filter_id) @@ -97,6 +103,7 @@ class RepoSidebarFilter(SidebarFilter): self.add_text_entry(_('Address'), self.filter_address) self.add_text_entry(_('URL'), self.filter_url) self.add_text_entry(_('Note'), self.filter_note) + self.add_entry(_('Tag'), self.tag) self.add_filter_entry(_('Custom filter'), self.generic) self.add_regex_entry(self.filter_regex) @@ -107,6 +114,7 @@ class RepoSidebarFilter(SidebarFilter): self.filter_url.set_text('') self.rtype.get_child().set_text('') self.filter_note.set_text('') + self.tag.set_active(0) self.generic.set_active(0) def get_filter(self): @@ -117,37 +125,40 @@ class RepoSidebarFilter(SidebarFilter): rtype = self.repo.get_type().xml_str() note = cuni(self.filter_note.get_text()).strip() regex = self.filter_regex.get_active() + tag = self.tag.get_active() > 0 gen = self.generic.get_active() > 0 empty = not (gid or title or address or url or rtype - or note or regex or gen) + or note or regex or tag or gen) if empty: generic_filter = None else: generic_filter = GenericRepoFilter() if gid: - if regex: - rule = RegExpIdOf([gid]) - else: - rule = HasIdOf([gid]) + rule = RegExpIdOf([gid], use_regex=regex) generic_filter.add_rule(rule) rule = HasRepo([title, rtype, address, url], use_regex=regex) generic_filter.add_rule(rule) if note: - if regex: - rule = HasNoteRegexp([note]) - else: - rule = HasNoteMatchingSubstringOf([note]) + rule = HasNoteRegexp([note], use_regex=regex) generic_filter.add_rule(rule) - if self.generic.get_active() != 0: - model = self.generic.get_model() - node = self.generic.get_active_iter() - obj = cuni(model.get_value(node, 0)) - rule = MatchesFilter([obj]) - generic_filter.add_rule(rule) + # check the Tag + if tag: + model = self.tag.get_model() + node = self.tag.get_active_iter() + attr = model.get_value(node, 0) + rule = HasTag([attr]) + generic_filter.add_rule(rule) + + if self.generic.get_active() != 0: + model = self.generic.get_model() + node = self.generic.get_active_iter() + obj = cuni(model.get_value(node, 0)) + rule = MatchesFilter([obj]) + generic_filter.add_rule(rule) return generic_filter @@ -159,3 +170,14 @@ class RepoSidebarFilter(SidebarFilter): self.generic.set_model(build_filter_model('Repository', [all_filter])) self.generic.set_active(0) + + def on_tags_changed(self, tag_list): + """ + Update the list of tags in the tag filter. + """ + model = Gtk.ListStore(str) + model.append(('',)) + for tag_name in tag_list: + model.append((tag_name,)) + self.tag.set_model(model) + self.tag.set_active(0) diff --git a/gramps/gui/filters/sidebar/_sourcesidebarfilter.py b/gramps/gui/filters/sidebar/_sourcesidebarfilter.py index c19432123..7af1a19c1 100644 --- a/gramps/gui/filters/sidebar/_sourcesidebarfilter.py +++ b/gramps/gui/filters/sidebar/_sourcesidebarfilter.py @@ -45,9 +45,8 @@ from .. import build_filter_model from . import SidebarFilter from gramps.gen.constfunc import cuni from gramps.gen.filters import GenericFilterFactory, rules -from gramps.gen.filters.rules.source import (RegExpIdOf, HasIdOf, HasSource, - HasNoteMatchingSubstringOf, - HasNoteRegexp, MatchesFilter) +from gramps.gen.filters.rules.source import (RegExpIdOf, HasSource, HasTag, + HasNoteRegexp, MatchesFilter) GenericSourceFilter = GenericFilterFactory('Source') #------------------------------------------------------------------------- @@ -68,6 +67,7 @@ class SourceSidebarFilter(SidebarFilter): self.filter_regex = Gtk.CheckButton(_('Use regular expressions')) + self.tag = Gtk.ComboBox() self.generic = Gtk.ComboBox() SidebarFilter.__init__(self, dbstate, uistate, "Source") @@ -80,12 +80,19 @@ class SourceSidebarFilter(SidebarFilter): self.generic.add_attribute(cell, 'text', 0) self.on_filters_changed('Source') + cell = Gtk.CellRendererText() + cell.set_property('width', self._FILTER_WIDTH) + cell.set_property('ellipsize', self._FILTER_ELLIPSIZE) + self.tag.pack_start(cell, True) + self.tag.add_attribute(cell, 'text', 0) + self.add_text_entry(_('ID'), self.filter_id) self.add_text_entry(_('Title'), self.filter_title) self.add_text_entry(_('Author'), self.filter_author) self.add_text_entry(_('Abbreviation'), self.filter_abbr) self.add_text_entry(_('Publication'), self.filter_pub) self.add_text_entry(_('Note'), self.filter_note) + self.add_entry(_('Tag'), self.tag) self.add_filter_entry(_('Custom filter'), self.generic) self.add_regex_entry(self.filter_regex) @@ -96,6 +103,7 @@ class SourceSidebarFilter(SidebarFilter): self.filter_abbr.set_text('') self.filter_pub.set_text('') self.filter_note.set_text('') + self.tag.set_active(0) self.generic.set_active(0) def get_filter(self): @@ -106,37 +114,40 @@ class SourceSidebarFilter(SidebarFilter): pub = cuni(self.filter_pub.get_text()).strip() note = cuni(self.filter_note.get_text()).strip() regex = self.filter_regex.get_active() + tag = self.tag.get_active() > 0 gen = self.generic.get_active() > 0 - empty = not (gid or title or author or abbr or pub or note or regex or - gen) + empty = not (gid or title or author or abbr or pub or note or regex + or tag or gen) if empty: generic_filter = None else: generic_filter = GenericSourceFilter() if gid: - if regex: - rule = RegExpIdOf([gid]) - else: - rule = HasIdOf([gid]) + rule = RegExpIdOf([gid], use_regex=regex) generic_filter.add_rule(rule) rule = HasSource([title, author, abbr, pub], use_regex=regex) generic_filter.add_rule(rule) if note: - if regex: - rule = HasNoteRegexp([note]) - else: - rule = HasNoteMatchingSubstringOf([note]) + rule = HasNoteRegexp([note], use_regex=regex) generic_filter.add_rule(rule) - if self.generic.get_active() != 0: - model = self.generic.get_model() - node = self.generic.get_active_iter() - obj = cuni(model.get_value(node, 0)) - rule = MatchesFilter([obj]) - generic_filter.add_rule(rule) + # check the Tag + if tag: + model = self.tag.get_model() + node = self.tag.get_active_iter() + attr = model.get_value(node, 0) + rule = HasTag([attr]) + generic_filter.add_rule(rule) + + if self.generic.get_active() != 0: + model = self.generic.get_model() + node = self.generic.get_active_iter() + obj = cuni(model.get_value(node, 0)) + rule = MatchesFilter([obj]) + generic_filter.add_rule(rule) return generic_filter @@ -147,3 +158,14 @@ class SourceSidebarFilter(SidebarFilter): all_filter.add_rule(rules.source.AllSources([])) self.generic.set_model(build_filter_model('Source', [all_filter])) self.generic.set_active(0) + + def on_tags_changed(self, tag_list): + """ + Update the list of tags in the tag filter. + """ + model = Gtk.ListStore(str) + model.append(('',)) + for tag_name in tag_list: + model.append((tag_name,)) + self.tag.set_model(model) + self.tag.set_active(0)