* src/Filters/_GenericFilter.py: Support Source filters.

* src/Filters/SideBar/Makefile.am (pkgdata_PYTHON): Ship new file.
	* src/Filters/Rules/Source/Makefile.am: Ship new files.
	* src/FilterEditor/_EditRule.py: Support Source filters.
	* src/FilterEditor/_FilterEditor.py: Support Source filters.
	* src/FilterEditor/_ShowResults.py: Support Source filters.
	* src/Filters/Rules/Source/__init__.py: Expose new modules.
	* src/Filters/SideBar/_SourceSidebarFilter.py: Add module.
	* src/Filters/SideBar/__init__.py: Expose new module.
	* src/Filters/Rules/_Rule.py (Rule.match_substring): Add
	convenience method for simple substring search.
	* src/Filters/Rules/Source/_RegExpIdOf.py: Add module.
	* src/Filters/Rules/Source/_MatchesFilter.py: Add module.
	* src/Filters/Rules/Source/_HasNoteRegexp.py: Add module.
	* src/Filters/Rules/Source/_HasNoteMatchingSubstringOf.py: Add module.
	* src/Filters/Rules/Source/_HasIdOf.py: Add module.
	* src/Filters/Rules/Source/_SourcePrivate.py: Add module.
	* src/Filters/Rules/Source/_AllSources.py: Add module.



	


svn: r7138
This commit is contained in:
Alex Roitman 2006-08-06 06:26:10 +00:00
parent 14504b1f30
commit a2237d7da5
25 changed files with 660 additions and 10 deletions

View File

@ -1,4 +1,26 @@
2006-08-05 Alex Roitman <shura@gramps-project.org>
* src/Filters/_GenericFilter.py: Support Source filters.
* src/Filters/SideBar/Makefile.am (pkgdata_PYTHON): Ship new file.
* src/Filters/Rules/Source/Makefile.am: Ship new files.
* src/FilterEditor/_EditRule.py: Support Source filters.
* src/FilterEditor/_FilterEditor.py: Support Source filters.
* src/FilterEditor/_ShowResults.py: Support Source filters.
* src/Filters/Rules/Source/__init__.py: Expose new modules.
* src/Filters/SideBar/_SourceSidebarFilter.py: Add module.
* src/Filters/SideBar/__init__.py: Expose new module.
* src/Filters/Rules/_Rule.py (Rule.match_substring): Add
convenience method for simple substring search.
* src/Filters/Rules/Source/_RegExpIdOf.py: Add module.
* src/Filters/Rules/Source/_MatchesFilter.py: Add module.
* src/Filters/Rules/Source/_HasNoteRegexp.py: Add module.
* src/Filters/Rules/Source/_HasNoteMatchingSubstringOf.py: Add module.
* src/Filters/Rules/Source/_HasIdOf.py: Add module.
* src/Filters/Rules/Source/_SourcePrivate.py: Add module.
* src/Filters/Rules/Source/_AllSources.py: Add module.
* src/Filters/Rules/Family/Makefile.am (pkgdata_PYTHON): Ship new file.
* src/Filters/Rules/Family/_MemberBase.py: Add new module.
* src/Filters/SideBar/_PersonSidebarFilter.py: Minor changes.

View File

@ -518,9 +518,25 @@ src/Filters/Rules/Event/_HasIdOf.py
src/Filters/Rules/Event/_HasType.py
src/Filters/Rules/Event/_HasNoteMatchingSubstringOf.py
src/Filters/Rules/Event/__init__.py
# Filters.Rules.Place package
src/Filters/Rules/Place/__init__.py
# Filters.Rules.Source package
src/Filters/Rules/Source/_MatchesFilter.py
src/Filters/Rules/Source/_SourcePrivate.py
src/Filters/Rules/Source/_RegExpIdOf.py
src/Filters/Rules/Source/_HasSource.py
src/Filters/Rules/Source/_HasNoteMatchingSubstringOf.py
src/Filters/Rules/Source/_AllSources.py
src/Filters/Rules/Source/_HasNoteRegexp.py
src/Filters/Rules/Source/_HasIdOf.py
src/Filters/Rules/Source/__init__.py
# Filters.Rules.Media package
src/Filters/Rules/Media/__init__.py
# Filters.Rules.Repository package
src/Filters/Rules/Repository/__init__.py
# Filters.SideBar package
@ -528,6 +544,7 @@ src/Filters/SideBar/_EventSidebarFilter.py
src/Filters/SideBar/_FamilySidebarFilter.py
src/Filters/SideBar/_PersonSidebarFilter.py
src/Filters/SideBar/_SidebarFilter.py
src/Filters/SideBar/_SourceSidebarFilter.py
# FilterEditor package
src/FilterEditor/_FilterEditor.py

View File

