Enhanced Relationship Calculator

svn: r628
This commit is contained in:
Don Allingham 2001-12-16 21:50:28 +00:00
parent 43852bf81c
commit 70632c4f2a
4 changed files with 1317 additions and 1043 deletions

Binary file not shown.

View File

@ -36,6 +36,7 @@ _ = intl.gettext
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #
#
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def filter(person,index,list,map): def filter(person,index,list,map):
if person == None: if person == None:
@ -53,45 +54,159 @@ def filter(person,index,list,map):
# #
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def cousin(level,removed): def get_cousin(f,s,level,removed):
if level == 1: if level == 1:
root = " is the 1st cousin"
elif level == 2:
root = " is the 2nd cousin"
elif level == 3:
root = " is the 3rd cousin"
else:
root = " is the %dth cousin" % level
if removed == 0: if removed == 0:
root = root + " of " return "%s is the first cousin of %s." %(f,s)
elif removed == 1: elif removed == 1:
root = root + " once removed of " return "%s is the first cousin once removed of %s." %(f,s)
elif removed == 2: elif removed == 2:
root = root + " twice removed of " return "%s is the first cousin twice removed of %s." %(f,s)
else: else:
root = root + " %d times removed of " % removed return "%s is the first cousin %d times removed of %s." % (f,s,removed)
return root
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def get_prefix(level,root):
if level == 1:
return " is the " + root + " of "
elif level == 2: elif level == 2:
return " is the grand" + root + " of " if removed == 0:
elif level == 3: return "%s is the second cousin of %s." %(f,s)
return " is the great grand" + root + " of " elif removed == 1:
elif level == 4: return "%s is the second cousin once removed of %s." %(f,s)
return " is the 2nd great grand" + root + " of " elif removed == 2:
elif level == 5: return "%s is the second cousin twice removed of %s." %(f,s)
return " is the 3rd great grand" + root + " of "
else: else:
return " is the %dth great grand%s of " % (level - 2,root) return "%s is the second cousin %d times removed of %s." % (f,s,removed)
elif level == 3:
if removed == 0:
return "%s is the third cousin of %s." %(f,s)
elif removed == 1:
return "%s is the third cousin once removed of %s." %(f,s)
elif removed == 2:
return "%s is the third cousin twice removed of %s." %(f,s)
else:
return "%s is the third cousin %d times removed of %s." % (f,s,removed)
else:
if removed == 0:
return "%s is the %dth cousin of %s." %(f,level,s)
elif removed == 1:
return "%s is the %dth cousin once removed of %s." %(f,level,s)
elif removed == 2:
return "%s is the %dth cousin twice removed of %s." %(f,level,s)
else:
return "%s is the %dth cousin %d times removed of %s." % (f,level,s,removed)
def get_father(f,s,level):
if level == 1:
return "%s is the father of %s." % (s,f)
elif level == 2:
return "%s is the grandfather of %s." % (s,f)
elif level == 3:
return "%s is the great grandfather of %s." % (s,f)
elif level == 4:
return "%s is the 2nd great grandfather of %s." % (s,f)
elif level == 5:
return "%s is the 3rd great grandfather of %s." % (s,f)
else:
return "%s is the %dth great grandfather of %s." % (s,level-2,f)
def get_son(f,s,level):
if level == 1:
return "%s is the son of %s." % (s,f)
elif level == 2:
return "%s is the grandson of %s." % (s,f)
elif level == 3:
return "%s is the great grandson of %s." % (s,f)
elif level == 4:
return "%s is the 2nd great grandson of %s." % (s,f)
elif level == 5:
return "%s is the 3rd great grandson of %s." % (s,f)
else:
return "%s is the %dth great grandson of %s." % (s,level-2,f)
def get_mother(f,s,level):
if level == 1:
return "%s is the mother of %s." % (s,f)
elif level == 2:
return "%s is the grandmother of %s." % (s,f)
elif level == 3:
return "%s is the great grandmother of %s." % (s,f)
elif level == 4:
return "%s is the 2nd great grandmother of %s." % (s,f)
elif level == 5:
return "%s is the 3rd great grandmother of %s." % (s,f)
else:
return "%s is the %dth great grandmother of %s." % (s,level-2,f)
def get_daughter(f,s,level):
if level == 1:
return "%s is the daughter of %s." % (s,f)
elif level == 2:
return "%s is the granddaughter of %s." % (s,f)
elif level == 3:
return "%s is the great granddaughter of %s." % (s,f)
elif level == 4:
return "%s is the 2nd great granddaughter of %s." % (s,f)
elif level == 5:
return "%s is the 3rd great granddaughter of %s." % (s,f)
else:
return "%s is the %dth great granddaughter of %s." % (s,level-2,f)
def get_aunt(f,s,level):
if level == 1:
return "%s is the sister of %s." % (s,f)
elif level == 2:
return "%s is the aunt of %s." % (s,f)
elif level == 3:
return "%s is the grandaunt of %s." % (s,f)
elif level == 4:
return "%s is the great grandaunt of %s." % (s,f)
elif level == 5:
return "%s is the 2nd great grandaunt of %s." % (s,f)
elif level == 6:
return "%s is the 3rd great grandaunt of %s." % (s,f)
else:
return "%s is the %dth great grandaunt of %s." % (s,level-3,f)
def get_uncle(f,s,level):
if level == 1:
return "%s is the brother of %s." % (s,f)
elif level == 2:
return "%s is the uncle of %s." % (s,f)
elif level == 3:
return "%s is the granduncle of %s." % (s,f)
elif level == 4:
return "%s is the great granduncle of %s." % (s,f)
elif level == 5:
return "%s is the 2nd great granduncle of %s." % (s,f)
elif level == 6:
return "%s is the 3rd great granduncle of %s." % (s,f)
else:
return "%s is the %dth great granduncle of %s." % (s,level-3,f)
def get_nephew(f,s,level):
if level == 1:
return "%s is the nephew of %s." % (s,f)
elif level == 2:
return "%s is the grandnephew of %s." % (s,f)
elif level == 3:
return "%s is the great grandnephew of %s." % (s,f)
elif level == 4:
return "%s is the 2nd great grandnephew of %s." % (s,f)
elif level == 5:
return "%s is the 3rd great grandnephew of %s." % (s,f)
else:
return "%s is the %dth great grandnephew of %s." % (s,level-2,f)
def get_niece(f,s,level):
if level == 1:
return "%s is the niece of %s." % (s,f)
elif level == 2:
return "%s is the grandniece of %s." % (s,f)
elif level == 3:
return "%s is the great grandniece of %s." % (s,f)
elif level == 4:
return "%s is the 2nd great grandniece of %s." % (s,f)
elif level == 5:
return "%s is the 3rd great grandniece of %s." % (s,f)
else:
return "%s is the %dth great grandniece of %s." % (s,level-2,f)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -99,7 +214,6 @@ def get_prefix(level,root):
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def runTool(database,person,callback): def runTool(database,person,callback):
RelCalc(database,person) RelCalc(database,person)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -125,13 +239,15 @@ class RelCalc:
name_list = self.db.getPersonMap().values() name_list = self.db.getPersonMap().values()
name_list.sort(sort.by_last_name) name_list.sort(sort.by_last_name)
index = 0 index = 0
for per in name_list: self.people.freeze()
name = per.getPrimaryName().getName() for p in name_list:
birthday = per.getBirth().getDate() name = p.getPrimaryName().getName()
id = per.getId() birthday = p.getBirth().getDate()
id = p.getId()
self.people.append([name,id,birthday]) self.people.append([name,id,birthday])
self.people.set_row_data(index,per) self.people.set_row_data(index,p)
index = index + 1 index = index + 1
self.people.thaw()
self.glade.signal_autoconnect({ self.glade.signal_autoconnect({
"on_close_clicked" : utils.destroy_passed_object, "on_close_clicked" : utils.destroy_passed_object,
@ -169,6 +285,7 @@ class RelCalc:
secondName = other_person.getPrimaryName().getRegularName() secondName = other_person.getPrimaryName().getRegularName()
length = len(common) length = len(common)
if length == 1: if length == 1:
person = common[0] person = common[0]
secondRel = firstMap[person] secondRel = firstMap[person]
@ -194,41 +311,32 @@ class RelCalc:
msg = _("There is no relationship between %s and %s.") msg = _("There is no relationship between %s and %s.")
text = msg % (firstName,secondName) text = msg % (firstName,secondName)
elif firstRel == 0: elif firstRel == 0:
if other_person.getGender() == RelLib.Person.male:
root = "father"
else:
root = "mother"
if secondRel == 0: if secondRel == 0:
text = firstName + " and " + secondName + " are the same person." text = "%s and $s are the same person." % (firstName,secondName)
elif other_person.getGender() == RelLib.Person.male:
text = get_father(firstName,secondName,secondRel)
else: else:
text = secondName + get_prefix(secondRel,root) + firstName text = get_mother(firstName,secondName,secondRel)
elif secondRel == 0: elif secondRel == 0:
if other_person.getGender() == RelLib.Person.male: if other_person.getGender() == RelLib.Person.male:
text = secondName + get_prefix(firstRel,"son") + firstName + "." text = get_son(firstName,secondName,firstRel)
else: else:
text = secondName + get_prefix(firstRel,"daughter") + firstName + "." text = get_daughter(firstName,secondName,firstRel)
elif firstRel == 1: elif firstRel == 1:
if other_person.getGender() == RelLib.Person.male: if other_person.getGender() == RelLib.Person.male:
root = "uncle" text = get_uncle(firstName,secondName,secondRel)
else: else:
root = "aunt" text = get_aunt(firstName,secondName,secondRel)
if secondRel == 1:
if other_person.getGender() == RelLib.Person.male:
text = secondName + " is the brother of " + firstName + "."
else:
text = secondName + " is the sister of " + firstName + "."
else:
text = secondName + get_prefix(secondRel-1,root) + firstName + "."
elif secondRel == 1: elif secondRel == 1:
if other_person.getGender() == RelLib.Person.male: if other_person.getGender() == RelLib.Person.male:
text = secondName + get_prefix(firstRel-1,"nephew") + firstName + "." text = get_nephew(firstName,secondName,firstRel-1)
else: else:
text = secondName + get_prefix(firstRel-1,"niece") + firstName + "." text = get_niece(firstName,secondName,firstRel-1)
else: else:
if secondRel > firstRel: if secondRel > firstRel:
text = secondName + cousin(firstRel-1,secondRel-firstRel) + firstName + "." text = get_cousin(firstName,secondName,firstRel-1,secondRel-firstRel)
else: else:
text = secondName + cousin(secondRel-1,firstRel-secondRel) + firstName + "." text = get_cousin(firstName,secondName,secondRel-1,firstRel-secondRel)
text1 = self.glade.get_widget("text1") text1 = self.glade.get_widget("text1")
text1.set_point(0) text1.set_point(0)

View File

@ -13,30 +13,40 @@
</project> </project>
<widget> <widget>
<class>GtkDialog</class> <class>GnomeDialog</class>
<name>relcalc</name> <name>relcalc</name>
<title>Gramps - Relationship Calculator</title> <title>Gramps - Relationship Calculator</title>
<type>GTK_WINDOW_TOPLEVEL</type> <type>GTK_WINDOW_TOPLEVEL</type>
<position>GTK_WIN_POS_CENTER</position> <position>GTK_WIN_POS_NONE</position>
<modal>True</modal> <modal>False</modal>
<allow_shrink>True</allow_shrink> <allow_shrink>False</allow_shrink>
<allow_grow>True</allow_grow> <allow_grow>True</allow_grow>
<auto_shrink>False</auto_shrink> <auto_shrink>False</auto_shrink>
<auto_close>False</auto_close>
<hide_on_close>False</hide_on_close>
<widget> <widget>
<class>GtkVBox</class> <class>GtkVBox</class>
<child_name>Dialog:vbox</child_name> <child_name>GnomeDialog:vbox</child_name>
<name>dialog-vbox1</name> <name>dialog-vbox2</name>
<homogeneous>False</homogeneous> <homogeneous>False</homogeneous>
<spacing>0</spacing> <spacing>8</spacing>
<child>
<padding>4</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget> <widget>
<class>GtkHBox</class> <class>GtkHButtonBox</class>
<child_name>Dialog:action_area</child_name> <child_name>GnomeDialog:action_area</child_name>
<name>dialog-action_area1</name> <name>dialog-action_area2</name>
<border_width>10</border_width> <layout_style>GTK_BUTTONBOX_END</layout_style>
<homogeneous>True</homogeneous> <spacing>8</spacing>
<spacing>5</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> <child>
<padding>0</padding> <padding>0</padding>
<expand>False</expand> <expand>False</expand>
@ -44,49 +54,31 @@
<pack>GTK_PACK_END</pack> <pack>GTK_PACK_END</pack>
</child> </child>
<widget>
<class>GtkHButtonBox</class>
<name>hbuttonbox1</name>
<layout_style>GTK_BUTTONBOX_END</layout_style>
<spacing>30</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>True</expand>
<fill>True</fill>
</child>
<widget> <widget>
<class>GtkButton</class> <class>GtkButton</class>
<name>button1</name> <name>button4</name>
<can_default>True</can_default> <can_default>True</can_default>
<can_focus>True</can_focus> <can_focus>True</can_focus>
<signal> <signal>
<name>clicked</name> <name>clicked</name>
<handler>on_apply_clicked</handler> <handler>on_apply_clicked</handler>
<last_modification_time>Tue, 06 Feb 2001 23:47:29 GMT</last_modification_time> <last_modification_time>Sun, 16 Dec 2001 21:43:15 GMT</last_modification_time>
</signal> </signal>
<stock_button>GNOME_STOCK_BUTTON_APPLY</stock_button> <stock_button>GNOME_STOCK_BUTTON_APPLY</stock_button>
<relief>GTK_RELIEF_NORMAL</relief>
</widget> </widget>
<widget> <widget>
<class>GtkButton</class> <class>GtkButton</class>
<name>button2</name> <name>button5</name>
<can_default>True</can_default> <can_default>True</can_default>
<can_focus>True</can_focus> <can_focus>True</can_focus>
<signal> <signal>
<name>clicked</name> <name>clicked</name>
<handler>on_close_clicked</handler> <handler>on_close_clicked</handler>
<object>relcalc</object> <object>relcalc</object>
<last_modification_time>Tue, 06 Feb 2001 23:47:17 GMT</last_modification_time> <last_modification_time>Sun, 16 Dec 2001 21:43:37 GMT</last_modification_time>
</signal> </signal>
<stock_button>GNOME_STOCK_BUTTON_CLOSE</stock_button> <stock_button>GNOME_STOCK_BUTTON_CLOSE</stock_button>
<relief>GTK_RELIEF_NORMAL</relief>
</widget>
</widget> </widget>
</widget> </widget>
@ -144,8 +136,8 @@
<widget> <widget>
<class>GtkCList</class> <class>GtkCList</class>
<name>peopleList</name> <name>peopleList</name>
<width>500</width> <width>550</width>
<height>150</height> <height>200</height>
<can_focus>True</can_focus> <can_focus>True</can_focus>
<signal> <signal>
<name>select_row</name> <name>select_row</name>
@ -225,7 +217,7 @@
<widget> <widget>
<class>GtkText</class> <class>GtkText</class>
<name>text1</name> <name>text1</name>
<height>75</height> <height>100</height>
<can_focus>True</can_focus> <can_focus>True</can_focus>
<editable>False</editable> <editable>False</editable>
<text></text> <text></text>

File diff suppressed because it is too large Load Diff