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:
parent
993013774f
commit
67cb93a28c
@ -247,6 +247,14 @@ class EventType(GrampsType):
|
|||||||
"""
|
"""
|
||||||
return self.value == self.MARRIAGE
|
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):
|
def is_divorce(self):
|
||||||
"""
|
"""
|
||||||
Returns True if EventType is DIVORCE, False otherwise.
|
Returns True if EventType is DIVORCE, False otherwise.
|
||||||
|
@ -68,3 +68,53 @@ def get_death_or_fallback(db, person, format=None):
|
|||||||
return event
|
return event
|
||||||
return None
|
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
|
||||||
|
@ -48,8 +48,10 @@ import DateHandler
|
|||||||
from gen.display.name import displayer as name_displayer
|
from gen.display.name import displayer as name_displayer
|
||||||
import gen.lib
|
import gen.lib
|
||||||
from gen.lib import EventRoleType
|
from gen.lib import EventRoleType
|
||||||
|
|
||||||
from gui.views.treemodels.flatbasemodel import FlatBaseModel
|
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]))
|
return unicode(gen.lib.FamilyRelType(data[5]))
|
||||||
|
|
||||||
def column_marriage(self, data):
|
def column_marriage(self, data):
|
||||||
erlist = [gen.lib.EventRef().unserialize(item) for item in data[6]]
|
from gen.utils import get_marriage_or_fallback
|
||||||
erlist = [x for x in erlist if x.get_role()==EventRoleType.FAMILY or
|
family = self.db.get_family_from_handle(data[0])
|
||||||
x.get_role()==EventRoleType.PRIMARY]
|
event = get_marriage_or_fallback(self.db, family, "<i>%s</i>")
|
||||||
event = self.db.marriage_from_eventref_list(erlist)
|
|
||||||
if event:
|
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:
|
else:
|
||||||
return u''
|
return u''
|
||||||
|
|
||||||
def sort_marriage(self, data):
|
def sort_marriage(self, data):
|
||||||
erlist = [gen.lib.EventRef().unserialize(item) for item in data[6]]
|
from gen.utils import get_marriage_or_fallback
|
||||||
event = self.db.marriage_from_eventref_list(erlist)
|
family = self.db.get_family_from_handle(data[0])
|
||||||
|
event = get_marriage_or_fallback(self.db, family)
|
||||||
if event:
|
if event:
|
||||||
return "%09d" % event.date.get_sort_value()
|
return "%09d" % event.date.get_sort_value()
|
||||||
else:
|
else:
|
||||||
|
@ -40,7 +40,7 @@ from cgi import escape
|
|||||||
import gen.lib
|
import gen.lib
|
||||||
import DateHandler
|
import DateHandler
|
||||||
from gen.display.name import displayer as name_displayer
|
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._text_cache = {}
|
||||||
self._markup_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
|
""" 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 = ""
|
text = ""
|
||||||
for event_ref in family.get_event_ref_list():
|
marriage = get_marriage_or_fallback(self.dbstate.db, family)
|
||||||
event = self.dbstate.db.get_event_from_handle(event_ref.ref)
|
if marriage and use_markup and marriage.get_type() != gen.lib.EventType.MARRIAGE:
|
||||||
if event and event.get_type() == gen.lib.EventType.MARRIAGE and \
|
mdate = "<i>%s %s</i>" % (marriage.get_type().get_abbreviation(),
|
||||||
(event_ref.get_role() == gen.lib.EventRoleType.FAMILY or
|
escape(DateHandler.get_date(marriage)))
|
||||||
event_ref.get_role() == gen.lib.EventRoleType.PRIMARY ):
|
mplace = "<i>%s</i>" % escape(self.get_place_name(marriage.get_place_handle()))
|
||||||
if line_count < 3:
|
name = "<i>%s</i>" % str(marriage.get_type())
|
||||||
return DateHandler.get_date(event)
|
elif marriage and use_markup:
|
||||||
name = str(event.get_type())
|
mdate = "%s %s" % (marriage.get_type().get_abbreviation(),
|
||||||
text += name
|
escape(DateHandler.get_date(marriage)))
|
||||||
text += "\n"
|
mplace = escape(self.get_place_name(marriage.get_place_handle()))
|
||||||
text += DateHandler.get_date(event)
|
name = str(marriage.get_type())
|
||||||
text += "\n"
|
elif marriage:
|
||||||
text += self.get_place_name(event.get_place_handle())
|
mdate = "%s %s" % (marriage.get_type().get_abbreviation(),
|
||||||
if line_count < 5:
|
DateHandler.get_date(marriage))
|
||||||
return text
|
mplace = self.get_place_name(marriage.get_place_handle())
|
||||||
break
|
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:
|
if not text:
|
||||||
text = str(family.get_relationship())
|
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
|
return text
|
||||||
|
|
||||||
def get_place_name(self, place_handle):
|
def get_place_name(self, place_handle):
|
||||||
|
@ -73,6 +73,7 @@ class FamilyView(ListView):
|
|||||||
COL_TAGS = 5
|
COL_TAGS = 5
|
||||||
COL_CHAN = 6
|
COL_CHAN = 6
|
||||||
# name of the columns
|
# name of the columns
|
||||||
|
MARKUP_COLS = [COL_MARDATE]
|
||||||
COLUMN_NAMES = [
|
COLUMN_NAMES = [
|
||||||
_('ID'),
|
_('ID'),
|
||||||
_('Father'),
|
_('Father'),
|
||||||
@ -114,7 +115,8 @@ class FamilyView(ListView):
|
|||||||
signal_map, dbstate.db.get_family_bookmarks(),
|
signal_map, dbstate.db.get_family_bookmarks(),
|
||||||
Bookmarks.FamilyBookmarks, nav_group,
|
Bookmarks.FamilyBookmarks, nav_group,
|
||||||
multiple=True,
|
multiple=True,
|
||||||
filter_class=FamilySidebarFilter)
|
filter_class=FamilySidebarFilter,
|
||||||
|
markup=FamilyView.MARKUP_COLS)
|
||||||
|
|
||||||
self.func_list.update({
|
self.func_list.update({
|
||||||
'<CONTROL>J' : self.jump,
|
'<CONTROL>J' : self.jump,
|
||||||
|
@ -1218,11 +1218,12 @@ class PedigreeView(NavigationView):
|
|||||||
((self.tree_style == 1 and positions[i][2]) or
|
((self.tree_style == 1 and positions[i][2]) or
|
||||||
(self.tree_style in [0, 2] and (level+1) < size)):
|
(self.tree_style in [0, 2] and (level+1) < size)):
|
||||||
if lst[i] and lst[i][2]:
|
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:
|
else:
|
||||||
text = " "
|
text = " "
|
||||||
label = gtk.Label(text)
|
label = gtk.Label(text)
|
||||||
label.set_justify(gtk.JUSTIFY_LEFT)
|
label.set_justify(gtk.JUSTIFY_LEFT)
|
||||||
|
label.set_use_markup(True)
|
||||||
label.set_line_wrap(True)
|
label.set_line_wrap(True)
|
||||||
label.set_alignment(0.1, 0.5)
|
label.set_alignment(0.1, 0.5)
|
||||||
if self.tree_style in [0, 2]:
|
if self.tree_style in [0, 2]:
|
||||||
|
Loading…
Reference in New Issue
Block a user