2006-07-10 Don Allingham <don@gramps-project.org>

* src/DataViews/_FamlyList.py: add filter editor support
	* src/FilterEditor/_FilterEditor.py: add family support
	* src/FilterEditor/_EditRule.py: add family support
	* src/Filters/_FamilySidebarFilter.py: start of family support
	* src/Filters/Rules/Family/_HasRelType.py: start of family filters
	* src/Filters/Rules/Family/__init__.py: start of family filters



svn: r7014
This commit is contained in:
Don Allingham 2006-07-10 17:45:18 +00:00
parent 65e8840903
commit a895871b60
7 changed files with 235 additions and 5 deletions

View File

@ -1,3 +1,11 @@
2006-07-10 Don Allingham <don@gramps-project.org>
* src/DataViews/_FamlyList.py: add filter editor support
* src/FilterEditor/_FilterEditor.py: add family support
* src/FilterEditor/_EditRule.py: add family support
* src/Filters/_FamilySidebarFilter.py: start of family support
* src/Filters/Rules/Family/_HasRelType.py: start of family filters
* src/Filters/Rules/Family/__init__.py: start of family filters
2006-07-09 Don Allingham <don@gramps-project.org>
* configure.in: up the version number
* src/DataViews/_FamilyList.py: add support for sidebar filter

View File

@ -29,6 +29,7 @@ import PageView
import DisplayModels
import Bookmarks
import Errors
import const
from Filters import FamilySidebarFilter
#-------------------------------------------------------------------------
@ -74,6 +75,23 @@ class FamilyListView(PageView.ListView):
self.updating = False
def define_actions(self):
# add the Forward action group to handle the Forward button
PageView.ListView.define_actions(self)
self.add_action('FilterEdit', None, _('Family Filter Editor'),
callback=self.filter_editor,)
def filter_editor(self,obj):
from FilterEditor import FilterEditor
FilterEditor(
'Family',
const.custom_filters,
self.dbstate,
self.uistate)
def add_bookmark(self, obj):
mlist = []
self.selection.selected_foreach(self.blist, mlist)
@ -108,6 +126,7 @@ class FamilyListView(PageView.ListView):
<menuitem action="Remove"/>
</placeholder>
<menuitem action="ColumnEdit"/>
<menuitem action="FilterEdit"/>
</menu>
<menu action="BookMenu">
<placeholder name="AddEditBook">

View File

@ -350,7 +350,13 @@ class EditRule(ManagedWindow.ManagedWindow):
self.page = []
self.class2page = {}
the_map = {}
for class_obj in Rules.Person.editor_rule_list:
if self.space == "Family":
class_list = Rules.Family.editor_rule_list
else:
class_list = Rules.Person.editor_rule_list
for class_obj in class_list:
arglist = class_obj.labels
vallist = []
tlist = []

View File

@ -65,11 +65,11 @@ import ManagedWindow
#
#-------------------------------------------------------------------------
class FilterEditor(ManagedWindow.ManagedWindow):
def __init__(self, space, filterdb, dbstate, uistate):
def __init__(self, space, filterdb, dbstate, uistate, ftype=GenericFilter):
ManagedWindow.ManagedWindow.__init__(self, uistate, [],
FilterEditor)
self.ftype = ftype
self.dbstate = dbstate
self.db = dbstate.db
self.filterdb = FilterList(filterdb)
@ -138,7 +138,7 @@ class FilterEditor(ManagedWindow.ManagedWindow):
def add_new_filter(self,obj):
from _EditFilter import EditFilter
the_filter = GenericFilter()
the_filter = self.ftype()
EditFilter(self.space, self.dbstate, self.uistate, self.track,
the_filter, self.filterdb, self.draw_filters)
@ -157,7 +157,8 @@ class FilterEditor(ManagedWindow.ManagedWindow):
from _ShowResults import ShowResults
filt = self.clist.get_object(node)
handle_list = filt.apply(self.db,self.db.get_person_handles(sort_handles=False))
handle_list = filt.apply(
self.db, self.db.get_person_handles(sort_handles=False))
ShowResults(self.db, self.uistate, self.track, handle_list,
filt.get_name())

View File

