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>
* src/Merge/_MergePerson.py
* src/Merge/_MergeSource.py

View File

@ -38,7 +38,7 @@ from DateHandler import LANG_TO_DISPLAY, LANG, parser, displayer
#--------------------------------------------------------------
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:
return LANG_TO_DISPLAY[LANG].formats
@ -53,7 +53,7 @@ def set_format(value):
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.
@ -61,23 +61,25 @@ def set_date(date_base, text) :
@type date_base: DateBase
@param text: The text to use for the text string in date
@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) :
"""
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
determined by the locale's DateDisplay instance.
@return: Returns a string representing the DateBase date
@rtype: str
"""
return displayer.display(date_base.get_date_object())
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
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
@rtype: str
"""
return displayer.quote_display(date_base.get_date_object())

View File

@ -67,8 +67,8 @@ import ManagedWindow
# Sorting function for the filter rules
#
#-------------------------------------------------------------------------
def by_rule_name(f,s):
return cmp(f.name,s.name)
def by_rule_name(f, s):
return cmp(f.name, s.name)
#-------------------------------------------------------------------------
#
@ -93,22 +93,25 @@ _name2typeclass = {
#-------------------------------------------------------------------------
class MyBoolean(gtk.CheckButton):
def __init__(self,label=None):
gtk.CheckButton.__init__(self,label)
def __init__(self, label=None):
gtk.CheckButton.__init__(self, label)
self.show()
def get_text(self):
"""
This method returns the text to save. It should be the same
no matter the present locale (English or numeric types).
Return the text to save.
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
is an issue (events/attr/etc types) then it has to be overridden.
"""
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))
self.set_active(is_active)
@ -120,15 +123,15 @@ class MyBoolean(gtk.CheckButton):
#-------------------------------------------------------------------------
class MyInteger(gtk.SpinButton):
def __init__(self,min,max):
def __init__(self, min, max):
gtk.SpinButton.__init__(self)
self.set_adjustment(gtk.Adjustment(min,min,max,1))
self.set_adjustment(gtk.Adjustment(min, min, max, 1))
self.show()
def get_text(self):
return str(self.get_value_as_int())
def set_text(self,val):
def set_text(self, val):
self.set_value(int(val))
#-------------------------------------------------------------------------
@ -137,20 +140,23 @@ class MyInteger(gtk.SpinButton):
#
#-------------------------------------------------------------------------
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):
""" 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
"""
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.
"""
gtk.ComboBox.__init__(self)
store = gtk.ListStore(gobject.TYPE_STRING)
self.set_model(store)
cell = gtk.CellRendererText()
self.pack_start(cell,True)
self.add_attribute(cell,'text',0)
self.pack_start(cell, True)
self.add_attribute(cell, 'text', 0)
#remove own name from the list if given.
self.flist = [ f.get_name() for f in filters if \
(filter_name is None or f.get_name() != filter_name)]
@ -167,7 +173,7 @@ class MyFilters(gtk.ComboBox):
return ""
return self.flist[active]
def set_text(self,val):
def set_text(self, val):
if val in self.flist:
self.set_active(self.flist.index(val))
@ -183,8 +189,8 @@ class MyLesserEqualGreater(gtk.ComboBox):
store = gtk.ListStore(gobject.TYPE_STRING)
self.set_model(store)
cell = gtk.CellRendererText()
self.pack_start(cell,True)
self.add_attribute(cell,'text',0)
self.pack_start(cell, True)
self.add_attribute(cell, 'text', 0)
self.clist = [_('lesser than'), _('equal to'), _('greater than')]
for name in self.clist:
store.append(row=[name])
@ -197,7 +203,7 @@ class MyLesserEqualGreater(gtk.ComboBox):
return _('equal to')
return self.clist[active]
def set_text(self,val):
def set_text(self, val):
if val in self.clist:
self.set_active(self.clist.index(val))
else:
@ -216,8 +222,8 @@ class MySource(gtk.ComboBox):
store = gtk.ListStore(gobject.TYPE_STRING)
self.set_model(store)
cell = gtk.CellRendererText()
self.pack_start(cell,True)
self.add_attribute(cell,'text',0)
self.pack_start(cell, True)
self.add_attribute(cell, 'text', 0)
self.slist = []
for src_handle in self.db.get_source_handles(sort_handles=True):
@ -226,7 +232,7 @@ class MySource(gtk.ComboBox):
title = src.get_title()
if len(title) > 44:
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.show()
@ -237,7 +243,7 @@ class MySource(gtk.ComboBox):
return ""
return self.slist[active]
def set_text(self,val):
def set_text(self, val):
if val in self.slist:
self.set_active(self.slist.index(val))
@ -249,10 +255,10 @@ class MySource(gtk.ComboBox):
#-------------------------------------------------------------------------
class MyPlaces(gtk.Entry):
def __init__(self,places):
def __init__(self, places):
gtk.Entry.__init__(self)
AutoComp.fill_entry(self,places)
AutoComp.fill_entry(self, places)
self.show()
#-------------------------------------------------------------------------
@ -274,7 +280,7 @@ class MyID(gtk.HBox):
}
def __init__(self, dbstate, uistate, track, namespace='Person'):
gtk.HBox.__init__(self,False,6)
gtk.HBox.__init__(self, False, 6)
self.dbstate = dbstate
self.db = dbstate.db
self.uistate = uistate
@ -285,18 +291,18 @@ class MyID(gtk.HBox):
self.entry.show()
self.button = gtk.Button()
self.button.set_label(_('Select...'))
self.button.connect('clicked',self.button_press)
self.button.connect('clicked', self.button_press)
self.button.show()
self.pack_start(self.entry)
self.add(self.button)
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.tooltips.enable()
self.show()
self.set_text('')
def button_press(self,obj):
def button_press(self, obj):
obj_class = self.namespace
selector = selector_factory(obj_class)
inst = selector(self.dbstate, self.uistate, self.track)
@ -309,7 +315,7 @@ class MyID(gtk.HBox):
def get_text(self):
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':
person = self.db.get_person_from_gramps_id(gramps_id)
name = _nd.display_name(person.get_primary_name())
@ -336,12 +342,12 @@ class MyID(gtk.HBox):
name = note.get()
return name
def set_text(self,val):
def set_text(self, val):
try:
name = self.name_from_gramps_id(val)
self.tooltips.set_tip(self.entry,name)
self.tooltips.set_tip(self.entry, name)
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)
#-------------------------------------------------------------------------
@ -362,10 +368,10 @@ class MySelect(gtk.ComboBoxEntry):
def get_text(self):
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.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
vallist = []
tlist = []
self.page.append((class_obj,vallist,tlist))
self.page.append((class_obj, vallist, tlist))
pos = 0
l2 = gtk.Label(class_obj.name)
l2.set_alignment(0,0.5)
l2.set_alignment(0, 0.5)
l2.show()
c = gtk.TreeView()
c.set_data('d',pos)
c.set_data('d', pos)
c.show()
the_map[class_obj] = c
# Only add a table with parameters if there are any parameters
if arglist:
table = gtk.Table(3,len(arglist))
table = gtk.Table(3, len(arglist))
else:
table = gtk.Table(1,1)
table = gtk.Table(1, 1)
table.set_border_width(6)
table.set_col_spacings(6)
table.set_row_spacings(6)
table.show()
for v in arglist:
l = gtk.Label(v)
l.set_alignment(1,0.5)
l.set_alignment(1, 0.5)
l.show()
if v == _('Place:'):
t = MyPlaces([])
@ -466,9 +472,10 @@ class EditRule(ManagedWindow.ManagedWindow):
elif v == _('Reference count must be:'):
t = MyLesserEqualGreater()
elif v == _('Number of generations:'):
t = MyInteger(1,32)
t = MyInteger(1, 32)
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:'):
t = MySource(self.db)
elif v == _('Filter name:'):
@ -490,20 +497,22 @@ class EditRule(ManagedWindow.ManagedWindow):
elif v == _('Regular-Expression matching:'):
t = MyBoolean(_('Use regular expression'))
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:
t = MyEntry()
tlist.append(t)
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(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)
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.page_num = self.page_num + 1
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()
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.set_model(self.store)
@ -533,16 +542,16 @@ class EditRule(ManagedWindow.ManagedWindow):
catlist.sort()
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] = []
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:
category = class_obj.category
top_level[category].append(class_obj.name)
node = self.store.insert_after(top_node[category],prev)
self.store.set(node,0,class_obj.name,1,class_obj)
node = self.store.insert_after(top_node[category], prev)
self.store.set(node, 0, class_obj.name, 1, class_obj)
#
# if this is an edit rule, save the node
@ -554,53 +563,57 @@ class EditRule(ManagedWindow.ManagedWindow):
page = self.class2page[self.active_rule.__class__]
self.notebook.set_current_page(page)
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()
for i in range(0,len(tlist)):
for i in range(0, len(tlist)):
tlist[i].set_text(r[i])
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('help').connect('clicked',self.on_help_clicked)
self.get_widget('help').connect('clicked', self.on_help_clicked)
self.show()
def on_help_clicked(self,obj):
"""Display the relevant portion of GRAMPS manual"""
def on_help_clicked(self, obj):
"""
Display the relevant portion of GRAMPS manual.
"""
GrampsDisplay.help('append-filtref')
def close_window(self,obj):
def close_window(self, obj):
self.close()
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"""
def on_node_selected(self, obj):
"""
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:
try:
class_obj = store.get_value(node,1)
class_obj = store.get_value(node, 1)
self.display_values(class_obj)
except:
self.valuebox.set_sensitive(0)
self.rule_name.set_text(_('No rule selected'))
self.get_widget('description').set_text('')
def display_values(self,class_obj):
def display_values(self, class_obj):
page = self.class2page[class_obj]
self.notebook.set_current_page(page)
self.valuebox.set_sensitive(1)
self.rule_name.set_text(class_obj.name)
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'):
return
try:
page = self.notebook.get_current_page()
(class_obj,vallist,tlist) = self.page[page]
(class_obj, vallist, tlist) = self.page[page]
value_list = []
for selector_class in tlist:
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 Filters.Rules._Rule import Rule
from Filters.Rules import Rule
#-------------------------------------------------------------------------
#
@ -41,7 +41,7 @@ from Filters.Rules._Rule import 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:') ]
name = _('Event with the particular type')

View File

@ -32,7 +32,7 @@ from gettext import gettext as _
# 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):
"""Rule that checks against another filter"""
"""Rule that checks against another filter."""
name = _('Events matching the <filter>')
description = _("Matches events matched by the specified filter name")

View File

@ -32,7 +32,7 @@ from gettext import gettext as _
# 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.
Subclasses need to define the namespace class attribute.
"""
labels = [_('Person filter name:'), _('Include Family events:')]
@ -52,10 +53,11 @@ class MatchesPersonFilter(MatchesFilterBase):
description = _("Matches events of persons matched by the specified "
"person filter name")
category = _('General filters')
# we want to have this filter show person filters
namespace = 'Person'
def prepare(self,db):
def prepare(self, db):
MatchesFilterBase.prepare(self, db)
try :
@ -67,7 +69,7 @@ class MatchesPersonFilter(MatchesFilterBase):
self.MPF_famevents = False
def apply(self,db,event):
def apply(self, db, event):
filt = self.find_filter()
if filt:
for (classname, handle) in db.find_backlink_handles(

View File

@ -32,7 +32,7 @@ from gettext import gettext as _
# 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 "
"specified source filter name")
category = _('General filters')
# we want to have this filter show source filters
namespace = 'Source'
@ -64,5 +65,5 @@ class MatchesSourceFilter(MatchesFilterBase):
for sourcehandle in sourcelist:
#check if source in source filter
if self.MSF_filt.check(db, sourcehandle):
return True
return True
return False

View File

@ -32,7 +32,7 @@ from gettext import gettext as _
# 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):
"""Rule that checks against another filter"""
"""Rule that checks against another filter."""
name = _('Families matching the <filter>')
description = _("Matches families matched by the specified filter name")

View File

@ -32,7 +32,7 @@ from gettext import gettext as _
# 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):
"""Rule that checks against another filter"""
"""Rule that checks against another filter."""
name = _('Media objects matching the <filter>')
description = _("Matches media objects matched by the "

View File

@ -32,7 +32,7 @@ from gettext import gettext as _
# 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):
"""Rule that checks against another filter"""
"""Rule that checks against another filter."""
name = _('Notes matching the <filter>')
description = _("Matches notes matched "

View File

@ -32,7 +32,7 @@ from gettext import gettext as _
# 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.
Subclasses need to define the namespace class attribute.
"""
labels = [_('Event filter name:')]
@ -52,6 +53,7 @@ class MatchesEventFilter(MatchesFilterBase):
description = _("Matches persons who have events that match a certain"
" event filter")
category = _('General filters')
# we want to have this filter show event filters
namespace = 'Event'
@ -67,5 +69,5 @@ class MatchesEventFilter(MatchesFilterBase):
for eventhandle in eventlist:
#check if event in event filter
if self.MEF_filt.check(db, eventhandle):
return True
return True
return False

View File

@ -32,7 +32,7 @@ from gettext import gettext as _
# 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):
"""Rule that checks against another filter"""
"""Rule that checks against another filter."""
name = _('People matching the <filter>')
description = _("Matches people matched by the specified filter name")

View File

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

View File

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

View File

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

View File

@ -32,7 +32,7 @@ from gettext import gettext as _
# 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):
"""Rule that checks for a person with a specific GRAMPS ID"""
"""Rule that checks for a person with a specific GRAMPS ID."""
labels = [ _('ID:') ]
name = _('Object with <Id>')
description = _("Matches objects with a specified GRAMPS ID")
category = _('General filters')
def apply(self,db,obj):
def apply(self, db, obj):
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 Filters.Rules._Rule import Rule
from Filters.Rules import Rule
#-------------------------------------------------------------------------
#
@ -41,7 +41,7 @@ from Filters.Rules._Rule import 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:')]
@ -49,7 +49,7 @@ class HasMarkerBase(Rule):
description = _("Matches markers of a partikular type")
category = _('General filters')
def apply(self,db,obj):
def apply(self, db, obj):
specified_type = MarkerType()
specified_type.set_from_xml_str(self.list[0])
return obj.get_marker() == specified_type

View File

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

View File

@ -32,20 +32,21 @@ from gettext import gettext as _
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Filters.Rules._Rule import Rule
from Filters.Rules import Rule
#-------------------------------------------------------------------------
# "People having notes that contain a substring"
#-------------------------------------------------------------------------
class HasNoteSubstrBase(Rule):
"""People having notes containing <subtring>"""
"""People having notes containing <substring>."""
labels = [ _('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')
def apply(self,db,person):
def apply(self, db, person):
notelist = person.get_note_list()
for notehandle in notelist:
note = db.get_note_from_handle(notehandle)

View File

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

View File

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

View File

@ -32,13 +32,13 @@ from gettext import gettext as _
# GRAMPS modules
#
#-------------------------------------------------------------------------
from _Rule import Rule
from Filters.Rules import Rule
#-------------------------------------------------------------------------
# "HasTextMatchingSubstringOf"
#-------------------------------------------------------------------------
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:'),
_('Case sensitive:'),

View File

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

View File

@ -33,7 +33,7 @@ from gettext import gettext as _
#
#-------------------------------------------------------------------------
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.
Subclasses need to define the namespace class attribute.
"""
labels = [_('Filter name:')]
@ -53,7 +54,7 @@ class MatchesFilterBase(Rule):
description = _("Matches objects matched by the specified filter name")
category = _('General filters')
def prepare(self,db):
def prepare(self, db):
if Filters.SystemFilters:
for filt in Filters.SystemFilters.get_filters(self.namespace):
if filt.get_name() == self.list[0]:
@ -77,7 +78,7 @@ class MatchesFilterBase(Rule):
for rule in filt.flist:
rule.reset()
def apply(self,db,obj):
def apply(self, db, obj):
if Filters.SystemFilters:
for filt in Filters.SystemFilters.get_filters(self.namespace):
if filt.get_name() == self.list[0]:
@ -89,8 +90,8 @@ class MatchesFilterBase(Rule):
return False
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:
for filt in Filters.SystemFilters.get_filters(self.namespace):

View File

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

View File

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

View File

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