Fix of issue 2515.

svn: r11343
This commit is contained in:
Peter Landgren 2008-11-24 18:48:51 +00:00
parent 44c8b26f10
commit 48bc0362e8

View File

@ -1,63 +1,63 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2002-2006 Donald N. Allingham # Copyright (C) 2002-2006 Donald N. Allingham
# Copyright (C) 2008 Brian G. Matherly # Copyright (C) 2008 Brian G. Matherly
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
# $Id: _HasNoteRegexp.py 9912 2008-01-22 09:17:46Z acraphae $ # $Id: _HasNoteRegexp.py 9912 2008-01-22 09:17:46Z acraphae $
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Standard Python modules # Standard Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import re import re
from gettext import gettext as _ from gettext import gettext as _
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from Filters.Rules import Rule from Filters.Rules import Rule
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# "Repos having notes that contain a substring" # "Repos having notes that contain a substring"
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class MatchesRegexpOf(Rule): class MatchesRegexpOf(Rule):
labels = [ _('Regular expression:')] labels = [ _('Regular expression:')]
name = _('Notes containing <regular expression>') name = _('Notes containing <regular expression>')
description = _("Matches notes who contain text " description = _("Matches notes who contain text "
"matching a regular expression") "matching a regular expression")
category = _('General filters') category = _('General filters')
def __init__(self, list): def __init__(self, list):
Rule.__init__(self, list) Rule.__init__(self, list)
try: try:
self.match = re.compile(list[0], re.I|re.U|re.L) self.match = re.compile(list[0], re.I|re.U|re.L)
except: except:
self.match = re.compile('') self.match = re.compile('')
def apply(self, db, note): def apply(self, db, note):
""" Apply the filter """ """ Apply the filter """
text = unicode(note.get()) text = unicode(note.get())
if self.match.match(text) is not None: if self.match.match(text) is not None:
return True return True
return False return False