Code cleanup

svn: r609
This commit is contained in:
Don Allingham 2001-12-09 05:24:29 +00:00
parent c78037f9f9
commit 7701714b77
21 changed files with 430 additions and 518 deletions

View File

@ -1,4 +1,3 @@
#! /usr/bin/python -O
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
@ -52,16 +51,27 @@ import libglade
import const import const
import utils import utils
import RelImage import RelImage
from RelLib import Photo import RelLib
class AddMediaObject: class AddMediaObject:
"""
Displays the Add Media Dialog window, allowing the user to select
a media object from the file system, while providing a description.
"""
def __init__(self,db,update): def __init__(self,db,update):
"""
Creates and displays the dialog box
db - the database in which the new object is to be stored
update - a function to call to update the display
"""
self.db = db self.db = db
self.glade = libglade.GladeXML(const.imageselFile,"imageSelect") self.glade = libglade.GladeXML(const.imageselFile,"imageSelect")
self.window = self.glade.get_widget("imageSelect") self.window = self.glade.get_widget("imageSelect")
self.description = self.glade.get_widget("photoDescription") self.description = self.glade.get_widget("photoDescription")
self.image = self.glade.get_widget("image") self.image = self.glade.get_widget("image")
self.file_text = self.glade.get_widget("fname")
self.update = update self.update = update
self.temp_name = "" self.temp_name = ""
@ -75,19 +85,24 @@ class AddMediaObject:
self.window.show() self.window.show()
def on_savephoto_clicked(self,obj): def on_savephoto_clicked(self,obj):
"""
Callback function called with the save button is pressed.
A new media object is created, and added to the database.
"""
filename = self.glade.get_widget("photosel").get_full_path(0) filename = self.glade.get_widget("photosel").get_full_path(0)
description = self.description.get_text() description = self.description.get_text()
external = self.glade.get_widget("private") external = self.glade.get_widget("private")
if os.path.exists(filename) == 0: if os.path.exists(filename) == 0:
err = _("%s is not a valid file name or does not exist.") % filename msgstr = _("%s is not a valid file name or does not exist.")
GnomeErrorDialog(err) GnomeErrorDialog(msgstr % filename)
return return
type = utils.get_mime_type(filename) type = utils.get_mime_type(filename)
mobj = Photo()
if description == "": if description == "":
description = os.path.basename(filename) description = os.path.basename(filename)
mobj = RelLib.Photo()
mobj.setDescription(description) mobj.setDescription(description)
mobj.setMimeType(type) mobj.setMimeType(type)
self.db.addObject(mobj) self.db.addObject(mobj)
@ -104,19 +119,24 @@ class AddMediaObject:
utils.destroy_passed_object(obj) utils.destroy_passed_object(obj)
def on_name_changed(self,obj): def on_name_changed(self,obj):
filename = self.glade.get_widget("fname").get_text() """
Called anytime the filename text window changes. Checks to
see if the file exists. If it does, the imgae is loaded into
the preview window.
"""
filename = self.file_text.get_text()
basename = os.path.basename(filename) basename = os.path.basename(filename)
(root,ext) = os.path.splitext(basename) (root,ext) = os.path.splitext(basename)
old_title = self.description.get_text() old_title = self.description.get_text()
if old_title == "" or old_title == self.temp_name: if old_title == '' or old_title == self.temp_name:
self.description.set_text(root) self.description.set_text(root)
self.temp_name = root self.temp_name = root
if os.path.isfile(filename): if os.path.isfile(filename):
type = utils.get_mime_type(filename) type = utils.get_mime_type(filename)
if type[0:5] == "image": if type[0:5] == 'image':
image = RelImage.scale_image(filename,const.thumbScale) image = RelImage.scale_image(filename,const.thumbScale)
self.image.load_imlib(image) self.image.load_imlib(image)
else: else:

View File

@ -45,14 +45,26 @@ import libglade
# gramps modules # gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from RelLib import * import RelLib
import const import const
import sort import sort
import utils import utils
class AddSpouse: class AddSpouse:
"""
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,update,addperson): def __init__(self,db,person,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.db = db
self.update = update self.update = update
self.person = person self.person = person
@ -61,9 +73,9 @@ class AddSpouse:
self.glade = libglade.GladeXML(const.gladeFile, "spouseDialog") self.glade = libglade.GladeXML(const.gladeFile, "spouseDialog")
self.rel_combo = self.glade.get_widget("rel_combo") self.rel_combo = self.glade.get_widget("rel_combo")
self.rel_type = self.glade.get_widget("rel_type") self.relation_type = self.glade.get_widget("rel_type")
self.spouse_list = self.glade.get_widget("spouseList") self.spouse_list = self.glade.get_widget("spouseList")
self.rel_def = self.glade.get_widget("reldef") self.relation_def = self.glade.get_widget("reldef")
self.top = self.glade.get_widget("spouseDialog") self.top = self.glade.get_widget("spouseDialog")
self.given = self.glade.get_widget("given") self.given = self.glade.get_widget("given")
self.surname = self.glade.get_widget("surname") self.surname = self.glade.get_widget("surname")
@ -76,97 +88,111 @@ class AddSpouse:
self.top.editable_enters(self.given) self.top.editable_enters(self.given)
self.top.editable_enters(self.surname) self.top.editable_enters(self.surname)
self.name_list = self.db.getPersonMap().values()
self.name_list.sort(sort.by_last_name)
self.glade.signal_autoconnect({ self.glade.signal_autoconnect({
"on_select_spouse_clicked" : self.on_select_spouse_clicked, "on_select_spouse_clicked" : self.select_spouse_clicked,
"on_new_spouse_clicked" : self.on_new_spouse_clicked, "on_new_spouse_clicked" : self.new_spouse_clicked,
"on_rel_type_changed" : self.on_rel_type_changed, "on_rel_type_changed" : self.relation_type_changed,
"on_combo_insert_text" : utils.combo_insert_text, "on_combo_insert_text" : utils.combo_insert_text,
"destroy_passed_object" : utils.destroy_passed_object "destroy_passed_object" : utils.destroy_passed_object
}) })
self.rel_type.set_text(_("Married")) self.relation_type.set_text(_("Married"))
def on_new_spouse_clicked(self,obj): def new_spouse_clicked(self,obj):
select_spouse = Person() """
self.db.addPerson(select_spouse) Called when the spouse to be added does not exist, and needs
name = Name() to be created and added to the database
select_spouse.setPrimaryName(name) """
spouse = RelLib.Person()
self.db.addPerson(spouse)
name = spouse.getPrimaryName()
name.setSurname(string.strip(self.surname.get_text())) name.setSurname(string.strip(self.surname.get_text()))
name.setFirstName(string.strip(self.given.get_text())) name.setFirstName(string.strip(self.given.get_text()))
reltype = const.save_frel(self.rel_type.get_text())
if reltype == "Partners": relation = const.save_frel(self.relation_type.get_text())
select_spouse.setGender(self.person.getGender()) if relation == "Partners":
spouse.setGender(self.person.getGender())
elif self.person.getGender() == RelLib.Person.male:
spouse.setGender(RelLib.Person.female)
else: else:
if self.person.getGender() == Person.male: spouse.setGender(RelLib.Person.male)
select_spouse.setGender(Person.female)
else:
select_spouse.setGender(Person.male)
utils.modified()
family = self.db.newFamily() family = self.db.newFamily()
family.setRelationship(relation)
self.person.addFamily(family) self.person.addFamily(family)
select_spouse.addFamily(family) spouse.addFamily(family)
if self.person.getGender() == Person.male: if self.person.getGender() == Person.male:
family.setMother(select_spouse) family.setMother(spouse)
family.setFather(self.person) family.setFather(self.person)
else: else:
family.setFather(select_spouse) family.setFather(spouse)
family.setMother(self.person) family.setMother(self.person)
family.setRelationship(reltype)
utils.destroy_passed_object(obj) utils.destroy_passed_object(obj)
self.addperson(select_spouse) utils.modified()
self.addperson(spouse)
self.update(family) self.update(family)
def on_select_spouse_clicked(self,obj): 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: if len(self.spouse_list.selection) == 0:
return return
row = self.spouse_list.selection[0] row = self.spouse_list.selection[0]
select_spouse = self.spouse_list.get_row_data(row) spouse = self.spouse_list.get_row_data(row)
# don't do anything if the marriage already exists
for f in self.person.getFamilyList(): for f in self.person.getFamilyList():
if select_spouse == f.getMother() or select_spouse == f.getFather(): if spouse == f.getMother() or spouse == f.getFather():
utils.destroy_passed_object(obj) utils.destroy_passed_object(obj)
return return
utils.modified() utils.modified()
family = self.db.newFamily() family = self.db.newFamily()
self.person.addFamily(family) self.person.addFamily(family)
select_spouse.addFamily(family) spouse.addFamily(family)
if self.person.getGender() == Person.male: if self.person.getGender() == RelLib.Person.male:
family.setMother(select_spouse) family.setMother(spouse)
family.setFather(self.person) family.setFather(self.person)
else: else:
family.setFather(select_spouse) family.setFather(spouse)
family.setMother(self.person) family.setMother(self.person)
family.setRelationship(const.save_frel(self.rel_type.get_text())) family.setRelationship(const.save_frel(self.relation_type.get_text()))
utils.destroy_passed_object(obj) utils.destroy_passed_object(obj)
self.update(family) self.update(family)
def on_rel_type_changed(self,obj): def relation_type_changed(self,obj):
"""
nameList = self.db.getPersonMap().values() Called whenever the relationship type changes. Rebuilds the
nameList.sort(sort.by_last_name) the potential spouse list.
self.spouse_list.clear() """
self.spouse_list.freeze()
text = obj.get_text() text = obj.get_text()
self.rel_def.set_text(const.relationship_def(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() gender = self.person.getGender()
if text == _("Partners"): if text == _("Partners"):
if gender == Person.male: if gender == RelLib.Person.male:
gender = Person.female gender = RelLib.Person.female
else: else:
gender = Person.male gender = RelLib.Person.male
index = 0 index = 0
for person in nameList: self.spouse_list.clear()
self.spouse_list.freeze()
for person in self.name_list:
if person.getGender() == gender: if person.getGender() == gender:
continue continue
name = person.getPrimaryName().getName() name = person.getPrimaryName().getName()

View File

@ -32,7 +32,7 @@ import libglade
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import const import const
import utils import utils
from RelLib import * import Date
from intl import gettext from intl import gettext
_ = gettext _ = gettext
@ -43,10 +43,17 @@ _ = gettext
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class AddressEditor: class AddressEditor:
"""
Displays a dialog that allows the user to edit a address.
"""
def __init__(self,parent,addr): def __init__(self,parent,addr):
self.parent = parent """
self.addr = addr Displays the dialog box.
parent - The class that called the Address editor.
addr - The address that is to be edited
"""
# Get the important widgets from the glade description
self.top = libglade.GladeXML(const.editPersonFile, "addr_edit") self.top = libglade.GladeXML(const.editPersonFile, "addr_edit")
self.window = self.top.get_widget("addr_edit") self.window = self.top.get_widget("addr_edit")
self.addr_start = self.top.get_widget("address_start") self.addr_start = self.top.get_widget("address_start")
@ -58,10 +65,8 @@ class AddressEditor:
self.note_field = self.top.get_widget("addr_note") self.note_field = self.top.get_widget("addr_note")
self.priv = self.top.get_widget("priv") self.priv = self.top.get_widget("priv")
if self.addr: self.parent = parent
self.srcreflist = self.addr.getSourceRefList() self.addr = addr
else:
self.srcreflist = []
name = parent.person.getPrimaryName().getName() name = parent.person.getPrimaryName().getName()
text = _("Address Editor for %s") % name text = _("Address Editor for %s") % name
@ -76,30 +81,37 @@ class AddressEditor:
self.window.editable_enters(self.postal); self.window.editable_enters(self.postal);
self.window.editable_enters(self.note_field); self.window.editable_enters(self.note_field);
if self.addr != None: if self.addr:
self.srcreflist = self.addr.getSourceRefList()
self.addr_start.set_text(self.addr.getDate()) self.addr_start.set_text(self.addr.getDate())
self.street.set_text(self.addr.getStreet()) self.street.set_text(self.addr.getStreet())
self.city.set_text(self.addr.getCity()) self.city.set_text(self.addr.getCity())
self.state.set_text(self.addr.getState()) self.state.set_text(self.addr.getState())
self.country.set_text(self.addr.getCountry()) self.country.set_text(self.addr.getCountry())
self.postal.set_text(self.addr.getPostal()) self.postal.set_text(self.addr.getPostal())
self.priv.set_active(self.addr.getPrivacy()) self.priv.set_active(self.addr.getPrivacy())
self.note_field.set_point(0) self.note_field.set_point(0)
self.note_field.insert_defaults(self.addr.getNote()) self.note_field.insert_defaults(self.addr.getNote())
self.note_field.set_word_wrap(1) self.note_field.set_word_wrap(1)
else:
self.srcreflist = []
self.top.signal_autoconnect({ self.top.signal_autoconnect({
"destroy_passed_object" : utils.destroy_passed_object, "destroy_passed_object" : utils.destroy_passed_object,
"on_addr_edit_ok_clicked" : self.on_addr_edit_ok_clicked, "on_addr_edit_ok_clicked" : self.ok_clicked,
"on_source_clicked" : self.on_addr_source_clicked "on_source_clicked" : self.source_clicked
}) })
def on_addr_source_clicked(self,obj): def source_clicked(self,obj):
"""Displays the SourceSelector, allowing sources to be edited"""
import Sources import Sources
Sources.SourceSelector(self.srcreflist,self.parent,src_changed) Sources.SourceSelector(self.srcreflist,self.parent,src_changed)
def on_addr_edit_ok_clicked(self,obj): def ok_clicked(self,obj):
"""
Called when the OK button is pressed. Gets data from the
form and updates the Address data structure
"""
date = self.addr_start.get_text() date = self.addr_start.get_text()
street = self.street.get_text() street = self.street.get_text()
city = self.city.get_text() city = self.city.get_text()
@ -114,45 +126,55 @@ class AddressEditor:
self.addr.setSourceRefList(self.srcreflist) self.addr.setSourceRefList(self.srcreflist)
self.parent.plist.append(self.addr) self.parent.plist.append(self.addr)
self.update_address(date,street,city,state,country,postal,note,priv) self.update(date,street,city,state,country,postal,note,priv)
self.parent.redraw_addr_list() self.parent.redraw_addr_list()
utils.destroy_passed_object(obj) utils.destroy_passed_object(obj)
def update_address(self,date,street,city,state,country,postal,note,priv): def check(self,get,set,data):
d = Date() """Compares a data item, updates if necessary, and sets the
parents lists_changed flag"""
if get() != data:
set(data)
self.parent.lists_changed = 1
def update(self,date,street,city,state,country,postal,note,priv):
"""Compares the data items, and updates if necessary"""
d = Date.Date()
d.set(date) d.set(date)
if self.addr.getDate() != d.getDate(): if self.addr.getDate() != d.getDate():
self.addr.setDate(date) self.addr.setDate(date)
self.parent.lists_changed = 1 self.parent.lists_changed = 1
if self.addr.getState() != state: self.check(self.addr.getDate,self.addr.setDate,state)
self.addr.setState(state) self.check(self.addr.getStreet,self.addr.setStreet,street)
self.parent.lists_changed = 1 self.check(self.addr.getCountry,self.addr.setCountry,country)
self.check(self.addr.getCity,self.addr.setCity,city)
self.check(self.addr.getPostal,self.addr.setPostal,postal)
self.check(self.addr.getNote,self.addr.setNote,note)
self.check(self.addr.getPrivacy,self.addr.setPrivacy,priv)
if self.addr.getStreet() != street: # if self.addr.getState() != state:
self.addr.setStreet(street) # self.addr.setState(state)
self.parent.lists_changed = 1 # self.parent.lists_changed = 1
# if self.addr.getStreet() != street:
if self.addr.getCountry() != country: # self.addr.setStreet(street)
self.addr.setCountry(country) # self.parent.lists_changed = 1
self.parent.lists_changed = 1 # if self.addr.getCountry() != country:
# self.addr.setCountry(country)
if self.addr.getCity() != city: # self.parent.lists_changed = 1
self.addr.setCity(city) # if self.addr.getCity() != city:
self.parent.lists_changed = 1 # self.addr.setCity(city)
# self.parent.lists_changed = 1
if self.addr.getPostal() != postal: # if self.addr.getPostal() != postal:
self.addr.setPostal(postal) # self.addr.setPostal(postal)
self.parent.lists_changed = 1 # self.parent.lists_changed = 1
# if self.addr.getNote() != note:
if self.addr.getNote() != note: # self.addr.setNote(note)
self.addr.setNote(note) # self.parent.lists_changed = 1
self.parent.lists_changed = 1 # if self.addr.getPrivacy() != priv:
# self.addr.setPrivacy(priv)
if self.addr.getPrivacy() != priv: # self.parent.lists_changed = 1
self.addr.setPrivacy(priv)
self.parent.lists_changed = 1
def src_changed(parent): def src_changed(parent):
parent.lists_changed = 1 parent.lists_changed = 1

View File

@ -53,28 +53,21 @@ _NAMEINST = "namelist"
class Bookmarks : class Bookmarks :
"Handle the bookmarks interface for Gramps" "Handle the bookmarks interface for Gramps"
#---------------------------------------------------------------------
#
# __init__ - Creates a the bookmark editor
#
# arguments are:
# bookmarks - list of People
# menu - parent menu to attach users
# callback - task to connect to the menu item as a callback
#
#---------------------------------------------------------------------
def __init__(self,bookmarks,menu,callback): def __init__(self,bookmarks,menu,callback):
"""
Creates a the bookmark editor
bookmarks - list of People
menu - parent menu to attach users
callback - task to connect to the menu item as a callback
"""
self.menu = menu self.menu = menu
self.bookmarks = bookmarks self.bookmarks = bookmarks
self.callback = callback self.callback = callback
self.redraw() self.redraw()
#---------------------------------------------------------------------
#
# redraw - (re)create the pulldown menu
#
#---------------------------------------------------------------------
def redraw(self): def redraw(self):
"""Create the pulldown menu"""
if len(self.bookmarks) > 0: if len(self.bookmarks) > 0:
self.myMenu = gtk.GtkMenu() self.myMenu = gtk.GtkMenu()
for person in self.bookmarks: for person in self.bookmarks:
@ -85,39 +78,30 @@ class Bookmarks :
self.menu.remove_submenu() self.menu.remove_submenu()
self.menu.set_sensitive(0) self.menu.set_sensitive(0)
#---------------------------------------------------------------------
#
# add - adds the person to the bookmarks, appended to the botom
#
#---------------------------------------------------------------------
def add(self,person): def add(self,person):
"""appends the person to the bottom of the bookmarks"""
if person not in self.bookmarks: if person not in self.bookmarks:
utils.modified() utils.modified()
self.bookmarks.append(person) self.bookmarks.append(person)
self.redraw() self.redraw()
#---------------------------------------------------------------------
#
# add_to_menu - adds a person's name to the drop down menu
#
#---------------------------------------------------------------------
def add_to_menu(self,person): def add_to_menu(self,person):
"""adds a person's name to the drop down menu"""
item = gtk.GtkMenuItem(person.getPrimaryName().getName()) item = gtk.GtkMenuItem(person.getPrimaryName().getName())
item.connect("activate", self.callback, person) item.connect("activate", self.callback, person)
item.show() item.show()
self.myMenu.append(item) self.myMenu.append(item)
#---------------------------------------------------------------------
#
# edit - display the bookmark editor.
#
# The current bookmarked people are inserted into the namelist,
# attaching the person object to the corresponding row. The currently
# selected row is attached to the name list. This is either 0 if the
# list is not empty, or -1 if it is.
#
#---------------------------------------------------------------------
def edit(self): def edit(self):
"""
display the bookmark editor.
The current bookmarked people are inserted into the namelist,
attaching the person object to the corresponding row. The currently
selected row is attached to the name list. This is either 0 if the
list is not empty, or -1 if it is.
"""
top = libglade.GladeXML(const.bookFile,_TOPINST) top = libglade.GladeXML(const.bookFile,_TOPINST)
self.namelist = top.get_widget(_NAMEINST) self.namelist = top.get_widget(_NAMEINST)
index = 0 index = 0
@ -127,41 +111,43 @@ class Bookmarks :
index = index + 1 index = index + 1
top.signal_autoconnect({ top.signal_autoconnect({
"on_ok_clicked" : self.on_ok_clicked, "on_ok_clicked" : self.ok_clicked,
"on_down_clicked" : self.on_down_clicked, "on_down_clicked" : self.down_clicked,
"on_up_clicked" : self.on_up_clicked, "on_up_clicked" : self.up_clicked,
"on_delete_clicked" : self.on_delete_clicked, "on_delete_clicked" : self.delete_clicked,
"on_cancel_clicked" : self.on_cancel_clicked "on_cancel_clicked" : self.cancel_clicked
}) })
def on_delete_clicked(self,obj): def delete_clicked(self,obj):
"""Removes the current selection from the list"""
if len(obj.selection) > 0: if len(obj.selection) > 0:
index = obj.selection[0] obj.remove(obj.selection[0])
obj.remove(index)
def on_up_clicked(self,obj): def up_clicked(self,obj):
"""Moves the current selection up one row"""
if len(obj.selection) > 0: if len(obj.selection) > 0:
index = obj.selection[0] index = obj.selection[0]
obj.swap_rows(index-1,index) obj.swap_rows(index-1,index)
def on_down_clicked(self,obj): def down_clicked(self,obj):
"""Moves the current selection down one row"""
if len(obj.selection) > 0: if len(obj.selection) > 0:
index = obj.selection[0] index = obj.selection[0]
if index != obj.rows-1: if index != obj.rows-1:
obj.swap_rows(index+1,index) obj.swap_rows(index+1,index)
def on_ok_clicked(self,obj): def ok_clicked(self,obj):
"""Saves the current bookmarks from the list"""
del self.bookmarks[0:] del self.bookmarks[0:]
for index in range(0,self.namelist.rows): for index in range(0,self.namelist.rows):
person = self.namelist.get_row_data(index) person = self.namelist.get_row_data(index)
if person: if person:
self.bookmarks.append(person) self.bookmarks.append(person)
self.redraw() self.redraw()
obj.destroy() obj.destroy()
def on_cancel_clicked(self,obj): def cancel_clicked(self,obj):
"""Closes the current window"""
obj.destroy() obj.destroy()

