Choose spouse if not defined

svn: r873
This commit is contained in:
Don Allingham 2002-03-29 03:40:17 +00:00
parent 34f671b0d3
commit aa73aed965
3 changed files with 309 additions and 2 deletions

View File

@ -187,3 +187,132 @@ class AddSpouse:
index = index + 1
self.spouse_list.thaw()
class SetSpouse:
"""
Displays the AddSpouse dialog, allowing the user to create a new
family with the passed person as one spouse, and another person to
be selected.
"""
def __init__(self,db,person,family,update,addperson):
"""
Displays the AddSpouse dialog box.
db - database to which to add the new family
person - the current person, will be one of the parents
update - function that updates the family display
addperson - function that adds a person to the person view
"""
self.db = db
self.update = update
self.person = person
self.family = family
self.addperson = addperson
self.glade = libglade.GladeXML(const.gladeFile, "spouseDialog")
self.rel_combo = self.glade.get_widget("rel_combo")
self.relation_type = self.glade.get_widget("rel_type")
self.spouse_list = self.glade.get_widget("spouseList")
self.relation_def = self.glade.get_widget("reldef")
self.top = self.glade.get_widget("spouseDialog")
self.name_list = self.db.getPersonMap().values()
self.name_list.sort(sort.by_last_name)
self.rel_combo.set_popdown_strings(const.familyRelations)
title = _("Choose Spouse/Partner of %s") % GrampsCfg.nameof(person)
self.glade.get_widget("spouseTitle").set_text(title)
self.glade.signal_autoconnect({
"on_select_spouse_clicked" : self.select_spouse_clicked,
"on_new_spouse_clicked" : self.new_spouse_clicked,
"on_rel_type_changed" : self.relation_type_changed,
"on_combo_insert_text" : Utils.combo_insert_text,
"destroy_passed_object" : Utils.destroy_passed_object
})
self.relation_type.set_text(_("Married"))
def new_spouse_clicked(self,obj):
"""
Called when the spouse to be added does not exist, and needs
to be created and added to the database
"""
import QuickAdd
relation = const.save_frel(self.relation_type.get_text())
if relation == "Partners":
if self.person.getGender() == RelLib.Person.male:
gen = "male"
else:
gen = "female"
elif self.person.getGender() == RelLib.Person.male:
gen = "female"
else:
gen = "male"
QuickAdd.QuickAdd(self.db,gen,self.update_list)
def update_list(self,person):
self.name_list.append(person)
self.name_list.sort(sort.by_last_name)
self.addperson(person)
self.relation_type_changed(self.relation_type)
def select_spouse_clicked(self,obj):
"""
Called when the spouse to be added already exists and has been
selected from the list.
"""
if len(self.spouse_list.selection) == 0:
return
row = self.spouse_list.selection[0]
spouse = self.spouse_list.get_row_data(row)
# don't do anything if the marriage already exists
for f in self.person.getFamilyList():
if spouse == f.getMother() or spouse == f.getFather():
Utils.destroy_passed_object(obj)
return
Utils.modified()
if self.family.getFather() == self.person:
self.family.setMother(spouse)
else:
self.family.setFather(spouse)
spouse.addFamily(self.family)
self.family.setRelationship(const.save_frel(self.relation_type.get_text()))
Utils.destroy_passed_object(obj)
self.update(self.family)
def relation_type_changed(self,obj):
"""
Called whenever the relationship type changes. Rebuilds the
the potential spouse list.
"""
text = obj.get_text()
self.relation_def.set_text(const.relationship_def(text))
# determine the gender of the people to be loaded into
# the potential spouse list. If Partners is selected, use
# the same gender as the current person.
gender = self.person.getGender()
if text == _("Partners"):
if gender == RelLib.Person.male:
gender = RelLib.Person.female
else:
gender = RelLib.Person.male
index = 0
self.spouse_list.clear()
self.spouse_list.freeze()
for person in self.name_list:
if person.getGender() == gender:
continue
name = person.getPrimaryName().getName()
self.spouse_list.append([name,Utils.birthday(person)])
self.spouse_list.set_row_data(index,person)
index = index + 1
self.spouse_list.thaw()

View File

