From 4ee02a80afb66e34c2a0f6c95a76b41790f4d48a Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Fri, 30 Aug 2013 20:33:09 +0000 Subject: [PATCH] Fix regular expressions in sidebar filters svn: r22966 --- src/Filters/SideBar/_CitationSidebarFilter.py | 15 +++----- src/Filters/SideBar/_EventSidebarFilter.py | 13 ++----- src/Filters/SideBar/_FamilySidebarFilter.py | 34 +++++-------------- src/Filters/SideBar/_MediaSidebarFilter.py | 15 +++----- src/Filters/SideBar/_NoteSidebarFilter.py | 8 ++--- src/Filters/SideBar/_PersonSidebarFilter.py | 22 ++++-------- src/Filters/SideBar/_PlaceSidebarFilter.py | 14 +++----- src/Filters/SideBar/_RepoSidebarFilter.py | 15 +++----- src/Filters/SideBar/_SourceSidebarFilter.py | 13 ++----- 9 files changed, 38 insertions(+), 111 deletions(-) diff --git a/src/Filters/SideBar/_CitationSidebarFilter.py b/src/Filters/SideBar/_CitationSidebarFilter.py index 58d53d066..38ad752f8 100644 --- a/src/Filters/SideBar/_CitationSidebarFilter.py +++ b/src/Filters/SideBar/_CitationSidebarFilter.py @@ -44,9 +44,8 @@ from gui.widgets import MonitoredMenu, DateEntry import gen.lib from Filters.SideBar import SidebarFilter from Filters import GenericFilterFactory, build_filter_model, Rules -from Filters.Rules.Citation import (RegExpIdOf, HasIdOf, HasCitation, - HasNoteMatchingSubstringOf, HasNoteRegexp, - MatchesFilter) +from Filters.Rules.Citation import (RegExpIdOf, HasCitation, HasNoteRegexp, + MatchesFilter) from Utils import confidence GenericCitationFilter = GenericFilterFactory('Citation') #------------------------------------------------------------------------- @@ -130,20 +129,14 @@ class CitationSidebarFilter(SidebarFilter): 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: diff --git a/src/Filters/SideBar/_EventSidebarFilter.py b/src/Filters/SideBar/_EventSidebarFilter.py index 5e2dcc2ca..a4add480e 100644 --- a/src/Filters/SideBar/_EventSidebarFilter.py +++ b/src/Filters/SideBar/_EventSidebarFilter.py @@ -44,8 +44,7 @@ import gen.lib from Filters.SideBar import SidebarFilter from Filters import GenericFilterFactory, build_filter_model, Rules -from Filters.Rules.Event import (RegExpIdOf, HasIdOf, HasNoteRegexp, - HasNoteMatchingSubstringOf, MatchesFilter, +from Filters.Rules.Event import (RegExpIdOf, HasNoteRegexp, MatchesFilter, HasEvent) GenericEventFilter = GenericFilterFactory('Event') @@ -128,10 +127,7 @@ class EventSidebarFilter(SidebarFilter): 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], @@ -139,10 +135,7 @@ 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: diff --git a/src/Filters/SideBar/_FamilySidebarFilter.py b/src/Filters/SideBar/_FamilySidebarFilter.py index e5df9fefa..ed3b37263 100644 --- a/src/Filters/SideBar/_FamilySidebarFilter.py +++ b/src/Filters/SideBar/_FamilySidebarFilter.py @@ -45,12 +45,9 @@ import gen.lib from Filters.SideBar import SidebarFilter from Filters import GenericFilterFactory, build_filter_model, Rules -from Filters.Rules.Family import (RegExpIdOf, HasIdOf, RegExpFatherName, - SearchFatherName, RegExpMotherName, - SearchMotherName, RegExpChildName, - SearchChildName, HasEvent, HasRelType, - HasTag, HasNoteRegexp, - HasNoteMatchingSubstringOf, MatchesFilter) +from Filters.Rules.Family import (RegExpIdOf, HasEvent, RegExpFatherName, + RegExpMotherName, RegExpChildName, HasTag, + HasRelType, HasNoteRegexp, MatchesFilter) GenericFamilyFilter = GenericFilterFactory('Family') #------------------------------------------------------------------------- @@ -152,31 +149,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: @@ -188,10 +173,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/src/Filters/SideBar/_MediaSidebarFilter.py b/src/Filters/SideBar/_MediaSidebarFilter.py index dda2a3d6a..f5470b4a1 100644 --- a/src/Filters/SideBar/_MediaSidebarFilter.py +++ b/src/Filters/SideBar/_MediaSidebarFilter.py @@ -43,9 +43,8 @@ import gtk from gui import widgets from Filters.SideBar import SidebarFilter from Filters import GenericFilterFactory, build_filter_model, Rules -from Filters.Rules.MediaObject import (RegExpIdOf, HasIdOf, HasMedia, HasTag, - HasNoteRegexp, MatchesFilter, - HasNoteMatchingSubstringOf) +from Filters.Rules.MediaObject import (RegExpIdOf, HasMedia, HasTag, + HasNoteRegexp, MatchesFilter) GenericMediaFilter = GenericFilterFactory('MediaObject') #------------------------------------------------------------------------- @@ -123,20 +122,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/src/Filters/SideBar/_NoteSidebarFilter.py b/src/Filters/SideBar/_NoteSidebarFilter.py index 9bff57b1f..d407d0cbd 100644 --- a/src/Filters/SideBar/_NoteSidebarFilter.py +++ b/src/Filters/SideBar/_NoteSidebarFilter.py @@ -45,8 +45,7 @@ from gen.lib import Note, NoteType from Filters.SideBar import SidebarFilter from Filters import GenericFilterFactory, build_filter_model, Rules -from Filters.Rules.Note import (RegExpIdOf, HasIdOf, HasNote, MatchesFilter, - HasTag) +from Filters.Rules.Note import RegExpIdOf, HasNote, MatchesFilter, HasTag GenericNoteFilter = GenericFilterFactory('Note') #------------------------------------------------------------------------- @@ -120,10 +119,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/src/Filters/SideBar/_PersonSidebarFilter.py b/src/Filters/SideBar/_PersonSidebarFilter.py index 8fcc7aa3c..ceb1db553 100644 --- a/src/Filters/SideBar/_PersonSidebarFilter.py +++ b/src/Filters/SideBar/_PersonSidebarFilter.py @@ -46,10 +46,9 @@ import gen.lib import DateHandler from Filters.SideBar import SidebarFilter -from Filters.Rules.Person import (RegExpName, SearchName, RegExpIdOf, MatchIdOf, - IsMale, IsFemale, HasUnknownGender, HasEvent, - HasTag, HasBirth, HasDeath, HasNoteRegexp, - HasNoteMatchingSubstringOf, MatchesFilter) +from Filters.Rules.Person import (RegExpName, RegExpIdOf, IsMale, IsFemale, + HasUnknownGender, HasEvent, HasTag, HasBirth, + HasDeath, HasNoteRegexp, MatchesFilter) from Filters import GenericFilter, build_filter_model, Rules def extract_text(entry_widget): @@ -182,19 +181,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 @@ -226,10 +219,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/src/Filters/SideBar/_PlaceSidebarFilter.py b/src/Filters/SideBar/_PlaceSidebarFilter.py index 7ce24545c..0ab47309f 100644 --- a/src/Filters/SideBar/_PlaceSidebarFilter.py +++ b/src/Filters/SideBar/_PlaceSidebarFilter.py @@ -44,8 +44,8 @@ import gtk from gui import widgets from Filters.SideBar import SidebarFilter from Filters import GenericFilterFactory, build_filter_model, Rules -from Filters.Rules.Place import (RegExpIdOf, HasIdOf, HasPlace, HasNoteRegexp, - HasNoteMatchingSubstringOf, MatchesFilter) +from Filters.Rules.Place import (RegExpIdOf, HasPlace, HasNoteRegexp, + MatchesFilter) GenericPlaceFilter = GenericFilterFactory('Place') #------------------------------------------------------------------------- @@ -133,10 +133,7 @@ class PlaceSidebarFilter(SidebarFilter): 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, @@ -144,10 +141,7 @@ 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) if self.generic.get_active() != 0: diff --git a/src/Filters/SideBar/_RepoSidebarFilter.py b/src/Filters/SideBar/_RepoSidebarFilter.py index 7fd32474a..e73f97ef7 100644 --- a/src/Filters/SideBar/_RepoSidebarFilter.py +++ b/src/Filters/SideBar/_RepoSidebarFilter.py @@ -44,9 +44,8 @@ from gen.lib import Repository, RepositoryType from Filters.SideBar import SidebarFilter from Filters import GenericFilterFactory, build_filter_model, Rules -from Filters.Rules.Repository import (RegExpIdOf, HasIdOf, HasRepo, - HasNoteRegexp, MatchesFilter, - HasNoteMatchingSubstringOf) +from Filters.Rules.Repository import (RegExpIdOf, HasRepo, HasNoteRegexp, + MatchesFilter) GenericRepoFilter = GenericFilterFactory('Repository') #------------------------------------------------------------------------- @@ -124,20 +123,14 @@ class RepoSidebarFilter(SidebarFilter): 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: diff --git a/src/Filters/SideBar/_SourceSidebarFilter.py b/src/Filters/SideBar/_SourceSidebarFilter.py index 32473fa83..01f78e92f 100644 --- a/src/Filters/SideBar/_SourceSidebarFilter.py +++ b/src/Filters/SideBar/_SourceSidebarFilter.py @@ -42,8 +42,7 @@ import gtk from gui import widgets from Filters.SideBar import SidebarFilter from Filters import GenericFilterFactory, build_filter_model, Rules -from Filters.Rules.Source import (RegExpIdOf, HasIdOf, HasSource, - HasNoteMatchingSubstringOf, HasNoteRegexp, +from Filters.Rules.Source import (RegExpIdOf, HasSource, HasNoteRegexp, MatchesFilter) GenericSourceFilter = GenericFilterFactory('Source') @@ -112,20 +111,14 @@ class SourceSidebarFilter(SidebarFilter): 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: