2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-04-26 00:54:40 +05:30
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# 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-12-02 08:05:49 +05:30
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
"Handle bookmarks for the gramps interface"
|
|
|
|
|
|
|
|
__author__ = "Donald N. Allingham"
|
|
|
|
__version__ = "$Revision$"
|
|
|
|
|
2005-08-18 11:28:28 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2005-12-25 09:31:47 +05:30
|
|
|
from cStringIO import StringIO
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2006-03-05 10:15:44 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# set up logging
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".Bookmarks")
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-12-02 08:05:49 +05:30
|
|
|
import gtk
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-12-06 12:08:09 +05:30
|
|
|
import GrampsDisplay
|
2005-01-01 09:57:15 +05:30
|
|
|
import NameDisplay
|
2005-08-18 11:28:28 +05:30
|
|
|
import ListModel
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Bookmarks
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-12-25 09:31:47 +05:30
|
|
|
|
2006-04-26 09:54:54 +05:30
|
|
|
_top = '''<ui><menubar name="MenuBar"><menu action="BookMenu">'''
|
|
|
|
_btm = '''</menu></menubar></ui>'''
|
2005-12-25 09:31:47 +05:30
|
|
|
|
|
|
|
DISABLED = -1
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
class Bookmarks :
|
|
|
|
"Handle the bookmarks interface for Gramps"
|
|
|
|
|
2006-04-26 00:54:40 +05:30
|
|
|
def __init__(self,dbstate,uistate,bookmarks):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""
|
2005-08-18 11:28:28 +05:30
|
|
|
Creates a the bookmark editor.
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
bookmarks - list of People
|
|
|
|
menu - parent menu to attach users
|
|
|
|
callback - task to connect to the menu item as a callback
|
|
|
|
"""
|
2005-12-25 09:31:47 +05:30
|
|
|
self.dbstate = dbstate
|
2006-04-26 00:54:40 +05:30
|
|
|
self.uistate = uistate
|
2002-10-20 19:55:16 +05:30
|
|
|
self.bookmarks = bookmarks
|
2005-12-25 09:31:47 +05:30
|
|
|
self.active = DISABLED
|
|
|
|
self.action_group = gtk.ActionGroup('Bookmarks')
|
2002-10-20 19:55:16 +05:30
|
|
|
self.redraw()
|
|
|
|
|
|
|
|
def redraw(self):
|
|
|
|
"""Create the pulldown menu"""
|
2005-12-25 09:31:47 +05:30
|
|
|
f = StringIO()
|
|
|
|
f.write(_top)
|
|
|
|
|
|
|
|
count = 0
|
|
|
|
if self.active != DISABLED:
|
2006-04-26 00:54:40 +05:30
|
|
|
self.uistate.uimanager.remove_ui(self.active)
|
|
|
|
self.uistate.uimanager.remove_action_group(self.action_group)
|
2005-12-25 09:31:47 +05:30
|
|
|
self.active = DISABLED
|
|
|
|
|
|
|
|
actions = []
|
2006-04-26 09:54:54 +05:30
|
|
|
|
|
|
|
if len(self.bookmarks) > 0:
|
|
|
|
f.write('<placeholder name="GoToBook">')
|
|
|
|
for item in self.bookmarks:
|
|
|
|
person = self.dbstate.db.get_person_from_handle(item)
|
|
|
|
name = NameDisplay.displayer.display(person)
|
|
|
|
action_id = "BM:%s" % item
|
|
|
|
f.write('<menuitem action="%s"/>' % action_id)
|
|
|
|
label = "%s [%s]" % (name,person.gramps_id)
|
|
|
|
func = make_callback(item,self.dbstate.change_active_handle)
|
|
|
|
actions.append((action_id,None,label,None,None,func))
|
|
|
|
count +=1
|
|
|
|
f.write('</placeholder>')
|
2005-12-25 09:31:47 +05:30
|
|
|
f.write(_btm)
|
|
|
|
self.action_group.add_actions(actions)
|
2006-04-26 00:54:40 +05:30
|
|
|
self.uistate.uimanager.insert_action_group(self.action_group,1)
|
2006-04-26 09:54:54 +05:30
|
|
|
print f.getvalue()
|
2006-04-26 00:54:40 +05:30
|
|
|
self.active = self.uistate.uimanager.add_ui_from_string(f.getvalue())
|
2005-12-25 09:31:47 +05:30
|
|
|
f.close()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-07-28 07:59:07 +05:30
|
|
|
def add(self,person_handle):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""appends the person to the bottom of the bookmarks"""
|
2004-07-28 07:59:07 +05:30
|
|
|
if person_handle not in self.bookmarks:
|
|
|
|
self.bookmarks.append(person_handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.redraw()
|
|
|
|
|
2005-08-18 11:28:28 +05:30
|
|
|
def remove_people(self,person_handle_list):
|
|
|
|
"""
|
|
|
|
Removes people from the list of bookmarked people.
|
|
|
|
|
|
|
|
This function is for use *outside* the bookmark editor
|
|
|
|
(removal when person is deleted or merged away).
|
|
|
|
"""
|
|
|
|
modified = False
|
|
|
|
for person_handle in person_handle_list:
|
|
|
|
if person_handle in self.bookmarks:
|
|
|
|
self.bookmarks.remove(person_handle)
|
|
|
|
modified = True
|
|
|
|
if modified:
|
|
|
|
self.redraw()
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def draw_window(self):
|
|
|
|
"""Draws the bookmark dialog box"""
|
|
|
|
title = "%s - GRAMPS" % _("Edit Bookmarks")
|
|
|
|
self.top = gtk.Dialog(title)
|
2003-03-23 01:56:44 +05:30
|
|
|
self.top.set_default_size(400,350)
|
2005-02-24 05:55:34 +05:30
|
|
|
self.top.set_has_separator(False)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.top.vbox.set_spacing(5)
|
2005-08-18 11:28:28 +05:30
|
|
|
label = gtk.Label('<span size="larger" weight="bold">%s</span>'
|
|
|
|
% _("Edit Bookmarks"))
|
2005-02-24 05:55:34 +05:30
|
|
|
label.set_use_markup(True)
|
2003-03-23 01:56:44 +05:30
|
|
|
self.top.vbox.pack_start(label,0,0,5)
|
2002-10-20 19:55:16 +05:30
|
|
|
box = gtk.HBox()
|
|
|
|
self.top.vbox.pack_start(box,1,1,5)
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2006-04-26 00:54:40 +05:30
|
|
|
name_titles = [(_('Name'),-1,200),(_('ID'),-1,50),('',-1,0)]
|
2005-08-18 11:28:28 +05:30
|
|
|
self.namelist = gtk.TreeView()
|
|
|
|
self.namemodel = ListModel.ListModel(self.namelist,name_titles)
|
|
|
|
self.namemodel_cols = len(name_titles)
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
slist = gtk.ScrolledWindow()
|
|
|
|
slist.add_with_viewport(self.namelist)
|
|
|
|
slist.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
|
|
|
box.pack_start(slist,1,1,5)
|
|
|
|
bbox = gtk.VButtonBox()
|
|
|
|
bbox.set_layout(gtk.BUTTONBOX_START)
|
2003-03-23 01:56:44 +05:30
|
|
|
bbox.set_spacing(6)
|
2005-08-18 11:28:28 +05:30
|
|
|
up = gtk.Button(stock=gtk.STOCK_GO_UP)
|
|
|
|
down = gtk.Button(stock=gtk.STOCK_GO_DOWN)
|
|
|
|
delete = gtk.Button(stock=gtk.STOCK_REMOVE)
|
2002-10-20 19:55:16 +05:30
|
|
|
up.connect('clicked', self.up_clicked)
|
|
|
|
down.connect('clicked',self.down_clicked)
|
|
|
|
delete.connect('clicked',self.delete_clicked)
|
2005-08-18 11:28:28 +05:30
|
|
|
self.top.add_button(gtk.STOCK_CLOSE,gtk.RESPONSE_CLOSE)
|
2003-12-02 08:05:49 +05:30
|
|
|
self.top.add_button(gtk.STOCK_HELP,gtk.RESPONSE_HELP)
|
2002-10-20 19:55:16 +05:30
|
|
|
bbox.add(up)
|
|
|
|
bbox.add(down)
|
|
|
|
bbox.add(delete)
|
|
|
|
box.pack_start(bbox,0,0,5)
|
|
|
|
self.top.show_all()
|
|
|
|
|
|
|
|
def edit(self):
|
|
|
|
"""
|
|
|
|
display the bookmark editor.
|
|
|
|
|
|
|
|
The current bookmarked people are inserted into the namelist,
|
|
|
|
attaching the person object to the corresponding row. The currently
|
|
|
|
selected row is attached to the name list. This is either 0 if the
|
|
|
|
list is not empty, or -1 if it is.
|
|
|
|
"""
|
|
|
|
self.draw_window()
|
2004-07-28 07:59:07 +05:30
|
|
|
for person_handle in self.bookmarks:
|
2005-12-25 09:31:47 +05:30
|
|
|
person = self.dbstate.db.get_person_from_handle(person_handle)
|
2005-08-18 11:28:28 +05:30
|
|
|
if person:
|
|
|
|
name = NameDisplay.displayer.display(person)
|
|
|
|
gramps_id = person.get_gramps_id()
|
2005-12-06 12:08:09 +05:30
|
|
|
self.namemodel.add([name,gramps_id,person_handle])
|
2005-08-18 11:28:28 +05:30
|
|
|
self.namemodel.connect_model()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-04-26 00:54:40 +05:30
|
|
|
self.modified = False
|
2003-12-02 08:05:49 +05:30
|
|
|
self.response = self.top.run()
|
2005-08-18 11:28:28 +05:30
|
|
|
if self.response == gtk.RESPONSE_HELP:
|
2003-12-02 08:05:49 +05:30
|
|
|
self.help_clicked()
|
2006-04-26 00:54:40 +05:30
|
|
|
if self.modified:
|
|
|
|
self.redraw()
|
2003-12-02 08:05:49 +05:30
|
|
|
self.top.destroy()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def delete_clicked(self,obj):
|
|
|
|
"""Removes the current selection from the list"""
|
2005-08-18 11:28:28 +05:30
|
|
|
store,the_iter = self.namemodel.get_selected()
|
|
|
|
if not the_iter:
|
|
|
|
return
|
|
|
|
row = self.namemodel.get_selected_row()
|
|
|
|
self.bookmarks.pop(row)
|
|
|
|
self.namemodel.remove(the_iter)
|
2006-04-26 00:54:40 +05:30
|
|
|
self.modified = True
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def up_clicked(self,obj):
|
|
|
|
"""Moves the current selection up one row"""
|
2005-08-18 11:28:28 +05:30
|
|
|
row = self.namemodel.get_selected_row()
|
|
|
|
if not row or row == -1:
|
|
|
|
return
|
|
|
|
store,the_iter = self.namemodel.get_selected()
|
|
|
|
data = self.namemodel.get_data(the_iter,range(self.namemodel_cols))
|
|
|
|
self.namemodel.remove(the_iter)
|
|
|
|
self.namemodel.insert(row-1,data,None,1)
|
|
|
|
handle = self.bookmarks.pop(row)
|
|
|
|
self.bookmarks.insert(row-1,handle)
|
2006-04-26 00:54:40 +05:30
|
|
|
self.modified = True
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def down_clicked(self,obj):
|
|
|
|
"""Moves the current selection down one row"""
|
2005-08-18 11:28:28 +05:30
|
|
|
row = self.namemodel.get_selected_row()
|
|
|
|
if row + 1 >= self.namemodel.count or row == -1:
|
|
|
|
return
|
|
|
|
store,the_iter = self.namemodel.get_selected()
|
|
|
|
data = self.namemodel.get_data(the_iter,range(self.namemodel_cols))
|
|
|
|
self.namemodel.remove(the_iter)
|
|
|
|
self.namemodel.insert(row+1,data,None,1)
|
|
|
|
handle = self.bookmarks.pop(row)
|
|
|
|
self.bookmarks.insert(row+1,handle)
|
2006-04-26 00:54:40 +05:30
|
|
|
self.modified = True
|
2003-12-02 08:05:49 +05:30
|
|
|
|
|
|
|
def help_clicked(self):
|
|
|
|
"""Display the relevant portion of GRAMPS manual"""
|
2005-12-06 12:08:09 +05:30
|
|
|
GrampsDisplay.help('gramps-nav')
|
2003-12-02 08:05:49 +05:30
|
|
|
self.response = self.top.run()
|
2005-12-25 09:31:47 +05:30
|
|
|
|
|
|
|
def make_callback(n,f):
|
|
|
|
return lambda x: f(n)
|