@ -32,6 +32,8 @@ import gtk
#
#-------------------------------------------------------------------------
import RelLib
import const
import Config
import PageView
import DisplayModels
import Utils
@ -40,6 +42,7 @@ import Errors
from DdTargets import DdTargets
from Editors import EditSource, DelSrcQuery
from QuestionDialog import QuestionDialog, ErrorDialog
from Filters.SideBar import SourceSidebarFilter
#-------------------------------------------------------------------------
#
@ -81,7 +84,11 @@ class SourceView(PageView.ListView):
self, _('Sources'), dbstate, uistate, column_names,
len(column_names), DisplayModels.SourceModel, signal_map,
dbstate.db.get_source_bookmarks(),
Bookmarks.SourceBookmarks, multiple=True)
Bookmarks.SourceBookmarks, multiple=True,
filter_class=SourceSidebarFilter)
Config.client.notify_add("/apps/gramps/interface/filter",
self.filter_toggle)
def get_bookmarks(self):
return self.dbstate.db.get_source_bookmarks()
@ -95,6 +102,27 @@ class SourceView(PageView.ListView):
_('_Column Editor'), callback=self.column_editor)
self.add_action('FastMerge', None, _('_Merge'),
callback=self.fast_merge)
self.add_action('FilterEdit', None, _('Source Filter Editor'),
callback=self.filter_editor,)
def filter_toggle(self, client, cnxn_id, etnry, data):
if Config.get(Config.FILTER):
self.search_bar.hide()
self.filter_pane.show()
active = True
else:
self.search_bar.show()
self.filter_pane.hide()
active = False
def filter_editor(self,obj):
from FilterEditor import FilterEditor
try:
FilterEditor('Source',const.custom_filters,
self.dbstate,self.uistate)
except Errors.WindowActiveError:
pass
def column_editor(self,obj):
import ColumnOrder
@ -132,6 +160,7 @@ class SourceView(PageView.ListView):
<menuitem action="Remove"/>
</placeholder>
<menuitem action="ColumnEdit"/>
<menuitem action="FilterEdit"/>
<placeholder name="Merge">
<menuitem action="FastMerge"/>
</placeholder>

View File

@ -373,6 +373,8 @@ class EditRule(ManagedWindow.ManagedWindow):
class_list = Rules.Family.editor_rule_list
elif self.space == "Event":
class_list = Rules.Event.editor_rule_list
elif self.space == 'Source':
class_list = Rules.Source.editor_rule_list
for class_obj in class_list:
arglist = class_obj.labels
@ -404,10 +406,8 @@ class EditRule(ManagedWindow.ManagedWindow):
t = MyPlaces([])
elif v == _('Number of generations:'):
t = MyInteger(1,32)
elif v == _('Person ID:'):
t = MyID(self.dbstate, self.uistate, self.track, 'Person')
elif v == _('Family ID:'):
t = MyID(self.dbstate, self.uistate, self.track, 'Family')
elif v == _('ID:'):
t = MyID(self.dbstate,self.uistate,self.track,self.space)
elif v == _('Source ID:'):
t = MySource(self.db)
elif v == _('Filter name:'):

View File

@ -174,3 +174,5 @@ class FilterEditor(ManagedWindow.ManagedWindow):
return self.db.get_family_handles()
elif self.space == 'Event':
return self.db.get_event_handles()
elif self.space == 'Source':
return self.db.get_source_handles()

View File

@ -115,6 +115,10 @@ class ShowResults(ManagedWindow.ManagedWindow):
event = self.db.get_event_from_handle(handle)
name = event.get_description()
gid = event.get_gramps_id()
elif self.space == 'Source':
source = self.db.get_source_from_handle(handle)
name = source.get_title()
gid = source.get_gramps_id()
return (name,gid)
def sort_val_from_handle(self, handle):
@ -128,4 +132,7 @@ class ShowResults(ManagedWindow.ManagedWindow):
elif self.space == 'Event':
name = self.db.get_event_from_handle(handle).get_description()
sortname = locale.strxfrm(name)
elif self.space == 'Source':
name = self.db.get_source_from_handle(handle).get_title()
sortname = locale.strxfrm(name)
return (sortname,handle)

View File

@ -42,6 +42,5 @@ from Filters.Rules import HasGrampsId
class HasIdOf(HasGrampsId):
"""Rule that checks for a family with a specific GRAMPS ID"""
labels = [ _('Event ID:') ]
name = _('Event with <Id>')
description = _("Matches an event with a specified GRAMPS ID")

View File

@ -25,6 +25,7 @@ Package providing filter rules for GRAMPS.
"""
__author__ = "Don Allingham"
from Filters.Rules._HasEventBase import HasEventBase as HasEvent
from _HasType import HasType

View File

@ -42,6 +42,5 @@ from Filters.Rules import HasGrampsId
class HasIdOf(HasGrampsId):
"""Rule that checks for a family with a specific GRAMPS ID"""
labels = [ _('Family ID:') ]
name = _('Family with <Id>')
description = _("Matches a family with a specified GRAMPS ID")

View File

@ -42,6 +42,5 @@ from Filters.Rules import HasGrampsId
class HasIdOf(HasGrampsId):
"""Rule that checks for a person with a specific GRAMPS ID"""
labels = [ _('Person ID:') ]
name = _('People with <Id>')
description = _("Matches people with a specified GRAMPS ID")

View File

@ -3,6 +3,14 @@
pkgdatadir = $(datadir)/@PACKAGE@/Filters/Rules/Source
pkgdata_PYTHON = \
_MatchesFilter.py\
_SourcePrivate.py\
_RegExpIdOf.py\
_HasNoteMatchingSubstringOf.py\
_AllSources.py\
_HasIdOf.py\
_HasSource.py\
_HasNoteRegexp.py\
__init__.py
pkgpyexecdir = @pkgpyexecdir@/Filters/Rules/Source

View File

@ -0,0 +1,46 @@
#
# 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$
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules._Everything import Everything
#-------------------------------------------------------------------------
#
# Everyone
#
#-------------------------------------------------------------------------
class AllSources(Everything):
"""Matches Everyone"""
name = _('Every source')
description = _('Matches every source in the database')

View File

@ -0,0 +1,46 @@
#
# 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$
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules import HasGrampsId
#-------------------------------------------------------------------------
#
# HasIdOf
#
#-------------------------------------------------------------------------
class HasIdOf(HasGrampsId):
"""Rule that checks for a source with a specific GRAMPS ID"""
name = _('Source with <Id>')
description = _("Matches a source with a specified GRAMPS ID")

View File

@ -0,0 +1,46 @@
#
# 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$
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules._HasNoteSubstrBase import HasNoteSubstrBase
#-------------------------------------------------------------------------
# "Events having notes that contain a substring"
#-------------------------------------------------------------------------
class HasNoteMatchingSubstringOf(HasNoteSubstrBase):
"""Sources having notes containing <subtring>"""
name = _('Sources having notes containing <substring>')
description = _("Matches sources whose notes contain text "
"matching a substring")

View File

@ -0,0 +1,44 @@
#
# 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$
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules._HasNoteRegexBase import HasNoteRegexBase
#-------------------------------------------------------------------------
# "Sources having notes that contain a substring"
#-------------------------------------------------------------------------
class HasNoteRegexp(HasNoteRegexBase):
name = _('Sources having notes containing <regular expression>')
description = _("Matches sources whose notes contain text "
"matching a regular expression")

View File

@ -0,0 +1,63 @@
#
# 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$
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules._Rule import Rule
#-------------------------------------------------------------------------
#
# HasEvent
#
#-------------------------------------------------------------------------
class HasSource(Rule):
"""Rule that checks for a person with a particular value"""
labels = [ _('Title:'),
_('Author:'),
_('Publication:') ]
name = _('Sources matching parameters')
description = _("Matches sources with particular parameters")
category = _('General filters')
def apply(self,db,source):
if not self.match_substring(0,source.get_title()):
return False
if not self.match_substring(1,source.get_author()):
return False
if not self.match_substring(2,source.get_publication_info()):
return False
return True

View File

@ -0,0 +1,47 @@
#
# 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$
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules._MatchesFilterBase import MatchesFilterBase
#-------------------------------------------------------------------------
#
# MatchesFilter
#
#-------------------------------------------------------------------------
class MatchesFilter(MatchesFilterBase):
"""Rule that checks against another filter"""
name = _('Sources matching the <filter>')
description = _("Matches sources macthed by the specified filter name")
namespace = 'Source'

View File

@ -0,0 +1,50 @@
#
# 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$
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules._RegExpIdBase import RegExpIdBase
#-------------------------------------------------------------------------
#
# HasIdOf
#
#-------------------------------------------------------------------------
class RegExpIdOf(RegExpIdBase):
"""
Rule that checks for a source whose GRAMPS ID
matches regular expression.
"""
name = _('Sources with <Id> matching regular expression')
description = _("Matches sources whose GRAMPS ID matches "
"the regular expression")

View File

@ -0,0 +1,44 @@
#
# 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$
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules._IsPrivate import IsPrivate
#-------------------------------------------------------------------------
# "Family marked private"
#-------------------------------------------------------------------------
class SourcePrivate(IsPrivate):
"""Source marked private"""
name = _('Sources marked private')
description = _("Matches sources that are indicated as private")

View File

@ -25,3 +25,22 @@ Package providing filter rules for GRAMPS.
"""
__author__ = "Don Allingham"
from _AllSources import AllSources
from _HasIdOf import HasIdOf
from _RegExpIdOf import RegExpIdOf
from _HasNoteRegexp import HasNoteRegexp
from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf
from _SourcePrivate import SourcePrivate
from _MatchesFilter import MatchesFilter
from _HasSource import HasSource
editor_rule_list = [
AllSources,
HasIdOf,
RegExpIdOf,
HasNoteRegexp,
HasNoteMatchingSubstringOf,
SourcePrivate,
MatchesFilter,
]

