* src/DataViews/_PedigreeView.py: Cache result of probably_alive(); Call find_tree() only once for all sizes; Cache results in FormattingHelper;
svn: r7929
This commit is contained in:
parent
28af33d307
commit
e62527c42a
@ -1,3 +1,7 @@
|
|||||||
|
2007-01-17 Martin Hawlisch <Martin.Hawlisch@gmx.de>
|
||||||
|
* src/DataViews/_PedigreeView.py: Cache result of probably_alive(); Call
|
||||||
|
find_tree() only once for all sizes; Cache results in FormattingHelper;
|
||||||
|
|
||||||
2007-01-17 Don Allingham <don@gramps-project.org>
|
2007-01-17 Don Allingham <don@gramps-project.org>
|
||||||
* src/DataViews/_PersonView.py: optimizations
|
* src/DataViews/_PersonView.py: optimizations
|
||||||
* src/ViewManager.py: optimizations
|
* src/ViewManager.py: optimizations
|
||||||
|
@ -121,7 +121,7 @@ class _PersonWidget_base:
|
|||||||
|
|
||||||
|
|
||||||
class PersonBoxWidget_cairo( gtk.DrawingArea, _PersonWidget_base):
|
class PersonBoxWidget_cairo( gtk.DrawingArea, _PersonWidget_base):
|
||||||
def __init__(self,fh,person,maxlines,image=None):
|
def __init__(self,fh,person,alive,maxlines,image=None):
|
||||||
gtk.DrawingArea.__init__(self)
|
gtk.DrawingArea.__init__(self)
|
||||||
_PersonWidget_base.__init__(self,fh,person)
|
_PersonWidget_base.__init__(self,fh,person)
|
||||||
self.add_events(gtk.gdk.BUTTON_PRESS_MASK) # Required for popup menu
|
self.add_events(gtk.gdk.BUTTON_PRESS_MASK) # Required for popup menu
|
||||||
@ -134,7 +134,6 @@ class PersonBoxWidget_cairo( gtk.DrawingArea, _PersonWidget_base):
|
|||||||
self.text = ""
|
self.text = ""
|
||||||
if self.person:
|
if self.person:
|
||||||
self.text = self.fh.format_person(self.person,self.maxlines,True)
|
self.text = self.fh.format_person(self.person,self.maxlines,True)
|
||||||
alive = Utils.probably_alive(self.person,self.fh.dbstate.db)
|
|
||||||
if alive and self.person.get_gender() == RelLib.Person.MALE:
|
if alive and self.person.get_gender() == RelLib.Person.MALE:
|
||||||
self.bgcolor = (185/256.0, 207/256.0, 231/256.0)
|
self.bgcolor = (185/256.0, 207/256.0, 231/256.0)
|
||||||
self.bordercolor = (32/256.0, 74/256.0, 135/256.0)
|
self.bordercolor = (32/256.0, 74/256.0, 135/256.0)
|
||||||
@ -258,13 +257,14 @@ class PersonBoxWidget_cairo( gtk.DrawingArea, _PersonWidget_base):
|
|||||||
|
|
||||||
|
|
||||||
class PersonBoxWidget( gtk.DrawingArea, _PersonWidget_base):
|
class PersonBoxWidget( gtk.DrawingArea, _PersonWidget_base):
|
||||||
def __init__(self,fh,person,maxlines,image=None):
|
def __init__(self,fh,person,alive,maxlines,image=None):
|
||||||
gtk.DrawingArea.__init__(self)
|
gtk.DrawingArea.__init__(self)
|
||||||
_PersonWidget_base.__init__(self,fh,person)
|
_PersonWidget_base.__init__(self,fh,person)
|
||||||
self.add_events(gtk.gdk.BUTTON_PRESS_MASK) # Required for popup menu
|
self.add_events(gtk.gdk.BUTTON_PRESS_MASK) # Required for popup menu
|
||||||
self.add_events(gtk.gdk.ENTER_NOTIFY_MASK) # Required for tooltip and mouse-over
|
self.add_events(gtk.gdk.ENTER_NOTIFY_MASK) # Required for tooltip and mouse-over
|
||||||
self.add_events(gtk.gdk.LEAVE_NOTIFY_MASK) # Required for tooltip and mouse-over
|
self.add_events(gtk.gdk.LEAVE_NOTIFY_MASK) # Required for tooltip and mouse-over
|
||||||
self.maxlines = maxlines
|
self.maxlines = maxlines
|
||||||
|
self.alive = alive;
|
||||||
try:
|
try:
|
||||||
self.image = gtk.gdk.pixbuf_new_from_file( image)
|
self.image = gtk.gdk.pixbuf_new_from_file( image)
|
||||||
except:
|
except:
|
||||||
@ -304,20 +304,19 @@ class PersonBoxWidget( gtk.DrawingArea, _PersonWidget_base):
|
|||||||
self.shadow_gc.line_style = gtk.gdk.LINE_SOLID
|
self.shadow_gc.line_style = gtk.gdk.LINE_SOLID
|
||||||
self.shadow_gc.line_width = 4
|
self.shadow_gc.line_width = 4
|
||||||
if self.person:
|
if self.person:
|
||||||
alive = Utils.probably_alive(self.person,self.fh.dbstate.db)
|
if self.alive and self.person.get_gender() == RelLib.Person.MALE:
|
||||||
if alive and self.person.get_gender() == RelLib.Person.MALE:
|
|
||||||
self.bg_gc.set_foreground( self.get_colormap().alloc_color("#b9cfe7"))
|
self.bg_gc.set_foreground( self.get_colormap().alloc_color("#b9cfe7"))
|
||||||
self.border_gc.set_foreground( self.get_colormap().alloc_color("#204a87"))
|
self.border_gc.set_foreground( self.get_colormap().alloc_color("#204a87"))
|
||||||
elif self.person.get_gender() == RelLib.Person.MALE:
|
elif self.person.get_gender() == RelLib.Person.MALE:
|
||||||
self.bg_gc.set_foreground( self.get_colormap().alloc_color("#b9cfe7"))
|
self.bg_gc.set_foreground( self.get_colormap().alloc_color("#b9cfe7"))
|
||||||
self.border_gc.set_foreground( self.get_colormap().alloc_color("#000000"))
|
self.border_gc.set_foreground( self.get_colormap().alloc_color("#000000"))
|
||||||
elif alive and self.person.get_gender() == RelLib.Person.FEMALE:
|
elif self.alive and self.person.get_gender() == RelLib.Person.FEMALE:
|
||||||
self.bg_gc.set_foreground( self.get_colormap().alloc_color("#ffcdf1"))
|
self.bg_gc.set_foreground( self.get_colormap().alloc_color("#ffcdf1"))
|
||||||
self.border_gc.set_foreground( self.get_colormap().alloc_color("#87206a"))
|
self.border_gc.set_foreground( self.get_colormap().alloc_color("#87206a"))
|
||||||
elif self.person.get_gender() == RelLib.Person.FEMALE:
|
elif self.person.get_gender() == RelLib.Person.FEMALE:
|
||||||
self.bg_gc.set_foreground( self.get_colormap().alloc_color("#ffcdf1"))
|
self.bg_gc.set_foreground( self.get_colormap().alloc_color("#ffcdf1"))
|
||||||
self.border_gc.set_foreground( self.get_colormap().alloc_color("#000000"))
|
self.border_gc.set_foreground( self.get_colormap().alloc_color("#000000"))
|
||||||
elif alive:
|
elif self.alive:
|
||||||
self.bg_gc.set_foreground( self.get_colormap().alloc_color("#f4dcb7"))
|
self.bg_gc.set_foreground( self.get_colormap().alloc_color("#f4dcb7"))
|
||||||
self.border_gc.set_foreground( self.get_colormap().alloc_color("#8f5902"))
|
self.border_gc.set_foreground( self.get_colormap().alloc_color("#8f5902"))
|
||||||
else:
|
else:
|
||||||
@ -351,6 +350,8 @@ class PersonBoxWidget( gtk.DrawingArea, _PersonWidget_base):
|
|||||||
class FormattingHelper:
|
class FormattingHelper:
|
||||||
def __init__(self,dbstate):
|
def __init__(self,dbstate):
|
||||||
self.dbstate = dbstate
|
self.dbstate = dbstate
|
||||||
|
self._text_cache = {}
|
||||||
|
self._markup_cache = {}
|
||||||
|
|
||||||
def format_relation( self, family, line_count):
|
def format_relation( self, family, line_count):
|
||||||
text = ""
|
text = ""
|
||||||
@ -388,43 +389,61 @@ class FormattingHelper:
|
|||||||
if not person:
|
if not person:
|
||||||
return ""
|
return ""
|
||||||
if use_markup:
|
if use_markup:
|
||||||
|
if person.handle in self._markup_cache:
|
||||||
|
if line_count in self._markup_cache[person.handle]:
|
||||||
|
return self._markup_cache[person.handle][line_count]
|
||||||
name = escape(NameDisplay.displayer.display(person))
|
name = escape(NameDisplay.displayer.display(person))
|
||||||
else:
|
else:
|
||||||
|
if person.handle in self._text_cache:
|
||||||
|
if line_count in self._text_cache[person.handle]:
|
||||||
|
return self._text_cache[person.handle][line_count]
|
||||||
name = NameDisplay.displayer.display(person)
|
name = NameDisplay.displayer.display(person)
|
||||||
if line_count < 3:
|
text = name
|
||||||
return name
|
if line_count >= 3:
|
||||||
|
birth = ReportUtils.get_birth_or_fallback(self.dbstate.db, person)
|
||||||
birth = ReportUtils.get_birth_or_fallback(self.dbstate.db, person)
|
if birth and use_markup and birth.get_type() != RelLib.EventType.BIRTH:
|
||||||
if birth and use_markup and birth.get_type() != RelLib.EventType.BIRTH:
|
bdate = "<i>%s</i>" % escape(DateHandler.get_date(birth))
|
||||||
bdate = "<i>%s</i>" % escape(DateHandler.get_date(birth))
|
bplace = "<i>%s</i>" % escape(self.get_place_name(birth.get_place_handle()))
|
||||||
bplace = "<i>%s</i>" % escape(self.get_place_name(birth.get_place_handle()))
|
elif birth and use_markup:
|
||||||
elif birth and use_markup:
|
bdate = escape(DateHandler.get_date(birth))
|
||||||
bdate = escape(DateHandler.get_date(birth))
|
bplace = escape(self.get_place_name(birth.get_place_handle()))
|
||||||
bplace = escape(self.get_place_name(birth.get_place_handle()))
|
elif birth:
|
||||||
elif birth:
|
bdate = DateHandler.get_date(birth)
|
||||||
bdate = DateHandler.get_date(birth)
|
bplace = self.get_place_name(birth.get_place_handle())
|
||||||
bplace = self.get_place_name(birth.get_place_handle())
|
else:
|
||||||
|
bdate = ""
|
||||||
|
bplace = ""
|
||||||
|
death = ReportUtils.get_death_or_fallback(self.dbstate.db, person)
|
||||||
|
if death and use_markup and death.get_type() != RelLib.EventType.DEATH:
|
||||||
|
ddate = "<i>%s</i>" % escape(DateHandler.get_date(death))
|
||||||
|
dplace = "<i>%s</i>" % escape(self.get_place_name(death.get_place_handle()))
|
||||||
|
elif death and use_markup:
|
||||||
|
ddate = escape(DateHandler.get_date(death))
|
||||||
|
dplace = escape(self.get_place_name(death.get_place_handle()))
|
||||||
|
elif death:
|
||||||
|
ddate = DateHandler.get_date(death)
|
||||||
|
dplace = self.get_place_name(death.get_place_handle())
|
||||||
|
else:
|
||||||
|
ddate = ""
|
||||||
|
dplace = ""
|
||||||
|
|
||||||
|
if line_count < 5:
|
||||||
|
text = "%s\n* %s\n+ %s" % (name,bdate,ddate)
|
||||||
|
else:
|
||||||
|
text = "%s\n* %s\n %s\n+ %s\n %s" % (name,bdate,bplace,ddate,dplace)
|
||||||
|
if use_markup:
|
||||||
|
if not person.handle in self._markup_cache:
|
||||||
|
self._markup_cache[person.handle] = {}
|
||||||
|
self._markup_cache[person.handle][line_count] = text
|
||||||
else:
|
else:
|
||||||
bdate = ""
|
if not person.handle in self._text_cache:
|
||||||
bplace = ""
|
self._text_cache[person.handle] = {}
|
||||||
death = ReportUtils.get_death_or_fallback(self.dbstate.db, person)
|
self._text_cache[person.handle][line_count] = text
|
||||||
if death and use_markup and death.get_type() != RelLib.EventType.DEATH:
|
return text
|
||||||
ddate = "<i>%s</i>" % escape(DateHandler.get_date(death))
|
|
||||||
dplace = "<i>%s</i>" % escape(self.get_place_name(death.get_place_handle()))
|
def clear_cache( self):
|
||||||
elif death and use_markup:
|
self._text_cache = {}
|
||||||
ddate = escape(DateHandler.get_date(death))
|
self._markup_cache = {}
|
||||||
dplace = escape(self.get_place_name(death.get_place_handle()))
|
|
||||||
elif death:
|
|
||||||
ddate = DateHandler.get_date(death)
|
|
||||||
dplace = self.get_place_name(death.get_place_handle())
|
|
||||||
else:
|
|
||||||
ddate = ""
|
|
||||||
dplace = ""
|
|
||||||
|
|
||||||
if line_count < 5:
|
|
||||||
return "%s\n* %s\n+ %s" % (name,bdate,ddate)
|
|
||||||
else:
|
|
||||||
return "%s\n* %s\n %s\n+ %s\n %s" % (name,bdate,bplace,ddate,dplace)
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -612,6 +631,7 @@ class PedigreeView(PageView.PersonNavView):
|
|||||||
self.uistate.modify_statusbar(self.dbstate)
|
self.uistate.modify_statusbar(self.dbstate)
|
||||||
|
|
||||||
def person_rebuild(self,dummy=None):
|
def person_rebuild(self,dummy=None):
|
||||||
|
self.format_helper.clear_cache()
|
||||||
self.dirty = True
|
self.dirty = True
|
||||||
if self.dbstate.active:
|
if self.dbstate.active:
|
||||||
self.rebuild_trees(self.dbstate.active.handle)
|
self.rebuild_trees(self.dbstate.active.handle)
|
||||||
@ -760,15 +780,17 @@ class PedigreeView(PageView.PersonNavView):
|
|||||||
((8,26,1,1),None,None),
|
((8,26,1,1),None,None),
|
||||||
((8,28,1,1),None,None),
|
((8,28,1,1),None,None),
|
||||||
((8,30,1,1),None,None))
|
((8,30,1,1),None,None))
|
||||||
self.rebuild( self.table_2, pos_2, person)
|
|
||||||
self.rebuild( self.table_3, pos_3, person)
|
# Build ancestor tree only one for all different sizes
|
||||||
self.rebuild( self.table_4, pos_4, person)
|
|
||||||
self.rebuild( self.table_5, pos_5, person)
|
|
||||||
|
|
||||||
def rebuild( self, table_widget, positions, active_person):
|
|
||||||
# Build ancestor tree
|
|
||||||
lst = [None]*31
|
lst = [None]*31
|
||||||
self.find_tree(active_person,0,1,lst)
|
self.find_tree(person,0,1,lst)
|
||||||
|
|
||||||
|
self.rebuild( self.table_2, pos_2, person, lst)
|
||||||
|
self.rebuild( self.table_3, pos_3, person, lst)
|
||||||
|
self.rebuild( self.table_4, pos_4, person, lst)
|
||||||
|
self.rebuild( self.table_5, pos_5, person, lst)
|
||||||
|
|
||||||
|
def rebuild( self, table_widget, positions, active_person, lst):
|
||||||
|
|
||||||
# Purge current table content
|
# Purge current table content
|
||||||
for child in table_widget.get_children():
|
for child in table_widget.get_children():
|
||||||
@ -789,9 +811,9 @@ class PedigreeView(PageView.PersonNavView):
|
|||||||
if not lst[i]:
|
if not lst[i]:
|
||||||
# No person -> show empty box
|
# No person -> show empty box
|
||||||
if cairo_available:
|
if cairo_available:
|
||||||
pw = PersonBoxWidget_cairo( self.format_helper, None, 0, None);
|
pw = PersonBoxWidget_cairo( self.format_helper, None, False, 0, None);
|
||||||
else:
|
else:
|
||||||
pw = PersonBoxWidget( self.format_helper, None, 0, None);
|
pw = PersonBoxWidget( self.format_helper, None, False, 0, None);
|
||||||
if i > 0 and lst[((i+1)/2)-1]:
|
if i > 0 and lst[((i+1)/2)-1]:
|
||||||
fam_h = None
|
fam_h = None
|
||||||
fam = lst[((i+1)/2)-1][2]
|
fam = lst[((i+1)/2)-1][2]
|
||||||
@ -822,9 +844,9 @@ class PedigreeView(PageView.PersonNavView):
|
|||||||
if mtype[0:5] == "image":
|
if mtype[0:5] == "image":
|
||||||
image = ImgManip.get_thumbnail_path(obj.get_path())
|
image = ImgManip.get_thumbnail_path(obj.get_path())
|
||||||
if cairo_available:
|
if cairo_available:
|
||||||
pw = PersonBoxWidget_cairo( self.format_helper, lst[i][0], positions[i][0][3], image);
|
pw = PersonBoxWidget_cairo( self.format_helper, lst[i][0], lst[i][3], positions[i][0][3], image);
|
||||||
else:
|
else:
|
||||||
pw = PersonBoxWidget( self.format_helper, lst[i][0], positions[i][0][3], image);
|
pw = PersonBoxWidget( self.format_helper, lst[i][0], lst[i][3], positions[i][0][3], image);
|
||||||
if positions[i][0][3] < 7:
|
if positions[i][0][3] < 7:
|
||||||
self.tooltips.set_tip(pw, self.format_helper.format_person(lst[i][0], 11))
|
self.tooltips.set_tip(pw, self.format_helper.format_person(lst[i][0], 11))
|
||||||
|
|
||||||
@ -1212,7 +1234,10 @@ class PedigreeView(PageView.PersonNavView):
|
|||||||
|
|
||||||
if depth > 5 or person == None:
|
if depth > 5 or person == None:
|
||||||
return
|
return
|
||||||
lst[index] = (person,val,None)
|
|
||||||
|
alive = Utils.probably_alive(person, self.dbstate.db)
|
||||||
|
|
||||||
|
lst[index] = (person,val,None,alive)
|
||||||
|
|
||||||
parent_families = person.get_parent_family_handle_list()
|
parent_families = person.get_parent_family_handle_list()
|
||||||
if parent_families:
|
if parent_families:
|
||||||
@ -1229,7 +1254,7 @@ class PedigreeView(PageView.PersonNavView):
|
|||||||
mrel = child_ref.mrel == RelLib.ChildRefType.BIRTH
|
mrel = child_ref.mrel == RelLib.ChildRefType.BIRTH
|
||||||
frel = child_ref.frel == RelLib.ChildRefType.BIRTH
|
frel = child_ref.frel == RelLib.ChildRefType.BIRTH
|
||||||
|
|
||||||
lst[index] = (person,val,family)
|
lst[index] = (person,val,family,alive)
|
||||||
father_handle = family.get_father_handle()
|
father_handle = family.get_father_handle()
|
||||||
if father_handle != None:
|
if father_handle != None:
|
||||||
father = self.dbstate.db.get_person_from_handle(father_handle)
|
father = self.dbstate.db.get_person_from_handle(father_handle)
|
||||||
|
Loading…
Reference in New Issue
Block a user