Added the ability to add a new person as the spouse

svn: r362
This commit is contained in:
Don Allingham 2001-08-23 22:13:56 +00:00
parent a9bb6540a2
commit 18273e3e70
5 changed files with 383 additions and 135 deletions

View File

@ -74,7 +74,6 @@ class GrampsParser(handler.ContentHandler):
#---------------------------------------------------------------------
def __init__(self,database,callback,base):
self.call = None
self.stext_list = []
self.scomments_list = []
self.note_list = []
@ -202,11 +201,11 @@ class GrampsParser(handler.ContentHandler):
#---------------------------------------------------------------------
def start_event(self,attrs):
self.event = Event()
self.event_type = u2l(string.capwords(attrs["type"]))
self.event_type = u2l(attrs["type"])
if attrs.has_key("conf"):
self.event.confidence = string.atoi(attrs["conf"])
self.event.confidence = int(attrs["conf"])
if attrs.has_key("priv"):
self.event.private = string.atoi(attrs["priv"])
self.event.private = int(attrs["priv"])
#---------------------------------------------------------------------
#
@ -216,12 +215,12 @@ class GrampsParser(handler.ContentHandler):
def start_attribute(self,attrs):
self.attribute = Attribute()
if attrs.has_key("conf"):
self.attribute.confidence = string.atoi(attrs["conf"])
self.attribute.confidence = int(attrs["conf"])
if attrs.has_key("priv"):
self.attribute.privacy = string.atoi(attrs["priv"])
self.attribute.privacy = int(attrs["priv"])
if attrs.has_key('type'):
self.in_old_attr = 1
self.attribute.setType(u2l(string.capwords(attrs["type"])))
self.attribute.setType(u2l(attrs["type"]))
else:
self.in_old_attr = 0
if self.person:
@ -238,9 +237,9 @@ class GrampsParser(handler.ContentHandler):
self.address = Address()
self.person.addAddress(self.address)
if attrs.has_key("conf"):
self.address.confidence = string.atoi(attrs["conf"])
self.address.confidence = int(attrs["conf"])
if attrs.has_key("priv"):
self.address.private = string.atoi(attrs["priv"])
self.address.private = int(attrs["priv"])
#---------------------------------------------------------------------
#
@ -257,7 +256,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def start_person(self,attrs):
if self.count % self.increment == 0:
if self.callback != None and self.count % self.increment == 0:
self.callback(float(self.count)/float(self.entries))
self.count = self.count + 1
self.person = self.db.findPersonNoMap(u2l(attrs["id"]))
@ -314,7 +313,7 @@ class GrampsParser(handler.ContentHandler):
url.set_path(u2l(attrs["href"]))
url.set_description(desc)
if attrs.has_key("priv"):
url.setPrivacy(string.atoi(attrs['priv']))
url.setPrivacy(int(attrs['priv']))
if self.person:
self.person.addUrl(url)
elif self.placeobj:
@ -328,7 +327,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def start_family(self,attrs):
if self.count % self.increment == 0:
if self.callback != None and self.count % self.increment == 0:
self.callback(float(self.count)/float(self.entries))
self.count = self.count + 1
self.family = self.db.findFamilyNoMap(u2l(attrs["id"]))
@ -379,9 +378,9 @@ class GrampsParser(handler.ContentHandler):
def start_name(self,attrs):
self.name = Name()
if attrs.has_key("conf"):
self.name.confidence = string.atoi(attrs["conf"])
self.name.confidence = int(attrs["conf"])
if attrs.has_key("priv"):
self.name.private = string.atoi(attrs["priv"])
self.name.private = int(attrs["priv"])
#---------------------------------------------------------------------
#
@ -517,14 +516,15 @@ class GrampsParser(handler.ContentHandler):
def stop_event(self,tag):
self.event.name = self.event_type
if self.event_type == "Birth":
self.person.setBirth(self.event)
elif self.event_type == "Death":
self.person.setDeath(self.event)
elif self.person:
self.person.EventList.append(self.event)
else:
if self.family:
self.family.EventList.append(self.event)
else:
if self.event_type == "Birth":
self.person.setBirth(self.event)
elif self.event_type == "Death":
self.person.setDeath(self.event)
else:
self.person.EventList.append(self.event)
self.event = None
#---------------------------------------------------------------------
@ -884,6 +884,8 @@ class GrampsParser(handler.ContentHandler):
func_map = {
"address" : (start_address, stop_address),
"addresses" : (None,None),
"childlist" : (None,None),
"aka" : (start_name, stop_aka),
"attribute" : (start_attribute, stop_attribute),
"attr_type" : (None,stop_attr_type),
@ -986,8 +988,6 @@ class GrampsParser(handler.ContentHandler):
if self.func:
self.data = self.data + data
#-------------------------------------------------------------------------
#
# Gramps database parsing class. Derived from SAX XML parser
@ -1010,7 +1010,7 @@ class GrampsImportParser(GrampsParser):
#
#---------------------------------------------------------------------
def start_person(self,attrs):
if self.count % self.increment == 0:
if self.callback != None and self.count % self.increment == 0:
self.callback(float(self.count)/float(self.entries))
self.count = self.count + 1
self.person = self.db.findPerson("x%s" % u2l(attrs["id"]),self.pmap)
@ -1048,7 +1048,7 @@ class GrampsImportParser(GrampsParser):
#
#---------------------------------------------------------------------
def start_family(self,attrs):
if self.count % self.increment == 0:
if self.callback != None and self.count % self.increment == 0:
self.callback(float(self.count)/float(self.entries))
self.count = self.count + 1
self.family = self.db.findFamily(u2l(attrs["id"]),self.fmap)

View File

@ -106,7 +106,7 @@ def importData(database, filename, callback):
# of data.
#
#-------------------------------------------------------------------------
def loadData(database, filename, callback):
def loadData(database, filename, callback=None):
basefile = os.path.dirname(filename)
database.smap = {}
@ -133,7 +133,8 @@ def loadData(database, filename, callback):
else:
xml_file = open(filename,"r")
except IOError,msg:
GnomeErrorDialog(_("%s could not be opened\n") % filename + str(msg))
filemsg = _("%s could not be opened\n") % filename
GnomeErrorDialog(filemsg + str(msg))
return 0
except:
GnomeErrorDialog(_("%s could not be opened\n") % filename)
@ -149,7 +150,8 @@ def loadData(database, filename, callback):
GnomeErrorDialog("%s\n%s" % (filemsg,errmsg))
return 0
except IOError,msg:
GnomeErrorDialog(_("Error reading %s") % filename + "\n" + str(msg))
errmsg = "%s\n%s" % (_("Error reading %s"),filename,str(msg))
GnomeErrorDialog(errmsg)
import traceback
traceback.print_exc()
return 0
@ -161,3 +163,16 @@ def loadData(database, filename, callback):
xml_file.close()
return 1
if __name__ == "__main__":
import sys
import time
import profile
database = RelDataBase()
t1 = time.time()
#profile.run('loadData(database, sys.argv[1])')
loadData(database,sys.argv[1])
t2 = time.time()
print t2-t1

View File

@ -377,6 +377,14 @@ def save_fattr(st):
#
#-------------------------------------------------------------------------
_frel2def = {
_("Married") : _("A legal or common-law relationship between a husband and wife"),
_("Unmarried"): _("No legal or common-law relationship between man and woman"),
_("Partners") : _("An established relationship between members of the same sex"),
_("Unknown") : _("Unknown relationship between a man and woman"),
_("Other") : _("An unspecified relationship between a man and woman")
}
_fr_e2l = {
"Married" : _("Married"),
"Unmarried" : _("Unmarried"),
@ -389,6 +397,17 @@ _fr_l2e = {}
for a in _fa_e2l.keys():
_fa_l2e[_fa_e2l[a]] = a
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def relationship_def(txt):
if _frel2def.has_key(txt):
return _frel2def[txt]
else:
return _("No definition available")
#-------------------------------------------------------------------------
#
#

View File

@ -185,7 +185,7 @@
<handler>on_person_list1_activate</handler>
<last_modification_time>Sun, 22 Oct 2000 23:07:54 GMT</last_modification_time>
</signal>
<label>Person _List</label>
<label>_People</label>
<right_justify>False</right_justify>
</widget>
@ -209,7 +209,7 @@
<handler>on_pedegree1_activate</handler>
<last_modification_time>Sun, 22 Oct 2000 23:08:36 GMT</last_modification_time>
</signal>
<label>_Pedigree</label>
<label>Pe_digree</label>
<right_justify>False</right_justify>
</widget>
@ -233,7 +233,7 @@
<handler>on_places_activate</handler>
<last_modification_time>Tue, 14 Aug 2001 13:39:34 GMT</last_modification_time>
</signal>
<label>_Places</label>
<label>P_laces</label>
<right_justify>False</right_justify>
</widget>
</widget>
@ -3094,8 +3094,6 @@
<widget>
<class>GtkVBox</class>
<name>vbox11</name>
<width>400</width>
<height>400</height>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
@ -3110,7 +3108,7 @@
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>10</padding>
<padding>5</padding>
<expand>False</expand>
<fill>False</fill>
</child>
@ -3118,82 +3116,21 @@
<widget>
<class>GtkHSeparator</class>
<name>hseparator18</name>
<name>hseparator21</name>
<child>
<padding>10</padding>
<padding>5</padding>
<expand>False</expand>
<fill>True</fill>
</child>
</widget>
<widget>
<class>GtkHBox</class>
<name>hbox29</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkLabel</class>
<name>label228</name>
<label>Relationship Type</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>GtkCombo</class>
<name>rel_combo</name>
<value_in_list>True</value_in_list>
<ok_if_empty>True</ok_if_empty>
<case_sensitive>False</case_sensitive>
<use_arrows>True</use_arrows>
<use_arrows_always>False</use_arrows_always>
<items></items>
<child>
<padding>10</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkEntry</class>
<child_name>GtkCombo:entry</child_name>
<name>rel_type</name>
<can_focus>True</can_focus>
<signal>
<name>changed</name>
<handler>on_rel_type_changed</handler>
<last_modification_time>Sat, 14 Jul 2001 15:29:20 GMT</last_modification_time>
</signal>
<editable>False</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
</widget>
</widget>
</widget>
<widget>
<class>GtkScrolledWindow</class>
<name>scrolledwindow9</name>
<hscrollbar_policy>GTK_POLICY_NEVER</hscrollbar_policy>
<vscrollbar_policy>GTK_POLICY_ALWAYS</vscrollbar_policy>
<hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy>
<vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy>
<class>GtkFrame</class>
<name>frame5</name>
<border_width>5</border_width>
<label>Select existing person as spouse</label>
<label_xalign>0</label_xalign>
<shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
<child>
<padding>0</padding>
<expand>True</expand>
@ -3201,46 +3138,251 @@
</child>
<widget>
<class>GtkCList</class>
<name>spouseList</name>
<class>GtkScrolledWindow</class>
<name>scrolledwindow9</name>
<border_width>10</border_width>
<width>400</width>
<height>450</height>
<can_focus>True</can_focus>
<signal>
<name>select_row</name>
<handler>on_spouseList_select_row</handler>
<last_modification_time>Sun, 19 Nov 2000 00:44:36 GMT</last_modification_time>
</signal>
<height>200</height>
<hscrollbar_policy>GTK_POLICY_NEVER</hscrollbar_policy>
<vscrollbar_policy>GTK_POLICY_ALWAYS</vscrollbar_policy>
<hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy>
<vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy>
<widget>
<class>GtkCList</class>
<name>spouseList</name>
<can_focus>True</can_focus>
<signal>
<name>select_row</name>
<handler>on_spouseList_select_row</handler>
<last_modification_time>Sun, 19 Nov 2000 00:44:36 GMT</last_modification_time>
</signal>
<columns>2</columns>
<column_widths>256,80</column_widths>
<selection_mode>GTK_SELECTION_SINGLE</selection_mode>
<show_titles>True</show_titles>
<shadow_type>GTK_SHADOW_IN</shadow_type>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>label65</name>
<label>Name</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
</widget>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>label66</name>
<label>Birthdate</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
</widget>
</widget>
</widget>
</widget>
<widget>
<class>GtkFrame</class>
<name>frame4</name>
<border_width>5</border_width>
<label>Add new person as spouse</label>
<label_xalign>0</label_xalign>
<shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
<child>
<padding>5</padding>
<expand>False</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkTable</class>
<name>table25</name>
<rows>2</rows>
<columns>2</columns>
<column_widths>203,80</column_widths>
<selection_mode>GTK_SELECTION_SINGLE</selection_mode>
<show_titles>True</show_titles>
<shadow_type>GTK_SHADOW_IN</shadow_type>
<homogeneous>False</homogeneous>
<row_spacing>5</row_spacing>
<column_spacing>5</column_spacing>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>label65</name>
<label>Name</label>
<name>label235</name>
<label>Given Name</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<xalign>1</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<xpad>5</xpad>
<ypad>5</ypad>
<child>
<left_attach>0</left_attach>
<right_attach>1</right_attach>
<top_attach>0</top_attach>
<bottom_attach>1</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>label66</name>
<label>Birthdate</label>
<name>label236</name>
<label>Surname</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>1</xalign>
<yalign>0.5</yalign>
<xpad>5</xpad>
<ypad>5</ypad>
<child>
<left_attach>0</left_attach>
<right_attach>1</right_attach>
<top_attach>1</top_attach>
<bottom_attach>2</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkEntry</class>
<name>given</name>
<can_focus>True</can_focus>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
<child>
<left_attach>1</left_attach>
<right_attach>2</right_attach>
<top_attach>0</top_attach>
<bottom_attach>1</bottom_attach>
<xpad>5</xpad>
<ypad>5</ypad>
<xexpand>True</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkEntry</class>
<name>surname</name>
<can_focus>True</can_focus>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
<child>
<left_attach>1</left_attach>
<right_attach>2</right_attach>
<top_attach>1</top_attach>
<bottom_attach>2</bottom_attach>
<xpad>5</xpad>
<ypad>5</ypad>
<xexpand>True</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
</widget>
</widget>
<widget>
<class>GtkFrame</class>
<name>frame6</name>
<border_width>5</border_width>
<label>Relationship Type</label>
<label_xalign>0</label_xalign>
<shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkVBox</class>
<name>vbox40</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<widget>
<class>GtkCombo</class>
<name>rel_combo</name>
<border_width>5</border_width>
<value_in_list>True</value_in_list>
<ok_if_empty>True</ok_if_empty>
<case_sensitive>False</case_sensitive>
<use_arrows>True</use_arrows>
<use_arrows_always>False</use_arrows_always>
<items></items>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
<widget>
<class>GtkEntry</class>
<child_name>GtkCombo:entry</child_name>
<name>rel_type</name>
<can_focus>True</can_focus>
<signal>
<name>changed</name>
<handler>on_rel_type_changed</handler>
<last_modification_time>Sat, 14 Jul 2001 15:29:20 GMT</last_modification_time>
</signal>
<editable>False</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
</widget>
</widget>
<widget>
<class>GtkLabel</class>
<name>reldef</name>
<label>Relationship definition</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<xpad>5</xpad>
<ypad>5</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
</widget>
</widget>
@ -3267,11 +3409,11 @@
<can_focus>True</can_focus>
<signal>
<name>clicked</name>
<handler>on_select_spouse_clicked</handler>
<handler>on_new_spouse_clicked</handler>
<object>spouseDialog</object>
<last_modification_time>Sun, 19 Nov 2000 00:52:25 GMT</last_modification_time>
<last_modification_time>Thu, 23 Aug 2001 21:21:10 GMT</last_modification_time>
</signal>
<stock_button>GNOME_STOCK_BUTTON_OK</stock_button>
<label>Add new person</label>
<relief>GTK_RELIEF_NORMAL</relief>
</widget>
@ -3282,10 +3424,19 @@
<can_focus>True</can_focus>
<signal>
<name>clicked</name>
<handler>destroy_passed_object</handler>
<handler>on_select_spouse_clicked</handler>
<object>spouseDialog</object>
<last_modification_time>Sun, 22 Oct 2000 20:51:13 GMT</last_modification_time>
<last_modification_time>Thu, 23 Aug 2001 21:21:01 GMT</last_modification_time>
</signal>
<label>Select existing person</label>
<relief>GTK_RELIEF_NORMAL</relief>
</widget>
<widget>
<class>GtkButton</class>
<name>button117</name>
<can_default>True</can_default>
<can_focus>True</can_focus>
<stock_button>GNOME_STOCK_BUTTON_CANCEL</stock_button>
<relief>GTK_RELIEF_NORMAL</relief>
</widget>

View File

@ -123,7 +123,9 @@ ODDFGCOLOR = "oddForeground"
ODDBGCOLOR = "oddBackground"
EVENFGCOLOR= "evenForeground"
EVENBGCOLOR= "evenBackground"
GIVEN = "g"
SURNAME = "s"
RELTYPE = "d"
#-------------------------------------------------------------------------
#
# Short hand function to return either the person's birthday, or an empty
@ -250,15 +252,22 @@ def on_remove_child_clicked(obj):
#-------------------------------------------------------------------------
def on_add_sp_clicked(obj):
spouseDialog = libglade.GladeXML(const.gladeFile, "spouseDialog")
spouseList = spouseDialog.get_widget("spouseList")
spouseDialog.get_widget("rel_combo").set_popdown_strings(const.familyRelations)
rel_type = spouseDialog.get_widget("rel_type")
rel_type.set_data("d",spouseList)
spouseDialog.get_widget("spouseDialog").set_data("d",rel_type)
rel_type.set_data("x",spouseDialog.get_widget("reldef"))
top = spouseDialog.get_widget("spouseDialog")
top.set_data(RELTYPE,rel_type)
top.set_data(GIVEN,spouseDialog.get_widget("given"))
top.set_data(SURNAME,spouseDialog.get_widget("surname"))
spouseDialog.signal_autoconnect({
"on_spouseList_select_row" : on_spouseList_select_row,
"on_select_spouse_clicked" : on_select_spouse_clicked,
"on_new_spouse_clicked" : on_new_spouse_clicked,
"on_rel_type_changed" : on_rel_type_changed,
"destroy_passed_object" : utils.destroy_passed_object
})
@ -519,7 +528,7 @@ def on_addchild_ok_clicked(obj):
# must do an apply filter here to make sure the main window gets updated
apply_filter()
redisplay_person_list(person)
load_family()
utils.modified()
utils.destroy_passed_object(obj)
@ -1358,6 +1367,56 @@ def on_select_spouse_clicked(obj):
load_family()
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def on_new_spouse_clicked(obj):
global active_spouse
global select_spouse
global active_family
select_spouse = Person()
database.addPerson(select_spouse)
name = Name()
select_spouse.setPrimaryName(name)
name.setSurname(string.strip(obj.get_data(SURNAME).get_text()))
name.setFirstName(string.strip(obj.get_data(GIVEN).get_text()))
reltype = const.save_frel(obj.get_data(RELTYPE).get_text())
if reltype == "Partners":
select_spouse.setGender(active_person.getGender())
else:
if active_person.getGender() == Person.male:
select_spouse.setGender(Person.female)
else:
select_spouse.setGender(Person.male)
utils.modified()
active_spouse = select_spouse
family = database.newFamily()
active_family = family
active_person.addFamily(family)
select_spouse.addFamily(family)
if active_person.getGender() == Person.male:
family.setMother(select_spouse)
family.setFather(active_person)
else:
family.setFather(select_spouse)
family.setMother(active_person)
family.setRelationship(const.save_frel(obj.get_data("d").get_text()))
select_spouse = None
utils.destroy_passed_object(obj)
redisplay_person_list(active_spouse)
load_family()
#-------------------------------------------------------------------------
#
#
@ -1474,8 +1533,12 @@ def on_rel_type_changed(obj):
spouse_list = obj.get_data("d")
spouse_list.clear()
spouse_list.freeze()
deftxt = obj.get_data("x")
text = obj.get_text()
deftxt.set_text(const.relationship_def(text))
gender = active_person.getGender()
if text == _("Partners"):
if gender == Person.male: