3719: Pedigree View: should display engagement date if no marriage known; added markup dates to family view to show fallback dates, and invalid dates; pedigreeview shows abbrev. date with markup, and tooltip details

svn: r16250
This commit is contained in:
Doug Blank 2010-12-05 17:58:56 +00:00
parent 993013774f
commit 67cb93a28c
7 changed files with 133 additions and 29 deletions

View File

@ -247,6 +247,14 @@ class EventType(GrampsType):
"""
return self.value == self.MARRIAGE
def is_marriage_fallback(self):
"""
Returns True if EventType is a marriage fallback, False
otherwise.
"""
return self.value in [self.ENGAGEMENT,
self.MARR_ALT]
def is_divorce(self):
"""
Returns True if EventType is DIVORCE, False otherwise.

View File

@ -379,7 +379,7 @@ class Family(SourceBase, NoteBase, MediaBase, AttributeBase, LdsOrdBase,
father and mother in the relationship.
"""
return self.type
def set_father_handle(self, person_handle):
"""
Set the database handle for :class:`~gen.lib.person.Person` that corresponds to male of the

View File

@ -68,3 +68,53 @@ def get_death_or_fallback(db, person, format=None):
return event
return None
def get_marriage_ref(db, family):
"""
Return a reference to the primary MARRIAGE event of the family.
"""
from gen.lib import EventType, EventRoleType
for event_ref in family.get_event_ref_list():
event = db.get_event_from_handle(event_ref.ref)
if (event and event.get_type() == EventType.MARRIAGE and
(event_ref.get_role() == EventRoleType.FAMILY or
event_ref.get_role() == EventRoleType.PRIMARY)):
return event_ref
return None
def get_primary_event_ref_list(db, family):
"""
Return a reference to the primary events of the family.
"""
from gen.lib import EventRoleType
retval = []
for event_ref in family.get_event_ref_list():
event = db.get_event_from_handle(event_ref.ref)
if (event and
(event_ref.get_role() == EventRoleType.FAMILY or
event_ref.get_role() == EventRoleType.PRIMARY)):
retval.append(event_ref)
return retval
def get_marriage_or_fallback(db, family, format=None):
"""
Get a MARRIAGE event from a family, or fallback to an
event around the time of marriage.
"""
from gen.lib import EventRoleType
marriage_ref = get_marriage_ref(db, family)
if marriage_ref: # regular marriage found
event = db.get_event_from_handle(marriage_ref.ref)
if event:
return event
# now search the event list for fallbacks
for event_ref in get_primary_event_ref_list(db, family):
if event_ref:
event = db.get_event_from_handle(event_ref.ref)
if (event
and event.type.is_marriage_fallback()
and (event_ref.role == EventRoleType.FAMILY or
event_ref.role == EventRoleType.PRIMARY)):
if format:
event.date.format = format
return event
return None

View File

@ -48,8 +48,10 @@ import DateHandler
from gen.display.name import displayer as name_displayer
import gen.lib
from gen.lib import EventRoleType
from gui.views.treemodels.flatbasemodel import FlatBaseModel
import config
invalid_date_format = config.get('preferences.invalid-date-format')
#-------------------------------------------------------------------------
#
@ -144,18 +146,23 @@ class FamilyModel(FlatBaseModel):
return unicode(gen.lib.FamilyRelType(data[5]))
def column_marriage(self, data):
erlist = [gen.lib.EventRef().unserialize(item) for item in data[6]]
erlist = [x for x in erlist if x.get_role()==EventRoleType.FAMILY or
x.get_role()==EventRoleType.PRIMARY]
event = self.db.marriage_from_eventref_list(erlist)
from gen.utils import get_marriage_or_fallback
family = self.db.get_family_from_handle(data[0])
event = get_marriage_or_fallback(self.db, family, "<i>%s</i>")
if event:
return DateHandler.displayer.display(event.date)
if event.date.format:
return event.date.format % DateHandler.displayer.display(event.date)
elif not DateHandler.get_date_valid(event):
return invalid_date_format % DateHandler.displayer.display(event.date)
else:
return "%s" % DateHandler.displayer.display(event.date)
else:
return u''
def sort_marriage(self, data):
erlist = [gen.lib.EventRef().unserialize(item) for item in data[6]]
event = self.db.marriage_from_eventref_list(erlist)
from gen.utils import get_marriage_or_fallback
family = self.db.get_family_from_handle(data[0])
event = get_marriage_or_fallback(self.db, family)
if event:
return "%09d" % event.date.get_sort_value()
else:

View File

@ -40,7 +40,7 @@ from cgi import escape
import gen.lib
import DateHandler
from gen.display.name import displayer as name_displayer
from gen.utils import get_birth_or_fallback, get_death_or_fallback
from gen.utils import get_birth_or_fallback, get_death_or_fallback, get_marriage_or_fallback
#-------------------------------------------------------------------------
#
@ -56,28 +56,64 @@ class FormattingHelper(object):
self._text_cache = {}
self._markup_cache = {}
def format_relation(self, family, line_count):
def format_relation(self, family, line_count, use_markup=False):
""" Format a relation between parents of a family
"""
if not family:
return ""
if use_markup:
if family.handle in self._markup_cache:
if line_count in self._markup_cache[family.handle]:
return self._markup_cache[family.handle][line_count]
else:
if family.handle in self._text_cache:
if line_count in self._text_cache[family.handle]:
return self._text_cache[family.handle][line_count]
text = ""
for event_ref in family.get_event_ref_list():
event = self.dbstate.db.get_event_from_handle(event_ref.ref)
if event and event.get_type() == gen.lib.EventType.MARRIAGE and \
(event_ref.get_role() == gen.lib.EventRoleType.FAMILY or
event_ref.get_role() == gen.lib.EventRoleType.PRIMARY ):
if line_count < 3:
return DateHandler.get_date(event)
name = str(event.get_type())
text += name
text += "\n"
text += DateHandler.get_date(event)
text += "\n"
text += self.get_place_name(event.get_place_handle())
if line_count < 5:
return text
break
marriage = get_marriage_or_fallback(self.dbstate.db, family)
if marriage and use_markup and marriage.get_type() != gen.lib.EventType.MARRIAGE:
mdate = "<i>%s %s</i>" % (marriage.get_type().get_abbreviation(),
escape(DateHandler.get_date(marriage)))
mplace = "<i>%s</i>" % escape(self.get_place_name(marriage.get_place_handle()))
name = "<i>%s</i>" % str(marriage.get_type())
elif marriage and use_markup:
mdate = "%s %s" % (marriage.get_type().get_abbreviation(),
escape(DateHandler.get_date(marriage)))
mplace = escape(self.get_place_name(marriage.get_place_handle()))
name = str(marriage.get_type())
elif marriage:
mdate = "%s %s" % (marriage.get_type().get_abbreviation(),
DateHandler.get_date(marriage))
mplace = self.get_place_name(marriage.get_place_handle())
name = str(marriage.get_type())
else:
mdate = ""
mplace = ""
name = ""
if line_count >= 1:
text += mdate
text += "\n"
if line_count >= 2:
text += name
text += "\n"
if line_count >= 3:
text += mplace
text += "\n"
if not text:
text = str(family.get_relationship())
if use_markup:
if not family.handle in self._markup_cache:
self._markup_cache[family.handle] = {}
self._markup_cache[family.handle][line_count] = text
else:
if not family.handle in self._text_cache:
self._text_cache[family.handle] = {}
self._text_cache[family.handle][line_count] = text
return text
def get_place_name(self, place_handle):

View File

@ -73,6 +73,7 @@ class FamilyView(ListView):
COL_TAGS = 5
COL_CHAN = 6
# name of the columns
MARKUP_COLS = [COL_MARDATE]
COLUMN_NAMES = [
_('ID'),
_('Father'),
@ -114,7 +115,8 @@ class FamilyView(ListView):
signal_map, dbstate.db.get_family_bookmarks(),
Bookmarks.FamilyBookmarks, nav_group,
multiple=True,
filter_class=FamilySidebarFilter)
filter_class=FamilySidebarFilter,
markup=FamilyView.MARKUP_COLS)
self.func_list.update({
'<CONTROL>J' : self.jump,

View File

@ -1218,11 +1218,12 @@ class PedigreeView(NavigationView):
((self.tree_style == 1 and positions[i][2]) or
(self.tree_style in [0, 2] and (level+1) < size)):
if lst[i] and lst[i][2]:
text = self.format_helper.format_relation(lst[i][2], 1)
text = self.format_helper.format_relation(lst[i][2], 1, True)
else:
text = " "
label = gtk.Label(text)
label.set_justify(gtk.JUSTIFY_LEFT)
label.set_use_markup(True)
label.set_line_wrap(True)
label.set_alignment(0.1, 0.5)
if self.tree_style in [0, 2]: