a2825098ec
svn: r19638
66 lines
2.3 KiB
Python
66 lines
2.3 KiB
Python
#
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
#
|
|
# Copyright (C) 2000-2007 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$
|
|
|
|
import time
|
|
import gen.filters
|
|
from gui.filtereditor import EditFilter
|
|
import const
|
|
from gen.filters import reload_custom_filters
|
|
from gen.ggettext import sgettext as _
|
|
|
|
def make_filter(dbstate, uistate, objclass, gramps_ids, title=None):
|
|
"""
|
|
Makes a Gramps Filter through dialog from a enumeration (list,
|
|
set, etc.) of gramps_ids of type objclass.
|
|
|
|
>>> make_filter(dbstate, uistate, 'Person', ['I0003', ...])
|
|
"""
|
|
FilterClass = gen.filters.GenericFilterFactory(objclass)
|
|
rule = getattr(getattr(gen.filters.rules, objclass),'RegExpIdOf')
|
|
filter = FilterClass()
|
|
if title is None:
|
|
title = _("Filter %s from Clipboard") % objclass
|
|
if callable(title):
|
|
title = title()
|
|
filter.set_name(title)
|
|
struct_time = time.localtime()
|
|
filter.set_comment( _("Created on %(year)4d/%(month)02d/%(day)02d") % {
|
|
'year': struct_time.tm_year,
|
|
'month': struct_time.tm_mon,
|
|
'day': struct_time.tm_mday})
|
|
re = "|".join(["^%s$" % gid for gid in sorted(gramps_ids)])
|
|
filter.add_rule(rule([re]))
|
|
filterdb = gen.filters.FilterList(const.CUSTOM_FILTERS)
|
|
filterdb.load()
|
|
EditFilter(objclass, dbstate, uistate, [],
|
|
filter, filterdb,
|
|
lambda : edit_filter_save(uistate, filterdb, objclass))
|
|
|
|
def edit_filter_save(uistate, filterdb, objclass):
|
|
"""
|
|
If a filter changed, save them all. Reloads, and also calls callback.
|
|
"""
|
|
filterdb.save()
|
|
reload_custom_filters()
|
|
uistate.emit('filters-changed', (objclass,))
|
|
|