2005-08-09 10:11:20 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000-2005 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
|
|
|
|
#
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gobject
|
|
|
|
import gtk
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import GrampsDbBase
|
|
|
|
import GrampsDBCallback
|
|
|
|
import GrampsKeys
|
|
|
|
import NameDisplay
|
|
|
|
|
2005-08-11 05:23:24 +05:30
|
|
|
class History(GrampsDBCallback.GrampsDBCallback):
|
|
|
|
|
|
|
|
__signals__ = {
|
|
|
|
'changed' : (list,),
|
|
|
|
'menu-changed' : (list,),
|
|
|
|
}
|
2005-08-09 10:11:20 +05:30
|
|
|
|
|
|
|
def __init__(self):
|
2005-08-11 05:23:24 +05:30
|
|
|
GrampsDBCallback.GrampsDBCallback.__init__(self)
|
2005-08-09 10:11:20 +05:30
|
|
|
self.history = []
|
|
|
|
self.mhistory = []
|
|
|
|
self.index = -1
|
|
|
|
self.lock = False
|
|
|
|
|
|
|
|
def clear(self):
|
|
|
|
self.history = []
|
|
|
|
self.mistory = []
|
|
|
|
self.index = -1
|
|
|
|
self.lock = False
|
|
|
|
|
|
|
|
def remove(self,person_handle,old_id=None):
|
|
|
|
"""Removes a person from the history list"""
|
|
|
|
if old_id:
|
|
|
|
del_id = old_id
|
|
|
|
else:
|
|
|
|
del_id = person_handle
|
|
|
|
|
|
|
|
hc = self.history.count(del_id)
|
|
|
|
for c in range(hc):
|
|
|
|
self.history.remove(del_id)
|
|
|
|
self.index -= 1
|
|
|
|
|
|
|
|
mhc = self.mhistory.count(del_id)
|
|
|
|
for c in range(mhc):
|
|
|
|
self.mhistory.remove(del_id)
|
2005-08-11 05:23:24 +05:30
|
|
|
self.emit('changed',(self.history,))
|
|
|
|
self.emit('menu-changed',(self.mhistory,))
|
2005-08-09 10:11:20 +05:30
|
|
|
|
2005-08-10 19:58:16 +05:30
|
|
|
def push(self,person_handle):
|
|
|
|
self.prune()
|
|
|
|
if len(self.history) == 0 or person_handle != self.history[-1]:
|
|
|
|
self.history.append(person_handle)
|
2005-08-11 05:23:24 +05:30
|
|
|
if person_handle not in self.mhistory:
|
|
|
|
self.mhistory.append(person_handle)
|
|
|
|
self.emit('menu-changed',(self.mhistory,))
|
2005-08-10 19:58:16 +05:30
|
|
|
self.index += 1
|
2005-08-11 05:23:24 +05:30
|
|
|
self.emit('changed',(self.history,))
|
2005-08-10 19:58:16 +05:30
|
|
|
|
|
|
|
def forward(self,step=1):
|
|
|
|
self.index += step
|
2005-08-11 05:23:24 +05:30
|
|
|
person_handle = self.history[self.index]
|
|
|
|
if person_handle not in self.mhistory:
|
|
|
|
self.mhistory.append(person_handle)
|
|
|
|
self.emit('menu-changed',(self.mhistory,))
|
2005-08-10 19:58:16 +05:30
|
|
|
return str(self.history[self.index])
|
|
|
|
|
|
|
|
def back(self,step=1):
|
|
|
|
self.index -= step
|
2005-08-11 05:23:24 +05:30
|
|
|
person_handle = self.history[self.index]
|
|
|
|
if person_handle not in self.mhistory:
|
|
|
|
self.mhistory.append(person_handle)
|
|
|
|
self.emit('menu-changed',(self.mhistory,))
|
2005-08-10 19:58:16 +05:30
|
|
|
return str(self.history[self.index])
|
|
|
|
|
|
|
|
def at_end(self):
|
|
|
|
return self.index+1 == len(self.history)
|
|
|
|
|
|
|
|
def at_front(self):
|
|
|
|
return self.index == 0
|
|
|
|
|
|
|
|
def prune(self):
|
|
|
|
if not self.at_end():
|
|
|
|
self.history = self.history[0:self.index+1]
|
|
|
|
|
2005-08-09 10:11:20 +05:30
|
|
|
class DbState(GrampsDBCallback.GrampsDBCallback):
|
|
|
|
|
|
|
|
__signals__ = {
|
|
|
|
'database-changed' : (GrampsDbBase.GrampsDbBase,),
|
2005-08-10 19:58:16 +05:30
|
|
|
'active-changed' : (str,),
|
|
|
|
'no-database' : None,
|
2005-08-09 10:11:20 +05:30
|
|
|
}
|
|
|
|
|
2005-08-11 05:23:24 +05:30
|
|
|
def __init__(self):
|
2005-08-09 10:11:20 +05:30
|
|
|
GrampsDBCallback.GrampsDBCallback.__init__(self)
|
|
|
|
self.db = GrampsDbBase.GrampsDbBase()
|
|
|
|
self.active = None
|
|
|
|
|
|
|
|
def change_active_person(self,person):
|
|
|
|
self.active = person
|
2005-08-10 19:58:16 +05:30
|
|
|
if person:
|
|
|
|
try:
|
|
|
|
self.emit('active-changed',(person.handle,))
|
|
|
|
except:
|
|
|
|
self.emit('active-changed',("",))
|
2005-08-09 10:11:20 +05:30
|
|
|
|
|
|
|
def change_active_handle(self,handle):
|
2005-08-09 15:48:56 +05:30
|
|
|
self.change_active_person(self.db.get_person_from_handle(handle))
|
2005-08-09 10:11:20 +05:30
|
|
|
|
|
|
|
def get_active_person(self):
|
|
|
|
return self.active
|
|
|
|
|
|
|
|
def change_database(self,db):
|
|
|
|
self.db = db
|
2005-08-10 19:58:16 +05:30
|
|
|
self.emit('database-changed',(self.db,))
|
|
|
|
|
|
|
|
def no_database(self):
|
|
|
|
self.db = GrampsDbBase.GrampsDbBase()
|
|
|
|
self.emit('no-database')
|
2005-08-09 10:11:20 +05:30
|
|
|
|
2005-08-11 05:23:24 +05:30
|
|
|
class DisplayState(GrampsDBCallback.GrampsDBCallback):
|
|
|
|
|
|
|
|
__signals__ = {
|
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self,window,status,uimanager,dbstate):
|
|
|
|
self.dbstate = dbstate
|
|
|
|
self.uimanager = uimanager
|
|
|
|
self.window = window
|
|
|
|
GrampsDBCallback.GrampsDBCallback.__init__(self)
|
|
|
|
self.status = status
|
|
|
|
self.status_id = status.get_context_id('GRAMPS')
|
|
|
|
self.phistory = History()
|
|
|
|
|
|
|
|
def modify_statusbar(self,active=None):
|
2005-08-09 10:11:20 +05:30
|
|
|
self.status.pop(self.status_id)
|
2005-08-11 05:23:24 +05:30
|
|
|
if self.dbstate.active == None:
|
2005-08-09 10:11:20 +05:30
|
|
|
self.status.push(self.status_id,"")
|
|
|
|
else:
|
|
|
|
if GrampsKeys.get_statusbar() <= 1:
|
2005-08-11 05:23:24 +05:30
|
|
|
pname = NameDisplay.displayer.display(self.dbstate.active)
|
|
|
|
name = "[%s] %s" % (self.dbstate.active.get_gramps_id(),pname)
|
2005-08-09 10:11:20 +05:30
|
|
|
else:
|
|
|
|
name = self.display_relationship()
|
|
|
|
self.status.push(self.status_id,name)
|
|
|
|
|
|
|
|
while gtk.events_pending():
|
|
|
|
gtk.main_iteration()
|
|
|
|
|
|
|
|
def status_text(self,text):
|
|
|
|
self.status.pop(self.status_id)
|
|
|
|
self.status.push(self.status_id,text)
|
|
|
|
while gtk.events_pending():
|
|
|
|
gtk.main_iteration()
|