Fix regular expressions in sidebar filters

svn: r22966
This commit is contained in:
Nick Hall 2013-08-30 20:33:09 +00:00
parent 6da4a00375
commit 4ee02a80af
9 changed files with 38 additions and 111 deletions

View File

@ -44,8 +44,7 @@ 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,
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:

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -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: