* src/Config/_GrampsConfigKeys.py: key for gen search depth

* src/GrampsCfg.py: Gramps preferences allows to set search depth
			of relationship.
	* src/Relationship.py: methods to change generation depth of search
	* src/plugins/rel_fr.py: remove depth use
	* src/plugins/all_relations.py: use depth, correct remark print error
	* src/plugins/rel_pl.py: remove depth use
	* src/DisplayState.py: hook to change relclass depth from GrampsCfg
	See also issue #1290

2007-11-22 Benny Malengier <benny.malengier@gramps-project.org>


svn: r9385
This commit is contained in:
Benny Malengier 2007-11-22 16:13:10 +00:00
parent 0dca36536d
commit 28de76d2c0
8 changed files with 97 additions and 24 deletions

View File

@ -1,3 +1,14 @@
2007-11-22 Benny Malengier <benny.malengier@gramps-project.org>
* src/Config/_GrampsConfigKeys.py: key for gen search depth
* src/GrampsCfg.py: Gramps preferences allows to set search depth
of relationship.
* src/Relationship.py: methods to change generation depth of search
* src/plugins/rel_fr.py: remove depth use
* src/plugins/all_relations.py: use depth, correct remark print error
* src/plugins/rel_pl.py: remove depth use
* src/DisplayState.py: hook to change relclass depth from GrampsCfg
See also issue #1290
2007-11-22 Benny Malengier <benny.malengier@gramps-project.org> 2007-11-22 Benny Malengier <benny.malengier@gramps-project.org>
* src/Relationship.py: remove old methods that are no longer used, * src/Relationship.py: remove old methods that are no longer used,
get_relationship() and get_relationship_distance() get_relationship() and get_relationship_distance()

View File

