Patches from Jeff Ollie for filters
svn: r910
This commit is contained in:
parent
b1de1f1439
commit
5707fc8339
@ -40,12 +40,14 @@ except:
|
|||||||
import types
|
import types
|
||||||
import os
|
import os
|
||||||
from string import find,join,strip,replace
|
from string import find,join,strip,replace
|
||||||
|
import gtk
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# GRAMPS modules
|
# GRAMPS modules
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
import const
|
||||||
from RelLib import *
|
from RelLib import *
|
||||||
import Date
|
import Date
|
||||||
from intl import gettext
|
from intl import gettext
|
||||||
@ -492,6 +494,23 @@ class HasNameOf(Rule):
|
|||||||
return 1
|
return 1
|
||||||
return 0
|
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
|
# GenericFilter
|
||||||
@ -576,6 +595,7 @@ tasks = {
|
|||||||
_("Has the family event") : HasFamilyEvent,
|
_("Has the family event") : HasFamilyEvent,
|
||||||
_("Has the personal attribute") : HasAttribute,
|
_("Has the personal attribute") : HasAttribute,
|
||||||
_("Has the family attribute") : HasFamilyAttribute,
|
_("Has the family attribute") : HasFamilyAttribute,
|
||||||
|
_("Matches the filter named") : MatchesFilter,
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -680,4 +700,78 @@ class FilterParser(handler.ContentHandler):
|
|||||||
def characters(self, data):
|
def characters(self, data):
|
||||||
pass
|
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
|
||||||
|
@ -644,7 +644,7 @@ class ReportDialog:
|
|||||||
(but not all) dialog boxes."""
|
(but not all) dialog boxes."""
|
||||||
|
|
||||||
(use_gen, use_break) = self.get_report_generations()
|
(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()
|
(em_label, extra_map, preset, em_tip) = self.get_report_extra_menu_info()
|
||||||
(et_label, string, et_tip) = self.get_report_extra_textbox_info()
|
(et_label, string, et_tip) = self.get_report_extra_textbox_info()
|
||||||
|
|
||||||
@ -654,7 +654,7 @@ class ReportDialog:
|
|||||||
max_rows = max_rows + 1
|
max_rows = max_rows + 1
|
||||||
if use_break:
|
if use_break:
|
||||||
max_rows = max_rows + 1
|
max_rows = max_rows + 1
|
||||||
if len(local_filter):
|
if len(local_filters):
|
||||||
max_rows = max_rows + 1
|
max_rows = max_rows + 1
|
||||||
if extra_map:
|
if extra_map:
|
||||||
max_rows = max_rows + 1
|
max_rows = max_rows + 1
|
||||||
@ -673,8 +673,7 @@ class ReportDialog:
|
|||||||
frame.add(table)
|
frame.add(table)
|
||||||
|
|
||||||
pad = ReportDialog.border_pad
|
pad = ReportDialog.border_pad
|
||||||
if len(local_filter):
|
if len(local_filters):
|
||||||
myMenu = GtkMenu()
|
|
||||||
self.filter_combo = GtkOptionMenu()
|
self.filter_combo = GtkOptionMenu()
|
||||||
l = GtkLabel(_("Filter"))
|
l = GtkLabel(_("Filter"))
|
||||||
l.set_alignment(1.0,0.5)
|
l.set_alignment(1.0,0.5)
|
||||||
@ -682,15 +681,10 @@ class ReportDialog:
|
|||||||
table.attach(self.filter_combo,1,2,row,row+1,
|
table.attach(self.filter_combo,1,2,row,row+1,
|
||||||
xpadding=pad,ypadding=pad)
|
xpadding=pad,ypadding=pad)
|
||||||
|
|
||||||
flist = GenericFilter.GenericFilterList(const.custom_filters)
|
menu = GenericFilter.build_filter_menu(local_filters)
|
||||||
flist.load()
|
|
||||||
for f in local_filter + flist.get_filters():
|
self.filter_combo.set_menu(menu)
|
||||||
menuitem = gtk.GtkMenuItem(_(f.get_name()))
|
self.filter_menu = menu
|
||||||
myMenu.append(menuitem)
|
|
||||||
menuitem.set_data("filter",f)
|
|
||||||
menuitem.show()
|
|
||||||
self.filter_combo.set_menu(myMenu)
|
|
||||||
self.filter_menu = myMenu
|
|
||||||
row = row + 1
|
row = row + 1
|
||||||
|
|
||||||
# Set up the generations spin and page break checkbox
|
# Set up the generations spin and page break checkbox
|
||||||
|
@ -54,6 +54,7 @@ if os.environ.has_key('GRAMPSDIR'):
|
|||||||
else:
|
else:
|
||||||
rootDir = "."
|
rootDir = "."
|
||||||
|
|
||||||
|
system_filters = "%s/system_filters.xml" % rootDir
|
||||||
custom_filters = "~/.gramps/custom_filters.xml"
|
custom_filters = "~/.gramps/custom_filters.xml"
|
||||||
icon = "%s/gramps.xpm" % rootDir
|
icon = "%s/gramps.xpm" % rootDir
|
||||||
logo = "%s/logo.png" % rootDir
|
logo = "%s/logo.png" % rootDir
|
||||||
|
@ -128,21 +128,12 @@ class EventComparison:
|
|||||||
top =self.filterDialog.get_widget("filters")
|
top =self.filterDialog.get_widget("filters")
|
||||||
filters = self.filterDialog.get_widget("filter_list")
|
filters = self.filterDialog.get_widget("filter_list")
|
||||||
|
|
||||||
myMenu = gtk.GtkMenu()
|
|
||||||
|
|
||||||
all = GenericFilter.GenericFilter()
|
all = GenericFilter.GenericFilter()
|
||||||
all.set_name(_("Entire Database"))
|
all.set_name(_("Entire Database"))
|
||||||
all.add_rule(GenericFilter.Everyone([]))
|
all.add_rule(GenericFilter.Everyone([]))
|
||||||
|
|
||||||
flist = GenericFilter.GenericFilterList(const.custom_filters)
|
self.filter_menu = GenericFilter.build_filter_menu([all])
|
||||||
flist.load()
|
filters.set_menu(self.filter_menu)
|
||||||
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)
|
|
||||||
top.show()
|
top.show()
|
||||||
|
|
||||||
def on_apply_clicked(self,obj):
|
def on_apply_clicked(self,obj):
|
||||||
|
@ -81,6 +81,8 @@ class FilterEditor:
|
|||||||
def close_filter_editor(self,obj):
|
def close_filter_editor(self,obj):
|
||||||
self.filterdb.save()
|
self.filterdb.save()
|
||||||
self.editor_top.destroy()
|
self.editor_top.destroy()
|
||||||
|
GenericFilter.reload_custom_filters()
|
||||||
|
GenericFilter.reload_system_filters()
|
||||||
|
|
||||||
def draw_filters(self):
|
def draw_filters(self):
|
||||||
row = 0
|
row = 0
|
||||||
@ -328,9 +330,17 @@ class ShowResults:
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
def runTool(database,person,callback):
|
def CustomFilterEditor(database,person,callback):
|
||||||
FilterEditor(const.custom_filters,database)
|
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
|
from Plugins import register_tool
|
||||||
|
|
||||||
register_tool(
|
register_tool(
|
||||||
runTool,
|
CustomFilterEditor,
|
||||||
_("Custom Filter Editor"),
|
_("Custom Filter Editor"),
|
||||||
category=_("Utilities"),
|
category=_("Utilities"),
|
||||||
description=_("The Custom Filter Editor builds custom "
|
description=_("The Custom Filter Editor builds custom "
|
||||||
"filters that can be used to select people "
|
"filters that can be used to select people "
|
||||||
"included reports, exports, and other utilities.")
|
"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.")
|
||||||
|
)
|
||||||
|
@ -309,7 +309,6 @@ class GedcomWriter:
|
|||||||
})
|
})
|
||||||
|
|
||||||
filter_obj = self.topDialog.get_widget("filter")
|
filter_obj = self.topDialog.get_widget("filter")
|
||||||
myMenu = gtk.GtkMenu()
|
|
||||||
|
|
||||||
all = GenericFilter.GenericFilter()
|
all = GenericFilter.GenericFilter()
|
||||||
all.set_name(_("Entire Database"))
|
all.set_name(_("Entire Database"))
|
||||||
@ -323,15 +322,8 @@ class GedcomWriter:
|
|||||||
ans.set_name(_("Ancestors of %s") % person.getPrimaryName().getName())
|
ans.set_name(_("Ancestors of %s") % person.getPrimaryName().getName())
|
||||||
ans.add_rule(GenericFilter.IsAncestorOf([person.getId()]))
|
ans.add_rule(GenericFilter.IsAncestorOf([person.getId()]))
|
||||||
|
|
||||||
flist = GenericFilter.GenericFilterList(const.custom_filters)
|
self.filter_menu = GenericFilter.build_filter_menu([all,des,ans])
|
||||||
flist.load()
|
filter_obj.set_menu(self.filter_menu)
|
||||||
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
|
|
||||||
|
|
||||||
gedmap = GedcomInfoDB()
|
gedmap = GedcomInfoDB()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user