2001-05-13 07:26:57 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000 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
|
|
|
|
#
|
|
|
|
|
|
|
|
"Handle bookmarks for the gramps interface"
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
import libglade
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Local modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import const
|
|
|
|
import utils
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
OBJECT = "o"
|
|
|
|
ROWS = "r"
|
|
|
|
INDEX = "i"
|
|
|
|
TOPINST = "top"
|
|
|
|
NAMEINST = "namelist"
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2001-08-31 09:10:23 +05:30
|
|
|
# Interface to gramps' bookmarks. Handles building the bookmarks menu
|
|
|
|
# for the main window, and provides the bookmark editor.
|
2001-05-13 07:26:57 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class Bookmarks :
|
|
|
|
"Handle the bookmarks interface for Gramps"
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# __init__ - Creates a the bookmark editor
|
|
|
|
#
|
2001-08-31 09:10:23 +05:30
|
|
|
# arguments are:
|
|
|
|
# bookmarks - list of People
|
|
|
|
# menu - parent menu to attach users
|
|
|
|
# callback - task to connect to the menu item as a callback
|
|
|
|
#
|
2001-05-13 07:26:57 +05:30
|
|
|
#---------------------------------------------------------------------
|
2001-08-31 09:10:23 +05:30
|
|
|
def __init__(self,bookmarks,menu,callback):
|
2001-05-13 07:26:57 +05:30
|
|
|
self.menu = menu
|
|
|
|
self.bookmarks = bookmarks
|
|
|
|
self.callback = callback
|
|
|
|
self.redraw()
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------
|
|
|
|
#
|
2001-08-31 09:10:23 +05:30
|
|
|
# redraw - (re)create the pulldown menu
|
2001-05-13 07:26:57 +05:30
|
|
|
#
|
|
|
|
#---------------------------------------------------------------------
|
|
|
|
def redraw(self):
|
|
|
|
if len(self.bookmarks) > 0:
|
|
|
|
self.myMenu = gtk.GtkMenu()
|
|
|
|
for person in self.bookmarks:
|
2001-08-31 09:10:23 +05:30
|
|
|
self.add_to_menu(person)
|
2001-05-13 07:26:57 +05:30
|
|
|
self.menu.set_submenu(self.myMenu)
|
|
|
|
self.menu.set_sensitive(1)
|
|
|
|
else:
|
|
|
|
self.menu.remove_submenu()
|
|
|
|
self.menu.set_sensitive(0)
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------
|
|
|
|
#
|
2001-08-31 09:10:23 +05:30
|
|
|
# add - adds the person to the bookmarks, appended to the botom
|
2001-05-13 07:26:57 +05:30
|
|
|
#
|
|
|
|
#---------------------------------------------------------------------
|
|
|
|
def add(self,person):
|
|
|
|
if person not in self.bookmarks:
|
|
|
|
utils.modified()
|
|
|
|
self.bookmarks.append(person)
|
2001-09-02 03:42:09 +05:30
|
|
|
self.redraw()
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
#---------------------------------------------------------------------
|
|
|
|
#
|
2001-08-31 09:10:23 +05:30
|
|
|
# add_to_menu - adds a person's name to the drop down menu
|
|
|
|
#
|
|
|
|
#---------------------------------------------------------------------
|
2001-09-01 22:43:15 +05:30
|
|
|
def add_to_menu(self,person):
|
2001-08-31 09:10:23 +05:30
|
|
|
item = gtk.GtkMenuItem(person.getPrimaryName().getName())
|
|
|
|
item.connect("activate", self.callback, person)
|
|
|
|
item.show()
|
|
|
|
self.myMenu.append(item)
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# edit - display the bookmark editor.
|
2001-05-13 07:26:57 +05:30
|
|
|
#
|
2001-08-31 09:10:23 +05:30
|
|
|
# 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.
|
2001-05-13 07:26:57 +05:30
|
|
|
#
|
|
|
|
#---------------------------------------------------------------------
|
|
|
|
def edit(self):
|
|
|
|
top = libglade.GladeXML(const.bookFile,TOPINST)
|
|
|
|
namelist = top.get_widget(NAMEINST)
|
|
|
|
self.index = 0
|
2001-08-31 09:10:23 +05:30
|
|
|
for person in self.bookmarks:
|
|
|
|
namelist.append([person.getPrimaryName().getName()])
|
|
|
|
namelist.set_row_data(self.index,person)
|
2001-05-13 07:26:57 +05:30
|
|
|
self.index = self.index + 1
|
|
|
|
|
|
|
|
if self.index > 0:
|
|
|
|
namelist.select_row(0,0)
|
|
|
|
namelist.set_data(INDEX,0)
|
|
|
|
else:
|
|
|
|
namelist.set_data(INDEX,-1)
|
|
|
|
namelist.set_data(ROWS,self.index)
|
|
|
|
|
|
|
|
top.signal_autoconnect({
|
|
|
|
"on_ok_clicked" : on_ok_clicked,
|
|
|
|
"on_down_clicked" : on_down_clicked,
|
|
|
|
"on_up_clicked" : on_up_clicked,
|
|
|
|
"on_namelist_select_row" : on_namelist_select_row,
|
|
|
|
"on_delete_clicked" : on_delete_clicked,
|
|
|
|
"on_cancel_clicked" : on_cancel_clicked
|
|
|
|
})
|
|
|
|
|
|
|
|
topBox = top.get_widget(TOPINST)
|
|
|
|
topBox.set_data(OBJECT,self)
|
|
|
|
topBox.set_data(NAMEINST,namelist)
|
|
|
|
topBox.show()
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2001-08-31 09:10:23 +05:30
|
|
|
# on_namelist_select_row - changes the selected row stored on the namelist
|
|
|
|
# to the row that was just selected.
|
2001-05-13 07:26:57 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def on_namelist_select_row(obj,row,junk,junk2):
|
|
|
|
obj.set_data(INDEX,row)
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2001-08-31 09:10:23 +05:30
|
|
|
# on_delete_clicked - gets the selected row and number of rows that have
|
|
|
|
# been attached to the namelist. If the selected row is greater than 0,
|
|
|
|
# then the row is deleted from the list. The number of rows is then
|
|
|
|
# decremented.
|
2001-05-13 07:26:57 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def on_delete_clicked(obj):
|
|
|
|
index = obj.get_data(INDEX)
|
|
|
|
rows = obj.get_data(ROWS)
|
|
|
|
if index >= 0:
|
|
|
|
obj.remove(index)
|
|
|
|
obj.set_data(ROWS,rows-1)
|
|
|
|
if index != 0:
|
|
|
|
obj.select_row(0,0)
|
|
|
|
else:
|
|
|
|
obj.unselect_all()
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2001-08-31 09:10:23 +05:30
|
|
|
# on_up_clicked - swap rows if the selected row is greater than 0
|
2001-05-13 07:26:57 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def on_up_clicked(obj):
|
|
|
|
index = obj.get_data(INDEX)
|
|
|
|
if index > 0:
|
|
|
|
obj.swap_rows(index-1,index)
|
|
|
|
obj.set_data(INDEX,index-1)
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2001-08-31 09:10:23 +05:30
|
|
|
# on_down_clicked - swap rows if the selected index is not the last index
|
2001-05-13 07:26:57 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def on_down_clicked(obj):
|
|
|
|
index = obj.get_data(INDEX)
|
|
|
|
rows = obj.get_data(ROWS)
|
|
|
|
if index != rows-1:
|
|
|
|
obj.swap_rows(index+1,index)
|
|
|
|
obj.set_data(INDEX,index+1)
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2001-08-31 09:10:23 +05:30
|
|
|
# on_ok_clicked - loop through the name list, extracting the attached
|
|
|
|
# person from list, and building up the new bookmark list. The menu is
|
|
|
|
# then redrawn.
|
2001-05-13 07:26:57 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def on_ok_clicked(obj):
|
2001-08-31 09:10:23 +05:30
|
|
|
bkmarks = obj.get_data(OBJECT)
|
2001-05-13 07:26:57 +05:30
|
|
|
namelist = obj.get_data(NAMEINST)
|
2001-08-31 09:10:23 +05:30
|
|
|
del bkmarks.bookmarks[0:]
|
2001-05-13 07:26:57 +05:30
|
|
|
|
2001-08-31 09:10:23 +05:30
|
|
|
for index in range(0,bkmarks.index):
|
2001-05-13 07:26:57 +05:30
|
|
|
person = namelist.get_row_data(index)
|
2001-08-31 09:10:23 +05:30
|
|
|
if person:
|
|
|
|
bkmarks.bookmarks.append(person)
|
|
|
|
|
|
|
|
bkmarks.redraw()
|
2001-05-13 07:26:57 +05:30
|
|
|
obj.destroy()
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2001-08-31 09:10:23 +05:30
|
|
|
# on_cancel_clicked - destroy the bookmark editor
|
2001-05-13 07:26:57 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def on_cancel_clicked(obj):
|
|
|
|
obj.destroy()
|
|
|
|
|
|
|
|
|
|
|
|
|