* src/Reorder.py: cleanup

* src/TransUtils.py: cleanup
	* src/TipOfDay.py: cleanup
	* src/SubstKeywords.py: cleanup
	* src/Utils.py: cleanup
	* src/soundex.py: cleanup
	* src/Sort.py: cleanup

2007-09-09  Don Allingham  <don@gramps-project.org>


svn: r8955
This commit is contained in:
Don Allingham 2007-09-10 03:03:46 +00:00
parent 6f7f0d710a
commit 2fdae3eff8
8 changed files with 290 additions and 292 deletions

View File

@ -1,3 +1,12 @@
2007-09-09 Don Allingham <don@gramps-project.org>
* src/Reorder.py: cleanup
* src/TransUtils.py: cleanup
* src/TipOfDay.py: cleanup
* src/SubstKeywords.py: cleanup
* src/Utils.py: cleanup
* src/soundex.py: cleanup
* src/Sort.py: cleanup
2007-09-09 Don Allingham <don@gramps-project.org>
* src/ViewManager.py: cleanup
* src/DisplayState.py: cleanup

View File

@ -7,7 +7,7 @@
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
@ -17,8 +17,6 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: _SourceView.py 7138 2006-08-06 06:26:10Z rshura $
from gettext import gettext as _
@ -29,157 +27,157 @@ from BasicUtils import name_displayer
import ListModel
import ManagedWindow
_parent_titles = [(_('Father'),-1,200),(_('Mother'),-1,200),('',-1,0)]
_family_titles = [(_('Spouse'),-1,200),(_('Relationship'),-1,200),('',-1,0)]
PARENT_TITLES = [(_('Father'), -1, 200), (_('Mother'), -1, 200), ('', -1, 0)]
FAMILY_TITLES = [(_('Spouse'), -1, 200), (_('Relationship'), -1, 200), ('', -1, 0)]
class Reorder(ManagedWindow.ManagedWindow):
def __init__(self, state, uistate, track, handle):
xml = gtk.glade.XML(const.GLADE_FILE, "reorder", "gramps")
top = xml.get_widget('reorder')
top = xml.get_widget('reorder')
self.dbstate = state
self.dbstate = state
ManagedWindow.ManagedWindow.__init__(self, uistate, track, self)
self.person = self.dbstate.db.get_person_from_handle(handle)
self.parent_list = self.person.get_parent_family_handle_list()
self.family_list = self.person.get_family_handle_list()
self.person = self.dbstate.db.get_person_from_handle(handle)
self.parent_list = self.person.get_parent_family_handle_list()
self.family_list = self.person.get_family_handle_list()
penable = len(self.parent_list) > 1
fenable = len(self.family_list) > 1
penable = len(self.parent_list) > 1
fenable = len(self.family_list) > 1
self.set_window(top, None, _("Reorder Relationships"))
self.set_window(top, None, _("Reorder Relationships"))
self.ptree = xml.get_widget('ptree')
self.pmodel = ListModel.ListModel(self.ptree,_parent_titles)
self.ptree = xml.get_widget('ptree')
self.pmodel = ListModel.ListModel(self.ptree, PARENT_TITLES)
self.ftree = xml.get_widget('ftree')
self.fmodel = ListModel.ListModel(self.ftree,_family_titles)
self.ftree = xml.get_widget('ftree')
self.fmodel = ListModel.ListModel(self.ftree, FAMILY_TITLES)
xml.get_widget('ok').connect('clicked', self.ok_clicked)
xml.get_widget('cancel').connect('clicked', self.cancel_clicked)
xml.get_widget('ok').connect('clicked', self.ok_clicked)
xml.get_widget('cancel').connect('clicked', self.cancel_clicked)
fup = xml.get_widget('fup')
fup.connect('clicked', self.fup_clicked)
fup.set_sensitive(fenable)
fup = xml.get_widget('fup')
fup.connect('clicked', self.fup_clicked)
fup.set_sensitive(fenable)
fdown = xml.get_widget('fdown')
fdown.connect('clicked', self.fdown_clicked)
fdown.set_sensitive(fenable)
fdown = xml.get_widget('fdown')
fdown.connect('clicked', self.fdown_clicked)
fdown.set_sensitive(fenable)
pup = xml.get_widget('pup')
pup.connect('clicked', self.pup_clicked)
pup.set_sensitive(penable)
pup = xml.get_widget('pup')
pup.connect('clicked', self.pup_clicked)
pup.set_sensitive(penable)
pdown = xml.get_widget('pdown')
pdown.connect('clicked', self.pdown_clicked)
pdown.set_sensitive(penable)
pdown = xml.get_widget('pdown')
pdown.connect('clicked', self.pdown_clicked)
pdown.set_sensitive(penable)
self.fill_data()
self.fill_data()
self.show()
self.show()
def fill_data(self):
self.fill_parents()
self.fill_family()
self.fill_parents()
self.fill_family()
def fill_parents(self):
for handle in self.parent_list:
family = self.dbstate.db.get_family_from_handle(handle)
fhandle = family.get_father_handle()
mhandle = family.get_mother_handle()
for handle in self.parent_list:
family = self.dbstate.db.get_family_from_handle(handle)
fhandle = family.get_father_handle()
mhandle = family.get_mother_handle()
fname = ""
if fhandle:
father = self.dbstate.db.get_person_from_handle(fhandle)
if father:
fname = name_displayer.display(father)
fname = ""
if fhandle:
father = self.dbstate.db.get_person_from_handle(fhandle)
if father:
fname = name_displayer.display(father)
mname = ""
if mhandle:
mother = self.dbstate.db.get_person_from_handle(mhandle)
if mother:
mname = name_displayer.display(mother)
mname = ""
if mhandle:
mother = self.dbstate.db.get_person_from_handle(mhandle)
if mother:
mname = name_displayer.display(mother)
self.pmodel.add([fname, mname, handle])
self.pmodel.add([fname, mname, handle])
def fill_family(self):
for handle in self.family_list:
for handle in self.family_list:
family = self.dbstate.db.get_family_from_handle(handle)
fhandle = family.get_father_handle()
mhandle = family.get_mother_handle()
family = self.dbstate.db.get_family_from_handle(handle)
fhandle = family.get_father_handle()
mhandle = family.get_mother_handle()
name = ""
name = ""
if fhandle and fhandle != self.person.handle:
spouse = self.dbstate.db.get_person_from_handle(fhandle)
if spouse:
name = name_displayer.display(spouse)
elif mhandle:
spouse = self.dbstate.db.get_person_from_handle(mhandle)
if spouse:
name = name_displayer.display(spouse)
if fhandle and fhandle != self.person.handle:
spouse = self.dbstate.db.get_person_from_handle(fhandle)
if spouse:
name = name_displayer.display(spouse)
elif mhandle:
spouse = self.dbstate.db.get_person_from_handle(mhandle)
if spouse:
name = name_displayer.display(spouse)
reltype = str(family.get_relationship())
reltype = str(family.get_relationship())
self.fmodel.add([name, reltype, handle])
self.fmodel.add([name, reltype, handle])
def cancel_clicked(self, obj):
self.close()
self.close()
def ok_clicked(self, obj):
trans = self.dbstate.db.transaction_begin()
self.dbstate.db.commit_person(self.person, trans)
name = name_displayer.display(self.person)
msg = _("Reorder Relationships: %s") % name
self.dbstate.db.commit_person(self.person, trans)
name = name_displayer.display(self.person)
msg = _("Reorder Relationships: %s") % name
self.dbstate.db.transaction_commit(trans, msg)
self.close()
self.close()
def pup_clicked(self,obj):
def pup_clicked(self, obj):
"""Moves the current selection up one row"""
row = self.pmodel.get_selected_row()
if not row or row == -1:
return
store,the_iter = self.pmodel.get_selected()
data = self.pmodel.get_data(the_iter,xrange(3))
store, the_iter = self.pmodel.get_selected()
data = self.pmodel.get_data(the_iter, xrange(3))
self.pmodel.remove(the_iter)
self.pmodel.insert(row-1,data,None,1)
self.pmodel.insert(row-1, data, None, 1)
handle = self.parent_list.pop(row)
self.parent_list.insert(row-1,handle)
self.parent_list.insert(row-1, handle)
def pdown_clicked(self, obj):
row = self.pmodel.get_selected_row()
if row + 1 >= self.pmodel.count or row == -1:
return
store,the_iter = self.pmodel.get_selected()
data = self.pmodel.get_data(the_iter,xrange(3))
store, the_iter = self.pmodel.get_selected()
data = self.pmodel.get_data(the_iter, xrange(3))
self.pmodel.remove(the_iter)
self.pmodel.insert(row+1,data,None,1)
self.pmodel.insert(row+1, data, None, 1)
handle = self.parent_list.pop(row)
self.parent_list.insert(row+1,handle)
self.parent_list.insert(row+1, handle)
def fup_clicked(self, obj):
row = self.fmodel.get_selected_row()
if not row or row == -1:
return
store,the_iter = self.fmodel.get_selected()
data = self.fmodel.get_data(the_iter,xrange(3))
store, the_iter = self.fmodel.get_selected()
data = self.fmodel.get_data(the_iter, xrange(3))
self.fmodel.remove(the_iter)
self.fmodel.insert(row-1,data,None,1)
self.fmodel.insert(row-1, data, None, 1)
handle = self.family_list.pop(row)
self.family_list.insert(row-1,handle)
self.family_list.insert(row-1, handle)
def fdown_clicked(self, obj):
row = self.fmodel.get_selected_row()
if row + 1 >= self.fmodel.count or row == -1:
return
store,the_iter = self.fmodel.get_selected()
data = self.fmodel.get_data(the_iter,xrange(3))
store, the_iter = self.fmodel.get_selected()
data = self.fmodel.get_data(the_iter, xrange(3))
self.fmodel.remove(the_iter)
self.fmodel.insert(row+1,data,None,1)
self.fmodel.insert(row+1, data, None, 1)
handle = self.family_list.pop(row)
self.family_list.insert(row+1,handle)
self.family_list.insert(row+1, handle)

