2008-02-22 Raphael Ackermann <raphael.ackermann@gmail.com>

* src/FilterEditor/_EditRule.py
    * src/Filters/Rules/_HasAttributeBase.py
    * src/Filters/Rules/Family/_MatchesFilter.py
    * src/Filters/Rules/Event/_MatchesFilter.py
    * src/Filters/Rules/Event/_MatchesSourceFilter.py
    * src/Filters/Rules/Event/_HasType.py
    * src/Filters/Rules/Event/_MatchesPersonFilter.py
    * src/Filters/Rules/_HasTextMatchingRegexpOf.py
    * src/Filters/Rules/_HasReferenceCountBase.py
    * src/Filters/Rules/_HasNoteSubstrBase.py
    * src/Filters/Rules/__init__.py
    * src/Filters/Rules/_HasGrampsId.py
    * src/Filters/Rules/_RegExpIdBase.py
    * src/Filters/Rules/_IsPrivate.py
    * src/Filters/Rules/_Rule.py
    * src/Filters/Rules/_HasMarkerBase.py
    * src/Filters/Rules/_HasEventBase.py
    * src/Filters/Rules/Note/_MatchesFilter.py
    * src/Filters/Rules/Person/_MatchesFilter.py
    * src/Filters/Rules/Person/_MatchesEventFilter.py
    * src/Filters/Rules/MediaObject/_MatchesFilter.py
    * src/Filters/Rules/_HasTextMatchingSubstringOf.py
    * src/Filters/Rules/_Everything.py
    * src/Filters/Rules/_MatchesFilterBase.py
    * src/Filters/Rules/_HasNoteRegexBase.py
    * src/DateHandler/_DateUtils.py
    pylint and doc fixes.

svn: r10094
This commit is contained in:
Raphael Ackermann
2008-02-22 10:50:06 +00:00
parent 19dd787311
commit f3db8c0e75
27 changed files with 222 additions and 174 deletions

View File

@@ -1,3 +1,33 @@
2008-02-22 Raphael Ackermann <raphael.ackermann@gmail.com>
* src/FilterEditor/_EditRule.py
* src/Filters/Rules/_HasAttributeBase.py
* src/Filters/Rules/Family/_MatchesFilter.py
* src/Filters/Rules/Event/_MatchesFilter.py
* src/Filters/Rules/Event/_MatchesSourceFilter.py
* src/Filters/Rules/Event/_HasType.py
* src/Filters/Rules/Event/_MatchesPersonFilter.py
* src/Filters/Rules/_HasTextMatchingRegexpOf.py
* src/Filters/Rules/_HasReferenceCountBase.py
* src/Filters/Rules/_HasNoteSubstrBase.py
* src/Filters/Rules/__init__.py
* src/Filters/Rules/_HasGrampsId.py
* src/Filters/Rules/_RegExpIdBase.py
* src/Filters/Rules/_IsPrivate.py
* src/Filters/Rules/_Rule.py
* src/Filters/Rules/_HasMarkerBase.py
* src/Filters/Rules/_HasEventBase.py
* src/Filters/Rules/Note/_MatchesFilter.py
* src/Filters/Rules/Person/_MatchesFilter.py
* src/Filters/Rules/Person/_MatchesEventFilter.py
* src/Filters/Rules/MediaObject/_MatchesFilter.py
* src/Filters/Rules/_HasTextMatchingSubstringOf.py
* src/Filters/Rules/_Everything.py
* src/Filters/Rules/_MatchesFilterBase.py
* src/Filters/Rules/_HasNoteRegexBase.py
* src/DateHandler/_DateUtils.py
pylint and doc fixes.
2008-02-20 Frederik De Richter <frederik.de.richter@pandora.be> 2008-02-20 Frederik De Richter <frederik.de.richter@pandora.be>
* src/Merge/_MergePerson.py * src/Merge/_MergePerson.py
* src/Merge/_MergeSource.py * src/Merge/_MergeSource.py

View File

@@ -38,7 +38,7 @@ from DateHandler import LANG_TO_DISPLAY, LANG, parser, displayer
#-------------------------------------------------------------- #--------------------------------------------------------------
def get_date_formats(): def get_date_formats():
""" """
Returns the lists supported formats for date parsers and displayers Return the lists supported formats for date parsers and displayers.
""" """
try: try:
return LANG_TO_DISPLAY[LANG].formats return LANG_TO_DISPLAY[LANG].formats
@@ -53,7 +53,7 @@ def set_format(value):
def set_date(date_base, text) : def set_date(date_base, text) :
""" """
Sets the date of the DateBase instance. Set the date of the DateBase instance.
The date is parsed into a Date instance. The date is parsed into a Date instance.
@@ -61,23 +61,25 @@ def set_date(date_base, text) :
@type date_base: DateBase @type date_base: DateBase
@param text: The text to use for the text string in date @param text: The text to use for the text string in date
@type text: str @type text: str
""" """
parser.set_date(date_base.get_date_object(),text) parser.set_date(date_base.get_date_object(), text)
def get_date(date_base) : def get_date(date_base) :
""" """
Returns a string representation of the date of the DateBase instance. Return a string representation of the date of the DateBase instance.
This representation is based off the default date display format This representation is based off the default date display format
determined by the locale's DateDisplay instance. determined by the locale's DateDisplay instance.
@return: Returns a string representing the DateBase date @return: Returns a string representing the DateBase date
@rtype: str @rtype: str
""" """
return displayer.display(date_base.get_date_object()) return displayer.display(date_base.get_date_object())
def get_quote_date(date_base): def get_quote_date(date_base):
""" """
Returns a string representation of the date of the DateBase instance. Return a string representation of the date of the DateBase instance.
This representation is based off the default date display format This representation is based off the default date display format
determined by the locale's DateDisplay instance. The date is determined by the locale's DateDisplay instance. The date is
@@ -85,5 +87,6 @@ def get_quote_date(date_base):
@return: Returns a string representing the DateBase date @return: Returns a string representing the DateBase date
@rtype: str @rtype: str
""" """
return displayer.quote_display(date_base.get_date_object()) return displayer.quote_display(date_base.get_date_object())

View File

@@ -67,8 +67,8 @@ import ManagedWindow
# Sorting function for the filter rules # Sorting function for the filter rules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def by_rule_name(f,s): def by_rule_name(f, s):
return cmp(f.name,s.name) return cmp(f.name, s.name)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -93,22 +93,25 @@ _name2typeclass = {
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class MyBoolean(gtk.CheckButton): class MyBoolean(gtk.CheckButton):
def __init__(self,label=None): def __init__(self, label=None):
gtk.CheckButton.__init__(self,label) gtk.CheckButton.__init__(self, label)
self.show() self.show()
def get_text(self): def get_text(self):
""" """
This method returns the text to save. It should be the same Return the text to save.
no matter the present locale (English or numeric types).
It should be the same no matter the present locale (English or numeric
types).
This class sets this to get_display_text, but when localization This class sets this to get_display_text, but when localization
is an issue (events/attr/etc types) then it has to be overridden. is an issue (events/attr/etc types) then it has to be overridden.
""" """
return str(int(self.get_active())) return str(int(self.get_active()))
def set_text(self,val): def set_text(self, val):
""" """
This method sets the selector state to display the passed value. Set the selector state to display the passed value.
""" """
is_active = bool(int(val)) is_active = bool(int(val))
self.set_active(is_active) self.set_active(is_active)
@@ -120,15 +123,15 @@ class MyBoolean(gtk.CheckButton):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class MyInteger(gtk.SpinButton): class MyInteger(gtk.SpinButton):
def __init__(self,min,max): def __init__(self, min, max):
gtk.SpinButton.__init__(self) gtk.SpinButton.__init__(self)
self.set_adjustment(gtk.Adjustment(min,min,max,1)) self.set_adjustment(gtk.Adjustment(min, min, max, 1))
self.show() self.show()
def get_text(self): def get_text(self):
return str(self.get_value_as_int()) return str(self.get_value_as_int())
def set_text(self,val): def set_text(self, val):
self.set_value(int(val)) self.set_value(int(val))
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@@ -137,20 +140,23 @@ class MyInteger(gtk.SpinButton):
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class MyFilters(gtk.ComboBox): class MyFilters(gtk.ComboBox):
"""Class to present a combobox of selectable filters """
Class to present a combobox of selectable filters.
""" """
def __init__(self, filters, filter_name=None): def __init__(self, filters, filter_name=None):
""" Construct the combobox from the entries of """
the filters list. Construct the combobox from the entries of the filters list.
filter_name is name of calling filter
If filter_name is given, it will be excluded from the dropdown box Filter_name is name of calling filter.
If filter_name is given, it will be excluded from the dropdown box.
""" """
gtk.ComboBox.__init__(self) gtk.ComboBox.__init__(self)
store = gtk.ListStore(gobject.TYPE_STRING) store = gtk.ListStore(gobject.TYPE_STRING)
self.set_model(store) self.set_model(store)
cell = gtk.CellRendererText() cell = gtk.CellRendererText()
self.pack_start(cell,True) self.pack_start(cell, True)
self.add_attribute(cell,'text',0) self.add_attribute(cell, 'text', 0)
#remove own name from the list if given. #remove own name from the list if given.
self.flist = [ f.get_name() for f in filters if \ self.flist = [ f.get_name() for f in filters if \
(filter_name is None or f.get_name() != filter_name)] (filter_name is None or f.get_name() != filter_name)]
@@ -167,7 +173,7 @@ class MyFilters(gtk.ComboBox):
return "" return ""
return self.flist[active] return self.flist[active]
def set_text(self,val): def set_text(self, val):
if val in self.flist: if val in self.flist:
self.set_active(self.flist.index(val)) self.set_active(self.flist.index(val))
@@ -183,8 +189,8 @@ class MyLesserEqualGreater(gtk.ComboBox):
store = gtk.ListStore(gobject.TYPE_STRING) store = gtk.ListStore(gobject.TYPE_STRING)
self.set_model(store) self.set_model(store)
cell = gtk.CellRendererText() cell = gtk.CellRendererText()
self.pack_start(cell,True) self.pack_start(cell, True)
self.add_attribute(cell,'text',0) self.add_attribute(cell, 'text', 0)
self.clist = [_('lesser than'), _('equal to'), _('greater than')] self.clist = [_('lesser than'), _('equal to'), _('greater than')]
for name in self.clist: for name in self.clist:
store.append(row=[name]) store.append(row=[name])
@@ -197,7 +203,7 @@ class MyLesserEqualGreater(gtk.ComboBox):
return _('equal to') return _('equal to')
return self.clist[active] return self.clist[active]
def set_text(self,val): def set_text(self, val):
if val in self.clist: if val in self.clist:
self.set_active(self.clist.index(val)) self.set_active(self.clist.index(val))
else: else:
@@ -216,8 +222,8 @@ class MySource(gtk.ComboBox):
store = gtk.ListStore(gobject.TYPE_STRING) store = gtk.ListStore(gobject.TYPE_STRING)
self.set_model(store) self.set_model(store)
cell = gtk.CellRendererText() cell = gtk.CellRendererText()
self.pack_start(cell,True) self.pack_start(cell, True)
self.add_attribute(cell,'text',0) self.add_attribute(cell, 'text', 0)
self.slist = [] self.slist = []
for src_handle in self.db.get_source_handles(sort_handles=True): for src_handle in self.db.get_source_handles(sort_handles=True):
@@ -226,7 +232,7 @@ class MySource(gtk.ComboBox):
title = src.get_title() title = src.get_title()
if len(title) > 44: if len(title) > 44:
title = title[:40] + "..." title = title[:40] + "..."
store.append(row=["%s [%s]" % (title,src.get_gramps_id())]) store.append(row=["%s [%s]" % (title, src.get_gramps_id())])
self.set_active(0) self.set_active(0)
self.show() self.show()
@@ -237,7 +243,7 @@ class MySource(gtk.ComboBox):
return "" return ""
return self.slist[active] return self.slist[active]
def set_text(self,val): def set_text(self, val):
if val in self.slist: if val in self.slist:
self.set_active(self.slist.index(val)) self.set_active(self.slist.index(val))
@@ -249,10 +255,10 @@ class MySource(gtk.ComboBox):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class MyPlaces(gtk.Entry): class MyPlaces(gtk.Entry):
def __init__(self,places): def __init__(self, places):
gtk.Entry.__init__(self) gtk.Entry.__init__(self)
AutoComp.fill_entry(self,places) AutoComp.fill_entry(self, places)
self.show() self.show()
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@@ -274,7 +280,7 @@ class MyID(gtk.HBox):
} }
def __init__(self, dbstate, uistate, track, namespace='Person'): def __init__(self, dbstate, uistate, track, namespace='Person'):
gtk.HBox.__init__(self,False,6) gtk.HBox.__init__(self, False, 6)
self.dbstate = dbstate self.dbstate = dbstate
self.db = dbstate.db self.db = dbstate.db
self.uistate = uistate self.uistate = uistate
@@ -285,18 +291,18 @@ class MyID(gtk.HBox):
self.entry.show() self.entry.show()
self.button = gtk.Button() self.button = gtk.Button()
self.button.set_label(_('Select...')) self.button.set_label(_('Select...'))
self.button.connect('clicked',self.button_press) self.button.connect('clicked', self.button_press)
self.button.show() self.button.show()
self.pack_start(self.entry) self.pack_start(self.entry)
self.add(self.button) self.add(self.button)
self.tooltips = gtk.Tooltips() self.tooltips = gtk.Tooltips()
self.tooltips.set_tip(self.button,_('Select %s from a list') self.tooltips.set_tip(self.button, _('Select %s from a list')
% self.obj_name[namespace]) % self.obj_name[namespace])
self.tooltips.enable() self.tooltips.enable()
self.show() self.show()
self.set_text('') self.set_text('')
def button_press(self,obj): def button_press(self, obj):
obj_class = self.namespace obj_class = self.namespace
selector = selector_factory(obj_class) selector = selector_factory(obj_class)
inst = selector(self.dbstate, self.uistate, self.track) inst = selector(self.dbstate, self.uistate, self.track)
@@ -309,7 +315,7 @@ class MyID(gtk.HBox):
def get_text(self): def get_text(self):
return unicode(self.entry.get_text()) return unicode(self.entry.get_text())
def name_from_gramps_id(self,gramps_id): def name_from_gramps_id(self, gramps_id):
if self.namespace == 'Person': if self.namespace == 'Person':
person = self.db.get_person_from_gramps_id(gramps_id) person = self.db.get_person_from_gramps_id(gramps_id)
name = _nd.display_name(person.get_primary_name()) name = _nd.display_name(person.get_primary_name())
@@ -336,12 +342,12 @@ class MyID(gtk.HBox):
name = note.get() name = note.get()
return name return name
def set_text(self,val): def set_text(self, val):
try: try:
name = self.name_from_gramps_id(val) name = self.name_from_gramps_id(val)
self.tooltips.set_tip(self.entry,name) self.tooltips.set_tip(self.entry, name)
except AttributeError: except AttributeError:
self.tooltips.set_tip(self.entry,_('Not a valid ID')) self.tooltips.set_tip(self.entry, _('Not a valid ID'))
self.entry.set_text(val) self.entry.set_text(val)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@@ -362,10 +368,10 @@ class MySelect(gtk.ComboBoxEntry):
def get_text(self): def get_text(self):
return self.type_class(self.sel.get_values()).xml_str() return self.type_class(self.sel.get_values()).xml_str()
def set_text(self,val): def set_text(self, val):
tc = self.type_class() tc = self.type_class()
tc.set_from_xml_str(val) tc.set_from_xml_str(val)
self.sel.set_values((tc.val,tc.string)) self.sel.set_values((tc.val, tc.string))
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -437,27 +443,27 @@ class EditRule(ManagedWindow.ManagedWindow):
arglist = class_obj.labels arglist = class_obj.labels
vallist = [] vallist = []
tlist = [] tlist = []
self.page.append((class_obj,vallist,tlist)) self.page.append((class_obj, vallist, tlist))
pos = 0 pos = 0
l2 = gtk.Label(class_obj.name) l2 = gtk.Label(class_obj.name)
l2.set_alignment(0,0.5) l2.set_alignment(0, 0.5)
l2.show() l2.show()
c = gtk.TreeView() c = gtk.TreeView()
c.set_data('d',pos) c.set_data('d', pos)
c.show() c.show()
the_map[class_obj] = c the_map[class_obj] = c
# Only add a table with parameters if there are any parameters # Only add a table with parameters if there are any parameters
if arglist: if arglist:
table = gtk.Table(3,len(arglist)) table = gtk.Table(3, len(arglist))
else: else:
table = gtk.Table(1,1) table = gtk.Table(1, 1)
table.set_border_width(6) table.set_border_width(6)
table.set_col_spacings(6) table.set_col_spacings(6)
table.set_row_spacings(6) table.set_row_spacings(6)
table.show() table.show()
for v in arglist: for v in arglist:
l = gtk.Label(v) l = gtk.Label(v)
l.set_alignment(1,0.5) l.set_alignment(1, 0.5)
l.show() l.show()
if v == _('Place:'): if v == _('Place:'):
t = MyPlaces([]) t = MyPlaces([])
@@ -466,9 +472,10 @@ class EditRule(ManagedWindow.ManagedWindow):
elif v == _('Reference count must be:'): elif v == _('Reference count must be:'):
t = MyLesserEqualGreater() t = MyLesserEqualGreater()
elif v == _('Number of generations:'): elif v == _('Number of generations:'):
t = MyInteger(1,32) t = MyInteger(1, 32)
elif v == _('ID:'): elif v == _('ID:'):
t = MyID(self.dbstate,self.uistate,self.track,self.namespace) t = MyID(self.dbstate, self.uistate, self.track,
self.namespace)
elif v == _('Source ID:'): elif v == _('Source ID:'):
t = MySource(self.db) t = MySource(self.db)
elif v == _('Filter name:'): elif v == _('Filter name:'):
@@ -490,20 +497,22 @@ class EditRule(ManagedWindow.ManagedWindow):
elif v == _('Regular-Expression matching:'): elif v == _('Regular-Expression matching:'):
t = MyBoolean(_('Use regular expression')) t = MyBoolean(_('Use regular expression'))
elif v == _('Include Family events:'): elif v == _('Include Family events:'):
t = MyBoolean(_('Also family events where person is wife/husband')) t = MyBoolean(_('Also family events where person is '
'wife/husband'))
else: else:
t = MyEntry() t = MyEntry()
tlist.append(t) tlist.append(t)
table.attach(l,1,2,pos,pos+1,gtk.FILL,0,5,5) table.attach(l, 1, 2, pos, pos+1, gtk.FILL, 0, 5, 5)
table.attach(t,2,3,pos,pos+1,gtk.EXPAND|gtk.FILL,0,5,5) table.attach(t, 2, 3, pos, pos+1, gtk.EXPAND|gtk.FILL, 0, 5, 5)
pos = pos + 1 pos = pos + 1
self.notebook.append_page(table,gtk.Label(class_obj.name)) self.notebook.append_page(table, gtk.Label(class_obj.name))
self.class2page[class_obj] = self.page_num self.class2page[class_obj] = self.page_num
self.page_num = self.page_num + 1 self.page_num = self.page_num + 1
self.page_num = 0 self.page_num = 0
self.store = gtk.TreeStore(gobject.TYPE_STRING,gobject.TYPE_PYOBJECT) self.store = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)
self.selection = self.rname.get_selection() self.selection = self.rname.get_selection()
col = gtk.TreeViewColumn(_('Rule Name'),gtk.CellRendererText(),text=0) col = gtk.TreeViewColumn(_('Rule Name'), gtk.CellRendererText(),
text=0)
self.rname.append_column(col) self.rname.append_column(col)
self.rname.set_model(self.store) self.rname.set_model(self.store)
@@ -533,16 +542,16 @@ class EditRule(ManagedWindow.ManagedWindow):
catlist.sort() catlist.sort()
for category in catlist: for category in catlist:
top_node[category] = self.store.insert_after(None,last_top) top_node[category] = self.store.insert_after(None, last_top)
top_level[category] = [] top_level[category] = []
last_top = top_node[category] last_top = top_node[category]
self.store.set(last_top,0,category,1,None) self.store.set(last_top, 0, category, 1, None)
for class_obj in keys: for class_obj in keys:
category = class_obj.category category = class_obj.category
top_level[category].append(class_obj.name) top_level[category].append(class_obj.name)
node = self.store.insert_after(top_node[category],prev) node = self.store.insert_after(top_node[category], prev)
self.store.set(node,0,class_obj.name,1,class_obj) self.store.set(node, 0, class_obj.name, 1, class_obj)
# #
# if this is an edit rule, save the node # if this is an edit rule, save the node
@@ -554,53 +563,57 @@ class EditRule(ManagedWindow.ManagedWindow):
page = self.class2page[self.active_rule.__class__] page = self.class2page[self.active_rule.__class__]
self.notebook.set_current_page(page) self.notebook.set_current_page(page)
self.display_values(self.active_rule.__class__) self.display_values(self.active_rule.__class__)
(class_obj,vallist,tlist) = self.page[page] (class_obj, vallist, tlist) = self.page[page]
r = self.active_rule.values() r = self.active_rule.values()
for i in range(0,len(tlist)): for i in range(0, len(tlist)):
tlist[i].set_text(r[i]) tlist[i].set_text(r[i])
self.selection.connect('changed', self.on_node_selected) self.selection.connect('changed', self.on_node_selected)
self.get_widget('ok').connect('clicked',self.rule_ok) self.get_widget('ok').connect('clicked', self.rule_ok)
self.get_widget('cancel').connect('clicked', self.close_window) self.get_widget('cancel').connect('clicked', self.close_window)
self.get_widget('help').connect('clicked',self.on_help_clicked) self.get_widget('help').connect('clicked', self.on_help_clicked)
self.show() self.show()
def on_help_clicked(self,obj): def on_help_clicked(self, obj):
"""Display the relevant portion of GRAMPS manual""" """
Display the relevant portion of GRAMPS manual.
"""
GrampsDisplay.help('append-filtref') GrampsDisplay.help('append-filtref')
def close_window(self,obj): def close_window(self, obj):
self.close() self.close()
def on_node_selected(self,obj): def on_node_selected(self, obj):
"""Updates the informational display on the right hand side of """
the dialog box with the description of the selected report""" Update the informational display on the right hand side of the dialog
box with the description of the selected report.
"""
store,node = self.selection.get_selected() store, node = self.selection.get_selected()
if node: if node:
try: try:
class_obj = store.get_value(node,1) class_obj = store.get_value(node, 1)
self.display_values(class_obj) self.display_values(class_obj)
except: except:
self.valuebox.set_sensitive(0) self.valuebox.set_sensitive(0)
self.rule_name.set_text(_('No rule selected')) self.rule_name.set_text(_('No rule selected'))
self.get_widget('description').set_text('') self.get_widget('description').set_text('')
def display_values(self,class_obj): def display_values(self, class_obj):
page = self.class2page[class_obj] page = self.class2page[class_obj]
self.notebook.set_current_page(page) self.notebook.set_current_page(page)
self.valuebox.set_sensitive(1) self.valuebox.set_sensitive(1)
self.rule_name.set_text(class_obj.name) self.rule_name.set_text(class_obj.name)
self.get_widget('description').set_text(class_obj.description) self.get_widget('description').set_text(class_obj.description)
def rule_ok(self,obj): def rule_ok(self, obj):
if self.rule_name.get_text() == _('No rule selected'): if self.rule_name.get_text() == _('No rule selected'):
return return
try: try:
page = self.notebook.get_current_page() page = self.notebook.get_current_page()
(class_obj,vallist,tlist) = self.page[page] (class_obj, vallist, tlist) = self.page[page]
value_list = [] value_list = []
for selector_class in tlist: for selector_class in tlist:
value_list.append(unicode(selector_class.get_text())) value_list.append(unicode(selector_class.get_text()))

View File

@@ -33,7 +33,7 @@ from gettext import gettext as _
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.lib import EventType from gen.lib import EventType
from Filters.Rules._Rule import Rule from Filters.Rules import Rule
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -41,7 +41,7 @@ from Filters.Rules._Rule import Rule
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class HasType(Rule): class HasType(Rule):
"""Rule that checks for an event of a particular type""" """Rule that checks for an event of a particular type."""
labels = [ _('Event type:') ] labels = [ _('Event type:') ]
name = _('Event with the particular type') name = _('Event with the particular type')

View File

@@ -32,7 +32,7 @@ from gettext import gettext as _
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from Filters.Rules._MatchesFilterBase import MatchesFilterBase from Filters.Rules import MatchesFilterBase
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -40,7 +40,7 @@ from Filters.Rules._MatchesFilterBase import MatchesFilterBase
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class MatchesFilter(MatchesFilterBase): class MatchesFilter(MatchesFilterBase):
"""Rule that checks against another filter""" """Rule that checks against another filter."""
name = _('Events matching the <filter>') name = _('Events matching the <filter>')
description = _("Matches events matched by the specified filter name") description = _("Matches events matched by the specified filter name")

View File

@@ -32,7 +32,7 @@ from gettext import gettext as _
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from Filters.Rules._MatchesFilterBase import MatchesFilterBase from Filters.Rules import MatchesFilterBase
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -45,6 +45,7 @@ class MatchesPersonFilter(MatchesFilterBase):
This is a base rule for subclassing by specific objects. This is a base rule for subclassing by specific objects.
Subclasses need to define the namespace class attribute. Subclasses need to define the namespace class attribute.
""" """
labels = [_('Person filter name:'), _('Include Family events:')] labels = [_('Person filter name:'), _('Include Family events:')]
@@ -52,10 +53,11 @@ class MatchesPersonFilter(MatchesFilterBase):
description = _("Matches events of persons matched by the specified " description = _("Matches events of persons matched by the specified "
"person filter name") "person filter name")
category = _('General filters') category = _('General filters')
# we want to have this filter show person filters # we want to have this filter show person filters
namespace = 'Person' namespace = 'Person'
def prepare(self,db): def prepare(self, db):
MatchesFilterBase.prepare(self, db) MatchesFilterBase.prepare(self, db)
try : try :
@@ -67,7 +69,7 @@ class MatchesPersonFilter(MatchesFilterBase):
self.MPF_famevents = False self.MPF_famevents = False
def apply(self,db,event): def apply(self, db, event):
filt = self.find_filter() filt = self.find_filter()
if filt: if filt:
for (classname, handle) in db.find_backlink_handles( for (classname, handle) in db.find_backlink_handles(

View File

@@ -32,7 +32,7 @@ from gettext import gettext as _
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from Filters.Rules._MatchesFilterBase import MatchesFilterBase from Filters.Rules import MatchesFilterBase
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -49,6 +49,7 @@ class MatchesSourceFilter(MatchesFilterBase):
description = _("Matches events with sources that match the " description = _("Matches events with sources that match the "
"specified source filter name") "specified source filter name")
category = _('General filters') category = _('General filters')
# we want to have this filter show source filters # we want to have this filter show source filters
namespace = 'Source' namespace = 'Source'
@@ -64,5 +65,5 @@ class MatchesSourceFilter(MatchesFilterBase):
for sourcehandle in sourcelist: for sourcehandle in sourcelist:
#check if source in source filter #check if source in source filter
if self.MSF_filt.check(db, sourcehandle): if self.MSF_filt.check(db, sourcehandle):
return True return True
return False return False

View File

@@ -32,7 +32,7 @@ from gettext import gettext as _
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from Filters.Rules._MatchesFilterBase import MatchesFilterBase from Filters.Rules import MatchesFilterBase
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -40,7 +40,7 @@ from Filters.Rules._MatchesFilterBase import MatchesFilterBase
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class MatchesFilter(MatchesFilterBase): class MatchesFilter(MatchesFilterBase):
"""Rule that checks against another filter""" """Rule that checks against another filter."""
name = _('Families matching the <filter>') name = _('Families matching the <filter>')
description = _("Matches families matched by the specified filter name") description = _("Matches families matched by the specified filter name")

View File

@@ -32,7 +32,7 @@ from gettext import gettext as _
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from Filters.Rules._MatchesFilterBase import MatchesFilterBase from Filters.Rules import MatchesFilterBase
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -40,7 +40,7 @@ from Filters.Rules._MatchesFilterBase import MatchesFilterBase
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class MatchesFilter(MatchesFilterBase): class MatchesFilter(MatchesFilterBase):
"""Rule that checks against another filter""" """Rule that checks against another filter."""
name = _('Media objects matching the <filter>') name = _('Media objects matching the <filter>')
description = _("Matches media objects matched by the " description = _("Matches media objects matched by the "

View File

@@ -32,7 +32,7 @@ from gettext import gettext as _
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from Filters.Rules._MatchesFilterBase import MatchesFilterBase from Filters.Rules import MatchesFilterBase
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -40,7 +40,7 @@ from Filters.Rules._MatchesFilterBase import MatchesFilterBase
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class MatchesFilter(MatchesFilterBase): class MatchesFilter(MatchesFilterBase):
"""Rule that checks against another filter""" """Rule that checks against another filter."""
name = _('Notes matching the <filter>') name = _('Notes matching the <filter>')
description = _("Matches notes matched " description = _("Matches notes matched "

View File

@@ -32,7 +32,7 @@ from gettext import gettext as _
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from Filters.Rules._MatchesFilterBase import MatchesFilterBase from Filters.Rules import MatchesFilterBase
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -45,6 +45,7 @@ class MatchesEventFilter(MatchesFilterBase):
This is a base rule for subclassing by specific objects. This is a base rule for subclassing by specific objects.
Subclasses need to define the namespace class attribute. Subclasses need to define the namespace class attribute.
""" """
labels = [_('Event filter name:')] labels = [_('Event filter name:')]
@@ -52,6 +53,7 @@ class MatchesEventFilter(MatchesFilterBase):
description = _("Matches persons who have events that match a certain" description = _("Matches persons who have events that match a certain"
" event filter") " event filter")
category = _('General filters') category = _('General filters')
# we want to have this filter show event filters # we want to have this filter show event filters
namespace = 'Event' namespace = 'Event'
@@ -67,5 +69,5 @@ class MatchesEventFilter(MatchesFilterBase):
for eventhandle in eventlist: for eventhandle in eventlist:
#check if event in event filter #check if event in event filter
if self.MEF_filt.check(db, eventhandle): if self.MEF_filt.check(db, eventhandle):
return True return True
return False return False

View File

@@ -32,7 +32,7 @@ from gettext import gettext as _
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from Filters.Rules._MatchesFilterBase import MatchesFilterBase from Filters.Rules import MatchesFilterBase
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -40,7 +40,7 @@ from Filters.Rules._MatchesFilterBase import MatchesFilterBase
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class MatchesFilter(MatchesFilterBase): class MatchesFilter(MatchesFilterBase):
"""Rule that checks against another filter""" """Rule that checks against another filter."""
name = _('People matching the <filter>') name = _('People matching the <filter>')
description = _("Matches people matched by the specified filter name") description = _("Matches people matched by the specified filter name")

View File

@@ -32,7 +32,7 @@ from gettext import gettext as _
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from _Rule import Rule from Filters.Rules import Rule
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -40,7 +40,7 @@ from _Rule import Rule
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class Everything(Rule): class Everything(Rule):
"""Matches Everyone""" """Match Everyone."""
name = _('Every object') name = _('Every object')
category = _('General filters') category = _('General filters')
@@ -49,5 +49,5 @@ class Everything(Rule):
def is_empty(self): def is_empty(self):
return True return True
def apply(self,db,obj): def apply(self, db, obj):
return True return True

View File

@@ -33,7 +33,7 @@ from gettext import gettext as _
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.lib import AttributeType from gen.lib import AttributeType
from Filters.Rules._Rule import Rule from Filters.Rules import Rule
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -41,7 +41,9 @@ from Filters.Rules._Rule import Rule
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class HasAttributeBase(Rule): class HasAttributeBase(Rule):
"""Rule that checks for an object with a particular attribute""" """
Rule that checks for an object with a particular attribute.
"""
labels = [ _('Attribute:'), _('Value:') ] labels = [ _('Attribute:'), _('Value:') ]
name = _('Objects with the <attribute>') name = _('Objects with the <attribute>')
@@ -49,7 +51,7 @@ class HasAttributeBase(Rule):
"of a particular value") "of a particular value")
category = _('General filters') category = _('General filters')
def apply(self,db,obj): def apply(self, db, obj):
if not self.list[0]: if not self.list[0]:
return False return False
for attr in obj.get_attribute_list(): for attr in obj.get_attribute_list():

View File

@@ -34,7 +34,7 @@ from gettext import gettext as _
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import DateHandler import DateHandler
from gen.lib import EventType from gen.lib import EventType
from Filters.Rules._Rule import Rule from Filters.Rules import Rule
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -42,7 +42,7 @@ from Filters.Rules._Rule import Rule
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class HasEventBase(Rule): class HasEventBase(Rule):
"""Rule that checks for an event with a particular value""" """Rule that checks for an event with a particular value."""
labels = [ _('Event type:'), labels = [ _('Event type:'),
@@ -53,7 +53,7 @@ class HasEventBase(Rule):
description = _("Matches events with particular parameters") description = _("Matches events with particular parameters")
category = _('Event filters') category = _('Event filters')
def prepare(self,db): def prepare(self, db):
self.date = None self.date = None
if self.list[0]: if self.list[0]:
self.etype = self.list[0] self.etype = self.list[0]
@@ -64,7 +64,7 @@ class HasEventBase(Rule):
self.date = DateHandler.parser.parse(self.list[1]) self.date = DateHandler.parser.parse(self.list[1])
except: pass except: pass
def apply(self,db,event): def apply(self, db, event):
if self.etype: if self.etype:
specified_type = EventType() specified_type = EventType()
specified_type.set_from_xml_str(self.etype) specified_type.set_from_xml_str(self.etype)
@@ -79,11 +79,11 @@ class HasEventBase(Rule):
return False return False
if self.list[2]: if self.list[2]:
pl_id = event.get_place_handle() place_id = event.get_place_handle()
if pl_id: if place_id:
pl = db.get_place_from_handle(pl_id) place = db.get_place_from_handle(place_id)
pn = pl.get_title() place_name = place.get_title()
if pn.upper().find(self.list[2].upper()) == -1: if place_name.upper().find(self.list[2].upper()) == -1:
return False return False
else: else:
return False return False

View File

@@ -32,7 +32,7 @@ from gettext import gettext as _
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from Filters.Rules._Rule import Rule from Filters.Rules import Rule
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -40,12 +40,12 @@ from Filters.Rules._Rule import Rule
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class HasGrampsId(Rule): class HasGrampsId(Rule):
"""Rule that checks for a person with a specific GRAMPS ID""" """Rule that checks for a person with a specific GRAMPS ID."""
labels = [ _('ID:') ] labels = [ _('ID:') ]
name = _('Object with <Id>') name = _('Object with <Id>')
description = _("Matches objects with a specified GRAMPS ID") description = _("Matches objects with a specified GRAMPS ID")
category = _('General filters') category = _('General filters')
def apply(self,db,obj): def apply(self, db, obj):
return obj.gramps_id.find(self.list[0]) !=-1 return obj.gramps_id.find(self.list[0]) !=-1

View File

@@ -33,7 +33,7 @@ from gettext import gettext as _
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.lib import MarkerType from gen.lib import MarkerType
from Filters.Rules._Rule import Rule from Filters.Rules import Rule
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -41,7 +41,7 @@ from Filters.Rules._Rule import Rule
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class HasMarkerBase(Rule): class HasMarkerBase(Rule):
"""Rule that checks for a person with a particular value""" """Rule that checks for a person with a particular value."""
labels = [ _('Marker type:')] labels = [ _('Marker type:')]
@@ -49,7 +49,7 @@ class HasMarkerBase(Rule):
description = _("Matches markers of a partikular type") description = _("Matches markers of a partikular type")
category = _('General filters') category = _('General filters')
def apply(self,db,obj): def apply(self, db, obj):
specified_type = MarkerType() specified_type = MarkerType()
specified_type.set_from_xml_str(self.list[0]) specified_type.set_from_xml_str(self.list[0])
return obj.get_marker() == specified_type return obj.get_marker() == specified_type

View File

@@ -33,13 +33,13 @@ from gettext import gettext as _
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from _Rule import Rule from Filters.Rules import Rule
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# "People having notes that contain a substring" # "People having notes that contain a substring"
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class HasNoteRegexBase(Rule): class HasNoteRegexBase(Rule):
"""People having notes containing <subtring>""" """People having notes containing <substring>."""
labels = [ _('Regular expression:')] labels = [ _('Regular expression:')]
name = _('Objects having notes containing <regular expression>') name = _('Objects having notes containing <regular expression>')
@@ -55,7 +55,7 @@ class HasNoteRegexBase(Rule):
except: except:
self.match = re.compile('') self.match = re.compile('')
def apply(self,db,person): def apply(self, db, person):
notelist = person.get_note_list() notelist = person.get_note_list()
for notehandle in notelist: for notehandle in notelist:
note = db.get_note_from_handle(notehandle) note = db.get_note_from_handle(notehandle)

View File

@@ -32,20 +32,21 @@ from gettext import gettext as _
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from Filters.Rules._Rule import Rule from Filters.Rules import Rule
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# "People having notes that contain a substring" # "People having notes that contain a substring"
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class HasNoteSubstrBase(Rule): class HasNoteSubstrBase(Rule):
"""People having notes containing <subtring>""" """People having notes containing <substring>."""
labels = [ _('Substring:')] labels = [ _('Substring:')]
name = _('Objects having notes containing <substring>') name = _('Objects having notes containing <substring>')
description = _("Matches objects whose notes contain text matching a substring") description = _("Matches objects whose notes contain text matching a "
"substring")
category = _('General filters') category = _('General filters')
def apply(self,db,person): def apply(self, db, person):
notelist = person.get_note_list() notelist = person.get_note_list()
for notehandle in notelist: for notehandle in notelist:
note = db.get_note_from_handle(notehandle) note = db.get_note_from_handle(notehandle)

View File

@@ -32,13 +32,13 @@ from gettext import gettext as _
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from Filters.Rules._Rule import Rule from Filters.Rules import Rule
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# "Objects with a certain reference count" # "Objects with a certain reference count"
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class HasReferenceCountBase(Rule): class HasReferenceCountBase(Rule):
"""Objects with a reference count of <count>""" """Objects with a reference count of <count>."""
labels = [ _('Reference count must be:'), _('Reference count:')] labels = [ _('Reference count must be:'), _('Reference count:')]
name = _('Objects with a reference count of <count>') name = _('Objects with a reference count of <count>')
@@ -46,27 +46,27 @@ class HasReferenceCountBase(Rule):
category = _('General filters') category = _('General filters')
def prepare(self,db): def prepare(self, db):
# things we want to do just once, not for every handle # things we want to do just once, not for every handle
if self.list[0] == _('lesser than'): if self.list[0] == _('lesser than'):
self.countType = 0 self.count_type = 0
elif self.list[0] == _('greater than'): elif self.list[0] == _('greater than'):
self.countType = 2 self.count_type = 2
else: else:
self.countType = 1 # "equal to" self.count_type = 1 # "equal to"
self.userSelectedCount = int(self.list[1]) self.userSelectedCount = int(self.list[1])
def apply(self,db,object): def apply(self, db, obj):
handle = object.get_handle() handle = obj.get_handle()
count = 0 count = 0
for item in db.find_backlink_handles(handle): for item in db.find_backlink_handles(handle):
count += 1 count += 1
if self.countType == 0: # "lesser than" if self.count_type == 0: # "lesser than"
return count < self.userSelectedCount return count < self.userSelectedCount
elif self.countType == 2: # "greater than" elif self.count_type == 2: # "greater than"
return count > self.userSelectedCount return count > self.userSelectedCount
# "equal to" # "equal to"
return count == self.userSelectedCount return count == self.userSelectedCount

View File

@@ -31,18 +31,17 @@
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from _HasTextMatchingSubstringOf import HasTextMatchingSubstringOf from Filters.Rules import HasTextMatchingSubstringOf
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# "HasTextMatchingRegexOf" # "HasTextMatchingRegexOf"
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class HasTextMatchingRegexpOf(HasTextMatchingSubstringOf): class HasTextMatchingRegexpOf(HasTextMatchingSubstringOf):
"""This is wrapping HasTextMatchingSubstringOf to enable the regex_match
parameter.
""" """
def __init__(self,list): Wrap HasTextMatchingSubstringOf to enable the regex_match parameter.
HasTextMatchingSubstringOf.__init__(self,list) """
def __init__(self, list):
HasTextMatchingSubstringOf.__init__(self, list)
# FIXME: This needs to be written for an arbitrary object # FIXME: This needs to be written for an arbitrary object
# if possible # if possible

View File

@@ -32,13 +32,13 @@ from gettext import gettext as _
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from _Rule import Rule from Filters.Rules import Rule
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# "HasTextMatchingSubstringOf" # "HasTextMatchingSubstringOf"
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class HasTextMatchingSubstringOf(Rule): class HasTextMatchingSubstringOf(Rule):
"""Rule that checks for string matches in any textual information""" """Rule that checks for string matches in any textual information."""
labels = [ _('Substring:'), labels = [ _('Substring:'),
_('Case sensitive:'), _('Case sensitive:'),

View File

@@ -32,17 +32,17 @@ from gettext import gettext as _
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from _Rule import Rule from Filters.Rules import Rule
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# "People marked private" # "People marked private"
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class IsPrivate(Rule): class IsPrivate(Rule):
"""Objects marked private""" """Objects marked private."""
name = _('Objects marked private') name = _('Objects marked private')
description = _("Matches objects that are indicated as private") description = _("Matches objects that are indicated as private")
category = _('General filters') category = _('General filters')
def apply(self,db,obj): def apply(self, db, obj):
return obj.get_privacy() return obj.get_privacy()

View File

@@ -33,7 +33,7 @@ from gettext import gettext as _
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import Filters import Filters
from _Rule import Rule from Filters.Rules import Rule
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -46,6 +46,7 @@ class MatchesFilterBase(Rule):
This is a base rule for subclassing by specific objects. This is a base rule for subclassing by specific objects.
Subclasses need to define the namespace class attribute. Subclasses need to define the namespace class attribute.
""" """
labels = [_('Filter name:')] labels = [_('Filter name:')]
@@ -53,7 +54,7 @@ class MatchesFilterBase(Rule):
description = _("Matches objects matched by the specified filter name") description = _("Matches objects matched by the specified filter name")
category = _('General filters') category = _('General filters')
def prepare(self,db): def prepare(self, db):
if Filters.SystemFilters: if Filters.SystemFilters:
for filt in Filters.SystemFilters.get_filters(self.namespace): for filt in Filters.SystemFilters.get_filters(self.namespace):
if filt.get_name() == self.list[0]: if filt.get_name() == self.list[0]:
@@ -77,7 +78,7 @@ class MatchesFilterBase(Rule):
for rule in filt.flist: for rule in filt.flist:
rule.reset() rule.reset()
def apply(self,db,obj): def apply(self, db, obj):
if Filters.SystemFilters: if Filters.SystemFilters:
for filt in Filters.SystemFilters.get_filters(self.namespace): for filt in Filters.SystemFilters.get_filters(self.namespace):
if filt.get_name() == self.list[0]: if filt.get_name() == self.list[0]:
@@ -89,8 +90,8 @@ class MatchesFilterBase(Rule):
return False return False
def find_filter(self): def find_filter(self):
""" helper function that can be usefull, returning the filter """
selected or None Return the selected filter or None.
""" """
if Filters.SystemFilters: if Filters.SystemFilters:
for filt in Filters.SystemFilters.get_filters(self.namespace): for filt in Filters.SystemFilters.get_filters(self.namespace):

View File

@@ -33,7 +33,7 @@ import re
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from _Rule import Rule from Filters.Rules import Rule
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -42,8 +42,7 @@ from _Rule import Rule
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class RegExpIdBase(Rule): class RegExpIdBase(Rule):
""" """
Rule that checks for an object whose GRAMPS ID Rule that checks for an object whose GRAMPS ID matches regular expression.
matches regular expression.
""" """
labels = [ _('Regular expression:') ] labels = [ _('Regular expression:') ]
@@ -56,9 +55,9 @@ class RegExpIdBase(Rule):
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,obj): def apply(self, db, obj):
return self.match.match(obj.gramps_id) != None return self.match.match(obj.gramps_id) != None

View File

@@ -33,26 +33,26 @@ from gettext import gettext as _
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class Rule: class Rule:
"""Base rule class""" """Base rule class."""
labels = [] labels = []
name = '' name = ''
category = _('Miscellaneous filters') category = _('Miscellaneous filters')
description = _('No description') description = _('No description')
def __init__(self,list): def __init__(self, list):
self.set_list(list) self.set_list(list)
def is_empty(self): def is_empty(self):
return False return False
def prepare(self,db): def prepare(self, db):
pass pass
def reset(self): def reset(self):
pass pass
def set_list(self,list): def set_list(self, list):
assert type(list) == type([]) or list == None, "Argument is not a list" assert type(list) == type([]) or list == None, "Argument is not a list"
assert len(list) == len(self.labels), \ assert len(list) == len(self.labels), \
"Number of arguments does not match number of labels.\n"\ "Number of arguments does not match number of labels.\n"\
@@ -65,7 +65,7 @@ class Rule:
def check(self): def check(self):
return len(self.list) == len(self.labels) return len(self.list) == len(self.labels)
def apply(self,db,person): def apply(self, db, person):
return True return True
def display_values(self): def display_values(self):
@@ -74,7 +74,7 @@ class Rule:
return ';'.join(v) return ';'.join(v)
def match_substring(self,param_index,str_var): def match_substring(self, param_index, str_var):
if self.list[param_index] and \ if self.list[param_index] and \
(str_var.upper().find(self.list[param_index].upper()) == -1): (str_var.upper().find(self.list[param_index].upper()) == -1):
return False return False

View File

@@ -26,19 +26,14 @@ Package providing filter rules for GRAMPS.
# Need to expose this to be available for filter plugins: # Need to expose this to be available for filter plugins:
# the plugins should say: from Filters.Rules import Rule # the plugins should say: from Filters.Rules import Rule
from _Rule import Rule from Filters.Rules._Rule import Rule
from _Everything import Everything from Filters.Rules._Everything import Everything
from _HasGrampsId import HasGrampsId from Filters.Rules._HasGrampsId import HasGrampsId
from _IsPrivate import IsPrivate from Filters.Rules._IsPrivate import IsPrivate
from _HasTextMatchingSubstringOf import HasTextMatchingSubstringOf from Filters.Rules._HasTextMatchingSubstringOf import HasTextMatchingSubstringOf
from _HasTextMatchingRegexpOf import HasTextMatchingRegexpOf from Filters.Rules._HasTextMatchingRegexpOf import HasTextMatchingRegexpOf
from Filters.Rules._MatchesFilterBase import MatchesFilterBase
import Person from Filters.Rules import (Person, Family, Event, Source, Place, MediaObject,
import Family Repository, Note)
import Event
import Source
import Place
import MediaObject
import Repository
import Note