@ -0,0 +1,55 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2002-2006 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: _HasAttribute.py 6529 2006-05-03 06:29:07Z rshura $
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules._Rule import Rule
#-------------------------------------------------------------------------
#
# HasAttribute
#
#-------------------------------------------------------------------------
class HasRelType(Rule):
"""Rule that checks for a person with a particular personal attribute"""
labels = [ _('Relationship Type:') ]
name = _('Family with the relationship type')
description = _("Matches family with the relationship type "
"of a particular value")
category = _('General filters')
def apply(self, db, obj):
if not self.list[0]:
return False
else:
return obj.get_relationship() == self.list[0]

View File

@ -25,3 +25,9 @@ Package providing filter rules for GRAMPS.
"""
__author__ = "Don Allingham"
from _HasRelType import HasRelType
editor_rule_list = [
HasRelType,
]

View File

@ -0,0 +1,135 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2002-2006 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: _FilterList.py 6529 2006-05-03 06:29:07Z rshura $
from gettext import gettext as _
import gtk
import GrampsWidgets
import RelLib
from _SidebarFilter import SidebarFilter
from Filters.Rules.Person import *
from Filters.Rules.Family import *
from Filters import GenericFamilyFilter, build_filter_model, Rules
class FamilySidebarFilter(SidebarFilter):
def __init__(self, clicked):
SidebarFilter.__init__(self)
self.clicked_func = clicked
def create_widget(self):
self.filter_id = gtk.Entry()
self.filter_event = RelLib.Event()
self.filter_event.set_type((RelLib.EventType.CUSTOM,''))
self.etype = gtk.ComboBoxEntry()
self.family_stub = RelLib.Family()
self.family_stub.set_relationship((RelLib.FamilyRelType.CUSTOM,''))
self.rtype = gtk.ComboBoxEntry()
self.event_menu = GrampsWidgets.MonitoredDataType(
self.etype,
self.filter_event.set_type,
self.filter_event.get_type)
self.rel_menu = GrampsWidgets.MonitoredDataType(
self.rtype,
self.family_stub.set_relationship,
self.family_stub.get_relationship)
self.filter_note = gtk.Entry()
self.filter_regex = gtk.CheckButton(_('Use regular expressions'))
all = GenericFamilyFilter()
all.set_name(_("None"))
all.add_rule(Rules.Person.Everyone([]))
self.generic = gtk.ComboBox()
cell = gtk.CellRendererText()
self.generic.pack_start(cell, True)
self.generic.add_attribute(cell, 'text', 0)
self.generic.set_model(build_filter_model('Family', [all]))
self.generic.set_active(0)
self.add_text_entry(_('ID'), self.filter_id)
self.add_entry(_('Relationship'), self.rtype)
self.add_entry(_('Has Event'), self.etype)
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_note.set_text('')
self.etype.child.set_text('')
self.rtype.child.set_text('')
self.generic.set_active(0)
def clicked(self, obj):
self.clicked_func()
def get_filter(self):
gid = self.filter_id.get_text().strip()
note = self.filter_note.get_text().strip()
regex = self.filter_regex.get_active()
gen = self.generic.get_active() > 0
if not gid and not str(self.filter_event.get_type()) and \
not str(self.family_stub.get_relationship()) and not note \
and not gen:
generic_filter = None
else:
generic_filter = GenericFamilyFilter()
if gid:
if regex:
rule = RegExpIdOf([gid])
else:
rule = MatchIdOf([gid])
generic_filter.add_rule(rule)
etype = self.filter_event.get_type()
if str(etype):
rule = HasEvent([etype, '', '', ''])
generic_filter.add_rule(rule)
rtype = self.family_stub.get_relationship()
if str(rtype):
rule = HasRelType([rtype])
generic_filter.add_rule(rule)
if note:
if regex:
rule = HasNoteRegexp([note])
else:
rule = HasNoteMatchingSubstringOf([note])
generic_filter.add_rule(rule)
if self.generic.get_active() != 0:
model = self.generic.get_model()
iter = self.generic.get_active_iter()
obj = model.get_value(iter, 0)
rule = MatchesFilter([obj])
generic_filter.add_rule(rule)
return generic_filter