Patches from Jeff Ollie for filters

svn: r910
This commit is contained in:
Don Allingham 2002-04-10 00:13:19 +00:00
parent b1de1f1439
commit 5707fc8339
6 changed files with 132 additions and 36 deletions

View File

@ -40,12 +40,14 @@ except:
import types
import os
from string import find,join,strip,replace
import gtk
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
import const
from RelLib import *
import Date
from intl import gettext
@ -492,6 +494,23 @@ class HasNameOf(Rule):
return 1
return 0
class MatchesFilter(Rule):
"""Rule that checks against another filter"""
labels = [_('Filter Name')]
def name(self):
return 'Matches the filter named'
def apply(self, p):
for filter in SystemFilters.get_filters():
if filter.get_name() == self.list[0]:
return len(filter.apply([p])) > 0
for filter in CustomFilters.get_filters():
if filter.get_name() == self.list[0]:
return len(filter.apply([p])) > 0
return 0
#-------------------------------------------------------------------------
#
# GenericFilter
@ -576,6 +595,7 @@ tasks = {
_("Has the family event") : HasFamilyEvent,
_("Has the personal attribute") : HasAttribute,
_("Has the family attribute") : HasFamilyAttribute,
_("Matches the filter named") : MatchesFilter,
}
#-------------------------------------------------------------------------
@ -680,4 +700,78 @@ class FilterParser(handler.ContentHandler):
def characters(self, data):
pass
SystemFilters = None
CustomFilters = None
def reload_system_filters():
global SystemFilters
SystemFilters = GenericFilterList(const.system_filters)
def reload_custom_filters():
global CustomFilters
CustomFilters = GenericFilterList(const.custom_filters)
if not SystemFilters:
reload_system_filters()
if not CustomFilters:
reload_custom_filters()
def build_filter_menu(local_filters = []):
menu = gtk.GtkMenu()
menuitem = gtk.GtkMenuItem(_("Local Filters"))
menu.append(menuitem)
menuitem.show()
menuitem.set_sensitive(0)
menuitem = gtk.GtkMenuItem()
menuitem.show()
menu.append(menuitem)
for filter in local_filters:
menuitem = gtk.GtkMenuItem(filter.get_name())
menuitem.show()
menu.append(menuitem)
menuitem.set_data("filter", filter)
menuitem = gtk.GtkMenuItem(_("System Filters"))
menuitem.show()
menu.append(menuitem)
menuitem.set_sensitive(0)
menuitem = gtk.GtkMenuItem()
menuitem.show()
menu.append(menuitem)
for filter in SystemFilters.get_filters():
menuitem = gtk.GtkMenuItem(_(filter.get_name()))
menuitem.show()
menu.append(menuitem)
menuitem.set_data("filter", filter)
menuitem = gtk.GtkMenuItem(_("Custom Filters"))
menu.append(menuitem)
menuitem.show()
menuitem.set_sensitive(0)
menuitem = gtk.GtkMenuItem()
menuitem.show()
menu.append(menuitem)
for filter in CustomFilters.get_filters():
menuitem = gtk.GtkMenuItem(_(filter.get_name()))
menuitem.show()
menu.append(menuitem)
menuitem.set_data("filter", filter)
if len(local_filters):
menu.set_active(2)
elif len(SystemFilters.get_filters()):
menu.set_active(4 + len(local_filters))
elif len(CustomFilters.get_filters()):
menu.set_active(6 + len(local_filters) + len(SystemFilters.get_filters()))
else:
menu.set_active(0)
return menu

View File

