* src/ChooseParents.py: removed

* src/ListBox.py: removed


svn: r5885
This commit is contained in:
Don Allingham 2006-02-05 05:19:51 +00:00
parent 11ec0429f6
commit b7577dc19a
10 changed files with 331 additions and 3916 deletions

View File

@ -1,4 +1,6 @@
2006-02-04 Don Allingham <don@gramps-project.org> 2006-02-04 Don Allingham <don@gramps-project.org>
* src/ChooseParents.py: removed
* src/ListBox.py: removed
* src/TransTable.py: removed * src/TransTable.py: removed
* src/AddSpouse.py: removed * src/AddSpouse.py: removed
* src/Marriage.py: removed * src/Marriage.py: removed

View File

@ -1,876 +0,0 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 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$
"""
ChooseParents interface allows users to select the paretns of an
individual.
"""
__author__ = "Donald N. Allingham"
__version__ = "$Revision$"
#-------------------------------------------------------------------------
#
# internationalization
#
#-------------------------------------------------------------------------
from gettext import gettext as _
import gc
#-------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
import logging
log = logging.getLogger(".")
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
import gtk.glade
import gtk.gdk
import gobject
#-------------------------------------------------------------------------
#
# gramps modules
#
#-------------------------------------------------------------------------
import GrampsDisplay
import RelLib
import const
import Utils
import PeopleModel
import NameDisplay
import DateHandler
import GenericFilter
import AutoComp
from QuestionDialog import ErrorDialog, WarningDialog
from WindowUtils import GladeIf
#-------------------------------------------------------------------------
#
# Constants
#
#-------------------------------------------------------------------------
UNKNOWN_REL = (RelLib.Person.CHILD_UNKNOWN,
Utils.child_relations[RelLib.Person.CHILD_UNKNOWN])
BIRTH_REL = (RelLib.Person.CHILD_BIRTH,
Utils.child_relations[RelLib.Person.CHILD_BIRTH])
MARRIED_REL = (RelLib.Family.MARRIED,
Utils.family_relations[RelLib.Family.MARRIED])
FAM_UNKNOWN_REL = (RelLib.Family.UNKNOWN,
Utils.family_relations[RelLib.Family.UNKNOWN])
CIVIL_UNION_REL = (RelLib.Family.CIVIL_UNION,
Utils.family_relations[RelLib.Family.CIVIL_UNION])
#-------------------------------------------------------------------------
#
# ChooseParents
#
#-------------------------------------------------------------------------
class ChooseParents:
"""
Displays the Choose Parents dialog box, allowing the parents
to be edited.
"""
def __init__(self,parent,db,person,family):
"""
Creates a ChoosePerson dialog box.
db - database associated the person
person - person whose parents we are selecting
family - current family
"""
self.parent = parent
self.db = db
self.child_windows = {}
self.person = self.db.get_person_from_handle(person.get_handle())
if family:
self.family = self.db.get_family_from_handle(family.get_handle())
else:
self.family = None
self.old_type = MARRIED_REL
self.type = MARRIED_REL
self.parent_selected = 0
self.renderer = gtk.CellRendererText()
self.sig_keys = [
db.connect('person-add', self.person_added),
db.connect('person-update', self.redraw),
db.connect('person-delete', self.redraw),
db.connect('person-rebuild', self.redraw_all)]
# set default filters
self.all_males_filter = GenericFilter.GenericFilter()
self.all_males_filter.add_rule(GenericFilter.IsMale([]))
self.all_females_filter = GenericFilter.GenericFilter()
self.all_females_filter.add_rule(GenericFilter.IsFemale([]))
bev = self.db.get_event_from_handle(person.birth_handle)
if bev and bev.date and bev.date.sortval != 0:
self.likely_females_filter = self.build_likely(False)
self.likely_males_filter = self.build_likely(True)
else:
self.likely_males_filter = self.all_males_filter
self.likely_females_filter = self.all_females_filter
self.father_filter = self.likely_males_filter
self.mother_filter = self.likely_females_filter
if self.family:
self.father = self.family.get_father_handle()
self.mother = self.family.get_mother_handle()
else:
self.mother = None
self.father = None
self.glade = gtk.glade.XML(const.gladeFile,"familyDialog","gramps")
self.gladeif = GladeIf(self.glade)
self.window = self.glade.get_widget("familyDialog")
self.flabel = self.glade.get_widget("flabel")
self.mlabel = self.glade.get_widget("mlabel")
self.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
self.mlabel.set_label("<i>%s</i>" % _("Loading..."))
self.flabel.set_label("<i>%s</i>" % _("Loading..."))
name = NameDisplay.displayer.display(self.person)
self.title_text = _("Choose the Parents of %s") % name
Utils.set_titles(self.window,self.glade.get_widget('title'),
self.title_text,_('Choose Parents'))
self.mcombo = self.glade.get_widget("mcombo")
self.fcombo = self.glade.get_widget("fcombo")
self.prel = self.glade.get_widget("prel_combo")
self.title = self.glade.get_widget("chooseTitle")
self.father_list = self.glade.get_widget("father_list")
self.mother_list = self.glade.get_widget("mother_list")
self.showallf = self.glade.get_widget('showallf')
self.showallm = self.glade.get_widget('showallm')
self.add_itself_to_menu()
gobject.idle_add(self.draw_list)
if gtk.gdk.screen_height() > 700:
self.father_list.set_size_request(-1,150)
self.mother_list.set_size_request(-1,150)
for (f,mr,fr) in self.person.get_parent_family_handle_list():
if f == self.family:
mrel = mr
frel = fr
break
else:
mrel = BIRTH_REL
frel = BIRTH_REL
if self.family:
self.type = self.family.get_relationship()
else:
self.type = MARRIED_REL
self.prel_selector = AutoComp.StandardCustomSelector(
Utils.family_relations,self.prel,
RelLib.Family.CUSTOM,RelLib.Family.MARRIED)
self.prel_selector.set_values(self.type)
self.redrawm()
self.gladeif.connect('familyDialog','delete_event', self.on_delete_event)
self.gladeif.connect('button44','clicked', self.close)
self.gladeif.connect('button42','clicked', self.save_parents_clicked)
self.gladeif.connect('button167','clicked', self.on_help_clicked)
self.gladeif.connect('button123','clicked', self.add_parent_clicked)
self.gladeif.connect('showallf','toggled', self.showallf_toggled)
self.gladeif.connect('prel_combo','changed', self.parent_relation_changed)
self.frel_selector = AutoComp.StandardCustomSelector(
Utils.child_relations,self.fcombo,
RelLib.Person.CHILD_CUSTOM,RelLib.Person.CHILD_BIRTH)
self.mrel_selector = AutoComp.StandardCustomSelector(
Utils.child_relations,self.mcombo,
RelLib.Person.CHILD_CUSTOM,RelLib.Person.CHILD_BIRTH)
self.frel_selector.set_values(frel)
self.mrel_selector.set_values(mrel)
# self.keys = const.child_rel_list
# self.build_list(self.mcombo,mrel)
# self.build_list(self.fcombo,frel)
self.window.show()
def draw_list(self):
self.build_father_list()
self.build_mother_list()
self.window.window.set_cursor(None)
def build_likely(self,is_male):
filt = GenericFilter.GenericFilter()
if is_male:
filt.add_rule(LikelyFather([self.person.handle]))
else:
filt.add_rule(LikelyMother([self.person.handle]))
return filt
def build_likely2(self,is_male):
birth_ref = self.person.get_birth_ref()
filt = GenericFilter.GenericFilter()
if is_male:
filt.add_rule(GenericFilter.IsMale([]))
else:
filt.add_rule(GenericFilter.IsFemale([]))
if birth_ref:
birth = self.db.get_event_from_handle(birth_ref.ref)
date_obj = RelLib.Date(birth.get_date_object())
year = date_obj.get_year()
if year:
date_obj.set_year(year-10)
date_obj.set_modifier(RelLib.Date.MOD_BEFORE)
rule = GenericFilter.HasBirth(
[DateHandler.displayer.display(date_obj),"",""])
filt.add_rule(rule)
date_obj = RelLib.Date(birth.get_date_object())
date_obj.set_year(year-60)
date_obj.set_modifier(RelLib.Date.MOD_AFTER)
rule = GenericFilter.HasBirth(
[DateHandler.displayer.display(date_obj),"",""])
filt.add_rule(rule)
return filt
def build_father_list(self):
self.father_selection = self.father_list.get_selection()
self.father_selection.connect('changed',self.father_list_select_row)
self.add_columns(self.father_list)
self.redrawf()
def build_mother_list(self):
self.mother_selection = self.mother_list.get_selection()
self.mother_selection.connect('changed',self.mother_list_select_row)
self.add_columns(self.mother_list)
self.redrawm()
def add_columns(self,tree):
column = gtk.TreeViewColumn(_('Name'), self.renderer,text=0)
column.set_resizable(True)
column.set_clickable(True)
column.set_sort_column_id(0)
column.set_fixed_width(255)
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
tree.append_column(column)
column = gtk.TreeViewColumn(_('ID'), self.renderer,text=1)
column.set_resizable(True)
column.set_clickable(True)
column.set_sort_column_id(1)
column.set_fixed_width(75)
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
#column.set_min_width(75)
tree.append_column(column)
column = gtk.TreeViewColumn(_('Birth date'), self.renderer,text=3)
#column.set_resizable(True)
column.set_clickable(True)
column.set_fixed_width(150)
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
tree.append_column(column)
def on_delete_event(self,obj,b):
self.gladeif.close()
self.remove_itself_from_menu()
self.close_child_windows()
gc.collect()
def close(self,obj):
self.gladeif.close()
self.remove_itself_from_menu()
self.close_child_windows()
self.window.destroy()
gc.collect()
def close_child_windows(self):
for child_window in self.child_windows.values():
child_window.close()
self.child_windows = {}
def add_itself_to_menu(self):
self.parent.child_windows[self] = self
self.win_menu_item = gtk.MenuItem(self.title_text)
self.win_menu_item.set_submenu(gtk.Menu())
self.win_menu_item.show()
self.parent.winsmenu.append(self.win_menu_item)
self.winsmenu = self.win_menu_item.get_submenu()
self.menu_item = gtk.MenuItem(_('Choose Parents'))
self.menu_item.connect("activate",self.present)
self.menu_item.show()
self.winsmenu.append(self.menu_item)
def remove_itself_from_menu(self):
del self.parent.child_windows[self]
self.menu_item.destroy()
self.winsmenu.destroy()
self.win_menu_item.destroy()
def present(self,obj):
self.window.present()
def on_help_clicked(self,obj):
"""Display the relevant portion of GRAMPS manual"""
GrampsDisplay.help('gramps-edit-quick')
def person_added(self,handle_list):
update_father = False
update_mother = False
for handle in handle_list:
person = self.db.get_person_from_handle(handle)
if person.get_gender() == RelLib.Person.MALE:
update_father = True
elif person.get_gender() == RelLib.Person.FEMALE:
update_mother = True
if update_father:
self.person_added_base(handle_list,self.father_model,
self.father_filter)
if update_mother:
self.person_added_base(handle_list,self.mother_model,
self.mother_filter)
def person_added_base(self,handle_list,model,data_filter):
for node in handle_list:
person = self.db.get_person_from_handle(node)
top = person.get_primary_name().get_group_name()
model.rebuild_data(data_filter)
if not model.is_visable(node):
continue
if (not model.sname_sub.has_key(top) or
len(model.sname_sub[top]) == 1):
path = model.on_get_path(top)
pnode = model.get_iter(path)
model.row_inserted(path,pnode)
path = model.on_get_path(node)
pnode = model.get_iter(path)
model.row_inserted(path,pnode)
def redraw(self,handle_list):
self.redrawf()
self.redrawm()
def redraw_all(self):
self.redrawf()
self.redrawm()
def redrawf(self):
"""Redraws the potential father list"""
self.father_model = PeopleModel.PeopleModel(self.db,self.father_filter)
self.father_list.set_model(self.father_model)
if self.type[0] == RelLib.Family.CIVIL_UNION:
self.flabel.set_label("<b>%s</b>" % _("Par_ent"))
else:
self.flabel.set_label("<b>%s</b>" % _("Fath_er"))
def redrawm(self):
"""Redraws the potential mother list"""
self.mother_model = PeopleModel.PeopleModel(self.db,self.mother_filter)
self.mother_list.set_model(self.mother_model)
if self.type[0] == RelLib.Family.CIVIL_UNION:
self.mlabel.set_label("<b>%s</b>" % _("Pa_rent"))
else:
self.mlabel.set_label("<b>%s</b>" % _("Mothe_r"))
def parent_relation_changed(self,obj):
"""Called everytime the parent relationship information is changed"""
self.old_type = self.type
self.type = self.prel_selector.get_values()
if (self.old_type[0] == RelLib.Family.CIVIL_UNION or
self.type[0] == RelLib.Family.CIVIL_UNION):
self.redrawf()
self.redrawm()
def showallf_toggled(self,obj):
if self.father_filter == self.likely_males_filter:
self.father_filter = self.all_males_filter
else:
self.father_filter = self.likely_males_filter
self.redrawf()
def showallm_toggled(self,obj):
if self.mother_filter == self.likely_females_filter:
self.mother_filter = self.all_females_filter
else:
self.mother_filter = self.likely_females_filter
self.redrawm()
def find_family(self,father_handle,mother_handle):
"""
Finds the family associated with the father and mother.
If one does not exist, it is created.
"""
if not father_handle and not mother_handle:
return None
for family_handle in self.db.get_family_handles():
family = self.db.get_family_from_handle(family_handle)
if (family.get_father_handle() == father_handle and
family.get_mother_handle() == mother_handle):
family.add_child_handle(self.person.get_handle())
return family
elif (family.get_father_handle() == mother_handle and
family.get_mother_handle() == father_handle):
family.add_child_handle(self.person.get_handle())
return family
family = RelLib.Family()
family.set_father_handle(father_handle)
family.set_mother_handle(mother_handle)
family.add_child_handle(self.person.get_handle())
family.set_handle(self.db.create_id())
family.set_gramps_id(self.db.find_next_family_gramps_id())
if father_handle:
self.father = self.db.get_person_from_handle(father_handle)
self.father.add_family_handle(family.get_handle())
if mother_handle:
self.mother = self.db.get_person_from_handle(mother_handle)
self.mother.add_family_handle(family.get_handle())
return family
def father_select_function(self,store,path,iter,id_list):
if len(path) != 1:
val = self.father_model.get_value(iter,PeopleModel.COLUMN_INT_ID)
id_list.append(val)
def mother_select_function(self,store,path,iter,id_list):
if len(path) != 1:
val = self.mother_model.get_value(iter,PeopleModel.COLUMN_INT_ID)
id_list.append(val)
def get_selected_father_handles(self):
mlist = []
self.father_selection.selected_foreach(self.father_select_function,
mlist)
return mlist
def get_selected_mother_handles(self):
mlist = []
self.mother_selection.selected_foreach(self.mother_select_function,
mlist)
return mlist
def father_list_select_row(self,obj):
"""Called when a row is selected in the father list. Sets the
active father based off the id associated with the row."""
idlist = self.get_selected_father_handles()
if idlist and idlist[0]:
self.father = self.db.get_person_from_handle(idlist[0])
else:
self.father = None
if not self.parent_selected and self.father:
self.parent_selected = 1
family_handle_list = self.father.get_family_handle_list()
if len(family_handle_list) >= 1:
family = self.db.get_family_from_handle(family_handle_list[0])
handle = family.get_mother_handle()
mother = self.db.get_person_from_handle(handle)
sname = mother.get_primary_name().get_surname()
tpath = self.mother_model.on_get_path(sname)
self.mother_list.expand_row(tpath,0)
path = self.mother_model.on_get_path(handle)
self.mother_selection.select_path(path)
self.mother_list.scroll_to_cell(path,None,1,0.5,0)
def mother_list_select_row(self,obj):
"""Called when a row is selected in the father list. Sets the
active father based off the id associated with the row."""
idlist = self.get_selected_mother_handles()
if idlist and idlist[0]:
self.mother = self.db.get_person_from_handle(idlist[0])
else:
self.mother = None
if not self.parent_selected and self.mother:
self.parent_selected = 1
family_handle_list = self.mother.get_family_handle_list()
if len(family_handle_list) >= 1:
family = self.db.get_family_from_handle(family_handle_list[0])
handle = family.get_father_handle()
father = self.db.get_person_from_handle(handle)
sname = father.get_primary_name().get_surname()
tpath = self.father_model.on_get_path(sname)
self.father_list.expand_row(tpath,0)
path = self.father_model.on_get_path(handle)
self.father_selection.select_path(path)
self.father_list.scroll_to_cell(path,None,1,0.5,0)
def save_parents_clicked(self,obj):
"""
Called with the OK button is pressed. Saves the selected people
as parents of the main person.
"""
for key in self.sig_keys:
self.db.disconnect(key)
try:
mother_rel = self.mrel_selector.get_values()
except KeyError:
mother_rel = BIRTH_REL
try:
father_rel = self.frel_selector.get_values()
except KeyError:
father_rel = BIRTH_REL
trans = self.db.transaction_begin()
father_handle = None
mother_handle = None
if self.father or self.mother:
if self.mother and not self.father:
if self.mother.get_gender() == RelLib.Person.MALE:
self.father = self.mother
father_handle = self.father.get_handle()
self.mother = None
else:
mother_handle = self.mother.get_handle()
elif self.father and not self.mother:
if self.father.get_gender() == RelLib.Person.FEMALE:
self.mother = self.father
self.father = None
mother_handle = self.mother.get_handle()
else:
father_handle = self.father.get_handle()
elif self.mother.get_gender() != self.father.get_gender():
if self.type[0] == RelLib.Family.CIVIL_UNION:
self.type = FAM_UNKNOWN_REL
if self.father.get_gender() == RelLib.Person.FEMALE:
self.father, self.mother = self.mother, self.father
father_handle = self.father.get_handle()
mother_handle = self.mother.get_handle()
else:
self.type = CIVIL_UNION_REL
father_handle = self.father.get_handle()
mother_handle = self.mother.get_handle()
if self.person.get_handle() in (father_handle,mother_handle):
ErrorDialog(_("Error selecting a child"),
_("A person cannot be linked as his/her own parent"),
self.window)
return
if father_handle or mother_handle:
self.family = self.find_family(father_handle,mother_handle)
self.family.add_child_handle(self.person.get_handle())
self.family.set_relationship(self.type)
self.change_family_type(self.family,mother_rel,father_rel,trans)
self.db.commit_person(self.person,trans)
if self.father:
self.db.commit_person(self.father,trans)
if self.mother:
self.db.commit_person(self.mother,trans)
self.db.commit_family(self.family,trans)
else:
self.family = None
self.db.transaction_commit(trans,_("Choose Parents"))
self.close(None)
def add_new_parent(self,epo,val):
"""Adds a new person to either the father list or the mother list,
depending on the gender of the person."""
person = epo.person
handle = person.get_handle()
name = person.get_primary_name().get_surname()
self.type = self.prel_selector.get_values()
if self.type[0] == RelLib.Family.CIVIL_UNION:
self.parent_relation_changed(self.prel)
elif person.get_gender() == RelLib.Person.MALE:
try:
path = self.father_model.on_get_path(handle)
top_path = self.father_model.on_get_path(name)
self.father_list.expand_row(top_path,0)
self.father_selection.select_path(path)
self.father_list.scroll_to_cell(path,None,1,0.5,0)
except KeyError:
self.father_filter = self.all_males_filter
self.redrawf()
path = self.father_model.on_get_path(handle)
top_path = self.father_model.on_get_path(name)
self.father_list.expand_row(top_path,0)
self.father_selection.select_path(path)
self.father_list.scroll_to_cell(path,None,1,0.5,0)
else:
try:
path = self.mother_model.on_get_path(handle)
top_path = self.mother_model.on_get_path(name)
self.mother_list.expand_row(top_path,0)
self.mother_selection.select_path(path)
self.mother_list.scroll_to_cell(path,None,1,0.5,0)
except:
self.mother_filter = self.all_females_filter
self.redrawm()
path = self.mother_model.on_get_path(handle)
top_path = self.mother_model.on_get_path(name)
self.mother_list.expand_row(top_path,0)
self.mother_selection.select_path(path)
self.mother_list.scroll_to_cell(path,None,1,0.5,0)
def add_parent_clicked(self,obj):
"""Called with the Add New Person button is pressed. Calls the QuickAdd
class to create a new person."""
person = RelLib.Person()
person.set_gender(RelLib.Person.UNKNOWN)
try:
import EditPerson
EditPerson.EditPerson(self, person,self.db,self.add_new_parent)
except:
log.error("Failed to add parent",exc_info=True)
def change_family_type(self,family,mother_rel,father_rel,trans):
"""
Changes the family type of the specified family. If the family
is None, the the relationship type shoud be deleted.
"""
family_handle = family.get_handle()
if self.person.get_handle() not in family.get_child_handle_list():
family.add_child_handle(self.person.get_handle())
for fam in self.person.get_parent_family_handle_list():
if family_handle == fam[0]:
if mother_rel == fam[1] and father_rel == fam[2]:
return
if mother_rel != fam[1] or father_rel != fam[2]:
self.person.remove_parent_family_handle(family_handle)
self.person.add_parent_family_handle(family_handle,
mother_rel,father_rel)
break
else:
self.person.add_parent_family_handle(family_handle,
mother_rel,father_rel)
#-------------------------------------------------------------------------
#
# ModifyParents
#
#-------------------------------------------------------------------------
class ModifyParents:
def __init__(self, db, person, family_handle, parent_window=None):
"""
Creates a ChoosePerson dialog box.
db - database associated the person
person - person whose parents we are selecting
family - current family
"""
self.db = db
self.person = person
self.family = self.db.get_family_from_handle(family_handle)
fid = self.family.get_father_handle()
mid = self.family.get_mother_handle()
self.father = self.db.get_person_from_handle(fid)
self.mother = self.db.get_person_from_handle(mid)
self.glade = gtk.glade.XML(const.gladeFile,"modparents","gramps")
self.gladeif = GladeIf(self.glade)
self.window = self.glade.get_widget("modparents")
self.title = self.glade.get_widget("title")
name = NameDisplay.displayer.display(self.person)
title = _("Modify the Parents of %s") % name
Utils.set_titles(self.window, self.title, title, _("Modify Parents"))
self.mother_rel = self.glade.get_widget("mrel")
self.father_rel = self.glade.get_widget("frel")
self.flabel = self.glade.get_widget("flabel")
self.mlabel = self.glade.get_widget("mlabel")
self.fcombo = self.glade.get_widget('fcombo')
self.mcombo = self.glade.get_widget('mcombo')
self.orig_mrel = BIRTH_REL
self.orig_frel = BIRTH_REL
for (f,mr,fr) in self.person.get_parent_family_handle_list():
if f == self.family.get_handle():
self.orig_mrel = mr
self.orig_frel = fr
self.gladeif.connect('button165','clicked', self.on_help_clicked)
self.title.set_use_markup(True)
if self.family.get_relationship() == RelLib.Family.CIVIL_UNION:
self.mlabel.set_label("<b>%s</b>" % _("Pa_rent"))
self.flabel.set_label("<b>%s</b>" % _("Par_ent"))
else:
self.mlabel.set_label('<b>%s</b>' % _("Mother"))
self.flabel.set_label('<b>%s</b>' % _("Father"))
if self.father:
fname = NameDisplay.displayer.display(self.father)
self.glade.get_widget("fname").set_text(fname)
else:
self.fcombo.set_sensitive(False)
if self.mother:
mname = NameDisplay.displayer.display(self.mother)
self.glade.get_widget("mname").set_text(mname)
else:
self.mcombo.set_sensitive(False)
self.pref = self.glade.get_widget('preferred')
if len(self.person.get_parent_family_handle_list()) > 1:
self.glade.get_widget('pref_label').show()
self.pref.show()
if self.family == self.person.get_parent_family_handle_list()[0]:
self.pref.set_active(True)
else:
self.pref.set_active(False)
if parent_window:
self.window.set_transient_for(parent_window)
if self.db.readonly:
self.fcombo.set_sensitive(False)
self.mcombo.set_sensitive(False)
self.glade.get_widget('ok').set_sensitive(False)
self.frel_selector = AutoComp.StandardCustomSelector(
Utils.child_relations,self.fcombo,
RelLib.Person.CHILD_CUSTOM,RelLib.Person.CHILD_BIRTH)
self.frel_selector.set_values(self.orig_frel)
self.mrel_selector = AutoComp.StandardCustomSelector(
Utils.child_relations,self.mcombo,
RelLib.Person.CHILD_CUSTOM,RelLib.Person.CHILD_BIRTH)
self.mrel_selector.set_values(self.orig_mrel)
self.val = self.window.run()
if self.val == gtk.RESPONSE_OK:
self.save_parents_clicked()
self.gladeif.close()
self.window.destroy()
gc.collect()
def on_help_clicked(self,obj):
"""Display the relevant portion of GRAMPS manual"""
GrampsDisplay.help('gramps-spec-par')
self.val = self.window.run()
def save_parents_clicked(self):
"""
Called with the OK button nis pressed. Saves the selected people
as parents of the main person.
"""
mother_rel = self.mrel_selector.get_values()
father_rel = self.frel_selector.get_values()
mod = False
fhandle = self.family.get_handle()
if mother_rel != self.orig_mrel or father_rel != self.orig_frel:
self.person.remove_parent_family_handle(fhandle)
self.person.add_parent_family_handle(fhandle,mother_rel,father_rel)
mod = True
if len(self.person.get_parent_family_handle_list()):
make_pref = self.pref.get_active()
plist = self.person.get_parent_family_handle_list()
if make_pref:
if self.family != plist[0]:
self.person.set_main_parent_family_handle(fhandle)
mod = True
else:
if self.family == plist[0]:
self.person.set_main_parent_family_handle(plist[0])
mod = True
if mod:
trans = self.db.transaction_begin()
self.db.commit_person(self.person,trans)
self.db.transaction_commit(trans,_("Modify Parents"))
#-------------------------------------------------------------------------
#
# Likely Filters
#
#-------------------------------------------------------------------------
class LikelyFilter(GenericFilter.Rule):
labels = [ 'Person handle' ]
category = _('General filters')
def __init__(self,data_list,gender):
GenericFilter.Rule.__init__(self,data_list)
self.gender = gender
def prepare(self,db):
person = db.get_person_from_handle(self.list[0])
birth = db.get_event_from_handle(person.birth_handle)
dateobj = Date.Date(birth.date)
year = dateobj.get_year()
dateobj.set_year(year-10)
self.lower = dateobj.sortval
dateobj.set_year(year-70)
self.upper = dateobj.sortval
def apply(self,db,person):
if person.gender != self.gender:
return False
if not person.birth_handle:
return True
event = db.get_event_from_handle(person.birth_handle)
return (event.date == None or event.date.sortval == 0 or
self.lower > event.date.sortval > self.upper)
class LikelyFather(LikelyFilter):
name = _('Likely Father')
description = _('Matches likely fathersn')
def __init__(self,data_list):
LikelyFilter.__init__(self,data_list,RelLib.Person.MALE)
class LikelyMother(LikelyFilter):
name = _('Likely Mother')
description = _('Matches likely mothers')
def __init__(self,data_list):
LikelyFilter.__init__(self,data_list,RelLib.Person.FEMALE)

View File

@ -54,6 +54,7 @@ import Utils
import GrampsMime import GrampsMime
import const import const
import ImgManip import ImgManip
import Spell
from DdTargets import DdTargets from DdTargets import DdTargets
from GrampsWidgets import SimpleButton from GrampsWidgets import SimpleButton
@ -937,6 +938,7 @@ class NoteTab(GrampsTab):
else: else:
self.flowed.set_active(True) self.flowed.set_active(True)
self.text.set_wrap_mode(gtk.WRAP_WORD) self.text.set_wrap_mode(gtk.WRAP_WORD)
self.spellcheck = Spell.Spell(self.text)
self.flowed.connect('toggled',self.flow_changed) self.flowed.connect('toggled',self.flow_changed)
@ -968,7 +970,9 @@ class NoteTab(GrampsTab):
def update(self,obj): def update(self,obj):
if self.note_obj: if self.note_obj:
text = self.buf.get_text(self.buf.get_start_iter(),self.buf.get_end_iter()) start = self.buf.get_start_iter()
stop = self.buf.get_end_iter()
text = self.buf.get_text(start,stop)
self.note_obj.set(text) self.note_obj.set(text)
else: else:
print "NOTE OBJ DOES NOT EXIST" print "NOTE OBJ DOES NOT EXIST"

View File

@ -751,46 +751,11 @@ class EditPerson(DisplayState.ManagedWindow):
self.pname.set_first_name(unicode(self.given.get_text())) self.pname.set_first_name(unicode(self.given.get_text()))
self.pname.set_title(unicode(self.title.get_text())) self.pname.set_title(unicode(self.title.get_text()))
NameEdit.NameEditor(self.dbstate, self.uistate, self.track, self.pname, self) NameEdit.NameEditor(self.dbstate, self.uistate, self.track,
self.pname, self)
def update_name(self,name): def update_name(self,name):
self.write_primary_name() self.write_primary_name()
# def on_ldsbap_source_clicked(self,obj):
# Sources.SourceSelector(self.dbstate, self.uistate, self.track,
# self.lds_baptism.get_source_references(),
# self,self.update_ldsbap_list)
# def update_ldsbap_list(self,list):
# self.lds_baptism.set_source_reference_list(list)
# def on_ldsbap_note_clicked(self,obj):
# NoteEdit.NoteEditor(self.lds_baptism,self,self.window,
# readonly=self.db.readonly)
# def on_ldsendow_source_clicked(self,obj):
# Sources.SourceSelector(self.dbstate, self.uistate, self.track,
# self.lds_endowment.get_source_references(),
# self,self.set_ldsendow_list)
# def set_ldsendow_list(self,list):
# self.lds_endowment.set_source_reference_list(list)
# def on_ldsendow_note_clicked(self,obj):
# NoteEdit.NoteEditor(self.lds_endowment,self,self.window,
# readonly=self.db.readonly)
# def on_ldsseal_source_clicked(self,obj):
# Sources.SourceSelector(self.dbstate, self.uistate, self.track,
# self.lds_sealing.get_source_references(),
# self,self.lds_seal_list)
# def lds_seal_list(self,list):
# self.lds_sealing.set_source_reference_list(list)
# def on_ldsseal_note_clicked(self,obj):
# NoteEdit.NoteEditor(self.lds_sealing,self,self.window,
# readonly=self.db.readonly)
def load_person_image(self): def load_person_image(self):
media_list = self.person.get_media_list() media_list = self.person.get_media_list()

