2003-10-05 01:32:38 +05:30
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000-2003 Donald N. Allingham
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2003-10-20 08:17:03 +05:30
|
|
|
# $Id$
|
|
|
|
|
2003-10-05 01:32:38 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# internationalization
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
from gettext import gettext as _
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gtk
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
|
|
|
|
|
|
|
from gtk.gdk import ACTION_COPY, BUTTON1_MASK
|
|
|
|
|
|
|
|
_sel_mode = gtk.SELECTION_MULTIPLE
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gtk
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-03-08 03:20:41 +05:30
|
|
|
import PeopleModel
|
2003-10-05 01:32:38 +05:30
|
|
|
import Filter
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# PeopleView
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class PeopleView:
|
|
|
|
|
|
|
|
def __init__(self,parent):
|
|
|
|
self.parent = parent
|
|
|
|
|
|
|
|
self.DataFilter = Filter.Filter("")
|
2004-03-08 03:20:41 +05:30
|
|
|
self.pscroll = self.parent.gtop.get_widget("pscroll")
|
|
|
|
self.person_tree = self.parent.gtop.get_widget("person_tree")
|
|
|
|
self.person_tree.set_rules_hint(gtk.TRUE)
|
|
|
|
|
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
|
|
|
|
column_n = gtk.TreeViewColumn(_('Name'), renderer,text=0)
|
|
|
|
column_n.set_resizable(gtk.TRUE)
|
|
|
|
column_n.set_clickable(gtk.TRUE)
|
|
|
|
column_n.set_min_width(225)
|
|
|
|
self.person_tree.append_column(column_n)
|
|
|
|
|
|
|
|
column_i = gtk.TreeViewColumn(_('ID'), renderer,text=1)
|
|
|
|
column_i.set_resizable(gtk.TRUE)
|
|
|
|
column_i.set_clickable(gtk.TRUE)
|
|
|
|
column_i.set_min_width(75)
|
|
|
|
self.person_tree.append_column(column_i)
|
|
|
|
|
|
|
|
column_g = gtk.TreeViewColumn(_('Gender'), renderer,text=2)
|
|
|
|
column_g.set_resizable(gtk.TRUE)
|
|
|
|
column_g.set_clickable(gtk.TRUE)
|
|
|
|
column_g.set_min_width(75)
|
|
|
|
self.person_tree.append_column(column_g)
|
|
|
|
|
|
|
|
column_b = gtk.TreeViewColumn(_('Birth Date'), renderer,text=3)
|
|
|
|
column_b.set_resizable(gtk.TRUE)
|
|
|
|
column_b.set_clickable(gtk.TRUE)
|
|
|
|
column_b.set_min_width(150)
|
|
|
|
self.person_tree.append_column(column_b)
|
|
|
|
|
|
|
|
column_d = gtk.TreeViewColumn(_('Death Date'), renderer,text=4)
|
|
|
|
column_d.set_resizable(gtk.TRUE)
|
|
|
|
column_d.set_clickable(gtk.TRUE)
|
|
|
|
column_d.set_min_width(150)
|
|
|
|
self.person_tree.append_column(column_d)
|
|
|
|
self.build_tree()
|
|
|
|
|
|
|
|
def build_tree(self):
|
|
|
|
self.person_tree.set_model(None)
|
|
|
|
self.person_model = PeopleModel.PeopleModel(self.parent.db)
|
|
|
|
self.person_tree.set_model(self.person_model)
|
|
|
|
|
|
|
|
self.person_selection = self.person_tree.get_selection()
|
|
|
|
self.person_selection.connect('changed',self.row_changed)
|
|
|
|
self.person_tree.connect('row_activated', self.alpha_event)
|
|
|
|
self.person_tree.connect('button-press-event',self.on_plist_button_press)
|
|
|
|
|
|
|
|
def blist(self,store,path,iter,id_list):
|
|
|
|
id_list.append(self.person_model.get_value(iter,1))
|
|
|
|
|
|
|
|
def get_selected_objects(self):
|
|
|
|
mlist = []
|
|
|
|
self.person_selection.selected_foreach(self.blist,mlist)
|
|
|
|
return mlist
|
2003-10-05 01:32:38 +05:30
|
|
|
|
|
|
|
def row_changed(self,obj):
|
2004-02-16 02:19:34 +05:30
|
|
|
"""Called with a row is changed. Check the selected objects from the person_tree
|
|
|
|
to get the IDs of the selected objects. Set the active person to the first person
|
|
|
|
in the list. If no one is selected, set the active person to None"""
|
2004-03-08 03:20:41 +05:30
|
|
|
selected_id_list = self.get_selected_objects()
|
2004-02-21 11:41:59 +05:30
|
|
|
if selected_id_list and selected_id_list[0]:
|
2003-10-05 01:32:38 +05:30
|
|
|
try:
|
2004-03-08 03:20:41 +05:30
|
|
|
person = self.parent.db.get_person(selected_id_list[0])
|
|
|
|
self.parent.change_active_person(person)
|
2003-10-05 01:32:38 +05:30
|
|
|
except:
|
|
|
|
self.parent.change_active_person(None)
|
|
|
|
self.person_tree.unselect()
|
2003-12-03 09:37:36 +05:30
|
|
|
|
2003-10-05 01:32:38 +05:30
|
|
|
def change_db(self,db):
|
2004-03-08 03:20:41 +05:30
|
|
|
self.build_tree()
|
2003-10-05 01:32:38 +05:30
|
|
|
|
|
|
|
def clear(self):
|
2004-03-08 03:20:41 +05:30
|
|
|
pass
|
2003-10-05 01:32:38 +05:30
|
|
|
|
|
|
|
def remove_from_person_list(self,person,old_id=None):
|
2004-02-16 02:19:34 +05:30
|
|
|
"""Remove the selected person from the list. A person object is expected,
|
|
|
|
not an ID"""
|
|
|
|
person_id = person.get_id()
|
2003-10-05 01:32:38 +05:30
|
|
|
if old_id:
|
|
|
|
del_id = old_id
|
|
|
|
else:
|
2004-02-16 02:19:34 +05:30
|
|
|
del_id = person_id
|
2003-10-05 01:32:38 +05:30
|
|
|
|
|
|
|
if self.id2col.has_key(del_id):
|
2003-10-05 10:04:31 +05:30
|
|
|
(model,iter) = self.id2col[del_id]
|
2003-12-25 09:44:51 +05:30
|
|
|
if iter:
|
|
|
|
model.remove(iter)
|
2003-10-05 01:32:38 +05:30
|
|
|
del self.id2col[del_id]
|
|
|
|
|
|
|
|
if person == self.parent.active_person:
|
|
|
|
self.parent.active_person = None
|
|
|
|
|
2003-10-07 04:19:16 +05:30
|
|
|
def remove_from_history(self,person,old_id=None):
|
2004-02-16 02:19:34 +05:30
|
|
|
"""Removes a person from the history list"""
|
|
|
|
|
|
|
|
person_id = person.get_id()
|
2003-10-07 04:19:16 +05:30
|
|
|
if old_id:
|
|
|
|
del_id = old_id
|
|
|
|
else:
|
2004-02-16 02:19:34 +05:30
|
|
|
del_id = person_id
|
2003-10-07 04:19:16 +05:30
|
|
|
|
|
|
|
hc = self.parent.history.count(del_id)
|
|
|
|
for c in range(hc):
|
|
|
|
self.parent.history.remove(del_id)
|
|
|
|
self.parent.hindex = self.parent.hindex - 1
|
|
|
|
|
|
|
|
mhc = self.parent.mhistory.count(del_id)
|
|
|
|
for c in range(mhc):
|
|
|
|
self.parent.mhistory.remove(del_id)
|
|
|
|
|
2003-10-05 01:32:38 +05:30
|
|
|
def apply_filter_clicked(self):
|
|
|
|
invert_filter = self.parent.filter_inv.get_active()
|
2003-12-17 10:53:16 +05:30
|
|
|
qualifer = unicode(self.parent.filter_text.get_text())
|
2003-10-05 01:32:38 +05:30
|
|
|
mi = self.parent.filter_list.get_menu().get_active()
|
|
|
|
class_init = mi.get_data("function")
|
|
|
|
self.DataFilter = class_init(qualifer)
|
|
|
|
self.DataFilter.set_invert(invert_filter)
|
|
|
|
self.model_used = {}
|
2003-11-02 01:25:30 +05:30
|
|
|
self.clear_person_tabs()
|
2003-10-05 01:32:38 +05:30
|
|
|
self.apply_filter(self.person_tree)
|
2003-11-02 01:25:30 +05:30
|
|
|
self.goto_active_person()
|
2003-10-05 01:32:38 +05:30
|
|
|
|
|
|
|
def add_to_person_list(self,person,change):
|
2004-02-14 11:10:30 +05:30
|
|
|
key = person.get_id()
|
2004-02-26 10:21:57 +05:30
|
|
|
val = self.parent.db.get_person_display(key)
|
2003-10-05 01:32:38 +05:30
|
|
|
pg = unicode(val[5])
|
|
|
|
pg = pg[0]
|
2004-02-01 03:02:01 +05:30
|
|
|
model = None
|
2003-10-05 01:32:38 +05:30
|
|
|
if self.DataFilter.compare(person):
|
|
|
|
|
|
|
|
if pg and pg != '@':
|
|
|
|
if not self.alpha_page.has_key(pg):
|
|
|
|
self.create_new_panel(pg)
|
|
|
|
model = self.alpha_page[pg]
|
|
|
|
else:
|
|
|
|
model = self.default_list
|
|
|
|
|
2004-02-19 10:37:46 +05:30
|
|
|
if val[3]:
|
|
|
|
bdate = self.parent.db.find_event_from_id(val[3]).get_date()
|
|
|
|
else:
|
|
|
|
bdate = ""
|
|
|
|
|
|
|
|
if val[4]:
|
|
|
|
ddate = self.parent.db.find_event_from_id(val[4]).get_date()
|
|
|
|
else:
|
|
|
|
ddate = ""
|
2004-02-21 11:41:59 +05:30
|
|
|
|
2004-02-19 10:37:46 +05:30
|
|
|
iter = model.add([val[0],val[1],val[2],bdate,ddate,val[5],
|
2003-10-06 09:59:50 +05:30
|
|
|
val[6],val[7],val[8]],1)
|
2003-10-05 01:32:38 +05:30
|
|
|
|
|
|
|
self.id2col[key] = (model,iter)
|
|
|
|
|
2003-11-26 22:12:54 +05:30
|
|
|
if change:
|
|
|
|
self.parent.change_active_person(person)
|
2004-02-26 10:21:57 +05:30
|
|
|
|
|
|
|
try:
|
|
|
|
self.goto_active_person()
|
|
|
|
except:
|
|
|
|
print "goto failed"
|
|
|
|
|
2004-02-01 03:02:01 +05:30
|
|
|
if model:
|
|
|
|
model.enable_sort()
|
2003-10-05 01:32:38 +05:30
|
|
|
|
|
|
|
def goto_active_person(self,first=0):
|
|
|
|
if not self.parent.active_person:
|
|
|
|
return
|
2004-03-08 03:20:41 +05:30
|
|
|
p = self.parent.active_person
|
|
|
|
id = p.get_id()
|
|
|
|
path = self.person_model.find_path(id)
|
|
|
|
top_path = self.person_model.find_path(p.get_primary_name().get_surname())
|
|
|
|
self.person_tree.expand_row(top_path,1)
|
|
|
|
self.person_selection.select_path(path)
|
|
|
|
self.person_tree.scroll_to_cell(path,None,1,0.5,0)
|
|
|
|
|
|
|
|
# itpath = model.model.get_path(iter)
|
|
|
|
# col = model.tree.get_column(0)
|
|
|
|
|
|
|
|
def alpha_event(self,obj,a,b):
|
2003-10-05 01:32:38 +05:30
|
|
|
self.parent.load_person(self.parent.active_person)
|
|
|
|
|
|
|
|
def apply_filter(self,current_model=None):
|
|
|
|
self.parent.status_text(_('Updating display...'))
|
|
|
|
self.parent.modify_statusbar()
|
|
|
|
|
|
|
|
def on_plist_button_press(self,obj,event):
|
|
|
|
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
|
2003-10-20 08:17:03 +05:30
|
|
|
self.build_people_context_menu(event)
|
2003-10-05 01:32:38 +05:30
|
|
|
|
2003-10-20 08:17:03 +05:30
|
|
|
def build_people_context_menu(self,event):
|
2003-10-05 01:32:38 +05:30
|
|
|
"""Builds the menu with navigation and
|
|
|
|
editing operations on the people's list"""
|
|
|
|
|
2003-10-06 07:12:55 +05:30
|
|
|
back_sensitivity = self.parent.hindex > 0
|
|
|
|
fwd_sensitivity = self.parent.hindex + 1 < len(self.parent.history)
|
2003-10-05 01:32:38 +05:30
|
|
|
mlist = self.person_tree.get_selected_objects()
|
|
|
|
if mlist:
|
|
|
|
sel_sensitivity = 1
|
|
|
|
else:
|
|
|
|
sel_sensitivity = 0
|
|
|
|
entries = [
|
2003-10-06 07:12:55 +05:30
|
|
|
(gtk.STOCK_GO_BACK,self.parent.back_clicked,back_sensitivity),
|
|
|
|
(gtk.STOCK_GO_FORWARD,self.parent.fwd_clicked,fwd_sensitivity),
|
2003-12-05 05:41:22 +05:30
|
|
|
#FIXME: revert to stock item when German gtk translation is fixed
|
|
|
|
#(gtk.STOCK_HOME,self.parent.on_home_clicked,1),
|
|
|
|
(_("Home"),self.parent.on_home_clicked,1),
|
2003-10-06 07:12:55 +05:30
|
|
|
(_("Add Bookmark"),self.parent.on_add_bookmark_activate,sel_sensitivity),
|
2003-10-05 01:32:38 +05:30
|
|
|
(None,None,0),
|
2003-10-06 07:12:55 +05:30
|
|
|
(gtk.STOCK_ADD, self.parent.add_button_clicked,1),
|
|
|
|
(gtk.STOCK_REMOVE, self.parent.remove_button_clicked,sel_sensitivity),
|
|
|
|
(_("Edit"), self.parent.edit_button_clicked,sel_sensitivity),
|
2003-10-05 01:32:38 +05:30
|
|
|
]
|
|
|
|
|
|
|
|
menu = gtk.Menu()
|
|
|
|
menu.set_title(_('People Menu'))
|
|
|
|
for stock_id,callback,sensitivity in entries:
|
|
|
|
item = gtk.ImageMenuItem(stock_id)
|
2003-12-05 05:41:22 +05:30
|
|
|
#FIXME: remove when German gtk translation is fixed
|
|
|
|
if stock_id == _("Home"):
|
|
|
|
im = gtk.image_new_from_stock(gtk.STOCK_HOME,gtk.ICON_SIZE_MENU)
|
|
|
|
im.show()
|
|
|
|
item.set_image(im)
|
2003-10-05 01:32:38 +05:30
|
|
|
if callback:
|
|
|
|
item.connect("activate",callback)
|
|
|
|
item.set_sensitive(sensitivity)
|
|
|
|
item.show()
|
|
|
|
menu.append(item)
|
2003-10-20 08:17:03 +05:30
|
|
|
menu.popup(None,None,None,event.button,event.time)
|
2003-10-05 01:32:38 +05:30
|
|
|
|
2003-10-05 10:04:31 +05:30
|
|
|
def redisplay_person_list(self,person):
|
2004-03-08 03:20:41 +05:30
|
|
|
self.person_model.rebuild_data()
|
2003-11-24 08:26:13 +05:30
|
|
|
|
|
|
|
def update_person_list(self,person,old_id):
|
2004-03-08 03:20:41 +05:30
|
|
|
self.person_model.rebuild_data()
|