@ -7394,4 +7394,159 @@ Unknown
</widget>
</widget>
<widget>
<class>GnomeDialog</class>
<name>add_or_new</name>
<title>Question - GRAMPS</title>
<type>GTK_WINDOW_TOPLEVEL</type>
<position>GTK_WIN_POS_NONE</position>
<modal>False</modal>
<allow_shrink>False</allow_shrink>
<allow_grow>False</allow_grow>
<auto_shrink>False</auto_shrink>
<auto_close>False</auto_close>
<hide_on_close>False</hide_on_close>
<widget>
<class>GtkVBox</class>
<child_name>GnomeDialog:vbox</child_name>
<name>dialog-vbox14</name>
<homogeneous>False</homogeneous>
<spacing>8</spacing>
<child>
<padding>4</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkHButtonBox</class>
<child_name>GnomeDialog:action_area</child_name>
<name>dialog-action_area14</name>
<layout_style>GTK_BUTTONBOX_END</layout_style>
<spacing>8</spacing>
<child_min_width>85</child_min_width>
<child_min_height>27</child_min_height>
<child_ipad_x>7</child_ipad_x>
<child_ipad_y>0</child_ipad_y>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>True</fill>
<pack>GTK_PACK_END</pack>
</child>
<widget>
<class>GtkButton</class>
<name>button150</name>
<can_default>True</can_default>
<can_focus>True</can_focus>
<signal>
<name>clicked</name>
<handler>on_add_clicked</handler>
<last_modification_time>Fri, 29 Mar 2002 03:16:22 GMT</last_modification_time>
</signal>
<label>Choose Spouse</label>
</widget>
<widget>
<class>GtkButton</class>
<name>button151</name>
<can_default>True</can_default>
<can_focus>True</can_focus>
<signal>
<name>clicked</name>
<handler>on_new_clicked</handler>
<last_modification_time>Fri, 29 Mar 2002 03:16:11 GMT</last_modification_time>
</signal>
<label>New Relationship</label>
</widget>
<widget>
<class>GtkButton</class>
<name>button152</name>
<can_default>True</can_default>
<can_focus>True</can_focus>
<signal>
<name>clicked</name>
<handler>on_cancel_clicked</handler>
<last_modification_time>Fri, 29 Mar 2002 03:16:42 GMT</last_modification_time>
</signal>
<stock_button>GNOME_STOCK_BUTTON_CANCEL</stock_button>
</widget>
</widget>
<widget>
<class>GtkVBox</class>
<name>vbox53</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkLabel</class>
<name>label306</name>
<label>Add a Spouse or Create a New Relationhip</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>10</xpad>
<ypad>10</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkHSeparator</class>
<name>hseparator25</name>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
</widget>
<widget>
<class>GtkHBox</class>
<name>hbox77</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
<widget>
<class>GtkLabel</class>
<name>label305</name>
<label>No spouse has been defined for the current relationship.
You can either define the spouse of the current relationship
or create a new relationship.</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>5</xpad>
<ypad>10</ypad>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
</widget>
</widget>
</widget>
</widget>
</widget>
</GTK-Interface>

View File

@ -452,12 +452,35 @@ class Gramps:
else:
self.active_family = None
def add_new_cancel(self,obj):
Utils.destroy_passed_object(self.addornew)
def add_new_new_relationship(self,obj):
import AddSpouse
Utils.destroy_passed_object(self.addornew)
AddSpouse.AddSpouse(self.database,self.active_person,
self.load_family,self.redisplay_person_list)
def on_add_sp_clicked(self,obj):
"""Add a new spouse to the current person"""
import AddSpouse
if self.active_person:
AddSpouse.AddSpouse(self.database,self.active_person,
self.load_family,self.redisplay_person_list)
if self.active_family and not self.active_spouse:
top = libglade.GladeXML(const.gladeFile, "add_or_new")
top.signal_autoconnect({
'on_cancel_clicked' : self.add_new_cancel,
'on_add_clicked' : self.add_new_choose_spouse,
'on_new_clicked' : self.add_new_new_relationship
})
self.addornew = top.get_widget('add_or_new')
else:
AddSpouse.AddSpouse(self.database,self.active_person,
self.load_family,self.redisplay_person_list)
def add_new_choose_spouse(self,obj):
import AddSpouse
Utils.destroy_passed_object(self.addornew)
AddSpouse.SetSpouse(self.database,self.active_person,self.active_family,
self.load_family, self.redisplay_person_list)
def on_edit_sp_clicked(self,obj):
"""Edit the marriage information for the current family"""