View File

@ -221,14 +221,14 @@ class EditPlace(DisplayState.ManagedWindow):
DisplayState.ManagedWindow.__init__(self, uistate, track, place) DisplayState.ManagedWindow.__init__(self, uistate, track, place)
self.sourcetab = Sources.SourceTab( # self.sourcetab = Sources.SourceTab(
self.dbstate, self.uistate, self.track, # self.dbstate, self.uistate, self.track,
self.srcreflist,self, # self.srcreflist,self,
self.top,self.window,self.slist, # self.top,self.window,self.slist,
self.top.get_widget('add_src'), # self.top.get_widget('add_src'),
self.top.get_widget('edit_src'), # self.top.get_widget('edit_src'),
self.top.get_widget('del_src'), # self.top.get_widget('del_src'),
self.dbstate.db.readonly) # self.dbstate.db.readonly)
if self.place.get_handle() == None or self.dbstate.db.readonly: if self.place.get_handle() == None or self.dbstate.db.readonly:
self.top.get_widget("add_photo").set_sensitive(0) self.top.get_widget("add_photo").set_sensitive(0)

View File

@ -206,7 +206,6 @@ class EventEditor(DisplayState.ManagedWindow):
""" """
Creates the notebook tabs and inserts them into the main Creates the notebook tabs and inserts them into the main
window. window.
""" """
vbox = self.top.get_widget('vbox') vbox = self.top.get_widget('vbox')
self.notebook = gtk.Notebook() self.notebook = gtk.Notebook()
@ -357,7 +356,6 @@ class EventEditor(DisplayState.ManagedWindow):
data.union(self.db.get_person_event_types()) data.union(self.db.get_person_event_types())
return list(data) return list(data)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# EventRefEditor class # EventRefEditor class
@ -394,31 +392,17 @@ class EventRefEditor(DisplayState.ManagedWindow):
self.place_field = self.top.get_widget("eer_place") self.place_field = self.top.get_widget("eer_place")
self.cause_field = self.top.get_widget("eer_cause") self.cause_field = self.top.get_widget("eer_cause")
self.slist = self.top.get_widget("eer_slist")
self.wlist = self.top.get_widget("eer_wlist")
self.date_field = self.top.get_widget("eer_date") self.date_field = self.top.get_widget("eer_date")
self.descr_field = self.top.get_widget("eer_description") self.descr_field = self.top.get_widget("eer_description")
self.ev_note_field = self.top.get_widget("eer_ev_note") self.ev_note_field = self.top.get_widget("eer_ev_note")
self.type_combo = self.top.get_widget("eer_type_combo") self.type_combo = self.top.get_widget("eer_type_combo")
self.ev_privacy = self.top.get_widget("eer_ev_priv") self.ev_privacy = self.top.get_widget("eer_ev_priv")
self.sources_label = self.top.get_widget("eer_sources_tab")
self.notes_label = self.top.get_widget("eer_note_tab")
self.general_label = self.top.get_widget("eer_general_tab") self.general_label = self.top.get_widget("eer_general_tab")
self.gallery_label = self.top.get_widget("eer_gallery_tab")
self.witnesses_label = self.top.get_widget("eer_witness_tab")
self.flowed = self.top.get_widget("eer_ev_flowed")
self.preform = self.top.get_widget("eer_ev_preform")
self.ok = self.top.get_widget('ok') self.ok = self.top.get_widget('ok')
self.expander = self.top.get_widget("eer_expander") self.expander = self.top.get_widget("eer_expander")
self.warning = self.top.get_widget("eer_warning") self.warning = self.top.get_widget("eer_warning")
self.notebook = self.top.get_widget('notebook')
add_src = self.top.get_widget('eer_add_src')
del_src = self.top.get_widget('eer_del_src')
add_witness = self.top.get_widget('eer_add_wit')
edit_witness = self.top.get_widget('eer_edit_wit')
del_witness = self.top.get_widget('eer_del_wit')
Utils.set_titles(self.window, Utils.set_titles(self.window,
self.top.get_widget('eer_title'), self.top.get_widget('eer_title'),
self.title) self.title)
@ -476,13 +460,6 @@ class EventRefEditor(DisplayState.ManagedWindow):
self.event_ref.set_role((default_role,role_dict[default_role])) self.event_ref.set_role((default_role,role_dict[default_role]))
self.event_ref.set_reference_handle(self.event.get_handle()) self.event_ref.set_reference_handle(self.event.get_handle())
self.srcreflist = self.event.get_source_references()
self.sourcetab = Sources.SourceTab(
self.state, self.uistate, self.track,
self.srcreflist, self, self.top, self.window, self.slist,
add_src, self.top.get_widget('eer_edit_src'), del_src,
self.db.readonly)
self.date_check = DateEdit.DateEdit(self.date, self.date_check = DateEdit.DateEdit(self.date,
self.date_field, self.date_field,
self.top.get_widget("eer_date_stat"), self.top.get_widget("eer_date_stat"),
@ -505,18 +482,33 @@ class EventRefEditor(DisplayState.ManagedWindow):
self.cause_field.set_text(self.event.get_cause()) self.cause_field.set_text(self.event.get_cause())
self.descr_field.set_text(self.event.get_description()) self.descr_field.set_text(self.event.get_description())
self.ev_privacy.set_active(self.event.get_privacy()) self.ev_privacy.set_active(self.event.get_privacy())
if self.event.get_note():
self.ev_note_field.get_buffer().set_text(event.get_note()) self._create_tabbed_pages()
Utils.bold_label(self.notes_label)
if event.get_note_format() == 1:
self.preform.set_active(1)
else:
self.flowed.set_active(1)
if self.event.get_media_list():
Utils.bold_label(self.gallery_label)
self.show() self.show()
def _add_page(self,page):
self.notebook.insert_page(page)
self.notebook.set_tab_label(page,page.get_tab_widget())
return page
def _create_tabbed_pages(self):
"""
Creates the notebook tabs and inserts them into the main
window.
"""
self.srcref_list = self._add_page(SourceEmbedList(
self.state,self.uistate, self.track,
self.event.source_list))
self.note_tab = self._add_page(NoteTab(
self.state, self.uistate, self.track,
self.event.get_note_object()))
self.gallery_tab = self._add_page(GalleryTab(
self.state, self.uistate, self.track,
self.event.get_media_list()))
def build_menu_names(self,eventref): def build_menu_names(self,eventref):
if self.event: if self.event:
if self.event.get_type()[0] == RelLib.Event.CUSTOM: if self.event.get_type()[0] == RelLib.Event.CUSTOM:

View File

@ -138,12 +138,12 @@ class LocalMediaProperties:
else: else:
self.srcreflist = [] self.srcreflist = []
self.sourcetab = Sources.SourceTab(self.srcreflist,self, # self.sourcetab = Sources.SourceTab(self.srcreflist,self,
self.change_dialog, # self.change_dialog,
self.window, self.slist, # self.window, self.slist,
self.change_dialog.get_widget('add_src'), # self.change_dialog.get_widget('add_src'),
self.change_dialog.get_widget('edit_src'), # self.change_dialog.get_widget('edit_src'),
self.change_dialog.get_widget('del_src')) # self.change_dialog.get_widget('del_src'))
descr_window.set_text(self.obj.get_description()) descr_window.set_text(self.obj.get_description())
mtype = self.obj.get_mime_type() mtype = self.obj.get_mime_type()

View File

@ -1,628 +0,0 @@
#
# 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
#
#-------------------------------------------------------------------------
from gettext import gettext as _
import cPickle as pickle
from sets import Set
import locale
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
import gtk
import gtk.gdk
#-------------------------------------------------------------------------
#
# gramps modules
#
#-------------------------------------------------------------------------
from ListModel import ListModel, NOSORT, COMBO, TEXT, TOGGLE
from DdTargets import DdTargets
import const
import RelLib
import UrlEdit
import NameEdit
import NoteEdit
import AttrEdit
import EventEdit
import AddrEdit
import NameDisplay
import Utils
import DateHandler
class ListBox:
"""
The ListBox manages the lists contained by the EditPerson or Marriage
dialogs. It manages the add, update, and delete buttons, along with the
handling of inline editing.
The primary argument is either Person or Family object.
"""
def __init__(self, state, uistate, track,
primary, obj, label, button_list, titles):
self.primary = primary
if self.primary.__class__.__name__ == 'Person':
self.name = NameDisplay.displayer.display(primary)
elif self.primary.__class__.__name__ == 'Family':
self.name = Utils.family_name(primary,state.db)
else:
self.name = ""
self.label = label
self.db = state.db
self.state = state
self.uistate = uistate
self.track = track
self.list_model = ListModel(
obj, titles, self.select_row, self.update)
self.blist = button_list
self.node_map = {}
self.tree = obj
self.changed = False
self.blist[0].connect('clicked',self.add)
self.blist[1].connect('clicked',self.update)
self.blist[2].connect('clicked',self.delete)
if len(self.blist) > 3:
self.blist[3].connect('clicked',self.select)
self.tree.connect('key_press_event', self.keypress)
self.change_list = Set()
def build_maps(self,custom,string_map):
name_map = {}
val_map = string_map
for key in val_map.keys():
val = val_map[key]
name_map[val] = key
return (name_map,val_map)
def keypress(self,obj,event):
if event.keyval == 65379:
print "insert"
def get_changed_objects(self):
return list(self.change_list)
def add_object(self,item):
self.data.append(item)
self.change_list.add(item)
def select_row(self,obj):
store, node = obj.get_selected()
enable = node != None
for button in self.blist[1:3]:
button.set_sensitive(enable)
def delete(self,obj):
"""Delete the selected event"""
if Utils.delete_selected(obj,self.data):
self.changed = True
self.redraw()
def update(self,obj):
raise NotImplementedError
def redraw(self):
self.list_model.clear()
self.node_map = {}
for item in self.data:
node = self.list_model.add(self.display_data(item),item)
self.node_map[item] = node
if self.data:
self.list_model.select_row(0)
self.set_label()
def display_data(self,item):
raise NotImplementedError
def delete(self,obj):
"""Deletes the selected name from the name list"""
store,node = self.list_model.get_selected()
if node:
self.data.remove(self.list_model.get_object(node))
self.list_model.remove(node)
self.changed = True
self.redraw()
def edit_callback(self,data):
self.changed = True
self.change_list.add(data)
if data not in self.data:
self.data.append(data)
self.redraw()
try:
self.list_model.select_iter(self.node_map[data])
except:
print "Edit callback failed"
def set_label(self):
if self.data:
self.list_model.select_row(0)
Utils.bold_label(self.label)
self.blist[1].set_sensitive(True)
self.blist[2].set_sensitive(True)
else:
Utils.unbold_label(self.label)
self.blist[1].set_sensitive(False)
self.blist[2].set_sensitive(False)
class ReorderListBox(ListBox):
def __init__(self,state,uistate,track,
primary,obj,label,button_list,evalues, dnd_type):
ListBox.__init__(self,state,uistate,track,
primary,obj,label,button_list,evalues)
self.dnd_type = dnd_type
obj.drag_dest_set(gtk.DEST_DEFAULT_ALL, [dnd_type.target()],
gtk.gdk.ACTION_COPY)
obj.drag_source_set(gtk.gdk.BUTTON1_MASK, [dnd_type.target()],
gtk.gdk.ACTION_COPY)
obj.connect('drag_data_get', self.drag_data_get)
obj.connect('drag_data_received',self.drag_data_received)
def drag_data_get(self,widget, context, sel_data, info, time):
node = self.list_model.get_selected_objects()
bits_per = 8; # we're going to pass a string
pickled = pickle.dumps(node[0]);
data = str((self.dnd_type.drag_type, self.primary.get_handle(), pickled));
sel_data.set(sel_data.target, bits_per, data)
def unpickle(self, data):
self.data.insert(pickle.loads(data))
def drag_data_received(self,widget,context,x,y,sel_data,info,time):
row = self.list_model.get_row_at(x,y)
if sel_data and sel_data.data:
exec 'data = %s' % sel_data.data
exec 'mytype = "%s"' % data[0]
exec 'primary = "%s"' % data[1]
if mytype != self.dnd_type.drag_type:
return
elif primary == self.primary.get_handle():
self.move_element(self.list_model.get_selected_row(),row)
else:
self.unpickle(data[2])
self.changed = True
self.redraw()
def move_element(self,src,dest):
if src != -1:
obj = self.data[src]
self.data.remove(obj)
self.data.insert(dest,obj)
class AttrListBox(ReorderListBox):
def __init__(self, state, uistate, track,
primary, obj, label, button_list):
if primary.__class__.__name__ == 'Person':
self.attr_dict = Utils.personal_attributes
elif primary.__class__.__name__ == 'Family':
self.attr_dict = Utils.family_attributes
custom_str = self.attr_dict[RelLib.Attribute.CUSTOM]
attrlist = filter(lambda x: x != custom_str,
self.attr_dict.values())
attrlist.sort(locale.strcoll)
titles = [
# Title Sort Col, Size, Type
(_('Attribute'), NOSORT, 200, COMBO, attrlist, self.set_type),
(_('Value'), NOSORT, 350, TEXT, None, self.set_value),
(_('Source'), NOSORT, 50, TOGGLE, None, None),
(_('Note'), NOSORT, 50, TOGGLE, None, None),
]
self.data = primary.get_attribute_list()[:]
ListBox.__init__(self, state, uistate, track,
primary, obj, label,
button_list, titles)
self.attr_name_map,self.attr_val_map = self.build_maps(
RelLib.Attribute.CUSTOM,self.attr_dict)
def set_type(self,index,value):
val = self.attr_name_map.get(value,RelLib.Attribute.CUSTOM)
if val == RelLib.Attribute.CUSTOM:
self.data[index].set_type((val,value))
else:
self.data[index].set_type((val,self.attr_val_map[val]))
self.change_list.add(self.data[index])
def set_value(self,index,value):
self.data[index].set_value(value)
def add(self,obj):
"""Brings up the AttributeEditor for a new attribute"""
AttrEdit.AttributeEditor(self.state, self.uistate, self.track,
None, self.name, self.attr_dict,
self.edit_callback)
def update(self,obj):
store,node = self.list_model.get_selected()
if node:
attr = self.list_model.get_object(node)
AttrEdit.AttributeEditor(self.state, self.uistate, self.track,
attr, self.name, self.attr_dict,
self.edit_callback)
def display_data(self,attr):
has_note = attr.get_note()
has_source = len(attr.get_source_references())> 0
etype = attr.get_type()
if etype[0] == RelLib.Attribute.CUSTOM \
or not self.attr_dict.has_key(etype[0]):
name = etype[1]
else:
name = self.attr_dict[etype[0]]
return [name, attr.get_value(), has_source, has_note]
class EventListBox(ReorderListBox):
titles = ['Event', 'Description','Date','Place','Source','Note']
def __init__(self,state,uistate,track,primary,obj,label,button_list):
self.data = []
self.primary = primary
self.state = state
self.uistate = uistate
if self.primary.__class__.__name__ == 'Person':
birth_ref = primary.get_birth_ref()
death_ref = primary.get_death_ref()
if birth_ref:
self.data.append(
(birth_ref,state.db.get_event_from_handle(birth_ref.ref)))
if death_ref:
self.data.append(
(death_ref,
state.db.get_event_from_handle(death_ref.ref))
)
self.ev_dict = Utils.personal_events
self.role_dict = Utils.event_roles
elif self.primary.__class__.__name__ == 'Family':
self.ev_dict = Utils.family_events
self.role_dict = Utils.family_event_roles
for event_ref in primary.get_event_ref_list():
self.data.append((event_ref,
state.db.get_event_from_handle(event_ref.ref)))
ev_custom_str = self.ev_dict[RelLib.Event.CUSTOM]
eventnames = filter(lambda x: x != ev_custom_str,
self.ev_dict.values())
eventnames.sort(locale.strcoll)
role_custom_str = self.role_dict[RelLib.EventRef.CUSTOM]
rolenames = filter(lambda x: x != role_custom_str,
self.role_dict.values())
self.place_dict = {}
for handle in self.state.db.get_place_handles():
title = self.state.db.get_place_from_handle(handle).get_title()
self.place_dict[title] = handle
placenames = self.place_dict.keys()
placenames.sort(locale.strcoll)
evalues = [
# Title Sort Col Size, Type Argument
(_('Event'), NOSORT, 100, COMBO, eventnames,self.set_type),
(_('Description'), NOSORT, 140, TEXT, None,self.set_description),
(_('Date'), NOSORT, 100, TEXT, None, self.set_date),
(_('Place'), NOSORT, 100, TEXT, None, self.set_place),
(_('Role'), NOSORT, 100, COMBO, rolenames, self.set_role),
(_('Source'), NOSORT, 50, TOGGLE, None, None),
(_('Note'), NOSORT, 50, TOGGLE, None, None),
]
ReorderListBox.__init__(self, state, uistate, track,
primary, obj, label,
button_list, evalues, DdTargets.EVENT)
self.ev_name_map,self.ev_val_map = self.build_maps(
RelLib.Event.CUSTOM,self.ev_dict)
self.ref_name_map,self.ref_val_map = self.build_maps(
RelLib.EventRef.CUSTOM,self.role_dict)
def set_type(self,index,value):
val = self.ev_name_map.get(value,RelLib.Event.CUSTOM)
if val == RelLib.Event.CUSTOM:
self.data[index][1].set_type((val,value))
else:
self.data[index][1].set_type((val,self.ev_val_map[val]))
self.change_list.add(self.data[index])
def set_role(self,index,value):
val = self.ref_name_map.get(value,RelLib.EventRef.CUSTOM)
if val == RelLib.EventRef.CUSTOM:
self.data[index][0].set_role((val,value))
else:
self.data[index][0].set_role((val,self.ref_val_map[val]))
self.change_list.add(self.data[index])
def set_description(self,index,value):
self.data[index][1].set_description(value)
self.change_list.add(self.data[index])
def set_place(self,index,value):
if not value.strip():
return
handle = self.place_dict.get(value,None)
if handle:
place = self.state.db.get_place_from_handle(handle)
else:
place = RelLib.Place()
place.set_title(value)
trans = self.state.db.transaction_begin()
self.state.db.add_place(place,trans)
self.state.db.transaction_commit(trans,_("Add Place"))
handle = place.get_handle()
self.data[index][1].set_place_handle(handle)
self.change_list.add(self.data[index])
def set_date(self,index,value):
DateHandler.set_date(self.data[index][1],value)
self.change_list.add(self.data[index])
def add(self,obj):
"""Brings up the EventEditor for a new event"""
EventEdit.EventRefEditor(self.state,self.uistate,self.track,
None,None,self.primary,self.edit_callback)
def select(self,obj):
"""
Creates eventref for an existing event.
"""
# select existing event
import SelectEvent
sel_event = SelectEvent.SelectEvent(self.state.db,_('Select Event'))
event = sel_event.run()
if event:
EventEdit.EventRefEditor(self.state,self.uistate,self.track,
event,None,self.primary,
self.edit_callback)
def update(self,obj):
store,node = self.list_model.get_selected()
if not node:
return
event_ref,event = self.list_model.get_object(node)
EventEdit.EventRefEditor(self.state,self.uistate,self.track,
event,event_ref,self.primary,
self.edit_callback)
def display_data(self,event_tuple):
(event_ref, event) = event_tuple
pid = event.get_place_handle()
if pid:
pname = self.db.get_place_from_handle(pid).get_title()
else:
pname = u''
has_note = event.get_note()
has_source = len(event.get_source_references())> 0
etype = event.get_type()
if etype[0] == RelLib.Event.CUSTOM \
or not self.ev_dict.has_key(etype[0]):
name = etype[1]
else:
name = self.ev_dict[etype[0]]
ref_role = event_ref.get_role()
if ref_role[0] == RelLib.EventRef.CUSTOM \
or not self.role_dict.has_key(ref_role[0]):
role = ref_role[1]
else:
role = self.role_dict[ref_role[0]]
return [name, event.get_description(), DateHandler.get_date(event),
pname, role, has_source, has_note]
class NameListBox(ReorderListBox):
def __init__(self, state, uistate, track, person, obj, label, button_list):
surnames = state.db.get_surname_list()
custom_str = Utils.name_types[RelLib.Name.CUSTOM]
types = filter(lambda x: x != custom_str, Utils.name_types.values())
types.sort(locale.strcoll)
titles = [
# Title Sort Col Size, Type
(_('Family Name'), NOSORT, 180, COMBO, surnames, self.set_name),
(_('Prefix'), NOSORT, 50, TEXT, None, self.set_prefix),
(_('Given Name'), NOSORT, 200, TEXT, None, self.set_given),
(_('Suffix'), NOSORT, 50, TEXT, None, self.set_suffix),
(_('Type'), NOSORT, 150, COMBO, types, self.set_type),
(_('Source'), NOSORT, 50, TOGGLE, None, None),
(_('Note'), NOSORT, 50, TOGGLE, None, None),
]
self.data = person.get_alternate_names()[:]
ReorderListBox.__init__(self, state, uistate, track,
person, obj, label,
button_list, titles, DdTargets.NAME)
self.name_name_map,self.name_val_map = self.build_maps(
RelLib.Name.CUSTOM,Utils.name_types)
def set_type(self,index,value):
val = self.name_name_map.get(value,RelLib.Name.CUSTOM)
if val == RelLib.Name.CUSTOM:
self.data[index].set_type((val,value))
else:
self.data[index].set_type((val,self.name_val_map[val]))
self.change_list.add(self.data[index])
def set_name(self,index,value):
self.data[index].set_surname(value)
def set_prefix(self,index,value):
self.data[index].set_surname_prefix(value)
def set_given(self,index,value):
self.data[index].set_first_name(value)
def set_suffix(self,index,value):
self.data[index].set_suffix(value)
def add(self,obj):
NameEdit.NameEditor(self.state, self.uistate, self.track,
None, self.edit_callback)
def update(self,obj):
store,node = self.list_model.get_selected()
if node:
NameEdit.NameEditor(self.state, self.uistate, self.track,
self.list_model.get_object(node),
self.edit_callback)
def display_data(self,name):
has_note = name.get_note()
has_source = len(name.get_source_references())> 0
the_type = name.get_type()
if the_type[0] == RelLib.Name.CUSTOM or \
not Utils.name_types.has_key(the_type[0]):
type_name = the_type[1]
else:
type_name = Utils.name_types[the_type[0]]
return [name.get_surname(),name.get_surname_prefix(),
name.get_first_name(), name.get_suffix(),
type_name,has_source,has_note]
def unpickle(self, data):
foo = pickle.loads(data);
for src in foo.get_source_references():
base_handle = src.get_base_handle()
newbase = self.db.get_source_from_handle(base_handle)
src.set_base_handle(newbase.get_handle())
self.data.insert(row,foo)
class AddressListBox(ReorderListBox):
def __init__(self,state,uistate,track,person,obj,label,button_list):
titles = [
# Title Sort Col Size, Type
(_('Date'), NOSORT, 175, TEXT, None, self.set_date),
(_('Address'), NOSORT, 150, TEXT, None, self.set_addr),
(_('City'), NOSORT, 100, TEXT, None, self.set_city),
(_('State/Province'),NOSORT, 75, TEXT, None, self.set_state),
(_('Country'), NOSORT, 100, TEXT, None, self.set_country),
(_('Source'), NOSORT, 50, TOGGLE, None, None),
(_('Note'), NOSORT, 50, TOGGLE, None, None),
]
self.data = person.get_address_list()[:]
ReorderListBox.__init__(self, state, uistate, track,
person, obj, label,
button_list, titles, DdTargets.ADDRESS)
def set_date(self,index,value):
DateHandler.set_date(self.data[index],value)
def set_addr(self,index,value):
self.data[index].set_street(value)
def set_city(self,index,value):
self.data[index].set_city(value)
def set_state(self,index,value):
self.data[index].set_state(value)
def set_country(self,index,value):
self.data[index].set_country(value)
def add(self,obj):
AddrEdit.AddressEditor(self.state, self.uistate, self.track, None,
self.edit_callback)
def update(self,obj):
store,node = self.list_model.get_selected()
if node:
item = self.list_model.get_object(node)
AddrEdit.AddressEditor(self.state, self.uistate, self.track, item,
self.edit_callback)
def display_data(self,item):
has_note = item.get_note()
has_source = len(item.get_source_references())> 0
return [DateHandler.get_date(item),item.get_street(),
item.get_city(), item.get_state(),
item.get_country(), has_source,has_note]
def unpickle(self,data):
foo = pickle.loads(data);
for src in foo.get_source_references():
base_handle = src.get_base_handle()
newbase = self.db.get_source_from_handle(base_handle)
src.set_base_handle(newbase.get_handle())
self.data.insert(row,foo)
class UrlListBox(ReorderListBox):
def __init__(self,state,uistate,track,person,obj,label,button_list):
titles = [
# Title Sort Col Size, Type
(_('Path'), NOSORT, 250, TEXT, None, self.set_path),
(_('Description'), NOSORT, 100, TEXT, None, self.set_description),
]
self.data = person.get_url_list()[:]
ReorderListBox.__init__(self, state, uistate, track,
person, obj, label,
button_list, titles, DdTargets.URL)
def set_path(self,index,value):
self.data[index].set_path(value)
def set_description(self,index,value):
self.data[index].set_description(value)
def add(self,obj):
UrlEdit.UrlEditor(self.state, self.uistate, self.track,
self.name, None, self.edit_callback)
def update(self,obj):
store,node = self.list_model.get_selected()
if node:
UrlEdit.UrlEditor(self.state, self.uistate, self.track,
self.name,
self.list_model.get_object(node),
self.edit_callback)
def display_data(self,url):
return [url.get_path(), url.get_description()]

View File

@ -55,283 +55,6 @@ import DisplayState
from DdTargets import DdTargets from DdTargets import DdTargets
from WindowUtils import GladeIf from WindowUtils import GladeIf
#-------------------------------------------------------------------------
#
# SourceSelector
#
#-------------------------------------------------------------------------
class SourceSelector(DisplayState.ManagedWindow):
def __init__(self,state,uistate,track,srclist,parent,update=None):
self.db = state.db
self.state = state
self.uistate = uistate
self.track = track
if srclist:
win_key = id(srclist)
else:
win_key = self
submenu_label = _('Source')
DisplayState.ManagedWindow.__init__(
self, uistate, self.track, win_key, submenu_label,
_('Source Selector'))
self.orig = srclist
self.list = []
for s in self.orig:
self.list.append(RelLib.SourceRef(s))
self.update=update
self.top = gtk.glade.XML(const.gladeFile,"sourcesel","gramps")
self.gladeif = GladeIf(self.top)
self.window = self.top.get_widget("sourcesel")
Utils.set_titles(self.window, self.top.get_widget('title'),
_('Source Reference Selection'))
self.gladeif.connect('sourcesel', 'delete_event', self.on_delete_event)
self.gladeif.connect('button138','clicked', self.close)
self.gladeif.connect('ok', 'clicked', self.src_ok_clicked)
self.gladeif.connect('button145', 'clicked', self.on_help_clicked)
self.gladeif.connect('add', 'clicked', self.add_src_clicked)
self.gladeif.connect('edit', 'clicked', self.edit_src_clicked)
self.gladeif.connect('delete', 'clicked', self.del_src_clicked)
self.slist = self.top.get_widget("slist")
self.edit = self.top.get_widget('edit')
self.delete = self.top.get_widget('delete')
self.delete.set_sensitive(not self.db.readonly)
self.selection = self.slist.get_selection()
self.model = gtk.ListStore(str,str)
self.slist.set_model(self.model)
self.top.get_widget('add').set_sensitive(not self.db.readonly)
self.top.get_widget('ok').set_sensitive(not self.db.readonly)
colno = 0
for title in [ (_('ID'),0,100), (_('Title'),1,150)]:
renderer = gtk.CellRendererText ()
renderer.set_fixed_height_from_font(1)
column = gtk.TreeViewColumn (title[0], renderer, text=colno)
colno += 1
column.set_clickable (True)
column.set_resizable(True)
column.set_sort_column_id(title[1])
column.set_min_width(title[2])
self.slist.append_column (column)
self.selection.connect('changed',self.selection_changed)
self.delete.set_sensitive(False)
self.edit.set_sensitive(False)
self.redraw()
if self.parent:
self.window.set_transient_for(self.parent.window)
self.add_itself_to_menu()
self.window.show()
def on_delete_event(self,obj,b):
self.gladeif.close()
gc.collect()
def close(self,obj):
self.gladeif.close()
self.window.destroy()
gc.collect()
def on_help_clicked(self,obj):
"""Display the relevant portion of GRAMPS manual"""
GrampsDisplay.help('gramps-edit-complete')
def selection_changed(self,obj):
(store,node) = self.selection.get_selected()
if node:
self.delete.set_sensitive(True)
self.edit.set_sensitive(True)
else:
self.delete.set_sensitive(False)
self.edit.set_sensitive(False)
def redraw(self):
self.model.clear()
for s in self.list:
base_handle = s.get_base_handle()
base = self.db.get_source_from_handle(base_handle)
node = self.model.append()
self.model.set(node,0,base.get_gramps_id(),1,base.get_title())
def src_ok_clicked(self,obj):
del self.orig[:]
for s in self.list:
self.orig.append(s)
if self.update:
self.update(self.orig)
self.close(obj)
def edit_src_clicked(self,obj):
store,node = self.selection.get_selected()
if node:
col = store.get_path(node)
src = self.list[col[0]]
SourceEditor(src,self.db,self.update_clist,self)
def update_clist(self,inst,ref):
inst.redraw()
def add_src_clicked(self,obj):
src = RelLib.SourceRef()
SourceEditor(src,self.db,self.add_ref,self)
def del_src_clicked(self,obj):
(store,node) = self.selection.get_selected()
if node:
path = store.get_path(node)
del self.list[path[0]]
self.redraw()
def add_ref(self,inst,ref):
self.parent.lists_changed = 1
inst.list.append(ref)
inst.redraw()
#-------------------------------------------------------------------------
#
# SourceTab
#
#-------------------------------------------------------------------------
class SourceTab:
def __init__(self, state, uistate, track, srclist, parent, top, window,
clist, add_btn, edit_btn, del_btn, readonly=False):
self.db = state.db
self.state = state
self.uistate = uistate
self.track = track
self.parent = parent
self.list = srclist
self.top = top
self.window = window
self.slist = clist
self.selection = clist.get_selection()
self.model = gtk.ListStore(str,str,object)
self.readonly = readonly
add_btn.set_sensitive(not readonly)
del_btn.set_sensitive(not readonly)
colno = 0
for title in [ (_('ID'),0,100), (_('Title'),1,150)]:
renderer = gtk.CellRendererText ()
column = gtk.TreeViewColumn (title[0], renderer, text=colno)
colno = colno + 1
column.set_clickable (True)
column.set_resizable(True)
column.set_sort_column_id(title[1])
column.set_min_width(title[2])
self.slist.append_column (column)
self.slist.set_model(self.model)
add_btn.connect('clicked', self.add_src_clicked)
edit_btn.connect('clicked', self.edit_src_clicked)
del_btn.connect('clicked', self.del_src_clicked)
self.slist.connect('button-press-event',self.double_click)
self.setup_drag_n_drop()
self.redraw()
def setup_drag_n_drop(self):
self.slist.drag_dest_set(gtk.DEST_DEFAULT_ALL,
[DdTargets.SOURCEREF.target()],
ACTION_COPY)
self.slist.drag_source_set(BUTTON1_MASK,
[DdTargets.SOURCEREF.target()],
ACTION_COPY)
self.slist.connect('drag_data_get', self.drag_data_get)
self.slist.connect('drag_begin', self.drag_begin)
if not self.readonly:
self.slist.connect('drag_data_received',self.drag_data_received)
def drag_data_received(self,widget,context,x,y,sel_data,info,time):
if self.db.readonly or self.readonly: # no DnD on readonly database
return
if sel_data and sel_data.data:
exec 'data = %s' % sel_data.data
exec 'mytype = "%s"' % data[0]
exec 'person = "%s"' % data[1]
if mytype != DdTargets.SOURCEREF.drag_type:
return
else:
foo = pickle.loads(data[2]);
self.list.append(foo)
self.lists_changed = True
self.redraw()
def drag_data_get(self,widget, context, sel_data, info, time):
store,node = self.selection.get_selected()
if not node:
return
ev = store.get_value(node,2)
bits_per = 8; # we're going to pass a string
pickled = pickle.dumps(ev);
data = str((DdTargets.SOURCEREF.drag_type,None,pickled));
sel_data.set(sel_data.target, bits_per, data)
def drag_begin(self, context, a):
return
def double_click(self,obj,event):
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
self.edit_src_clicked(obj)
def redraw(self):
self.model.clear()
for s in self.list:
base_handle = s.get_base_handle()
node = self.model.append()
base = self.db.get_source_from_handle(base_handle)
self.model.set(node,0,base.get_gramps_id(),1,base.get_title(),
2,s)
if self.list:
Utils.bold_label(self.parent.sources_label)
else:
Utils.unbold_label(self.parent.sources_label)
def update_clist(self,inst,ref):
inst.redraw()
self.parent.lists_changed = 1
def add_ref(self,inst,ref):
self.parent.lists_changed = 1
inst.list.append(ref)
inst.redraw()
def edit_src_clicked(self,obj):
store,node = self.selection.get_selected()
if node:
col = store.get_path(node)
src = self.list[col[0]]
SourceEditor(self.state, self.uistate, self.track,
src, self.update_clist)
def add_src_clicked(self,obj):
src = RelLib.SourceRef()
SourceEditor(self.state, self.uistate, self.track, src, self.add_ref)
def del_src_clicked(self,obj):
(store,node) = self.selection.get_selected()
if node:
path = store.get_path(node)
del self.list[path[0]]
self.parent.lists_changed = 1
self.redraw()
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# SourceEditor # SourceEditor

File diff suppressed because it is too large Load Diff