View File

@ -8,7 +8,7 @@
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
@ -22,7 +22,7 @@
"""
Provides sorting routines for use in GRAMPS. Since these functions are
intended to provide fast sorting, they tend to bypass access methods,
intended to provide fast sorting, they tend to bypass access methods,
and directly use class members. For this reason, care needs to be taken
to make sure these remain in sync with the rest of the design.
"""
@ -48,18 +48,13 @@ from BasicUtils import name_displayer as _nd
#
#-------------------------------------------------------------------------
_plist = [ 'de', 'van', 'von', 'la', 'di', 'le', 'du' ]
_prefix = {}
for i in _plist:
_prefix[i] = 1
class Sort:
def __init__(self,database):
def __init__(self, database):
self.database = database
def by_last_name(self,first_id,second_id):
"""Sort routine for comparing two last names. If last names are equal,
def by_last_name(self, first_id, second_id):
"""Sort routine for comparing two last names. If last names are equal,
uses the given name and suffix"""
first = self.database.get_person_from_handle(first_id)
second = self.database.get_person_from_handle(second_id)
@ -80,7 +75,7 @@ class Sort:
else:
return locale.strcoll(fsn, ssn)
def by_sorted_name(self,first_id,second_id):
def by_sorted_name(self, first_id, second_id):
"""
Sort routine for comparing two displayed names.
"""
@ -91,9 +86,9 @@ class Sort:
name1 = _nd.sorted(first)
name2 = _nd.sorted(second)
return locale.strcoll(name1,name2)
return locale.strcoll(name1, name2)
def by_birthdate(self,first_id,second_id):
def by_birthdate(self, first_id, second_id):
"""Sort routine for comparing two people by birth dates. If the birth dates
are equal, sorts by name"""
first = self.database.get_person_from_handle(first_id)
@ -114,23 +109,23 @@ class Sort:
dsv1 = date1.get_sort_value()
dsv2 = date2.get_sort_value()
val = cmp(dsv1,dsv2)
val = cmp(dsv1, dsv2)
if val == 0:
return self.by_last_name(first_id,second_id)
return self.by_last_name(first_id, second_id)
return val
def by_date(self,a_id,b_id):
def by_date(self, a_id, b_id):
"""Sort routine for comparing two events by their dates. """
if not (a_id and b_id):
return 0
a = self.database.get_event_from_handle(a_id)
b = self.database.get_event_from_handle(b_id)
return cmp(a.get_date_object(),b.get_date_object())
a_obj = self.database.get_event_from_handle(a_id)
b_obj = self.database.get_event_from_handle(b_id)
return cmp(a_obj.get_date_object(), b_obj.get_date_object())
def by_place_title(self,a_id,b_id):
def by_place_title(self, a_id, b_id):
"""Sort routine for comparing two events by their dates. """
if not (a_id and b_id):
return 0
a = self.database.get_place_from_handle(a_id)
b = self.database.get_place_from_handle(b_id)
return cmp(a.title,b.title)
a_obj = self.database.get_place_from_handle(a_id)
b_obj = self.database.get_place_from_handle(b_id)
return cmp(a_obj.title, b_obj.title)

View File

@ -8,7 +8,7 @@
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
@ -68,7 +68,7 @@ class SubstKeywords:
$M -> Place of preferred marriage
"""
def __init__(self,database,person_handle):
def __init__(self, database, person_handle):
"""Creates a new object and associates a person with it."""
person = database.get_person_from_handle(person_handle)
@ -124,35 +124,26 @@ class SubstKeywords:
if mplace_handle:
self.M = database.get_place_from_handle(mplace_handle).get_title()
def replace(self,line):
self.array = [ ("%n", self.n), ("%N", self.N), ("%b", self.b),
("%B", self.B), ("%d", self.d), ("%D", self.D),
("%i", self.i), ("%S", self.S), ("%s", self.s),
("%m", self.m), ("%M", self.M), ("$$", "$") ]
def replace(self, line):
"""Returns a new line of text with the substitutions performed."""
line = line.replace("$n",self.n)
line = line.replace("$N",self.N)
line = line.replace("$b",self.b)
line = line.replace("$B",self.B)
line = line.replace("$d",self.d)
line = line.replace("$D",self.D)
line = line.replace("$i",self.i)
line = line.replace("$S",self.S)
line = line.replace("$s",self.s)
line = line.replace("$m",self.m)
line = line.replace("$M",self.M)
return line.replace("$$",'$')
for (key, value) in self.array:
line = line.replace(key, value)
return line
def replace_and_clean(self, lines):
array = [ ("%n",self.n), ("%N",self.N), ("%b",self.b),
("%B",self.B), ("%d",self.d), ("%D",self.D),
("%i",self.i), ("%S",self.S), ("%s",self.s),
("%m",self.m), ("%M",self.M)]
new = []
for line in lines:
remove = False
for (key,value) in array:
for (key, value) in self.array:
if line.find(key) != -1:
if value:
line = line.replace(key,value)
line = line.replace(key, value)
else:
remove = True
if not remove:

View File

@ -8,7 +8,7 @@
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
@ -20,12 +20,17 @@
# $Id$
"""
Handles the Tip of the Day dialog
"""
#-------------------------------------------------------------------------
#
# standard python modules
#
#-------------------------------------------------------------------------
from xml.parsers.expat import ParserCreate
from xml.sax.saxutils import escape
from random import Random
from gettext import gettext as _
import os
@ -52,30 +57,30 @@ import ManagedWindow
#
#-------------------------------------------------------------------------
class TipOfDay(ManagedWindow.ManagedWindow):
def __init__(self,uistate):
def __init__(self, uistate):
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self)
xml = gtk.glade.XML(const.GLADE_FILE, "tod_window", "gramps")
window = xml.get_widget("tod_window")
self.set_window(window,
xml.get_widget("title"),
_("Tip of the Day"),
self.set_window(window,
xml.get_widget("title"),
_("Tip of the Day"),
_("Tip of the Day"))
self.tip = xml.get_widget("tip")
self.use = xml.get_widget('usetips')
self.use.set_active(Config.get(Config.USE_TIPS))
image = xml.get_widget('image')
image.set_from_file(os.path.join(const.IMAGE_DIR,'splash.jpg'))
image.set_from_file(os.path.join(const.IMAGE_DIR, 'splash.jpg'))
next = xml.get_widget('next')
next.connect("clicked",self.next_tip_cb)
next.connect("clicked", self.next_tip_cb)
close = xml.get_widget('close')
close.connect("clicked",self.close_cb)
close.connect("clicked", self.close_cb)
tp = TipParser()
self.tip_list = tp.get()
tparser = TipParser()
self.tip_list = tparser.get()
self.new_index = range(len(self.tip_list))
Random().shuffle(self.new_index)
@ -85,8 +90,9 @@ class TipOfDay(ManagedWindow.ManagedWindow):
window.show_all()
def next_tip_cb(self,dummy=None):
tip_text = self.escape(self.tip_list[self.new_index[self.index]])
def next_tip_cb(self, dummy=None):
tip_text = escape(self.tip_list[self.new_index[self.index]],
{ '"' : '&quot;' })
self.tip.set_text(_(tip_text))
self.tip.set_use_markup(True)
if self.index >= len(self.tip_list)-1:
@ -94,17 +100,11 @@ class TipOfDay(ManagedWindow.ManagedWindow):
else:
self.index += 1
def escape(self,text):
text = text.replace('&','&amp;'); # Must be first
text = text.replace(' > ',' &gt; ') # Replace standalone > char
text = text.replace('"','&quot;') # quotes
return text
def close_cb(self,dummy=None):
Config.set(Config.USE_TIPS,self.use.get_active())
def close_cb(self, dummy=None):
Config.set(Config.USE_TIPS, self.use.get_active())
self.close()
def build_menu_names(self,obj):
def build_menu_names(self, obj):
return (_("Tip of the Day"), None)
#-------------------------------------------------------------------------
@ -126,23 +126,27 @@ class TipParser:
"""
self.mylist = []
self.skip = False
xml_file = open(const.TIP_DATA)
self.tlist = []
p = ParserCreate()
p.StartElementHandler = self.startElement
p.EndElementHandler = self.endElement
p.CharacterDataHandler = self.characters
p.ParseFile(xml_file)
parser = ParserCreate()
parser.StartElementHandler = self.startElement
parser.EndElementHandler = self.endElement
parser.CharacterDataHandler = self.characters
parser.ParseFile(xml_file)
xml_file.close()
def get(self):
"""
Returns the list of tips
"""
return self.mylist
def setDocumentLocator(self,locator):
def setDocumentLocator(self, locator):
"""Sets the XML document locator"""
self.locator = locator
def startElement(self,tag,attrs):
def startElement(self, tag, attrs):
"""
Loads the dictionary when an XML tag of 'template' is found. The format
XML tag is <template title=\"name\" file=\"path\">
@ -156,7 +160,7 @@ class TipParser:
# let all the other tags through, except for the "tips" tag
self.tlist.append("<%s>" % tag)
def endElement(self,tag):
def endElement(self, tag):
if tag == "tip" and not self.skip:
text = ''.join(self.tlist)
self.mylist.append(' '.join(text.split()))

View File

@ -20,9 +20,13 @@
# $Id$
"""
Provides translation assistance
"""
from gettext import gettext
def sgettext(msgid,sep='|'):
def sgettext(msgid, sep='|'):
"""
Strip the context used for resolving translation ambiguities.

View File

@ -8,7 +8,7 @@
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
@ -57,32 +57,32 @@ from QuestionDialog import WarningDialog
#
#-------------------------------------------------------------------------
gender = {
RelLib.Person.MALE : _("male"),
RelLib.Person.FEMALE : _("female"),
RelLib.Person.UNKNOWN : _("unknown"),
RelLib.Person.MALE : _("male"),
RelLib.Person.FEMALE : _("female"),
RelLib.Person.UNKNOWN : _("unknown"),
}
def format_gender( type):
return gender.get(type[0],_("Invalid"))
return gender.get(type[0], _("Invalid"))
confidence = {
RelLib.SourceRef.CONF_VERY_HIGH : _("Very High"),
RelLib.SourceRef.CONF_HIGH : _("High"),
RelLib.SourceRef.CONF_NORMAL : _("Normal"),
RelLib.SourceRef.CONF_LOW : _("Low"),
RelLib.SourceRef.CONF_VERY_LOW : _("Very Low"),
RelLib.SourceRef.CONF_VERY_HIGH : _("Very High"),
RelLib.SourceRef.CONF_HIGH : _("High"),
RelLib.SourceRef.CONF_NORMAL : _("Normal"),
RelLib.SourceRef.CONF_LOW : _("Low"),
RelLib.SourceRef.CONF_VERY_LOW : _("Very Low"),
}
family_rel_descriptions = {
RelLib.FamilyRelType.MARRIED : _("A legal or common-law relationship "
"between a husband and wife"),
"between a husband and wife"),
RelLib.FamilyRelType.UNMARRIED : _("No legal or common-law relationship "
"between man and woman"),
"between man and woman"),
RelLib.FamilyRelType.CIVIL_UNION : _("An established relationship between "
"members of the same sex"),
"members of the same sex"),
RelLib.FamilyRelType.UNKNOWN : _("Unknown relationship between a man "
"and woman"),
"and woman"),
RelLib.FamilyRelType.CUSTOM : _("An unspecified relationship "
"a man and woman"),
"a man and woman"),
}
@ -109,16 +109,16 @@ def fix_encoding(value):
codeset = locale.getpreferredencoding()
except:
codeset = "UTF-8"
return unicode(value,codeset)
return unicode(value, codeset)
else:
return value
def xml_lang():
(loc,enc) = locale.getlocale()
if loc == None:
loc = locale.getlocale()
if loc[0] == None:
return ""
else:
return loc.replace('_','-')
return loc[0].replace('_', '-')
#-------------------------------------------------------------------------
#
@ -128,9 +128,9 @@ def xml_lang():
def force_unicode(n):
if type(n) != unicode:
return (unicode(n).lower(),unicode(n))
return (unicode(n).lower(), unicode(n))
else:
return (n.lower(),n)
return (n.lower(), n)
#-------------------------------------------------------------------------
#
@ -162,7 +162,7 @@ def family_name(family, db, noname=_("unknown")):
fname = name_displayer.display(father)
mname = name_displayer.display(mother)
name = _("%(father)s and %(mother)s") % {
"father" : fname,
"father" : fname,
"mother" : mname}
elif father:
name = name_displayer.display(father)
@ -182,7 +182,7 @@ def family_upper_name(family, db):
fname = father.get_primary_name().get_upper_name()
mname = mother.get_primary_name().get_upper_name()
name = _("%{father}s and %{mother}s") % {
'father' : fname,
'father' : fname,
'mother' : mname
}
elif father:
@ -196,7 +196,7 @@ def family_upper_name(family, db):
#
#
#-------------------------------------------------------------------------
def redraw_list(dlist,clist,func):
def redraw_list(dlist, clist, func):
clist.clear()
index = 0
@ -204,7 +204,7 @@ def redraw_list(dlist,clist,func):
col = 0
node = clist.append()
for data in func(obj):
clist.set_value(node,col,data)
clist.set_value(node, col, data)
col = col + 1
index = index + 1
return index
@ -214,12 +214,12 @@ def redraw_list(dlist,clist,func):
#
#
#-------------------------------------------------------------------------
def delete_selected(obj,list):
def delete_selected(obj, dlist):
sel = obj.get_selection()
model,node = sel.get_selected()
model, node = sel.get_selected()
if node:
index = model.get_path(node)[0]
del list[index]
del dlist[index]
return 1
#-------------------------------------------------------------------------
@ -227,10 +227,10 @@ def delete_selected(obj,list):
#
#
#-------------------------------------------------------------------------
def add_menuitem(menu,msg,obj,func):
def add_menuitem(menu, msg, obj, func):
item = gtk.MenuItem(msg)
item.set_data('o',obj)
item.connect("activate",func)
item.set_data('o', obj)
item.connect("activate", func)
item.show()
menu.append(item)
@ -246,7 +246,7 @@ def view_photo(photo):
prog = data[0]
except:
return
launch(prog,photo.get_path())
launch(prog, photo.get_path())
def find_file( filename):
# try the filename we got
@ -290,7 +290,8 @@ def find_folder( filename):
# Build list of elternate encodings
try:
encodings = [sys.getfilesystemencoding(), locale.getpreferredencoding(),
encodings = [sys.getfilesystemencoding(),
locale.getpreferredencoding(),
'UTF-8', 'ISO-8859-1']
except:
encodings = [sys.getfilesystemencoding(), 'UTF-8', 'ISO-8859-1']
@ -341,12 +342,12 @@ def build_string_optmenu(mapping, start_val):
#
#
#-------------------------------------------------------------------------
def build_columns(tree,list):
def build_columns(tree, list):
cnum = 0
for name in list:
renderer = gtk.CellRendererText()
renderer.set_fixed_height_from_font(1)
column = gtk.TreeViewColumn(name[0],renderer,text=cnum)
column = gtk.TreeViewColumn(name[0], renderer, text=cnum)
column.set_min_width(name[1])
if name[2] >= 0:
column.set_sort_column_id(name[2])
@ -365,22 +366,22 @@ def for_each_ancestor(db, start, func, data):
"""
Recursively iterate (breadth-first) over ancestors of
people listed in start.
Call func(data,pid) for the Id of each person encountered.
Call func(data, pid) for the Id of each person encountered.
Exit and return 1, as soon as func returns true.
Return 0 otherwise.
"""
todo = start
doneIds = {}
done_ids = set()
while len(todo):
p_handle = todo.pop()
p = db.get_person_from_handle(p_handle)
# Don't process the same handle twice. This can happen
# if there is a cycle in the database, or if the
# initial list contains X and some of X's ancestors.
if doneIds.has_key(p_handle):
if p_handle in done_ids:
continue
doneIds[p_handle] = 1
if func(data,p_handle):
done_ids.add(p_handle)
if func(data, p_handle):
return 1
for fam_handle in p.get_parent_family_handle_list():
fam = db.get_family_from_handle(fam_handle)
@ -394,13 +395,13 @@ def for_each_ancestor(db, start, func, data):
def title(n):
return '<span weight="bold" size="larger">%s</span>' % n
def set_title_label(xmlobj,t):
def set_title_label(xmlobj, t):
title_label = xmlobj.get_widget('title')
title_label.set_text('<span weight="bold" size="larger">%s</span>' % t)
title_label.set_use_markup(True)
from warnings import warn
def set_titles(window,title,t,msg=None):
def set_titles(window, title, t, msg=None):
warn('The Utils.set_titles is deprecated. Use ManagedWindow methods')
def gfloat(val):
@ -414,9 +415,9 @@ def gfloat(val):
return float(val)
except:
try:
return float(val.replace('.',','))
return float(val.replace('.', ', '))
except:
return float(val.replace(',','.'))
return float(val.replace(', ', '.'))
return 0.0
def gformat(val):
@ -428,7 +429,7 @@ def gformat(val):
decimal_point = locale.localeconv()['decimal_point']
return_val = "%.3f" % val
return return_val.replace(decimal_point,'.')
return return_val.replace(decimal_point, '.')
def search_for(name):
if name.startswith( '"' ):
@ -437,13 +438,13 @@ def search_for(name):
name = name.split()[0]
if os.sys.platform == "win32":
for i in os.environ['PATH'].split(';'):
fname = os.path.join(i,name)
if os.access(fname,os.X_OK) and not os.path.isdir(fname):
fname = os.path.join(i, name)
if os.access(fname, os.X_OK) and not os.path.isdir(fname):
return 1
else:
for i in os.environ['PATH'].split(':'):
fname = os.path.join(i,name)
if os.access(fname,os.X_OK) and not os.path.isdir(fname):
fname = os.path.join(i, name)
if os.access(fname, os.X_OK) and not os.path.isdir(fname):
return 1
return 0
@ -452,58 +453,58 @@ def search_for(name):
# Change label appearance
#
#-------------------------------------------------------------------------
def bold_label(label,widget=None):
def bold_label(label, widget=None):
if label.__class__ == gtk.Label:
text = unicode(label.get_text())
text = text.replace('<i>','')
text = text.replace('</i>','')
text = text.replace('<i>', '')
text = text.replace('</i>', '')
label.set_text("<b>%s</b>" % text )
label.set_use_markup(True)
else:
clist = label.get_children()
text = unicode(clist[1].get_text())
text = text.replace('<i>','')
text = text.replace('</i>','')
text = text.replace('<i>', '')
text = text.replace('</i>', '')
clist[0].show()
clist[1].set_text("<b>%s</b>" % text )
clist[1].set_use_markup(True)
if widget:
widget.window.set_cursor(None)
def unbold_label(label,widget=None):
def unbold_label(label, widget=None):
if label.__class__ == gtk.Label:
text = unicode(label.get_text())
text = text.replace('<b>','')
text = text.replace('</b>','')
text = text.replace('<i>','')
text = text.replace('</i>','')
text = text.replace('<b>', '')
text = text.replace('</b>', '')
text = text.replace('<i>', '')
text = text.replace('</i>', '')
label.set_text(text)
label.set_use_markup(False)
else:
clist = label.get_children()
text = unicode(clist[1].get_text())
text = text.replace('<b>','')
text = text.replace('</b>','')
text = text.replace('<i>','')
text = text.replace('</i>','')
text = text.replace('<b>', '')
text = text.replace('</b>', '')
text = text.replace('<i>', '')
text = text.replace('</i>', '')
clist[0].hide()
clist[1].set_text(text)
clist[1].set_use_markup(False)
if widget:
widget.window.set_cursor(None)
def temp_label(label,widget=None):
def temp_label(label, widget=None):
if label.__class__ == gtk.Label:
text = unicode(label.get_text())
text = text.replace('<b>','')
text = text.replace('</b>','')
text = text.replace('<b>', '')
text = text.replace('</b>', '')
label.set_text("<i>%s</i>" % text )
label.set_use_markup(True)
else:
clist = label.get_children()
text = unicode(clist[1].get_text())
text = text.replace('<b>','')
text = text.replace('</b>','')
text = text.replace('<b>', '')
text = text.replace('</b>', '')
clist[0].hide()
clist[1].set_text("<i>%s</i>" % text )
clist[1].set_use_markup(True)
@ -518,10 +519,10 @@ def temp_label(label,widget=None):
rand = random.Random(time.time())
def create_id():
return "%08x%08x" % ( int(time.time()*10000),
rand.randint(0,sys.maxint))
return "%08x%08x" % ( int(time.time()*10000),
rand.randint(0, sys.maxint))
def probably_alive(person,db,current_year=None,limit=0):
def probably_alive(person, db, current_year=None, limit=0):
"""Returns true if the person may be alive.
This works by a process of emlimination. If we can't find a good
@ -549,8 +550,8 @@ def probably_alive(person,db,current_year=None,limit=0):
# These are fairly good indications that someone's not alive.
for ev_ref in person.get_primary_event_ref_list():
ev = db.get_event_from_handle(ev_ref.ref)
if ev and int(ev.get_type()) in [RelLib.EventType.CAUSE_DEATH,
RelLib.EventType.BURIAL,
if ev and int(ev.get_type()) in [RelLib.EventType.CAUSE_DEATH,
RelLib.EventType.BURIAL,
RelLib.EventType.CREMATION]:
if not death_year:
death_year = ev.get_date_object().get_year()
@ -559,7 +560,7 @@ def probably_alive(person,db,current_year=None,limit=0):
return False
# For any other event of this person, check whether it happened
# too long ago. If so then the person is likely dead now.
elif ev and too_old(ev.get_date_object(),current_year):
elif ev and too_old(ev.get_date_object(), current_year):
return False
birth_year = None
@ -573,9 +574,9 @@ def probably_alive(person,db,current_year=None,limit=0):
birth_year = birth.get_date_object().get_year()
# Check whether the birth event is too old because the
# code above did not look at birth, only at other events
if too_old(birth.get_date_object(),current_year):
if too_old(birth.get_date_object(), current_year):
return False
if not_too_old(birth.get_date_object(),current_year):
if not_too_old(birth.get_date_object(), current_year):
return True
if not birth_year and death_year:
@ -584,7 +585,7 @@ def probably_alive(person,db,current_year=None,limit=0):
return False
# Neither birth nor death events are available. Try looking
# at siblings. If a sibling was born more than 120 years past,
# at siblings. If a sibling was born more than 120 years past,
# or more than 20 future, then problem then this person is
# probably not alive. If the sibling died more than 120 years
# past, or more than 120 years future, then probably not alive.
@ -637,7 +638,7 @@ def probably_alive(person,db,current_year=None,limit=0):
val = d.get_start_date()
val = d.get_year() - years
d.set_year(val)
if not not_too_old (d,current_year):
if not not_too_old (d, current_year):
return True
child_death_ref = child.get_death_ref()
@ -645,7 +646,7 @@ def probably_alive(person,db,current_year=None,limit=0):
child_death = db.get_event_from_handle(child_death_ref.ref)
dobj = child_death.get_date_object()
if dobj.get_start_date() != RelLib.Date.EMPTY:
if not not_too_old (dobj,current_year):
if not not_too_old (dobj, current_year):
return True
if descendants_too_old (child, years + min_generation):
@ -680,11 +681,8 @@ def probably_alive(person,db,current_year=None,limit=0):
father_birth_ref.ref)
dobj = father_birth.get_date_object()
if dobj.get_start_date() != RelLib.Date.EMPTY:
if not not_too_old (dobj,year - average_generation_gap):
#print father.get_primary_name().get_name(), " father of ", person.get_primary_name().get_name(), " is too old by birth. birth year ", dobj.get_year(), " test year ", year - average_generation_gap
if not not_too_old (dobj, year - average_generation_gap):
return True
#else:
#print father.get_primary_name().get_name(), " father of ", person.get_primary_name().get_name(), " is NOT too old by birth. birth year ", dobj.get_year(), " test year ", year - average_generation_gap
father_death_ref = father.get_death_ref()
if father_death_ref and father_death_ref.get_role() == RelLib.EventRoleType.PRIMARY:
@ -693,7 +691,6 @@ def probably_alive(person,db,current_year=None,limit=0):
dobj = father_death.get_date_object()
if dobj.get_start_date() != RelLib.Date.EMPTY:
if dobj.get_year() < year - average_generation_gap:
#print father.get_primary_name().get_name(), " father of ", person.get_primary_name().get_name(), " is too old by death."
return True
if ancestors_too_old (father, year - average_generation_gap):
@ -707,11 +704,8 @@ def probably_alive(person,db,current_year=None,limit=0):
mother_birth = db.get_event_from_handle(mother_birth_ref.ref)
dobj = mother_birth.get_date_object()
if dobj.get_start_date() != RelLib.Date.EMPTY:
if not not_too_old (dobj,year - average_generation_gap):
#print mother.get_primary_name().get_name(), " mother of ", person.get_primary_name().get_name(), " is too old by birth. birth year ", dobj.get_year(), " test year ", year - average_generation_gap
if not not_too_old (dobj, year - average_generation_gap):
return True
#else:
#print mother.get_primary_name().get_name(), " mother of ", person.get_primary_name().get_name(), " is NOT too old by birth. birth year ", dobj.get_year(), " test year ", year - average_generation_gap
mother_death_ref = mother.get_death_ref()
if mother_death_ref and mother_death_ref.get_role() == RelLib.EventRoleType.PRIMARY:
@ -720,7 +714,6 @@ def probably_alive(person,db,current_year=None,limit=0):
dobj = mother_death.get_date_object()
if dobj.get_start_date() != RelLib.Date.EMPTY:
if dobj.get_year() < year - average_generation_gap:
#print mother.get_primary_name().get_name(), " mother of ", person.get_primary_name().get_name(), " is too old by death."
return True
if ancestors_too_old (mother, year - average_generation_gap):
@ -739,7 +732,7 @@ def probably_alive(person,db,current_year=None,limit=0):
#print person.get_primary_name().get_name(), " is probably alive."
return True
def not_too_old(date,current_year=None):
def not_too_old(date, current_year=None):
if not current_year:
time_struct = time.localtime(time.time())
current_year = time_struct[0]
@ -748,7 +741,7 @@ def not_too_old(date,current_year=None):
return False
return (year != 0 and current_year - year < 110)
def too_old(date,current_year=None):
def too_old(date, current_year=None):
if current_year:
the_current_year = current_year
else:
@ -778,7 +771,7 @@ def get_referents(handle, db, primary_objects):
for primary in primary_objects:
primary_list = [item[1] for item in object_list if item[0] == primary]
the_lists = the_lists + (primary_list,)
the_lists = the_lists + (primary_list, )
return the_lists
@ -789,12 +782,12 @@ def get_source_referents(source_handle, db):
secondary child-objects) to a given source handle in a given database.
"""
_primaries = ('Person', 'Family', 'Event', 'Place',
_primaries = ('Person', 'Family', 'Event', 'Place',
'Source', 'MediaObject', 'Repository')
return (get_referents(source_handle, db, _primaries))
def get_media_referents(media_handle,db):
def get_media_referents(media_handle, db):
""" Find objects that refer the media object.
This function finds all primary objects that refer
@ -812,7 +805,7 @@ def get_note_referents(note_handle, db):
to a given note handle in a given database.
"""
_primaries = ('Person', 'Family', 'Event', 'Place',
_primaries = ('Person', 'Family', 'Event', 'Place',
'Source', 'MediaObject', 'Repository')
return (get_referents(note_handle, db, _primaries))
@ -824,12 +817,12 @@ def get_note_referents(note_handle, db):
#-------------------------------------------------------------------------
_NEW_NAME_PATTERN = '%s%sUntitled_%d.%s'
def get_new_filename(ext,folder='~/'):
def get_new_filename(ext, folder='~/'):
ix = 1
while os.path.isfile(os.path.expanduser(_NEW_NAME_PATTERN %
(folder,os.path.sep,ix,ext))):
(folder, os.path.sep, ix, ext))):
ix = ix + 1
return os.path.expanduser(_NEW_NAME_PATTERN % (folder,os.path.sep,ix,ext))
return os.path.expanduser(_NEW_NAME_PATTERN % (folder, os.path.sep, ix, ext))
def cast_to_bool(val):
if val == str(True):
@ -841,7 +834,7 @@ def get_type_converter(val):
Returns function that converts strings into the type of val.
"""
val_type = type(val)
if val_type in (str,unicode):
if val_type in (str, unicode):
return unicode
elif val_type == int:
return int
@ -849,7 +842,7 @@ def get_type_converter(val):
return float
elif val_type == bool:
return cast_to_bool
elif val_type in (list,tuple):
elif val_type in (list, tuple):
return list
def type_name(val):
@ -864,7 +857,7 @@ def type_name(val):
return 'int'
elif val_type == float:
return 'float'
elif val_type in (str,unicode):
elif val_type in (str, unicode):
return 'unicode'
return 'unicode'
@ -879,7 +872,7 @@ def get_type_converter_by_name(val_str):
return int
elif val_str == 'float':
return float
elif val_str in ('str','unicode'):
elif val_str in ('str', 'unicode'):
return unicode
return unicode
@ -896,7 +889,7 @@ def relative_path(original, base):
for i in range(min(len(base_list), len(target_list))):
if base_list[i] <> target_list[i]: break
else:
i+=1
i += 1
rel_list = [os.pardir] * (len(base_list)-i) + target_list[i:]
return os.path.join(*rel_list)
@ -904,13 +897,13 @@ class ProgressMeter:
"""
Progress meter class for GRAMPS.
"""
def __init__(self,title,header=''):
def __init__(self, title, header=''):
"""
Specify the title and the current pass header.
"""
self.old_val = -1
self.ptop = gtk.Dialog()
self.ptop.connect('delete_event',self.warn)
self.ptop.connect('delete_event', self.warn)
self.ptop.set_has_separator(False)
self.ptop.set_title(title)
self.ptop.set_border_width(12)
@ -924,13 +917,13 @@ class ProgressMeter:
self.ptop.vbox.set_border_width(24)
self.pbar = gtk.ProgressBar()
self.ptop.set_size_request(350,125)
self.ptop.set_size_request(350, 125)
self.ptop.vbox.add(self.pbar)
self.ptop.show_all()
if header == '':
self.lbl.hide()
def set_pass(self,header,total):
def set_pass(self, header, total):
"""
Reset for another pass. Provide a new header and define number
of steps to be used.
@ -966,10 +959,10 @@ class ProgressMeter:
while gtk.events_pending():
gtk.main_iteration()
def warn(self,*obj):
def warn(self, *obj):
WarningDialog(
_("Attempt to force closing the dialog"),
_("Please do not force closing this important dialog."),
_("Attempt to force closing the dialog"),
_("Please do not force closing this important dialog."),
self.ptop)
return True
@ -979,25 +972,25 @@ class ProgressMeter:
"""
self.ptop.destroy()
def launch(prog_str,path):
def launch(prog_str, path):
if sys.platform == "win32":
import subprocess
if prog_str.find("%1") != -1:
prog_str = prog_str.replace("%1",path)
prog_str = prog_str.replace("%1", path)
else:
prog_str = '%s "%s"' %(prog_str,path)
prog_str = '%s "%s"' % (prog_str, path)
subprocess.Popen(prog_str)
else:
subval = {
'%F' : path,
'%f' : path,
'%u' : path,
'%U' : path,
'%n' : path,
'%N' : path,
'%F' : path,
'%f' : path,
'%u' : path,
'%U' : path,
'%n' : path,
'%N' : path,
}
prog_data = prog_str.split()
@ -1021,19 +1014,19 @@ def launch(prog_str,path):
os.spawnvpe(os.P_NOWAIT, prog, prog_list, os.environ)
def profile(func,*args):
def profile(func, *args):
import hotshot, hotshot.stats
pr = hotshot.Profile('mystats.profile')
prf = hotshot.Profile('mystats.profile')
print "Start"
pr.runcall(func,*args)
prf.runcall(func, *args)
print "Finished"
pr.close()
prf.close()
print "Loading profile"
stats = hotshot.stats.load('mystats.profile')
print "done"
stats.strip_dirs()
stats.sort_stats('time','calls')
stats.sort_stats('time', 'calls')
stats.print_stats(100)
stats.print_callers(100)

View File

@ -18,6 +18,10 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""
Provides soundex calculation
"""
#-------------------------------------------------------------------------
#
# Standard python modules
@ -44,17 +48,17 @@ def soundex(strval):
strval = strval.upper().strip()
if not strval:
return "Z000"
return "Z000"
strval = strval.encode('iso-8859-1')
str2 = strval[0]
strval = strval.translate(TABLE, IGNORE)
if not strval:
return "Z000"
prev = strval[0]
for x in strval[1:]:
if x != prev and x != "0":
str2 = str2 + x
prev = x
for character in strval[1:]:
if character != prev and character != "0":
str2 = str2 + character
prev = character
# pad with zeros
str2 = str2+"0000"
return str2[:4]