* src/PedView.py: Fix anchors. Switch from storing person objects
to their IDs. Start on building Spouses and Siblings submenus in the context menu. svn: r3220
This commit is contained in:
parent
53ec8ad409
commit
445264275a
@ -1,5 +1,8 @@
|
|||||||
2004-06-21 Alex Roitman <shura@alex.neuro.umn.edu>
|
2004-06-21 Alex Roitman <shura@alex.neuro.umn.edu>
|
||||||
* src/data/gramps.keys, src/data/mime: Add package and GEDCOM.
|
* src/data/gramps.keys, src/data/mime: Add package and GEDCOM.
|
||||||
|
* src/PedView.py: Fix anchors. Switch from storing person objects
|
||||||
|
to their IDs. Start on building Spouses and Siblings submenus
|
||||||
|
in the context menu.
|
||||||
|
|
||||||
2004-06-20 Alex Roitman <shura@alex.neuro.umn.edu>
|
2004-06-20 Alex Roitman <shura@alex.neuro.umn.edu>
|
||||||
* configure.in: Bump up the version number.
|
* configure.in: Bump up the version number.
|
||||||
|
@ -37,6 +37,7 @@ import pango
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import GrampsCfg
|
import GrampsCfg
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
import Relationship
|
||||||
|
|
||||||
_PAD = 3
|
_PAD = 3
|
||||||
_CANVASPAD = 3
|
_CANVASPAD = 3
|
||||||
@ -44,7 +45,16 @@ _PERSON = "p"
|
|||||||
_BORN = _('b.')
|
_BORN = _('b.')
|
||||||
_DIED = _('d.')
|
_DIED = _('d.')
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# DispBox class
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
class DispBox:
|
class DispBox:
|
||||||
|
"""
|
||||||
|
This class handles the person box, including its expanded and
|
||||||
|
shrunk states, as well as the callbacks for events occurring in the box.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self,root,style,x,y,w,h,person,db,change,edit):
|
def __init__(self,root,style,x,y,w,h,person,db,change,edit):
|
||||||
shadow = _PAD
|
shadow = _PAD
|
||||||
@ -108,7 +118,7 @@ class DispBox:
|
|||||||
fill_color_gdk=style.text[gtk.STATE_NORMAL],
|
fill_color_gdk=style.text[gtk.STATE_NORMAL],
|
||||||
font=font, anchor=gtk.ANCHOR_WEST)
|
font=font, anchor=gtk.ANCHOR_WEST)
|
||||||
self.group.connect('event',self.group_event)
|
self.group.connect('event',self.group_event)
|
||||||
self.group.set_data(_PERSON,person)
|
self.group.set_data(_PERSON,person.get_id())
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
self.shadow.destroy()
|
self.shadow.destroy()
|
||||||
@ -277,7 +287,7 @@ class PedigreeView:
|
|||||||
|
|
||||||
gen_no = 1
|
gen_no = 1
|
||||||
if self.anchor:
|
if self.anchor:
|
||||||
gn = get_distance(self.anchor,self.active_person)
|
gn = get_distance(self.parent.db,self.anchor,self.active_person)
|
||||||
if gn == None:
|
if gn == None:
|
||||||
self.remove_anchor()
|
self.remove_anchor()
|
||||||
else:
|
else:
|
||||||
@ -384,7 +394,7 @@ class PedigreeView:
|
|||||||
label.set_alignment(0,0)
|
label.set_alignment(0,0)
|
||||||
menuitem.add(label)
|
menuitem.add(label)
|
||||||
myMenu.append(menuitem)
|
myMenu.append(menuitem)
|
||||||
menuitem.set_data(_PERSON,child)
|
menuitem.set_data(_PERSON,child_id)
|
||||||
menuitem.connect("activate",self.on_childmenu_changed)
|
menuitem.connect("activate",self.on_childmenu_changed)
|
||||||
menuitem.show()
|
menuitem.show()
|
||||||
myMenu.popup(None,None,None,0,0)
|
myMenu.popup(None,None,None,0,0)
|
||||||
@ -394,7 +404,8 @@ class PedigreeView:
|
|||||||
"""Callback for the pulldown menu selection, changing to the person
|
"""Callback for the pulldown menu selection, changing to the person
|
||||||
attached with menu item."""
|
attached with menu item."""
|
||||||
|
|
||||||
person = obj.get_data(_PERSON)
|
person_id = obj.get_data(_PERSON)
|
||||||
|
person = self.parent.db.try_to_find_person_from_id(person_id)
|
||||||
if person:
|
if person:
|
||||||
self.load_canvas(person)
|
self.load_canvas(person)
|
||||||
return 1
|
return 1
|
||||||
@ -405,7 +416,7 @@ class PedigreeView:
|
|||||||
to the button."""
|
to the button."""
|
||||||
|
|
||||||
button,arrow = self.make_arrow_button(gtk.ARROW_RIGHT,self.change_to_parent)
|
button,arrow = self.make_arrow_button(gtk.ARROW_RIGHT,self.change_to_parent)
|
||||||
button.set_data(_PERSON,parent)
|
button.set_data(_PERSON,parent.get_id())
|
||||||
|
|
||||||
item = self.root.add(gnome.canvas.CanvasWidget, widget=button, x=x, y=y+(h/2),
|
item = self.root.add(gnome.canvas.CanvasWidget, widget=button, x=x, y=y+(h/2),
|
||||||
height=h, width=h, size_pixels=1,
|
height=h, width=h, size_pixels=1,
|
||||||
@ -418,7 +429,8 @@ class PedigreeView:
|
|||||||
"""Callback to right pointing arrow button. Gets the person
|
"""Callback to right pointing arrow button. Gets the person
|
||||||
attached to the button and change the root person to that
|
attached to the button and change the root person to that
|
||||||
person, redrawing the view."""
|
person, redrawing the view."""
|
||||||
person = obj.get_data(_PERSON)
|
person_id = obj.get_data(_PERSON)
|
||||||
|
person = self.parent.db.try_to_find_person_from_id(person_id)
|
||||||
if self.active_person:
|
if self.active_person:
|
||||||
self.active_person = person
|
self.active_person = person
|
||||||
self.load_canvas(person)
|
self.load_canvas(person)
|
||||||
@ -432,7 +444,7 @@ class PedigreeView:
|
|||||||
item = self.root.add(gnome.canvas.CanvasLine, width_pixels=2,
|
item = self.root.add(gnome.canvas.CanvasLine, width_pixels=2,
|
||||||
points=pts, line_style=ls,
|
points=pts, line_style=ls,
|
||||||
fill_color_gdk=style.fg[gtk.STATE_NORMAL])
|
fill_color_gdk=style.fg[gtk.STATE_NORMAL])
|
||||||
item.set_data(_PERSON,data)
|
item.set_data(_PERSON,data.get_id())
|
||||||
item.connect("event",self.line_event)
|
item.connect("event",self.line_event)
|
||||||
self.canvas_items.append(item)
|
self.canvas_items.append(item)
|
||||||
|
|
||||||
@ -453,7 +465,8 @@ class PedigreeView:
|
|||||||
def line_event(self,obj,event):
|
def line_event(self,obj,event):
|
||||||
"""Catch X events over a line and respond to the ones we care about"""
|
"""Catch X events over a line and respond to the ones we care about"""
|
||||||
|
|
||||||
person = obj.get_data(_PERSON)
|
person_id = obj.get_data(_PERSON)
|
||||||
|
person = self.parent.db.try_to_find_person_from_id(person_id)
|
||||||
style = self.canvas.get_style()
|
style = self.canvas.get_style()
|
||||||
|
|
||||||
if event.type == gtk.gdk._2BUTTON_PRESS:
|
if event.type == gtk.gdk._2BUTTON_PRESS:
|
||||||
@ -511,9 +524,78 @@ class PedigreeView:
|
|||||||
def build_nav_menu(self,event):
|
def build_nav_menu(self,event):
|
||||||
"""Builds the menu with navigation."""
|
"""Builds the menu with navigation."""
|
||||||
|
|
||||||
|
# FIXME: need to get a person on whom the click was made,
|
||||||
|
# not the active person!!!
|
||||||
|
person = self.active_person
|
||||||
|
|
||||||
|
menu = gtk.Menu()
|
||||||
|
menu.set_title(_('People Menu'))
|
||||||
|
|
||||||
|
# Go over spouses and build their menu
|
||||||
|
item = gtk.MenuItem(_("Spouses"))
|
||||||
|
fam_list = person.get_family_id_list()
|
||||||
|
no_spouses = 1
|
||||||
|
for fam_id in fam_list:
|
||||||
|
family = self.parent.db.find_family_from_id(fam_id)
|
||||||
|
if family.get_father_id() == person.get_id():
|
||||||
|
sp_id = family.get_mother_id()
|
||||||
|
else:
|
||||||
|
sp_id = family.get_father_id()
|
||||||
|
spouse = self.parent.db.try_to_find_person_from_id(sp_id)
|
||||||
|
if not spouse:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if no_spouses:
|
||||||
|
no_spouses = 0
|
||||||
|
item.set_submenu(gtk.Menu())
|
||||||
|
sp_menu = item.get_submenu()
|
||||||
|
|
||||||
|
sp_item = gtk.MenuItem(GrampsCfg.nameof(spouse))
|
||||||
|
sp_item.set_data(_PERSON,sp_id)
|
||||||
|
sp_item.connect("activate",self.on_childmenu_changed)
|
||||||
|
sp_item.show()
|
||||||
|
sp_menu.append(sp_item)
|
||||||
|
|
||||||
|
if no_spouses:
|
||||||
|
item.set_sensitive(0)
|
||||||
|
|
||||||
|
item.show()
|
||||||
|
menu.append(item)
|
||||||
|
|
||||||
|
# Go over siblings and build their menu
|
||||||
|
item = gtk.MenuItem(_("Siblings"))
|
||||||
|
pfam_list = person.get_parent_family_id_list()
|
||||||
|
no_siblings = 1
|
||||||
|
for (f,mrel,frel) in pfam_list:
|
||||||
|
fam = self.parent.db.find_family_from_id(f)
|
||||||
|
sib_list = fam.get_child_id_list()
|
||||||
|
for sib_id in sib_list:
|
||||||
|
if sib_id == person.get_id():
|
||||||
|
continue
|
||||||
|
sib = self.parent.db.try_to_find_person_from_id(sib_id)
|
||||||
|
if not sib:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if no_siblings:
|
||||||
|
no_siblings = 0
|
||||||
|
item.set_submenu(gtk.Menu())
|
||||||
|
sib_menu = item.get_submenu()
|
||||||
|
|
||||||
|
sib_item = gtk.MenuItem(GrampsCfg.nameof(sib))
|
||||||
|
sib_item.set_data(_PERSON,sib_id)
|
||||||
|
sib_item.connect("activate",self.on_childmenu_changed)
|
||||||
|
sib_item.show()
|
||||||
|
sib_menu.append(sib_item)
|
||||||
|
|
||||||
|
if no_siblings:
|
||||||
|
item.set_sensitive(0)
|
||||||
|
item.show()
|
||||||
|
menu.append(item)
|
||||||
|
|
||||||
back_sensitivity = self.parent.hindex > 0
|
back_sensitivity = self.parent.hindex > 0
|
||||||
fwd_sensitivity = self.parent.hindex + 1 < len(self.parent.history)
|
fwd_sensitivity = self.parent.hindex + 1 < len(self.parent.history)
|
||||||
entries = [
|
entries = [
|
||||||
|
(None,None,0),
|
||||||
(gtk.STOCK_GO_BACK,self.parent.back_clicked,back_sensitivity),
|
(gtk.STOCK_GO_BACK,self.parent.back_clicked,back_sensitivity),
|
||||||
(gtk.STOCK_GO_FORWARD,self.parent.fwd_clicked,fwd_sensitivity),
|
(gtk.STOCK_GO_FORWARD,self.parent.fwd_clicked,fwd_sensitivity),
|
||||||
#FIXME: revert to stock item when German gtk translation is fixed
|
#FIXME: revert to stock item when German gtk translation is fixed
|
||||||
@ -523,8 +605,7 @@ class PedigreeView:
|
|||||||
(_("Set anchor"),self.on_anchor_set,1),
|
(_("Set anchor"),self.on_anchor_set,1),
|
||||||
(_("Remove anchor"),self.on_anchor_removed,1),
|
(_("Remove anchor"),self.on_anchor_removed,1),
|
||||||
]
|
]
|
||||||
menu = gtk.Menu()
|
|
||||||
menu.set_title(_('People Menu'))
|
|
||||||
for stock_id,callback,sensitivity in entries:
|
for stock_id,callback,sensitivity in entries:
|
||||||
item = gtk.ImageMenuItem(stock_id)
|
item = gtk.ImageMenuItem(stock_id)
|
||||||
#FIXME: remove when German gtk translation is fixed
|
#FIXME: remove when German gtk translation is fixed
|
||||||
@ -544,7 +625,7 @@ class PedigreeView:
|
|||||||
# Function to determine distance between people
|
# Function to determine distance between people
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
def get_distance(orig_person,other_person):
|
def get_distance(db,orig_person,other_person):
|
||||||
"""
|
"""
|
||||||
Returns a number of generations representing distance between two people.
|
Returns a number of generations representing distance between two people.
|
||||||
|
|
||||||
@ -567,23 +648,21 @@ def get_distance(orig_person,other_person):
|
|||||||
if orig_person == other_person:
|
if orig_person == other_person:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
return 0
|
|
||||||
# FIX THIS
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
apply_filter(orig_person,0,firstList,firstMap)
|
r = Relationship.RelationshipCalculator(db)
|
||||||
apply_filter(other_person,0,secondList,secondMap)
|
r.apply_filter(orig_person,0,firstList,firstMap)
|
||||||
|
r.apply_filter(other_person,0,secondList,secondMap)
|
||||||
except RuntimeError,msg:
|
except RuntimeError,msg:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
for person in firstList:
|
for person_id in firstList:
|
||||||
if person in secondList:
|
if person_id in secondList:
|
||||||
new_rank = firstMap[person.get_id()]
|
new_rank = firstMap[person_id]
|
||||||
if new_rank < rank:
|
if new_rank < rank:
|
||||||
rank = new_rank
|
rank = new_rank
|
||||||
common = [ person ]
|
common = [ person_id ]
|
||||||
elif new_rank == rank:
|
elif new_rank == rank:
|
||||||
common.append(person)
|
common.append(person_id)
|
||||||
|
|
||||||
if not common:
|
if not common:
|
||||||
return None
|
return None
|
||||||
@ -593,9 +672,9 @@ def get_distance(orig_person,other_person):
|
|||||||
|
|
||||||
length = len(common)
|
length = len(common)
|
||||||
|
|
||||||
person = common[0]
|
person_id = common[0]
|
||||||
secondRel = secondMap[person.get_id()]
|
secondRel = secondMap[person_id]
|
||||||
firstRel = firstMap[person.get_id()]
|
firstRel = firstMap[person_id]
|
||||||
if firstRel == None or secondRel == None:
|
if firstRel == None or secondRel == None:
|
||||||
return None
|
return None
|
||||||
return firstRel-secondRel
|
return firstRel-secondRel
|
||||||
|
Loading…
Reference in New Issue
Block a user