svn: r7137
This commit is contained in:
Alex Roitman 2006-08-06 01:29:11 +00:00
parent 9f55696c0c
commit c4c4b41470
5 changed files with 63 additions and 39 deletions

View File

@ -25,6 +25,7 @@ Package providing filter rules for GRAMPS.
"""
__author__ = "Don Allingham"
from Filters.Rules._HasEventBase import HasEventBase as HasEvent
from _HasType import HasType
from _AllEvents import AllEvents

View File

@ -40,7 +40,7 @@ from Filters.Rules._HasEventBase import HasEventBase
#
#-------------------------------------------------------------------------
class HasEvent(HasEventBase):
"""Rule that checks for a person with a particular value"""
"""Rule that checks for a family event with a particular value"""
labels = [ _('Family event:'),
_('Date:'),
@ -48,3 +48,12 @@ class HasEvent(HasEventBase):
_('Description:') ]
name = _('Families with the <event>')
description = _("Matches families with an event of a particular value")
def apply(self,db,family):
for event_ref in family.get_event_ref_list():
if not event_ref:
continue
event = db.get_event_from_handle(event_ref.ref)
if HasEventBase.apply(self,db,event):
return True
return False

View File

@ -49,3 +49,11 @@ class HasEvent(HasEventBase):
name = _('People with the personal <event>')
description = _("Matches people with a personal event of a particular value")
def apply(self,db,person):
for event_ref in person.get_event_ref_list():
if not event_ref:
continue
event = db.get_event_from_handle(event_ref.ref)
if HasEventBase.apply(self,db,event):
return True
return False

View File

@ -35,7 +35,7 @@ from gettext import gettext as _
import DateHandler
from RelLib import EventType
from Filters.Rules._Rule import Rule
from Filters.Rules._RuleUtils import date_cmp
from Filters.Rules._RuleUtils import loose_date_cmp
#-------------------------------------------------------------------------
#
@ -45,12 +45,13 @@ from Filters.Rules._RuleUtils import date_cmp
class HasEventBase(Rule):
"""Rule that checks for a person with a particular value"""
labels = [ _('Event:'),
labels = [ _('Event type:'),
_('Date:'),
_('Place:'),
_('Description:') ]
name = _('Objects with the <event>')
description = _("Matches objects with an event of a particular value")
name = _('Events matching parameters')
description = _("Matches events with particular parameters")
category = _('Event filters')
def prepare(self,db):
@ -64,30 +65,23 @@ class HasEventBase(Rule):
self.date = DateHandler.parser.parse(self.list[1])
except: pass
def apply(self,db,person):
for event_ref in person.get_event_ref_list():
if not event_ref:
continue
event = db.get_event_from_handle(event_ref.ref)
val = True
if self.etype:
specified_type = EventType()
specified_type.set_from_xml_str(self.etype)
if event.type != specified_type:
val = False
if self.list[3] and event.get_description().upper().find(
self.list[3].upper())==-1:
val = False
if self.date:
if date_cmp(self.date,event.get_date_object()):
val = False
if self.list[2]:
pl_id = event.get_place_handle()
if pl_id:
pl = db.get_place_from_handle(pl_id)
pn = pl.get_title()
if pn.upper().find(self.list[2].upper()) == -1:
val = False
if val:
return True
return False
def apply(self,db,event):
if self.etype:
specified_type = EventType()
specified_type.set_from_xml_str(self.etype)
if event.type != specified_type:
return False
if self.list[3] and event.get_description().upper().find(
self.list[3].upper())==-1:
return False
if self.date:
if not loose_date_cmp(self.date,event.get_date_object()):
return False
if self.list[2]:
pl_id = event.get_place_handle()
if pl_id:
pl = db.get_place_from_handle(pl_id)
pn = pl.get_title()
if pn.upper().find(self.list[2].upper()) == -1:
return False
return True

View File

@ -60,6 +60,7 @@ class EventSidebarFilter(SidebarFilter):
def create_widget(self):
self.filter_id = gtk.Entry()
self.filter_desc = gtk.Entry()
self.filter_event = RelLib.Event()
self.filter_event.set_type((RelLib.EventType.CUSTOM,''))
self.etype = gtk.ComboBoxEntry()
@ -69,8 +70,10 @@ class EventSidebarFilter(SidebarFilter):
self.filter_event.set_type,
self.filter_event.get_type)
self.filter_date = gtk.Entry()
self.filter_place = gtk.Entry()
self.filter_note = gtk.Entry()
self.filter_regex = gtk.CheckButton(_('Use regular expressions'))
all = GenericEventFilter()
@ -85,13 +88,19 @@ class EventSidebarFilter(SidebarFilter):
self.generic.set_active(0)
self.add_text_entry(_('ID'), self.filter_id)
self.add_text_entry(_('Description'), self.filter_desc)
self.add_entry(_('Type'), self.etype)
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(_('Custom filter'), self.generic)
self.add_entry(None, self.filter_regex)
def clear(self, obj):
self.filter_id.set_text('')
self.filter_desc.set_text('')
self.filter_date.set_text('')
self.filter_place.set_text('')
self.filter_note.set_text('')
self.etype.child.set_text('')
self.generic.set_active(0)
@ -101,12 +110,17 @@ class EventSidebarFilter(SidebarFilter):
def get_filter(self):
gid = unicode(self.filter_id.get_text()).strip()
desc = unicode(self.filter_desc.get_text()).strip()
date = unicode(self.filter_date.get_text()).strip()
place = unicode(self.filter_place.get_text()).strip()
note = unicode(self.filter_note.get_text()).strip()
regex = self.filter_regex.get_active()
gen = self.generic.get_active() > 0
etype = self.filter_event.get_type().xml_str()
if not gid and not str(self.filter_event.get_type()) \
and not note and not gen:
empty = not (gid or desc or date or place or note
or etype or regex or gen)
if empty:
generic_filter = None
else:
generic_filter = GenericEventFilter()
@ -117,10 +131,8 @@ class EventSidebarFilter(SidebarFilter):
rule = HasIdOf([gid])
generic_filter.add_rule(rule)
etype = self.filter_event.get_type().xml_str()
if str(etype):
rule = HasType([etype])
generic_filter.add_rule(rule)
rule = HasEvent([etype,date,place,desc])
generic_filter.add_rule(rule)
if note:
if regex: