Fixes to context menu

svn: r3222
This commit is contained in:
Alex Roitman 2004-06-21 21:23:35 +00:00
parent 7cf73d3415
commit de2c28febb

View File

@ -371,15 +371,7 @@ class PedigreeView:
# button. The menu consists of the children of the current root # button. The menu consists of the children of the current root
# person of the tree. Attach a child to each menu item. # person of the tree. Attach a child to each menu item.
def find_children(p): childlist = find_children(self.parent.db,self.active_person)
childlist = []
for family_id in p.get_family_id_list():
family = self.parent.db.find_family_from_id(family_id)
for child_id in family.get_child_id_list():
childlist.append(child_id)
return childlist
childlist = find_children(self.active_person)
if len(childlist) == 1: if len(childlist) == 1:
child = self.parent.db.try_to_find_person_from_id(childlist[0]) child = self.parent.db.try_to_find_person_from_id(childlist[0])
if child: if child:
@ -390,7 +382,7 @@ class PedigreeView:
child = self.parent.db.try_to_find_person_from_id(child_id) child = self.parent.db.try_to_find_person_from_id(child_id)
cname = GrampsCfg.nameof(child) cname = GrampsCfg.nameof(child)
menuitem = gtk.MenuItem(None) menuitem = gtk.MenuItem(None)
if find_children(child): if find_children(self.parent.db,child):
label = gtk.Label('<b><i>%s</i></b>' % cname) label = gtk.Label('<b><i>%s</i></b>' % cname)
else: else:
label = gtk.Label(cname) label = gtk.Label(cname)
@ -525,13 +517,14 @@ class PedigreeView:
def on_canvas_press(self,obj,event): def on_canvas_press(self,obj,event):
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3: if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
self.build_nav_menu(event) self.build_nav_menu(event)
return gtk.TRUE
def build_nav_menu(self,event): def add_nav_portion_to_menu(self,menu):
"""Builds the menu with only history-based navigation.""" """
This function adds a common history-navigation portion
menu = gtk.Menu() to the context menu. Used by both build_nav_menu() and
menu.set_title(_('People Menu')) build_full_nav_menu() methods.
"""
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 = [
@ -557,12 +550,19 @@ class PedigreeView:
item.set_sensitive(sensitivity) item.set_sensitive(sensitivity)
item.show() item.show()
menu.append(item) menu.append(item)
def build_nav_menu(self,event):
"""Builds the menu with only history-based navigation."""
menu = gtk.Menu()
menu.set_title(_('People Menu'))
self.add_nav_portion_to_menu(menu)
menu.popup(None,None,None,event.button,event.time) menu.popup(None,None,None,event.button,event.time)
def build_full_nav_menu(self,event,person): def build_full_nav_menu(self,event,person):
""" """
Builds the full menu (including Siblings, Spouses, etc) Builds the full menu (including Siblings, Spouses, Children,
with navigation. and Parents) with navigation.
""" """
menu = gtk.Menu() menu = gtk.Menu()
@ -629,32 +629,81 @@ class PedigreeView:
item.show() item.show()
menu.append(item) menu.append(item)
back_sensitivity = self.parent.hindex > 0 # Go over children and build their menu
fwd_sensitivity = self.parent.hindex + 1 < len(self.parent.history) item = gtk.MenuItem(_("Children"))
entries = [ no_children = 1
(None,None,0), childlist = find_children(self.parent.db,person)
(gtk.STOCK_GO_BACK,self.parent.back_clicked,back_sensitivity), for child_id in childlist:
(gtk.STOCK_GO_FORWARD,self.parent.fwd_clicked,fwd_sensitivity), child = self.parent.db.try_to_find_person_from_id(child_id)
#FIXME: revert to stock item when German gtk translation is fixed if not child:
#(gtk.STOCK_HOME,self.parent.on_home_clicked,1), continue
(_("Home"),self.parent.on_home_clicked,1),
(None,None,0),
(_("Set anchor"),self.on_anchor_set,1),
(_("Remove anchor"),self.on_anchor_removed,1),
]
for stock_id,callback,sensitivity in entries: if no_children:
item = gtk.ImageMenuItem(stock_id) no_children = 0
#FIXME: remove when German gtk translation is fixed item.set_submenu(gtk.Menu())
if stock_id == _("Home"): child_menu = item.get_submenu()
im = gtk.image_new_from_stock(gtk.STOCK_HOME,gtk.ICON_SIZE_MENU)
im.show() if find_children(self.parent.db,child):
item.set_image(im) label = gtk.Label('<b><i>%s</i></b>' % GrampsCfg.nameof(child))
if callback: else:
item.connect("activate",callback) label = gtk.Label(GrampsCfg.nameof(child))
item.set_sensitive(sensitivity)
child_item = gtk.MenuItem(None)
label.set_use_markup(gtk.TRUE)
label.show()
label.set_alignment(0,0)
child_item.add(label)
child_item.set_data(_PERSON,child_id)
child_item.connect("activate",self.on_childmenu_changed)
child_item.show()
child_menu.append(child_item)
if no_children:
item.set_sensitive(0)
item.show() item.show()
menu.append(item) menu.append(item)
# Go over parents and build their menu
item = gtk.MenuItem(_("Parents"))
no_parents = 1
par_list = find_parents(self.parent.db,person)
for par_id in par_list:
par = self.parent.db.try_to_find_person_from_id(par_id)
if not par:
continue
if no_parents:
no_parents = 0
item.set_submenu(gtk.Menu())
par_menu = item.get_submenu()
if find_parents(self.parent.db,par):
label = gtk.Label('<b><i>%s</i></b>' % GrampsCfg.nameof(par))
else:
label = gtk.Label(GrampsCfg.nameof(par))
par_item = gtk.MenuItem(None)
label.set_use_markup(gtk.TRUE)
label.show()
label.set_alignment(0,0)
par_item.add(label)
par_item.set_data(_PERSON,par_id)
par_item.connect("activate",self.on_childmenu_changed)
par_item.show()
par_menu.append(par_item)
if no_parents:
item.set_sensitive(0)
item.show()
menu.append(item)
# Add separator
item = gtk.MenuItem(None)
item.show()
menu.append(item)
# Add history-based navigation
self.add_nav_portion_to_menu(menu)
menu.popup(None,None,None,event.button,event.time) menu.popup(None,None,None,event.button,event.time)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -707,11 +756,45 @@ def get_distance(db,orig_person,other_person):
firstRel = None firstRel = None
secondRel = None secondRel = None
length = len(common)
person_id = common[0] person_id = common[0]
secondRel = secondMap[person_id] secondRel = secondMap[person_id]
firstRel = firstMap[person_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
#-------------------------------------------------------------------------
#
# Function to return children's list of a person
#
#-------------------------------------------------------------------------
def find_children(db,p):
"""
Returns the list of all children's IDs for a person.
"""
childlist = []
for family_id in p.get_family_id_list():
family = db.find_family_from_id(family_id)
for child_id in family.get_child_id_list():
childlist.append(child_id)
return childlist
#-------------------------------------------------------------------------
#
# Function to return parent's list of a person
#
#-------------------------------------------------------------------------
def find_parents(db,p):
"""
Returns the unique list of all parents' IDs for a person.
"""
parentlist = []
for (f,mrel,frel) in p.get_parent_family_id_list():
family = db.find_family_from_id(f)
father_id = family.get_father_id()
mother_id = family.get_mother_id()
if father_id not in parentlist:
parentlist.append(father_id)
if mother_id not in parentlist:
parentlist.append(mother_id)
return parentlist