2006-06-21 Don Allingham <don@gramps-project.org>
* src/Filters/__init__.py: include new build_filter_model * src/Filters/_FilterMenu.py: build_filter_model * src/Filters/Rules/Person/_MatchesFilter.py: handle custom and system models properly * src/Filters/_PersonSidebarFilter.py: add custom filter menu svn: r6932
This commit is contained in:
parent
d55e082c30
commit
1f526eee1c
@ -1,3 +1,10 @@
|
||||
2006-06-21 Don Allingham <don@gramps-project.org>
|
||||
* src/Filters/__init__.py: include new build_filter_model
|
||||
* src/Filters/_FilterMenu.py: build_filter_model
|
||||
* src/Filters/Rules/Person/_MatchesFilter.py: handle custom and
|
||||
system models properly
|
||||
* src/Filters/_PersonSidebarFilter.py: add custom filter menu
|
||||
|
||||
2006-06-20 Don Allingham <don@gramps-project.org>
|
||||
* src/Filters/_SidebarFilter.py: change from CLEAR to RESET
|
||||
* src/DataViews/_PersonView.py (PersonView.person_updated): if surname
|
||||
|
@ -32,7 +32,8 @@ from gettext import gettext as _
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from Filters import SystemFilters, CustomFilters
|
||||
import Filters
|
||||
#from Filters import SystemFilters, CustomFilters
|
||||
from Filters.Rules._Rule import Rule
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -49,30 +50,36 @@ class MatchesFilter(Rule):
|
||||
category = _('General filters')
|
||||
|
||||
def prepare(self,db):
|
||||
for filt in SystemFilters.get_filters():
|
||||
if filt.get_name() == self.list[0]:
|
||||
for rule in filt.flist:
|
||||
rule.prepare(db)
|
||||
for filt in CustomFilters.get_filters():
|
||||
if filt.get_name() == self.list[0]:
|
||||
for rule in filt.flist:
|
||||
rule.prepare(db)
|
||||
if Filters.SystemFilters:
|
||||
for filt in Filters.SystemFilters.get_filters('Person'):
|
||||
if filt.get_name() == self.list[0]:
|
||||
for rule in filt.flist:
|
||||
rule.prepare(db)
|
||||
if Filters.CustomFilters:
|
||||
for filt in Filters.CustomFilters.get_filters('Person'):
|
||||
if filt.get_name() == self.list[0]:
|
||||
for rule in filt.flist:
|
||||
rule.prepare(db)
|
||||
|
||||
def reset(self):
|
||||
for filt in SystemFilters.get_filters():
|
||||
if filt.get_name() == self.list[0]:
|
||||
for rule in filt.flist:
|
||||
rule.reset()
|
||||
for filt in CustomFilters.get_filters():
|
||||
if filt.get_name() == self.list[0]:
|
||||
for rule in filt.flist:
|
||||
rule.reset()
|
||||
if Filters.SystemFilters:
|
||||
for filt in Filters.SystemFilters.get_filters('Person'):
|
||||
if filt.get_name() == self.list[0]:
|
||||
for rule in filt.flist:
|
||||
rule.reset()
|
||||
if Filters.CustomFilters:
|
||||
for filt in Filters.CustomFilters.get_filters('Person'):
|
||||
if filt.get_name() == self.list[0]:
|
||||
for rule in filt.flist:
|
||||
rule.reset()
|
||||
|
||||
def apply(self,db,person):
|
||||
for filt in SystemFilters.get_filters():
|
||||
if filt.get_name() == self.list[0]:
|
||||
return filt.check(db,person.handle)
|
||||
for filt in CustomFilters.get_filters():
|
||||
if filt.get_name() == self.list[0]:
|
||||
return filt.check(db,person.handle)
|
||||
if Filters.SystemFilters:
|
||||
for filt in Filters.SystemFilters.get_filters('Person'):
|
||||
if filt.get_name() == self.list[0]:
|
||||
return filt.check(db,person.handle)
|
||||
if Filters.CustomFilters:
|
||||
for filt in Filters.CustomFilters.get_filters('Person'):
|
||||
if filt.get_name() == self.list[0]:
|
||||
return filt.check(db,person.handle)
|
||||
return False
|
||||
|
@ -43,26 +43,37 @@ from Filters import SystemFilters, CustomFilters
|
||||
def build_filter_menu(local_filters = [], default=""):
|
||||
menu = gtk.Menu()
|
||||
|
||||
cnt = 0
|
||||
for filt in local_filters:
|
||||
menuitem = gtk.MenuItem(filt.get_name())
|
||||
menuitem.show()
|
||||
menu.append(menuitem)
|
||||
menuitem.set_data("filter", filt)
|
||||
cnt += 1
|
||||
|
||||
for filt in SystemFilters.get_filters():
|
||||
menuitem = gtk.MenuItem(_(filt.get_name()))
|
||||
menuitem.show()
|
||||
menu.append(menuitem)
|
||||
menuitem.set_data("filter", filt)
|
||||
cnt += 1
|
||||
|
||||
for filt in CustomFilters.get_filters():
|
||||
menuitem = gtk.MenuItem(_(filt.get_name()))
|
||||
menuitem.show()
|
||||
menu.append(menuitem)
|
||||
menuitem.set_data("filter", filt)
|
||||
cnt += 1
|
||||
|
||||
return menu
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# This is used by plugins to create a menu of available filters
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def build_filter_model(space, local = [], default=""):
|
||||
model = gtk.ListStore(str, object)
|
||||
|
||||
flist = local + SystemFilters.get_filters(space) + \
|
||||
CustomFilters.get_filters(space)
|
||||
|
||||
for filt in flist:
|
||||
model.append(row=[filt.get_name(), filt])
|
||||
return model
|
||||
|
@ -27,7 +27,7 @@ import RelLib
|
||||
|
||||
from _SidebarFilter import SidebarFilter
|
||||
from Filters.Rules.Person import *
|
||||
from Filters import GenericFilter
|
||||
from Filters import GenericFilter, build_filter_model, Rules
|
||||
|
||||
class PersonSidebarFilter(SidebarFilter):
|
||||
|
||||
@ -57,6 +57,17 @@ class PersonSidebarFilter(SidebarFilter):
|
||||
|
||||
self.filter_regex = gtk.CheckButton(_('Use regular expressions'))
|
||||
|
||||
all = GenericFilter()
|
||||
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('Person', [all]))
|
||||
self.generic.set_active(0)
|
||||
|
||||
self.add_text_entry(_('Name'), self.filter_name)
|
||||
self.add_text_entry(_('ID'), self.filter_id)
|
||||
self.add_entry(_('Gender'), self.filter_gender)
|
||||
@ -64,6 +75,7 @@ class PersonSidebarFilter(SidebarFilter):
|
||||
self.add_text_entry(_('Death date'), self.filter_death)
|
||||
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):
|
||||
@ -74,6 +86,7 @@ class PersonSidebarFilter(SidebarFilter):
|
||||
self.filter_note.set_text('')
|
||||
self.filter_gender.set_active(0)
|
||||
self.etype.child.set_text('')
|
||||
self.generic.set_active(0)
|
||||
|
||||
def clicked(self, obj):
|
||||
self.clicked_func()
|
||||
@ -86,10 +99,11 @@ class PersonSidebarFilter(SidebarFilter):
|
||||
note = self.filter_note.get_text().strip()
|
||||
gender = self.filter_gender.get_active()
|
||||
regex = self.filter_regex.get_active()
|
||||
gen = self.generic.get_active() > 0
|
||||
|
||||
if not name and not gid and not birth and not death \
|
||||
and not str(self.filter_event.get_type()) and \
|
||||
not note and not gender > 0:
|
||||
not note and not gender > 0 and not gen:
|
||||
generic_filter = None
|
||||
else:
|
||||
generic_filter = GenericFilter()
|
||||
@ -130,5 +144,13 @@ class PersonSidebarFilter(SidebarFilter):
|
||||
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
|
||||
|
||||
|
@ -52,7 +52,7 @@ if not CustomFilters:
|
||||
|
||||
from _FilterWidget import FilterWidget
|
||||
from _FilterComboBox import FilterComboBox
|
||||
from _FilterMenu import build_filter_menu
|
||||
from _FilterMenu import build_filter_menu, build_filter_model
|
||||
from _FilterStore import FilterStore
|
||||
from _SearchBar import SearchBar
|
||||
from _SearchFilter import SearchFilter
|
||||
|
Loading…
Reference in New Issue
Block a user