@ -159,6 +159,7 @@ MAX_AGE_PROB_ALIVE = ('behavior', 'max-age-prob-alive', 1)
MAX_SIB_AGE_DIFF = ('behavior', 'max-sib-age-diff', 1) MAX_SIB_AGE_DIFF = ('behavior', 'max-sib-age-diff', 1)
MIN_GENERATION_YEARS = ('behavior', 'min-generation-years', 1) MIN_GENERATION_YEARS = ('behavior', 'min-generation-years', 1)
AVG_GENERATION_GAP = ('behavior', 'avg-generation-gap', 1) AVG_GENERATION_GAP = ('behavior', 'avg-generation-gap', 1)
GENERATION_DEPTH = ('behavior', 'generation-depth', 1)
default_value = { default_value = {
DEFAULT_SOURCE : False, DEFAULT_SOURCE : False,
@ -274,4 +275,5 @@ default_value = {
MAX_SIB_AGE_DIFF : 20, MAX_SIB_AGE_DIFF : 20,
MIN_GENERATION_YEARS : 13, MIN_GENERATION_YEARS : 13,
AVG_GENERATION_GAP : 20, AVG_GENERATION_GAP : 20,
GENERATION_DEPTH : 15,
} }

View File

@ -343,6 +343,14 @@ class DisplayState(gen.utils.GrampsDBCallback):
""" """
self.relationship = _PluginMgr.relationship_class() self.relationship = _PluginMgr.relationship_class()
def set_gendepth(self, value):
""" Set the generations we search back for showing relationships
on GRAMPS interface. Value must be integer > 0
This method will be used by the preference editor when user changes
the generations.
"""
self.relationship.set_depth(value)
def display_relationship(self, dbstate): def display_relationship(self, dbstate):
''' Construct the relationship in order to show it in the statusbar ''' Construct the relationship in order to show it in the statusbar
This can be a time intensive calculation, so we only want to do This can be a time intensive calculation, so we only want to do

View File

@ -519,6 +519,9 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
4, Config.RELEDITBTN) 4, Config.RELEDITBTN)
self.add_checkbox(table, _('Remember last view displayed'), self.add_checkbox(table, _('Remember last view displayed'),
5, Config.USE_LAST_VIEW) 5, Config.USE_LAST_VIEW)
self.add_pos_int_entry(table,
_('Number of generations for relationship determination'),
6, Config.GENERATION_DEPTH, self.update_gen_depth)
return table return table
@ -552,6 +555,18 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
xoptions=gtk.FILL) xoptions=gtk.FILL)
table.attach(entry, 1, 2, index, index+1, yoptions=0) table.attach(entry, 1, 2, index, index+1, yoptions=0)
def add_pos_int_entry(self, table, label, index, constant, callback=None):
''' entry field for positive integers
'''
lwidget = BasicLabel("%s: " % label)
entry = gtk.Entry()
entry.set_text(str(Config.get(constant)))
if callback:
entry.connect('changed', callback, constant)
table.attach(lwidget, 1, 2, index, index+1, yoptions=0,
xoptions=gtk.FILL)
table.attach(entry, 2, 3, index, index+1, yoptions=0)
def add_color(self, table, label, index, constant): def add_color(self, table, label, index, constant):
lwidget = BasicLabel("%s: " % label) lwidget = BasicLabel("%s: " % label)
hexval = Config.get(constant) hexval = Config.get(constant)
@ -568,6 +583,25 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
def update_entry(self, obj, constant): def update_entry(self, obj, constant):
Config.set(constant, unicode(obj.get_text())) Config.set(constant, unicode(obj.get_text()))
def update_gen_depth(self, obj, constant):
ok = True
if not obj.get_text():
return
try:
intval = int(obj.get_text())
except:
intval = Config.get(constant)
ok = False
if intval < 0 :
intval = Config.get(constant)
ok = False
if ok:
Config.set(constant, intval)
#immediately use this value in displaystate.
self.uistate.set_gendepth(intval)
else:
obj.set_text(str(intval))
def update_color(self, obj, constant, color_hex_label): def update_color(self, obj, constant, color_hex_label):
color = obj.get_color() color = obj.get_color()
hexval = "#%02x%02x%02x" % (color.red/256, hexval = "#%02x%02x%02x" % (color.red/256,

View File

@ -30,6 +30,7 @@ import gen.lib
import types import types
from TransUtils import sgettext as _ from TransUtils import sgettext as _
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #
@ -339,7 +340,6 @@ _nephews_nieces_level = [ "",
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
MAX_DEPTH = 15
class RelationshipCalculator: class RelationshipCalculator:
@ -386,6 +386,26 @@ class RelationshipCalculator:
self.map_handle = None self.map_handle = None
self.map_meta = None self.map_meta = None
self.__db_connected = False self.__db_connected = False
self.depth = 15
try:
import Config
self.set_depth(Config.get(Config.GENERATION_DEPTH))
except ImportError:
pass
def set_depth(self, depth):
''' set how deep relationships must be searched. Input must be an
integer > 0
'''
if not depth == self.depth:
self.depth = depth
self.dirtymap = True
def get_depth(self):
''' obtain depth of relationship search
'''
return self.depth
DIST_FATHER = "distant %(step)sancestor%(inlaw)s (%(level)d generations)" DIST_FATHER = "distant %(step)sancestor%(inlaw)s (%(level)d generations)"
@ -628,8 +648,7 @@ class RelationshipCalculator:
other_person, other_person,
all_families=False, all_families=False,
all_dist=False, all_dist=False,
only_birth=True, only_birth=True):
max_depth = MAX_DEPTH):
""" """
Returns if all_dist == True a 'tuple, string': Returns if all_dist == True a 'tuple, string':
(rank, person handle, firstRel_str, firstRel_fam, (rank, person handle, firstRel_str, firstRel_fam,
@ -680,13 +699,11 @@ class RelationshipCalculator:
@param only_birth: if True only parents with birth relation are @param only_birth: if True only parents with birth relation are
considered considered
@type only_birth: bool @type only_birth: bool
@param max_depth: how many generations deep do we search?
@type max_depth: int
""" """
#data storage to communicate with recursive functions #data storage to communicate with recursive functions
self.__maxDepthReached = False self.__maxDepthReached = False
self.__loopDetected = False self.__loopDetected = False
self.__max_depth = max_depth self.__max_depth = self.get_depth()
self.__all_families = all_families self.__all_families = all_families
self.__all_dist = all_dist self.__all_dist = all_dist
self.__only_birth = only_birth self.__only_birth = only_birth
@ -711,16 +728,17 @@ class RelationshipCalculator:
and not self.dirtymap): and not self.dirtymap):
firstMap = self.stored_map firstMap = self.stored_map
self.__maxDepthReached, self.__loopDetected, \ self.__maxDepthReached, self.__loopDetected, \
self.__max_depth, self.__all_families,\ self.__all_families,\
self.__all_dist, self.__only_birth,\ self.__all_dist, self.__only_birth,\
self.__crosslinks, self.__msg = self.map_meta self.__crosslinks, self.__msg = self.map_meta
self.__msg = list(self.__msg)
else: else:
self.__apply_filter(db, orig_person, '', [], firstMap) self.__apply_filter(db, orig_person, '', [], firstMap)
self.map_meta = (self.__maxDepthReached, self.map_meta = (self.__maxDepthReached,
self.__loopDetected, self.__loopDetected,
self.__max_depth, self.__all_families, self.__all_families,
self.__all_dist, self.__only_birth, self.__all_dist, self.__only_birth,
self.__crosslinks, self.__msg) self.__crosslinks, list(self.__msg))
self.__apply_filter(db, other_person, '', [], secondMap, self.__apply_filter(db, other_person, '', [], secondMap,
stoprecursemap = firstMap) stoprecursemap = firstMap)
except RuntimeError: except RuntimeError:
@ -784,7 +802,7 @@ class RelationshipCalculator:
if self.__maxDepthReached : if self.__maxDepthReached :
self.__msg += [_('Family tree reaches back more than the maximum ' self.__msg += [_('Family tree reaches back more than the maximum '
'%d generations searched.\nIt is possible that ' '%d generations searched.\nIt is possible that '
'relationships have been missed') % (max_depth)] 'relationships have been missed') % (self.__max_depth)]
if common and not self.__all_dist : if common and not self.__all_dist :
rank = common[0][0] rank = common[0][0]
@ -823,9 +841,9 @@ class RelationshipCalculator:
if depth > self.__max_depth: if depth > self.__max_depth:
self.__maxDepthReached = True self.__maxDepthReached = True
print 'Maximum ancestor generations ('+str(depth)+') reached', \ #print 'Maximum ancestor generations ('+str(depth)+') reached', \
'(' + rel_str + ').',\ # '(' + rel_str + ').',\
'Stopping relation algorithm.' # 'Stopping relation algorithm.'
return return
depth += 1 depth += 1

View File

@ -95,8 +95,7 @@ class AllRelReport():
self.database, self.person, self.home_person, self.database, self.person, self.home_person,
all_families=True, all_families=True,
all_dist=True, all_dist=True,
only_birth=False, only_birth=False)
max_depth=20)
#all relations #all relations
if (not common or common[0][0]== -1 ) and not is_spouse: if (not common or common[0][0]== -1 ) and not is_spouse:
rstr = _("%(person)s and %(active_person)s are not " rstr = _("%(person)s and %(active_person)s are not "
@ -143,10 +142,9 @@ class AllRelReport():
self.database, inlawpers, inlawhome, self.database, inlawpers, inlawhome,
all_families=True, all_families=True,
all_dist=True, all_dist=True,
only_birth=False, only_birth=False)
max_depth=20)
if msg: if msg:
self.msg_list.append(msg) self.msg_list += msg
if common and not common[0][0] == -1: if common and not common[0][0] == -1:
if not inlawwritten: if not inlawwritten:
rstr = _("%(person)s and %(active_person)s have " rstr = _("%(person)s and %(active_person)s have "
@ -180,7 +178,7 @@ class AllRelReport():
inlawa = inlawa, inlawb = inlawb, inlawa = inlawa, inlawb = inlawb,
count = count, skip_list = skip, count = count, skip_list = skip,
first = False) first = False)
self.remarks(self.msg_list) self.remarks(self.msg_list, True)
def get_inlaws(self, person): def get_inlaws(self, person):
inlaws = [] inlaws = []
@ -324,13 +322,17 @@ class AllRelReport():
count += 1 count += 1
return count return count
def remarks(self, msg_list): def remarks(self, msg_list, inlaw=False):
if msg_list : if msg_list :
sdoc = self.sdoc sdoc = self.sdoc
sdoc.paragraph("") sdoc.paragraph("")
if inlaw:
sdoc.header1(_("Remarks with inlaw family"))
else:
sdoc.header1(_("Remarks")) sdoc.header1(_("Remarks"))
sdoc.paragraph("") sdoc.paragraph("")
sdoc.paragraph(_("The following problems where encountered:")) sdoc.paragraph(_("The following problems where encountered:"))
for msg in msg_list : for msg in msg_list :
sdoc.paragraph(msg) sdoc.paragraph(msg)
sdoc.paragraph("") sdoc.paragraph("")

View File

@ -125,8 +125,6 @@ _nephews_nieces_level = [ "", "les neveux et les nièces",
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
MAX_DEPTH = 15
class RelationshipCalculator(Relationship.RelationshipCalculator): class RelationshipCalculator(Relationship.RelationshipCalculator):
#sibling strings #sibling strings

View File

@ -494,7 +494,7 @@ class RelationshipCalculator(Relationship.RelationshipCalculator):
""" DEPRECATED -- DO NOT USE """ DEPRECATED -- DO NOT USE
copied here from Relationship.py as no longer needed elsewhere copied here from Relationship.py as no longer needed elsewhere
""" """
if person == None or depth > MAX_DEPTH: if person == None or depth > 15:
return return
depth += 1 depth += 1
plist.append(person.handle) plist.append(person.handle)