gramps/src/DisplayState.py

155 lines
4.8 KiB
Python
Raw Normal View History

#
# 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,),
}
def __init__(self):
2005-08-11 05:23:24 +05:30
GrampsDBCallback.GrampsDBCallback.__init__(self)
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,))
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,))
self.index += 1
2005-08-11 05:23:24 +05:30
self.emit('changed',(self.history,))
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,))
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,))
return str(self.history[self.index])
def at_end(self):
return self.index+1 == len(self.history)
def at_front(self):
2005-08-11 22:49:03 +05:30
return self.index <= 0
def prune(self):
if not self.at_end():
self.history = self.history[0:self.index+1]
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):
self.status.pop(self.status_id)
2005-08-11 05:23:24 +05:30
if self.dbstate.active == None:
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)
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()