View File

@ -18,13 +18,13 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
#-------------------------------------------------------------------
# #
# The original algorithms for this module came from Scott E. Lee's # The original algorithms for this module came from Scott E. Lee's
# C implementation. The original C source can be found at Scott's # C implementation. The original C source can be found at Scott's
# web site at http://www.scottlee.com # web site at http://www.scottlee.com
# #
#-------------------------------------------------------------------
_FR_SDN_OFFSET = 2375474 _FR_SDN_OFFSET = 2375474
_FR_DAYS_PER_4_YEARS = 1461 _FR_DAYS_PER_4_YEARS = 1461
@ -59,8 +59,14 @@ _NOON = (18 * _HALAKIM_PER_HOUR)
_AM3_11_20 = ((9 * _HALAKIM_PER_HOUR) + 204) _AM3_11_20 = ((9 * _HALAKIM_PER_HOUR) + 204)
_AM9_32_43 = ((15 * _HALAKIM_PER_HOUR) + 589) _AM9_32_43 = ((15 * _HALAKIM_PER_HOUR) + 589)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
monthsPerYear = [ monthsPerYear = [
12, 12, 13, 12, 12, 13, 12, 13, 12, 12, 13, 12, 12, 13, 12, 12, 13, 12, 13 12, 12, 13, 12, 12, 13, 12, 13, 12,
12, 13, 12, 12, 13, 12, 12, 13, 12, 13
] ]
yearOffset = [ yearOffset = [
@ -68,21 +74,27 @@ yearOffset = [
136, 148, 160, 173, 185, 197, 210, 222 136, 148, 160, 173, 185, 197, 210, 222
] ]
def french_to_sdn(year,month,day): #-------------------------------------------------------------------------
if (year < 1 or year > 14 or month < 1 or month > 13 or day < 1 or day > 30): #
return 0 #
#
#-------------------------------------------------------------------------
return (year*_FR_DAYS_PER_4_YEARS)/4 + (month-1)*_FR_DAYS_PER_MONTH + day +_FR_SDN_OFFSET def french_to_sdn(y,m,d):
"""Converts a French Republican Calendar date to an SDN number"""
if (y < 1 or y > 14 or m < 1 or m > 13 or d < 1 or d > 30):
return 0
return (y*_FR_DAYS_PER_4_YEARS)/4+(m-1)*_FR_DAYS_PER_MONTH+d+_FR_SDN_OFFSET
def sdn_to_french(sdn): def sdn_to_french(sdn):
"""Converts an SDN number to a French Republican Calendar date"""
if (sdn < _FR_FIRST_VALID or sdn > _FR_LAST_VALID) : if (sdn < _FR_FIRST_VALID or sdn > _FR_LAST_VALID) :
return (0,0,0) return (0,0,0)
temp = (sdn-_FR_SDN_OFFSET)*4 - 1 temp = (sdn-_FR_SDN_OFFSET)*4 - 1
year = temp/_FR_DAYS_PER_4_YEARS year = temp/_FR_DAYS_PER_4_YEARS
dayOfYear = (temp%_FR_DAYS_PER_4_YEARS)/4 dayOfYear = (temp%_FR_DAYS_PER_4_YEARS)/4
month = dayOfYear / _FR_DAYS_PER_MONTH + 1 month = (dayOfYear/_FR_DAYS_PER_MONTH)+1
day = dayOfYear % _FR_DAYS_PER_MONTH + 1 day = (dayOfYear%_FR_DAYS_PER_MONTH)+1
return (year,month,day) return (year,month,day)

View File

@ -38,15 +38,17 @@ import libglade
# gramps modules # gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from RelLib import * import RelLib
import const import const
import sort import sort
import utils import utils
import Config import Config
class ChooseParents: class ChooseParents:
"""
Displays the Choose Parents dialog box, allowing the parents
to be edited.
"""
def __init__(self,db,person,family,family_update,full_update): def __init__(self,db,person,family,family_update,full_update):
self.db = db self.db = db
self.person = person self.person = person
@ -62,42 +64,40 @@ class ChooseParents:
self.father = None self.father = None
self.glade = libglade.GladeXML(const.gladeFile,"familyDialog") self.glade = libglade.GladeXML(const.gladeFile,"familyDialog")
self.top = self.glade.get_widget("familyDialog") self.top = self.glade.get_widget("familyDialog")
self.mrel = self.glade.get_widget("mrel") self.mother_rel = self.glade.get_widget("mrel")
self.frel = self.glade.get_widget("frel") self.father_rel = self.glade.get_widget("frel")
self.fcombo = self.glade.get_widget("prel_combo") self.fcombo = self.glade.get_widget("prel_combo")
self.prel = self.glade.get_widget("prel") self.prel = self.glade.get_widget("prel")
self.title = self.glade.get_widget("chooseTitle") self.title = self.glade.get_widget("chooseTitle")
self.fatherName = self.glade.get_widget("fatherName") self.father_name = self.glade.get_widget("fatherName")
self.motherName = self.glade.get_widget("motherName") self.mother_name = self.glade.get_widget("motherName")
self.father_list = self.glade.get_widget("fatherList") self.father_list = self.glade.get_widget("fatherList")
self.mother_list = self.glade.get_widget("motherList") self.mother_list = self.glade.get_widget("motherList")
self.flabel = self.glade.get_widget("flabel") self.flabel = self.glade.get_widget("flabel")
self.mlabel = self.glade.get_widget("mlabel") self.mlabel = self.glade.get_widget("mlabel")
self.fcombo.set_popdown_strings(const.familyRelations) self.fcombo.set_popdown_strings(const.familyRelations)
if self.family and self.family == self.person.getMainFamily(): if self.family and self.family == self.person.getMainFamily():
self.mrel.set_text(_("Birth")) self.mother_rel.set_text(_("Birth"))
self.frel.set_text(_("Birth")) self.father_rel.set_text(_("Birth"))
else: else:
for (f,mr,fr) in self.person.getAltFamilyList(): for (f,mr,fr) in self.person.getAltFamilyList():
if f == self.family: if f == self.family:
self.mrel.set_text(_(mr)) self.mother_rel.set_text(_(mr))
self.frel.set_text(_(fr)) self.father_rel.set_text(_(fr))
break break
else: else:
self.mrel.set_text(_("Birth")) self.mother_rel.set_text(_("Birth"))
self.frel.set_text(_("Birth")) self.father_rel.set_text(_("Birth"))
self.glade.signal_autoconnect({ self.glade.signal_autoconnect({
"on_motherList_select_row" : self.on_mother_list_select_row, "on_motherList_select_row" : self.mother_list_select_row,
"on_fatherList_select_row" : self.on_father_list_select_row, "on_fatherList_select_row" : self.father_list_select_row,
"on_save_parents_clicked" : self.on_save_parents_clicked, "on_save_parents_clicked" : self.save_parents_clicked,
"on_addmother_clicked" : self.on_addmother_clicked, "on_addmother_clicked" : self.add_mother_clicked,
"on_addfather_clicked" : self.on_addfather_clicked, "on_addfather_clicked" : self.add_father_clicked,
"on_prel_changed" : self.on_prel_changed, "on_prel_changed" : self.parent_relation_changed,
"on_combo_insert_text" : utils.combo_insert_text, "on_combo_insert_text" : utils.combo_insert_text,
"destroy_passed_object" : utils.destroy_passed_object "destroy_passed_object" : utils.destroy_passed_object
}) })
@ -107,15 +107,15 @@ class ChooseParents:
if self.family: if self.family:
self.prel.set_text(_(self.family.getRelationship())) self.prel.set_text(_(self.family.getRelationship()))
else: else:
self.on_prel_changed(self.prel) self.parent_relation_changed(self.prel)
self.top.show() self.top.show()
def on_prel_changed(self,obj): def parent_relation_changed(self,obj):
type = obj.get_text() type = obj.get_text()
self.fatherName.set_text(Config.nameof(self.father)) self.father_name.set_text(Config.nameof(self.father))
self.motherName.set_text(Config.nameof(self.mother)) self.mother_name.set_text(Config.nameof(self.mother))
self.father_list.freeze() self.father_list.freeze()
self.mother_list.freeze() self.mother_list.freeze()
@ -133,18 +133,19 @@ class ChooseParents:
father_index = 1 father_index = 1
mother_index = 1 mother_index = 1
for person in people: for person in people:
if person == self.person or person.getGender() == Person.unknown: if person == self.person:
continue
if person.getGender() == RelLib.Person.unknown:
continue continue
rdata = [utils.phonebook_name(person),utils.birthday(person)] rdata = [utils.phonebook_name(person),utils.birthday(person)]
if type == "Partners": if type == "Partners":
self.father_list.append(rdata) self.father_list.append(rdata)
self.father_list.set_row_data(father_index,person) self.father_list.set_row_data(father_index,person)
father_index = father_index + 1 father_index = father_index + 1
self.mother_list.append(rdata) self.mother_list.append(rdata)
self.mother_list.set_row_data(mother_index,person) self.mother_list.set_row_data(mother_index,person)
mother_index = mother_index + 1 mother_index = mother_index + 1
elif person.getGender() == Person.male: elif person.getGender() == RelLib.Person.male:
self.father_list.append(rdata) self.father_list.append(rdata)
self.father_list.set_row_data(father_index,person) self.father_list.set_row_data(father_index,person)
father_index = father_index + 1 father_index = father_index + 1
@ -164,7 +165,10 @@ class ChooseParents:
self.father_list.thaw() self.father_list.thaw()
def find_family(self,father,mother): def find_family(self,father,mother):
"""
Finds the family associated with the father and mother.
If one does not exist, it is created.
"""
if not father and not mother: if not father and not mother:
return None return None
@ -184,37 +188,36 @@ class ChooseParents:
father.addFamily(family) father.addFamily(family)
if mother: if mother:
mother.addFamily(family) mother.addFamily(family)
return family return family
def on_mother_list_select_row(self,obj,a,b,c): def mother_list_select_row(self,obj,a,b,c):
self.mother = obj.get_row_data(a) self.mother = obj.get_row_data(a)
self.motherName.set_text(Config.nameof(self.mother)) self.mother_name.set_text(Config.nameof(self.mother))
def on_father_list_select_row(self,obj,a,b,c): def father_list_select_row(self,obj,a,b,c):
self.father = obj.get_row_data(a) self.father = obj.get_row_data(a)
self.fatherName.set_text(Config.nameof(self.father)) self.father_name.set_text(Config.nameof(self.father))
def on_save_parents_clicked(self,obj): def save_parents_clicked(self,obj):
mrel = const.childRelations[self.mrel.get_text()] mother_rel = const.childRelations[self.mother_rel.get_text()]
frel = const.childRelations[self.frel.get_text()] father_rel = const.childRelations[self.father_rel.get_text()]
type = const.save_frel(self.prel.get_text()) type = const.save_frel(self.prel.get_text())
if self.father or self.mother: if self.father or self.mother:
if self.mother and not self.father: if self.mother and not self.father:
if self.mother.getGender() == Person.male: if self.mother.getGender() == RelLib.Person.male:
self.father = self.mother self.father = self.mother
self.mother = None self.mother = None
self.family = self.find_family(self.father,self.mother) self.family = self.find_family(self.father,self.mother)
elif self.father and not self.mother: elif self.father and not self.mother:
if self.father.getGender() == Person.female: if self.father.getGender() == RelLib.Person.female:
self.mother = self.father self.mother = self.father
self.father = None self.father = None
self.family = self.find_family(self.father,self.mother) self.family = self.find_family(self.father,self.mother)
elif self.mother.getGender() != self.father.getGender(): elif self.mother.getGender() != self.father.getGender():
if type == "Partners": if type == "Partners":
type = "Unknown" type = "Unknown"
if self.father.getGender() == Person.female: if self.father.getGender() == RelLib.Person.female:
x = self.father x = self.father
self.father = self.mother self.father = self.mother
self.mother = x self.mother = x
@ -228,14 +231,14 @@ class ChooseParents:
utils.destroy_passed_object(obj) utils.destroy_passed_object(obj)
if self.family: if self.family:
self.family.setRelationship(type) self.family.setRelationship(type)
self.change_family_type(self.family,mrel,frel) self.change_family_type(self.family,mother_rel,father_rel)
self.family_update(self.family) self.family_update(self.family)
def on_addparent_clicked(self,obj,sex): def add_parent_clicked(self,obj,sex):
self.xml = libglade.GladeXML(const.gladeFile,"addperson") self.xml = libglade.GladeXML(const.gladeFile,"addperson")
self.xml.get_widget(sex).set_active(1) self.xml.get_widget(sex).set_active(1)
self.xml.signal_autoconnect({ self.xml.signal_autoconnect({
"on_addfather_close": self.on_addparent_close, "on_addfather_close": self.add_parent_close,
"on_combo_insert_text" : utils.combo_insert_text, "on_combo_insert_text" : utils.combo_insert_text,
"destroy_passed_object" : utils.destroy_passed_object "destroy_passed_object" : utils.destroy_passed_object
}) })
@ -245,83 +248,77 @@ class ChooseParents:
window.editable_enters(self.xml.get_widget("surname")) window.editable_enters(self.xml.get_widget("surname"))
utils.attach_surnames(self.xml.get_widget("surnameCombo")) utils.attach_surnames(self.xml.get_widget("surnameCombo"))
def on_addfather_clicked(self,obj): def add_father_clicked(self,obj):
self.on_addparent_clicked(obj,"male") self.add_parent_clicked(obj,"male")
def on_addmother_clicked(self,obj): def add_mother_clicked(self,obj):
self.on_addparent_clicked(obj,"female") self.add_parent_clicked(obj,"female")
def change_family_type(self,family,mrel,frel): def change_family_type(self,family,mother_rel,father_rel):
"""
Changes the family type of the specified family. If the family
is None, the the relationship type shoud be deleted.
"""
is_main = mother_rel == "Birth" and father_rel == "Birth"
is_main = (mrel == "Birth") and (frel == "Birth") if family == self.person.getMainFamily():
# make sure that the person is listed as a child
if not family: if self.person not in family.getChildList():
if is_main:
main = self.person.getMainFamily()
if main:
main.removeChild(self.person)
self.person.setMainFamily(None)
else:
for fam in self.person.getAltFamilyList():
if is_main:
self.person.removeAltFamily(fam[0])
fam.removeChild(self.person)
return
elif family == self.person.getMainFamily():
family.addChild(self.person) family.addChild(self.person)
# if the relationships indicate that this is no longer
# the main family, we need to delete the main family,
# and add it as an alternate family (assuming that it
# does not already in the list)
if not is_main: if not is_main:
utils.modified()
self.person.setMainFamily(None) self.person.setMainFamily(None)
for fam in self.person.getAltFamilyList(): for fam in self.person.getAltFamilyList():
if fam[0] == family: if fam[0] == family:
fam[1] = type if fam[1] == mother_rel and fam[2] == father_rel:
break return
elif fam[1] == type:
fam[0] = family
break
else: else:
self.person.addAltFamily(family,mrel,frel) self.person.removeFamily(fam[0])
else: else:
self.person.addAltFamily(family,mother_rel,father_rel)
# The family is not already the main family
else:
if self.person not in family.getChildList():
family.addChild(self.person) family.addChild(self.person)
for fam in self.person.getAltFamilyList(): for fam in self.person.getAltFamilyList():
if family == fam[0]: if family == fam[0]:
if is_main: if is_main:
self.person.setMainFamily(family) self.person.setMainFamily(family)
self.person.removeAltFamily(family) self.person.removeAltFamily(family)
utils.modified()
break break
if mrel == fam[1] and frel == fam[2]: if mother_rel == fam[1] and father_rel == fam[2]:
break return
if mrel != fam[1] or frel != fam[2]: if mother_rel != fam[1] or father_rel != fam[2]:
self.person.removeAltFamily(family) self.person.removeAltFamily(family)
self.person.addAltFamily(family,mrel,frel) self.person.addAltFamily(family,mother_rel,father_rel)
utils.modified()
break break
else: else:
if is_main: if is_main:
self.person.setMainFamily(family) self.person.setMainFamily(family)
else: else:
self.person.addAltFamily(family,mrel,frel) self.person.addAltFamily(family,mother_rel,father_rel)
utils.modified() utils.modified()
def on_addparent_close(self,obj): def add_parent_close(self,obj):
surname = self.xml.get_widget("surname").get_text() surname = self.xml.get_widget("surname").get_text()
given = self.xml.get_widget("given").get_text() given = self.xml.get_widget("given").get_text()
person = Person() person = RelLib.Person()
self.db.addPerson(person) self.db.addPerson(person)
name = Name() name = person.getPrimaryName()
name.setSurname(surname) name.setSurname(surname)
name.setFirstName(given) name.setFirstName(given)
person.setPrimaryName(name)
if self.xml.get_widget("male").get_active(): if self.xml.get_widget("male").get_active():
person.setGender(Person.male) person.setGender(RelLib.Person.male)
self.father = person self.father = person
else: else:
person.setGender(Person.female) person.setGender(RelLib.Person.female)
self.mother = person self.mother = person
utils.modified() utils.modified()
self.on_prel_changed(self.prel) self.parent_relation_changed(self.prel)
utils.destroy_passed_object(obj) utils.destroy_passed_object(obj)
self.full_update() self.full_update()

View File

@ -44,17 +44,20 @@ FRENCH = 3
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
_fmonth = [ _fmonth = [
"Vendémiaire", "Brumaire", "Frimaire", "Nivôse", "Pluviôse", "Vendémiaire", "Brumaire", "Frimaire", "Nivôse", "Pluviôse",
"Ventôse", "Germinal", "Floréal", "Prairial", "Messidor", "Thermidor", "Ventôse", "Germinal", "Floréal", "Prairial", "Messidor",
"Fructidor", "Extra", ] "Thermidor", "Fructidor", "Extra",
]
_fmonth2num = { _fmonth2num = {
"vend" : 0, "brum" : 1, "frim" : 2, "nivo" : 3, "pluv" : 4, "vend" : 0, "brum" : 1, "frim" : 2, "nivo" : 3, "pluv" : 4,
"vent" : 5, "germ" : 6, "flor" : 7, "prai" : 8, "mess" : 9, "vent" : 5, "germ" : 6, "flor" : 7, "prai" : 8, "mess" : 9,
"ther" :10, "fruc" :11, "extr" : 12,"comp" :12, "nivô" : 3 } "ther" :10, "fruc" :11, "extr" : 12,"comp" :12, "nivô" : 3
}
_hmonth = [ _hmonth = [
"Tishri", "Heshvan", "Kislev", "Tevet", "Shevat", "AdarI", "Tishri", "Heshvan", "Kislev", "Tevet", "Shevat", "AdarI",
"AdarII", "Nisan", "Iyyar", "Sivan", "Tammuz", "Av", "Elul" "AdarII", "Nisan", "Iyyar", "Sivan", "Tammuz", "Av",
"Elul",
] ]
_hmonth2num = { _hmonth2num = {
@ -67,23 +70,20 @@ _hmonth2num = {
"aav" :11, "ell" :12, "aav" :11, "ell" :12,
} }
_mname = [ _("January"), _("February"), _("March"), _("April"), _mname = [
_("January"), _("February"), _("March"), _("April"),
_("May"), _("June"), _("July"), _("August"), _("May"), _("June"), _("July"), _("August"),
_("September"), _("October"), _("November"), _("December") ] _("September"), _("October"), _("November"), _("December")
]
_m2num = { string.lower(_mname[0][0:3]) : 0,
string.lower(_mname[1][0:3]) : 1,
string.lower(_mname[2][0:3]) : 2,
string.lower(_mname[3][0:3]) : 3,
string.lower(_mname[4][0:3]) : 4,
string.lower(_mname[5][0:3]) : 5,
string.lower(_mname[6][0:3]) : 6,
string.lower(_mname[7][0:3]) : 7,
string.lower(_mname[8][0:3]) : 8,
string.lower(_mname[9][0:3]) : 9,
string.lower(_mname[10][0:3]) : 10,
string.lower(_mname[11][0:3]) : 11 }
_m2num = {
string.lower(_mname[0][0:3]): 0, string.lower(_mname[1][0:3]): 1,
string.lower(_mname[2][0:3]): 2, string.lower(_mname[3][0:3]): 3,
string.lower(_mname[4][0:3]): 4, string.lower(_mname[5][0:3]): 5,
string.lower(_mname[6][0:3]): 6, string.lower(_mname[7][0:3]): 7,
string.lower(_mname[8][0:3]): 8, string.lower(_mname[9][0:3]): 9,
string.lower(_mname[10][0:3]): 10, string.lower(_mname[11][0:3]): 11
}
UNDEF = -999999 UNDEF = -999999
@ -98,9 +98,6 @@ class Date:
Error = "Illegal Date" Error = "Illegal Date"
range = 1
normal = 0
# The last part of these two strings must remain untranslated. It # The last part of these two strings must remain untranslated. It
# is required to read saved data from XML. # is required to read saved data from XML.
from_str = _("(from|between|bet|bet.") + "|FROM)" from_str = _("(from|between|bet|bet.") + "|FROM)"
@ -147,15 +144,6 @@ class Date:
def getYear(self): def getYear(self):
return self.start.year return self.start.year
def getHighYear(self):
if self.stop == None:
return self.start.year
else:
return self.stop.year
def getLowYear(self):
return self.start.getYear()
def getMonth(self): def getMonth(self):
if self.start.month == UNDEF: if self.start.month == UNDEF:
return UNDEF return UNDEF
@ -264,16 +252,6 @@ class Date:
d2 = self.stop.display_calendar(month_map) d2 = self.stop.display_calendar(month_map)
return "%s %s %s %s (%s)" % ( _("from"),d1,_("to"), d2,cal_str) return "%s %s %s %s (%s)" % ( _("from"),d1,_("to"), d2,cal_str)
def getSaveDate(self):
if self.range == 1:
d1 = self.start.getSaveDate()
d2 = self.stop.getSaveDate()
return "FROM %s TO %s" % (d1,d2)
elif self.range == -1:
return self.text
else:
return self.start.getSaveDate()
def isEmpty(self): def isEmpty(self):
s = self.start s = self.start
return s.year==UNDEF and s.month==UNDEF and s.day==UNDEF return s.year==UNDEF and s.month==UNDEF and s.day==UNDEF
@ -315,31 +293,29 @@ class SingleDate:
before = 2 before = 2
after = 3 after = 3
emname =[ 'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', emname =[
'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC' ] 'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN',
'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'
]
em2num ={ "jan" : 0, "feb" : 1, "mar" : 2, "apr" : 3, em2num ={
"jan" : 0, "feb" : 1, "mar" : 2, "apr" : 3,
"may" : 4, "jun" : 5, "jul" : 6, "aug" : 7, "may" : 4, "jun" : 5, "jul" : 6, "aug" : 7,
"sep" : 8, "oct" : 9, "nov" : 10,"dec" : 11 } "sep" : 8, "oct" : 9, "nov" : 10,"dec" : 11
}
m2v = { _("abt") : about , m2v = {
_("about") : about, _("abt") : about , _("about") : about,
_("abt.") : about, _("abt.") : about, _("est") : about ,
_("est") : about , _("est.") : about , _("circa") : about,
_("est.") : about , _("around") : about, _("before") : before,
_("circa") : about, _("bef") : before, _("bef.") : before,
_("around") : about, _("after") : after, _("aft.") : after,
_("before") : before,
_("bef") : before,
_("bef.") : before,
_("after") : after,
_("aft.") : after,
_("aft") : after, _("aft") : after,
# And the untranslated versions for reading saved data from XML. # And the untranslated versions for reading saved data from XML.
"abt" : about, "abt" : about, "about" : about,
"about" : about, "after" : after, "before": before
"after" : after, }
"before" : before }
modifiers = '(' + \ modifiers = '(' + \
_("abt\.?") + '|' + \ _("abt\.?") + '|' + \
@ -357,7 +333,6 @@ class SingleDate:
fmt1 = compile(start+"(\S+)(\s+\d+\s*,)?\s*(\d+)?\s*$", IGNORECASE) fmt1 = compile(start+"(\S+)(\s+\d+\s*,)?\s*(\d+)?\s*$", IGNORECASE)
fmt2 = compile(start+"(\d+)\.?\s+(\S+)(\s+\d+)?\s*$", IGNORECASE) fmt2 = compile(start+"(\d+)\.?\s+(\S+)(\s+\d+)?\s*$", IGNORECASE)
quick= compile(start + "(\d+)?\s(\S\S\S)?\s(\d+)?", IGNORECASE)
fmt3 = compile(start+r"([?\d]+)\s*[./-]\s*([?\d]+)\s*[./-]\s*([?\d]+)\s*$", fmt3 = compile(start+r"([?\d]+)\s*[./-]\s*([?\d]+)\s*[./-]\s*([?\d]+)\s*$",
IGNORECASE) IGNORECASE)
fmt7 = compile(start+r"([?\d]+)\s*[./-]\s*([?\d]+)\s*$", IGNORECASE) fmt7 = compile(start+r"([?\d]+)\s*[./-]\s*([?\d]+)\s*$", IGNORECASE)
@ -383,8 +358,7 @@ class SingleDate:
if val == None: if val == None:
self.mode = SingleDate.exact self.mode = SingleDate.exact
else: else:
val = string.lower(val) self.mode = SingleDate.m2v[string.lower(val)]
self.mode = SingleDate.m2v[val]
def setMonth(self,val): def setMonth(self,val):
if val > 12 or val < 0: if val > 12 or val < 0:
@ -435,6 +409,7 @@ class SingleDate:
self.month = _m2num[string.lower(text[0:3])] self.month = _m2num[string.lower(text[0:3])]
except KeyError: except KeyError:
self.setMonthStrEng(text) self.setMonthStrEng(text)
raise Date.Error,text
def setMonthStrEng(self,text): def setMonthStrEng(self,text):
try: try:
@ -463,33 +438,6 @@ class SingleDate:
d = "-%02d" % self.day d = "-%02d" % self.day
return "%s%s%s" % (y,m,d) return "%s%s%s" % (y,m,d)
def getSaveDate(self):
if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF :
return ""
elif self.day == UNDEF:
if self.month == UNDEF:
retval = str(self.year)
elif self.year == UNDEF:
retval = SingleDate.emname[self.month]
else:
retval = "%s %d" % (SingleDate.emname[self.month],self.year)
elif self.month == UNDEF:
retval = str(self.year)
else:
month = SingleDate.emname[self.month]
if self.year == UNDEF:
retval = "%d %s ????" % (self.day,month)
else:
retval = "%d %s %d" % (self.day,month,self.year)
if self.mode == SingleDate.about:
retval = "ABOUT %s" % retval
elif self.mode == SingleDate.before:
retval = "BEFORE" + " " + retval
elif self.mode == SingleDate.after:
retval = "AFTER" + " " + retval
return retval
def get_fmt1(self): def get_fmt1(self):
if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF : if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF :
return "" return ""
@ -841,8 +789,6 @@ class SingleDate:
matches = match.groups() matches = match.groups()
self.setMode(matches[0]) self.setMode(matches[0])
self.setMonthStr(matches[2]) self.setMonthStr(matches[2])
if self.month == UNDEF:
raise Date.Error,text
self.day = int(matches[1]) self.day = int(matches[1])
if len(matches) == 4 and matches[3] != None: if len(matches) == 4 and matches[3] != None:
self.setYearVal(matches[3]) self.setYearVal(matches[3])
@ -891,21 +837,14 @@ class SingleDate:
match = SingleDate.fmt1.match(text) match = SingleDate.fmt1.match(text)
if match != None: if match != None:
matches = match.groups() (mode,mon,day,year) = match.groups()
self.setMode(matches[0]) self.setMode(mode)
self.setMonthStr(matches[1]) self.setMonthStr(mon)
if self.month == UNDEF: if day:
raise Date.Error,text self.setDayVal(int(string.replace(day,',','')))
val = matches[2]
if val:
self.day = int(string.replace(val,',',''))
else: else:
self.day = UNDEF self.day = UNDEF
val = matches[3] self.setYearVal(year)
if val:
self.setYearVal(matches[3])
else:
self.setYearVal(UNDEF)
return 1 return 1
match = SingleDate.fmt4.match(text) match = SingleDate.fmt4.match(text)
@ -913,8 +852,6 @@ class SingleDate:
matches = match.groups() matches = match.groups()
self.setMode(matches[0]) self.setMode(matches[0])
self.setMonthStr(matches[1]) self.setMonthStr(matches[1])
if self.month == UNDEF:
raise Date.Error,text
self.day = UNDEF self.day = UNDEF
if len(matches) == 4: if len(matches) == 4:
self.setYearVal(matches[3]) self.setYearVal(matches[3])
@ -1007,37 +944,5 @@ def compare_dates(f,s):
else: else:
return cmp(first.day,second.day) return cmp(first.day,second.day)
_func = SingleDate.fmtFunc[0] _func = SingleDate.fmtFunc[0]
if __name__ == "__main__":
def checkit(s):
d = Date()
d.set(s)
print s, ':', d.getDate(), ':', d.getQuoteDate()
for code in range(0,7):
Date.formatCode = code
Date.entryCode = 0
print "\nFormat Code = %d\n" % code
checkit("June 11")
checkit("1923")
checkit("11/12/1293")
checkit("11 JAN 1923")
checkit("11-1-1929")
checkit("4/3/1203")
checkit("3/1203")
checkit("?/3/1203")
checkit("January 4, 1923")
checkit("before 3/3/1239")
checkit("est 2-3-1023")
checkit("between January 4, 1234 and NOV 4, 1245")
checkit("from 3-2-1234 to 5-4-2345")
Date.entryCode = 1
checkit("1/12/1999")
checkit("12/11/1999")
checkit("summer")
print "----------"
checkit("BET. 1994 - 1999")

View File

@ -391,10 +391,7 @@ class EditPerson:
self.redraw_event_list() self.redraw_event_list()
def ev_source_drag_data_get(self,widget, context, selection_data, info, time): def ev_source_drag_data_get(self,widget, context, selection_data, info, time):
if len(widget.selection) != 1: ev = widget.get_row_data(widget.focus_row)
return
row = widget.selection[0]
ev = widget.get_row_data(row)
bits_per = 8; # we're going to pass a string bits_per = 8; # we're going to pass a string
pickled = pickle.dumps(ev); pickled = pickle.dumps(ev);
@ -414,10 +411,7 @@ class EditPerson:
self.redraw_url_list() self.redraw_url_list()
def url_source_drag_data_get(self,widget, context, selection_data, info, time): def url_source_drag_data_get(self,widget, context, selection_data, info, time):
if len(widget.selection) != 1: ev = widget.get_row_data(widget.focus_row)
return
row = widget.selection[0]
ev = widget.get_row_data(row)
bits_per = 8; # we're going to pass a string bits_per = 8; # we're going to pass a string
pickled = pickle.dumps(ev); pickled = pickle.dumps(ev);
@ -441,10 +435,7 @@ class EditPerson:
self.redraw_attr_list() self.redraw_attr_list()
def at_source_drag_data_get(self,widget, context, selection_data, info, time): def at_source_drag_data_get(self,widget, context, selection_data, info, time):
if len(widget.selection) != 1: ev = widget.get_row_data(widget.focus_row)
return
row = widget.selection[0]
ev = widget.get_row_data(row)
bits_per = 8; # we're going to pass a string bits_per = 8; # we're going to pass a string
pickled = pickle.dumps(ev); pickled = pickle.dumps(ev);
@ -468,10 +459,7 @@ class EditPerson:
self.redraw_addr_list() self.redraw_addr_list()
def ad_source_drag_data_get(self,widget, context, selection_data, info, time): def ad_source_drag_data_get(self,widget, context, selection_data, info, time):
if len(widget.selection) != 1: ev = widget.get_row_data(widget.focus_row)
return
row = widget.selection[0]
ev = widget.get_row_data(row)
bits_per = 8; # we're going to pass a string bits_per = 8; # we're going to pass a string
pickled = pickle.dumps(ev); pickled = pickle.dumps(ev);

View File

@ -169,10 +169,7 @@ class EditPlace:
self.redraw_url_list() self.redraw_url_list()
def url_source_drag_data_get(self,widget, context, selection_data, info, time): def url_source_drag_data_get(self,widget, context, selection_data, info, time):
if len(widget.selection) != 1: ev = widget.get_row_data(widget.focus_row)
return
row = widget.selection[0]
ev = widget.get_row_data(row)
bits_per = 8; # we're going to pass a string bits_per = 8; # we're going to pass a string
pickled = pickle.dumps(ev); pickled = pickle.dumps(ev);

View File

@ -401,7 +401,11 @@ class GrampsParser:
self.placeobj.addPhoto(self.pref) self.placeobj.addPhoto(self.pref)
def start_daterange(self,attrs): def start_daterange(self,attrs):
if self.address: if self.source_ref:
d = self.source_ref.getDate()
elif self.ord:
d = self.ord.getDateObj()
elif self.address:
d = self.address.getDateObj() d = self.address.getDateObj()
else: else:
d = self.event.getDateObj() d = self.event.getDateObj()
@ -414,7 +418,9 @@ class GrampsParser:
d.range = 1 d.range = 1
def start_dateval(self,attrs): def start_dateval(self,attrs):
if self.ord: if self.source_ref:
d = self.source_ref.getDate()
elif self.ord:
d = self.ord.getDateObj() d = self.ord.getDateObj()
elif self.address: elif self.address:
d = self.address.getDateObj() d = self.address.getDateObj()
@ -432,7 +438,9 @@ class GrampsParser:
d.get_start_date().setMode(None) d.get_start_date().setMode(None)
def start_datestr(self,attrs): def start_datestr(self,attrs):
if self.ord: if self.source_ref:
d = self.source_ref.getDate()
elif self.ord:
d = self.ord.getDateObj() d = self.ord.getDateObj()
elif self.address: elif self.address:
d = self.address.getDateObj() d = self.address.getDateObj()

View File

@ -185,10 +185,7 @@ class Marriage:
self.redraw_event_list() self.redraw_event_list()
def ev_source_drag_data_get(self,widget, context, selection_data, info, time): def ev_source_drag_data_get(self,widget, context, selection_data, info, time):
if len(widget.selection) != 1: ev = widget.get_row_data(widget.focus_row)
return
row = widget.selection[0]
ev = widget.get_row_data(row)
bits_per = 8; # we're going to pass a string bits_per = 8; # we're going to pass a string
pickled = pickle.dumps(ev); pickled = pickle.dumps(ev);
@ -212,11 +209,7 @@ class Marriage:
self.redraw_attr_list() self.redraw_attr_list()
def at_source_drag_data_get(self,widget, context, selection_data, info, time): def at_source_drag_data_get(self,widget, context, selection_data, info, time):
if len(widget.selection) != 1: ev = widget.get_row_data(widget.focus_row)
return
row = widget.selection[0]
ev = widget.get_row_data(row)
bits_per = 8; # we're going to pass a string bits_per = 8; # we're going to pass a string
pickled = pickle.dumps(ev); pickled = pickle.dumps(ev);
data = str(('fattr',self.family.getId(),pickled)); data = str(('fattr',self.family.getId(),pickled));

View File

@ -277,9 +277,7 @@ class MediaView:
def on_drag_data_get(self,w, context, selection_data, info, time): def on_drag_data_get(self,w, context, selection_data, info, time):
if info == 1: if info == 1:
return return
if len(w.selection) > 0: d = w.get_row_data(w.focus_row)
row = w.selection[0]
d = w.get_row_data(row)
id = d.getId() id = d.getId()
selection_data.set(selection_data.target, 8, id) selection_data.set(selection_data.target, 8, id)
@ -288,7 +286,6 @@ class MediaView:
if data and data.format == 8: if data and data.format == 8:
d = string.strip(string.replace(data.data,'\0',' ')) d = string.strip(string.replace(data.data,'\0',' '))
protocol,site,file, j,k,l = urlparse.urlparse(d) protocol,site,file, j,k,l = urlparse.urlparse(d)
print protocol,site,file,j,k,l
if protocol == "file": if protocol == "file":
name = file name = file
mime = utils.get_mime_type(name) mime = utils.get_mime_type(name)

View File

@ -225,7 +225,6 @@ def reload_plugins(obj):
for plugin in _failed: for plugin in _failed:
try: try:
__import__(plugin) __import__(plugin)
print plugin
except: except:
print _("Failed to load the module: %s") % plugin print _("Failed to load the module: %s") % plugin
import traceback import traceback

View File

@ -1227,12 +1227,6 @@ class Event(DataObj):
"""sets the Date object associated with the Event""" """sets the Date object associated with the Event"""
self.date = date self.date = date
def getSaveDate(self) :
"""returns the date of the Event in the form wanted by gramps XML save"""
if self.date:
return self.date.getSaveDate()
return ""
class Family: class Family:
"""Represents a family unit in the gramps database""" """Represents a family unit in the gramps database"""

View File

@ -107,12 +107,12 @@ def dump_my_event(g,name,event,index=1):
if not event: if not event:
return return
date = event.getSaveDate() date = event.getDateObj()
place = event.getPlace() place = event.getPlace()
description = event.getDescription() description = event.getDescription()
cause = event.getCause() cause = event.getCause()
if (not name or name == "Birth" or name == "Death") and \ if (not name or name == "Birth" or name == "Death") and \
not date and not place and not description: date.isEmpty() and not place and not description:
return return
sp = " " * index sp = " " * index
@ -160,10 +160,10 @@ def dump_source_ref(g,source_ref,index=1):
p = source_ref.getPage() p = source_ref.getPage()
c = source_ref.getComments() c = source_ref.getComments()
t = source_ref.getText() t = source_ref.getText()
d = source_ref.getDate().getSaveDate() d = source_ref.getDate()
q = source_ref.getConfidence() q = source_ref.getConfidence()
g.write(" " * index) g.write(" " * index)
if p == "" and c == "" and t == "" and d == "" and q == 2: if p == "" and c == "" and t == "" and d.isEmpty() and q == 2:
g.write('<sourceref ref="%s"/>\n' % source.getId()) g.write('<sourceref ref="%s"/>\n' % source.getId())
else: else:
if q == 2: if q == 2:
@ -173,7 +173,7 @@ def dump_source_ref(g,source_ref,index=1):
write_line(g,"spage",p,index+1) write_line(g,"spage",p,index+1)
write_note(g,"scomments",c,index+1) write_note(g,"scomments",c,index+1)
write_note(g,"stext",t,index+1) write_note(g,"stext",t,index+1)
write_line(g,"sdate",d,index+1) write_date(g,d,index+1)
g.write("%s</sourceref>\n" % (" " * index)) g.write("%s</sourceref>\n" % (" " * index))
#------------------------------------------------------------------------- #-------------------------------------------------------------------------

View File

@ -79,6 +79,7 @@ revisionFile = "%s/revision.glade" % rootDir
srcselFile = "%s/srcsel.glade" % rootDir srcselFile = "%s/srcsel.glade" % rootDir
findFile = "%s/find.glade" % rootDir findFile = "%s/find.glade" % rootDir
mergeFile = "%s/mergedata.glade" % rootDir mergeFile = "%s/mergedata.glade" % rootDir
traceFile = "%s/trace.glade" % rootDir
pluginsDir = "%s/plugins" % rootDir pluginsDir = "%s/plugins" % rootDir
filtersDir = "%s/filters" % rootDir filtersDir = "%s/filters" % rootDir
dataDir = "%s/data" % rootDir dataDir = "%s/data" % rootDir

View File

@ -4,6 +4,9 @@ import traceback
import intl import intl
import os import os
import gtk import gtk
import gnome.ui
import const
intl.textdomain("gramps") intl.textdomain("gramps")
@ -23,10 +26,11 @@ try:
else: else:
gramps_main.main(None) gramps_main.main(None)
except: except:
traceback.print_exc() traceback.print_exc()
fname = os.path.expanduser("~/gramps.err") fname = os.path.expanduser("~/gramps.err")
errfile = open(fname,"w") errfile = open(fname,"w")
traceback.print_exc(file=errfile) traceback.print_exc(file=errfile)
errfile.close() errfile.close()

View File

@ -2029,6 +2029,7 @@ def main(arg):
read_file(Config.lastfile) read_file(Config.lastfile)
database.setResearcher(Config.owner) database.setResearcher(Config.owner)
gtk.mainloop() gtk.mainloop()
#------------------------------------------------------------------------- #-------------------------------------------------------------------------

View File

@ -666,13 +666,13 @@ class GedcomWriter:
birth = person.getBirth() birth = person.getBirth()
if not (self.private and birth.getPrivacy()): if not (self.private and birth.getPrivacy()):
if birth.getSaveDate() != "" or birth.getPlaceName() != "": if not birth.getDateObj().isEmpty() or birth.getPlaceName() != "":
self.g.write("1 BIRT\n") self.g.write("1 BIRT\n")
self.dump_event_stats(birth) self.dump_event_stats(birth)
death = person.getDeath() death = person.getDeath()
if not (self.private and death.getPrivacy()): if not (self.private and death.getPrivacy()):
if death.getSaveDate() != "" or death.getPlaceName() != "": if not death.getDateObj().isEmpty() or death.getPlaceName() != "":
self.g.write("1 DEAT\n") self.g.write("1 DEAT\n")
self.dump_event_stats(death) self.dump_event_stats(death)
@ -764,9 +764,7 @@ class GedcomWriter:
if self.private and addr.getPrivacy(): if self.private and addr.getPrivacy():
continue continue
self.g.write("1 RESI\n") self.g.write("1 RESI\n")
datestr = addr.getDateObj().getSaveDate() self.print_date("2 DATE",addr.getDateObj())
if datestr != "":
self.g.write("2 DATE %s\n" % self.cnvtxt(datestr))
if self.resi == 0: if self.resi == 0:
self.write_long_text("ADDR",2,addr.getStreet()) self.write_long_text("ADDR",2,addr.getStreet())
if addr.getCity() != "": if addr.getCity() != "":
@ -881,10 +879,7 @@ class GedcomWriter:
def dump_event_stats(self,event): def dump_event_stats(self,event):
dateobj = event.getDateObj() dateobj = event.getDateObj()
if not dateobj.isEmpty():
self.print_date("2 DATE",dateobj) self.print_date("2 DATE",dateobj)
elif dateobj.getText() != "":
self.g.write("2 DATE %s\n" % self.cnvtxt(dateobj.getText()))
if event.getPlaceName() != "": if event.getPlaceName() != "":
self.g.write("2 PLAC %s\n" % self.cnvtxt(event.getPlaceName())) self.g.write("2 PLAC %s\n" % self.cnvtxt(event.getPlaceName()))
if event.getCause() != "": if event.getCause() != "":
@ -906,8 +901,11 @@ class GedcomWriter:
def print_date(self,prefix,date): def print_date(self,prefix,date):
start = date.get_start_date() start = date.get_start_date()
if date.isEmpty():
if date.get_calendar() == Date.GREGORIAN: val = date.getText()
if val != "":
self.g.write("%s %s\n" % (prefix,self.cnvtxt(val)))
elif date.get_calendar() == Date.GREGORIAN:
if date.isRange(): if date.isRange():
val = "FROM %s TO %s" % (make_date(start,_month), val = "FROM %s TO %s" % (make_date(start,_month),
make_date(date.get_stop_date(),_month)) make_date(date.get_stop_date(),_month))
@ -969,12 +967,13 @@ class GedcomWriter:
self.g.write("%d PAGE %s\n" % (level+1,ref.getPage())) self.g.write("%d PAGE %s\n" % (level+1,ref.getPage()))
ref_text = ref.getText() ref_text = ref.getText()
if ref_text != "" or ref.getDate().getDate() != "": if ref_text != "" or not ref.getDate().isEmpty():
self.g.write('%d DATA\n' % (level+1)) self.g.write('%d DATA\n' % (level+1))
if ref_text != "": if ref_text != "":
self.write_long_text("TEXT",level+2,ref_text) self.write_long_text("TEXT",level+2,ref_text)
if ref.getDate().getDate(): pfx = "%d DATE" % (level+2)
self.g.write("%d DATE %s\n" % (level+2,ref.getDate().getSaveDate())) print pfx,ref.getDate()
self.print_date(pfx,ref.getDate())
if ref.getComments() != "": if ref.getComments() != "":
self.write_long_text("NOTE",level+1,ref.getComments()) self.write_long_text("NOTE",level+1,ref.getComments())

View File

@ -43,26 +43,19 @@ def soundex(str):
"Return the soundex value to a string argument." "Return the soundex value to a string argument."
str = string.strip(string.upper(str)) str = string.strip(string.upper(str))
if not str: if not str:
return "Z000" return "Z000"
str2 = str[0] str2 = str[0]
str = string.translate(str, TABLE, IGNORE) str = string.translate(str, TABLE, IGNORE)
if not str: if not str:
return "Z000" return "Z000"
prev = str[0] prev = str[0]
for x in str[1:]: for x in str[1:]:
if x != prev and x != "0": if x != prev and x != "0":
str2 = str2 + x str2 = str2 + x
prev = x prev = x
# pad with zeros # pad with zeros
str2 = str2+"0000" str2 = str2+"0000"
return str2[:4] return str2[:4]
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -72,5 +65,4 @@ def soundex(str):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def compare(str1, str2): def compare(str1, str2):
"1 if strings are close. 0 otherwise." "1 if strings are close. 0 otherwise."
return soundex(str1) == soundex(str2) return soundex(str1) == soundex(str2)

View File

@ -103,34 +103,25 @@ def phonebook_name(person):
return "" return ""
def family_name(family): def family_name(family):
"""Builds a name for the family from the parents names"""
father = family.getFather() father = family.getFather()
mother = family.getMother() mother = family.getMother()
if father and mother: if father and mother:
name = _("%s and %s") % (father.getPrimaryName().getName(),mother.getPrimaryName().getName()) fname = father.getPrimaryName().getName()
mname = mother.getPrimaryName().getName()
name = _("%s and %s") % (fname,mname)
elif father: elif father:
name = father.getPrimaryName().getName() name = father.getPrimaryName().getName()
else: else:
name = mother.getPrimaryName().getName() name = mother.getPrimaryName().getName()
return name return name
#-------------------------------------------------------------------------
#
# Short hand function to return either the person's name, or an empty
# string if the person is None
#
#-------------------------------------------------------------------------
def phonebook_from_name(name,alt): def phonebook_from_name(name,alt):
if alt: if alt:
return "%s *" % name.getName() return "%s *" % name.getName()
else: else:
return name.getName() return name.getName()
#-------------------------------------------------------------------------
#
# Short hand function to return either the person's name, or an empty
# string if the person is None
#
#-------------------------------------------------------------------------
def normal_name(person): def normal_name(person):
if person: if person:
return person.getPrimaryName().getRegularName() return person.getPrimaryName().getRegularName()
@ -155,33 +146,15 @@ def destroy_passed_object(obj):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
if string.find("%.3f" % 1.2, ",") == -1: if string.find("%.3f" % 1.2, ",") == -1:
_use_comma = 0
else:
_use_comma = 1
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
if _use_comma:
def txt2fl(st):
return string.atof(string.replace(st,'.',','))
else:
def txt2fl(st): def txt2fl(st):
return string.atof(string.replace(st,',','.')) return string.atof(string.replace(st,',','.'))
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
if _use_comma:
def fl2txt(fmt,val):
return string.replace(fmt % val, ',', '.')
else:
def fl2txt(fmt,val): def fl2txt(fmt,val):
return fmt % val return fmt % val
else:
def txt2fl(st):
return string.atof(string.replace(st,'.',','))
def fl2txt(fmt,val):
return string.replace(fmt % val, ',', '.')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -478,7 +451,6 @@ def combo_insert_text(combo,new_text,new_text_len,i_dont_care):
timer = gtk.timeout_add(5, combo_timer_callback, combo) timer = gtk.timeout_add(5, combo_timer_callback, combo)
combo.set_data("timer", timer); combo.set_data("timer", timer);
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# The combo box entry field lost focus. Go clear any selection. Why # The combo box entry field lost focus. Go clear any selection. Why
@ -489,7 +461,6 @@ def combo_insert_text(combo,new_text,new_text_len,i_dont_care):
def combo_lost_focus(entry,a,b): def combo_lost_focus(entry,a,b):
entry.select_region(0, 0) entry.select_region(0, 0)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# The workhorse routine of file completion. This routine grabs the # The workhorse routine of file completion. This routine grabs the