* 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:
@@ -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
|
||||
|
||||
@@ -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,8 +27,8 @@ 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):
|
||||
@@ -52,10 +50,10 @@ class Reorder(ManagedWindow.ManagedWindow):
|
||||
self.set_window(top, None, _("Reorder Relationships"))
|
||||
|
||||
self.ptree = xml.get_widget('ptree')
|
||||
self.pmodel = ListModel.ListModel(self.ptree,_parent_titles)
|
||||
self.pmodel = ListModel.ListModel(self.ptree, PARENT_TITLES)
|
||||
|
||||
self.ftree = xml.get_widget('ftree')
|
||||
self.fmodel = ListModel.ListModel(self.ftree,_family_titles)
|
||||
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)
|
||||
|
||||
19
src/Sort.py
19
src/Sort.py
@@ -48,13 +48,8 @@ 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):
|
||||
self.database = database
|
||||
|
||||
@@ -123,14 +118,14 @@ class Sort:
|
||||
"""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):
|
||||
"""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)
|
||||
|
||||
@@ -124,32 +124,23 @@ class SubstKeywords:
|
||||
if mplace_handle:
|
||||
self.M = database.get_place_from_handle(mplace_handle).get_title()
|
||||
|
||||
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("$$",'$')
|
||||
|
||||
def replace_and_clean(self, lines):
|
||||
array = [ ("%n",self.n), ("%N",self.N), ("%b",self.b),
|
||||
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)]
|
||||
("%m", self.m), ("%M", self.M), ("$$", "$") ]
|
||||
|
||||
def replace(self, line):
|
||||
"""Returns a new line of text with the substitutions performed."""
|
||||
for (key, value) in self.array:
|
||||
line = line.replace(key, value)
|
||||
return line
|
||||
|
||||
def replace_and_clean(self, lines):
|
||||
|
||||
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)
|
||||
|
||||
@@ -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
|
||||
@@ -74,8 +79,8 @@ class TipOfDay(ManagedWindow.ManagedWindow):
|
||||
close = xml.get_widget('close')
|
||||
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)
|
||||
@@ -86,7 +91,8 @@ 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]])
|
||||
tip_text = escape(self.tip_list[self.new_index[self.index]],
|
||||
{ '"' : '"' })
|
||||
self.tip.set_text(_(tip_text))
|
||||
self.tip.set_use_markup(True)
|
||||
if self.index >= len(self.tip_list)-1:
|
||||
@@ -94,12 +100,6 @@ class TipOfDay(ManagedWindow.ManagedWindow):
|
||||
else:
|
||||
self.index += 1
|
||||
|
||||
def escape(self,text):
|
||||
text = text.replace('&','&'); # Must be first
|
||||
text = text.replace(' > ',' > ') # Replace standalone > char
|
||||
text = text.replace('"','"') # quotes
|
||||
return text
|
||||
|
||||
def close_cb(self, dummy=None):
|
||||
Config.set(Config.USE_TIPS, self.use.get_active())
|
||||
self.close()
|
||||
@@ -126,16 +126,20 @@ 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):
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
|
||||
# $Id$
|
||||
|
||||
"""
|
||||
Provides translation assistance
|
||||
"""
|
||||
|
||||
from gettext import gettext
|
||||
|
||||
def sgettext(msgid, sep='|'):
|
||||
|
||||
33
src/Utils.py
33
src/Utils.py
@@ -114,11 +114,11 @@ def fix_encoding(value):
|
||||
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('_', '-')
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@@ -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()
|
||||
if node:
|
||||
index = model.get_path(node)[0]
|
||||
del list[index]
|
||||
del dlist[index]
|
||||
return 1
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@@ -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']
|
||||
@@ -370,16 +371,16 @@ def for_each_ancestor(db, start, func, data):
|
||||
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
|
||||
done_ids.add(p_handle)
|
||||
if func(data, p_handle):
|
||||
return 1
|
||||
for fam_handle in p.get_parent_family_handle_list():
|
||||
@@ -681,10 +682,7 @@ def probably_alive(person,db,current_year=None,limit=0):
|
||||
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
|
||||
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):
|
||||
@@ -708,10 +705,7 @@ def probably_alive(person,db,current_year=None,limit=0):
|
||||
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
|
||||
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):
|
||||
@@ -1024,11 +1017,11 @@ def launch(prog_str,path):
|
||||
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"
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
"""
|
||||
Provides soundex calculation
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Standard python modules
|
||||
@@ -51,10 +55,10 @@ def soundex(strval):
|
||||
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]
|
||||
|
||||
Reference in New Issue
Block a user