@ -644,7 +644,7 @@ class ReportDialog:
(but not all) dialog boxes."""
(use_gen, use_break) = self.get_report_generations()
local_filter = self.get_report_filters()
local_filters = self.get_report_filters()
(em_label, extra_map, preset, em_tip) = self.get_report_extra_menu_info()
(et_label, string, et_tip) = self.get_report_extra_textbox_info()
@ -654,7 +654,7 @@ class ReportDialog:
max_rows = max_rows + 1
if use_break:
max_rows = max_rows + 1
if len(local_filter):
if len(local_filters):
max_rows = max_rows + 1
if extra_map:
max_rows = max_rows + 1
@ -673,8 +673,7 @@ class ReportDialog:
frame.add(table)
pad = ReportDialog.border_pad
if len(local_filter):
myMenu = GtkMenu()
if len(local_filters):
self.filter_combo = GtkOptionMenu()
l = GtkLabel(_("Filter"))
l.set_alignment(1.0,0.5)
@ -682,15 +681,10 @@ class ReportDialog:
table.attach(self.filter_combo,1,2,row,row+1,
xpadding=pad,ypadding=pad)
flist = GenericFilter.GenericFilterList(const.custom_filters)
flist.load()
for f in local_filter + flist.get_filters():
menuitem = gtk.GtkMenuItem(_(f.get_name()))
myMenu.append(menuitem)
menuitem.set_data("filter",f)
menuitem.show()
self.filter_combo.set_menu(myMenu)
self.filter_menu = myMenu
menu = GenericFilter.build_filter_menu(local_filters)
self.filter_combo.set_menu(menu)
self.filter_menu = menu
row = row + 1
# Set up the generations spin and page break checkbox

View File

@ -54,6 +54,7 @@ if os.environ.has_key('GRAMPSDIR'):
else:
rootDir = "."
system_filters = "%s/system_filters.xml" % rootDir
custom_filters = "~/.gramps/custom_filters.xml"
icon = "%s/gramps.xpm" % rootDir
logo = "%s/logo.png" % rootDir

View File

@ -128,21 +128,12 @@ class EventComparison:
top =self.filterDialog.get_widget("filters")
filters = self.filterDialog.get_widget("filter_list")
myMenu = gtk.GtkMenu()
all = GenericFilter.GenericFilter()
all.set_name(_("Entire Database"))
all.add_rule(GenericFilter.Everyone([]))
flist = GenericFilter.GenericFilterList(const.custom_filters)
flist.load()
for f in [all] + flist.get_filters():
menuitem = gtk.GtkMenuItem(_(f.get_name()))
myMenu.append(menuitem)
menuitem.set_data("filter",f)
menuitem.show()
self.filter_menu = myMenu
filters.set_menu(myMenu)
self.filter_menu = GenericFilter.build_filter_menu([all])
filters.set_menu(self.filter_menu)
top.show()
def on_apply_clicked(self,obj):

View File

@ -81,6 +81,8 @@ class FilterEditor:
def close_filter_editor(self,obj):
self.filterdb.save()
self.editor_top.destroy()
GenericFilter.reload_custom_filters()
GenericFilter.reload_system_filters()
def draw_filters(self):
row = 0
@ -328,9 +330,17 @@ class ShowResults:
#
#
#-------------------------------------------------------------------------
def runTool(database,person,callback):
def CustomFilterEditor(database,person,callback):
FilterEditor(const.custom_filters,database)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def SystemFilterEditor(database,person,callback):
FilterEditor(const.system_filters,database)
#-------------------------------------------------------------------------
#
#
@ -339,10 +349,24 @@ def runTool(database,person,callback):
from Plugins import register_tool
register_tool(
runTool,
CustomFilterEditor,
_("Custom Filter Editor"),
category=_("Utilities"),
description=_("The Custom Filter Editor builds custom "
"filters that can be used to select people "
"included reports, exports, and other utilities.")
)
if ((os.path.exists(const.system_filters) and
os.access(const.system_filters, os.W_OK)) or
(os.path.exists(os.path.dirname(const.system_filters)) and
os.access(os.path.dirname(const.system_filters), os.W_OK))):
register_tool(
SystemFilterEditor,
_("System Filter Editor"),
category=_("Utilities"),
description=_("The System Filter Editor builds custom "
"filters that can be used by anyone on the system "
"to select people included reports, exports, "
"and other utilities.")
)

View File

@ -309,7 +309,6 @@ class GedcomWriter:
})
filter_obj = self.topDialog.get_widget("filter")
myMenu = gtk.GtkMenu()
all = GenericFilter.GenericFilter()
all.set_name(_("Entire Database"))
@ -323,15 +322,8 @@ class GedcomWriter:
ans.set_name(_("Ancestors of %s") % person.getPrimaryName().getName())
ans.add_rule(GenericFilter.IsAncestorOf([person.getId()]))
flist = GenericFilter.GenericFilterList(const.custom_filters)
flist.load()
for f in [all,des,ans] + flist.get_filters():
menuitem = gtk.GtkMenuItem(_(f.get_name()))
myMenu.append(menuitem)
menuitem.set_data("filter",f)
menuitem.show()
filter_obj.set_menu(myMenu)
self.filter_menu = myMenu
self.filter_menu = GenericFilter.build_filter_menu([all,des,ans])
filter_obj.set_menu(self.filter_menu)
gedmap = GedcomInfoDB()