View File

@ -73,3 +73,10 @@ class Rule:
for ix in range(0,len(self.list)) if self.list[ix] ]
return ';'.join(v)
def match_substring(self,param_index,str_var):
if self.list[param_index] and \
(str_var.upper().find(self.list[param_index].upper()) == -1):
return False
else:
return True

View File

@ -7,7 +7,8 @@ pkgdata_PYTHON = \
_FamilySidebarFilter.py \
__init__.py \
_SidebarFilter.py \
_PersonSidebarFilter.py
_PersonSidebarFilter.py\
_SourceSidebarFilter.py
pkgpyexecdir = @pkgpyexecdir@/Filters/SideBar
pkgpythondir = @pkgpythondir@/Filters/SideBar

View File

@ -0,0 +1,138 @@
#
# 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$
#-------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# gtk
#
#-------------------------------------------------------------------------
import gtk
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
import GrampsWidgets
import RelLib
from _SidebarFilter import SidebarFilter
from Filters import GenericFilterFactory, build_filter_model, Rules
from Filters.Rules.Source import *
GenericSourceFilter = GenericFilterFactory('Source')
#-------------------------------------------------------------------------
#
# PersonSidebarFilter class
#
#-------------------------------------------------------------------------
class SourceSidebarFilter(SidebarFilter):
def __init__(self, clicked):
SidebarFilter.__init__(self)
self.clicked_func = clicked
def create_widget(self):
self.filter_id = gtk.Entry()
self.filter_title = gtk.Entry()
self.filter_author = gtk.Entry()
self.filter_pub = gtk.Entry()
self.filter_note = gtk.Entry()
self.filter_regex = gtk.CheckButton(_('Use regular expressions'))
all = GenericSourceFilter()
all.set_name(_("None"))
all.add_rule(Rules.Source.AllSources([]))
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('Source', [all]))
self.generic.set_active(0)
self.add_text_entry(_('ID'), self.filter_id)
self.add_text_entry(_('Title'), self.filter_title)
self.add_text_entry(_('Author'), self.filter_author)
self.add_text_entry(_('Publication'), self.filter_pub)
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_title.set_text('')
self.filter_author.set_text('')
self.filter_pub.set_text('')
self.filter_note.set_text('')
self.generic.set_active(0)
def clicked(self, obj):
self.clicked_func()
def get_filter(self):
gid = unicode(self.filter_id.get_text()).strip()
title = unicode(self.filter_title.get_text()).strip()
author = unicode(self.filter_author.get_text()).strip()
pub = unicode(self.filter_pub.get_text()).strip()
note = unicode(self.filter_note.get_text()).strip()
regex = self.filter_regex.get_active()
gen = self.generic.get_active() > 0
empty = not (gid or title or author or pub or note or regex or gen)
if empty:
generic_filter = None
else:
generic_filter = GenericSourceFilter()
if gid:
if regex:
rule = RegExpIdOf([gid])
else:
rule = HasIdOf([gid])
generic_filter.add_rule(rule)
rule = HasSource([title,author,pub])
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

View File

@ -30,3 +30,4 @@ from _SidebarFilter import SidebarFilter
from _PersonSidebarFilter import PersonSidebarFilter
from _FamilySidebarFilter import FamilySidebarFilter
from _EventSidebarFilter import EventSidebarFilter
from _SourceSidebarFilter import SourceSidebarFilter

View File

@ -218,7 +218,6 @@ class GenericFamilyFilter(GenericFilter):
def find_from_handle(self, db, handle):
return db.get_family_from_handle(handle)
class GenericEventFilter(GenericFilter):
def __init__(self, source=None):
@ -232,6 +231,20 @@ class GenericEventFilter(GenericFilter):
def find_from_handle(self, db, handle):
return db.get_event_from_handle(handle)
class GenericSourceFilter(GenericFilter):
def __init__(self, source=None):
GenericFilter.__init__(self, source)
def get_cursor(db, self):
return db.get_source_cursor()
def make_obj(self):
return RelLib.Source()
def find_from_handle(self, db, handle):
return db.get_source_from_handle(handle)
def GenericFilterFactory(namespace):
if namespace == 'Person':
@ -240,3 +253,5 @@ def GenericFilterFactory(namespace):
return GenericFamilyFilter
elif namespace == 'Event':
return GenericEventFilter
elif namespace == 'Source':
return GenericSourceFilter