* src/GenericFilter.py: implement short-circuit if only rule is
Everyone * src/NameDisplay.py: optimization * src/PeopleModel.py: optimization of data building svn: r5810
This commit is contained in:
parent
997be85261
commit
77a4023f9e
@ -1,5 +1,9 @@
|
||||
2006-01-20 Don Allingham <don@gramps-project.org>
|
||||
* src/GrampsDb/_GrampsBSDDB.py: remove function call in find_surname
|
||||
* src/GenericFilter.py: implement short-circuit if only rule is
|
||||
Everyone
|
||||
* src/NameDisplay.py: optimization
|
||||
* src/PeopleModel.py: optimization of data building
|
||||
|
||||
2006-01-20 Alex Roitman <shura@gramps-project.org>
|
||||
* src/GrampsDb/_GrampsBSDDB.py (transaction_begin,
|
||||
|
@ -95,6 +95,9 @@ class Rule:
|
||||
def __init__(self,list):
|
||||
self.set_list(list)
|
||||
|
||||
def is_empty(self):
|
||||
return False
|
||||
|
||||
def prepare(self,db):
|
||||
pass
|
||||
|
||||
@ -136,6 +139,9 @@ class Everyone(Rule):
|
||||
category = _('General filters')
|
||||
description = _('Matches everyone in the database')
|
||||
|
||||
def is_empty(self):
|
||||
return True
|
||||
|
||||
def apply(self,db,person):
|
||||
return True
|
||||
|
||||
@ -1902,6 +1908,9 @@ class GenericFilter:
|
||||
self.logical_op = 'and'
|
||||
self.invert = False
|
||||
|
||||
def is_empty(self):
|
||||
return len(self.flist) == 1 and self.flist[0].is_empty()
|
||||
|
||||
def set_logical_op(self,val):
|
||||
if val in GenericFilter.logical_functions:
|
||||
self.logical_op = val
|
||||
|
@ -29,7 +29,7 @@ Class handling language-specific displaying of names.
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import RelLib
|
||||
from RelLib import Name
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -64,107 +64,28 @@ class NameDisplay:
|
||||
def sorted(self,person):
|
||||
"""
|
||||
Returns a text string representing the L{RelLib.Person} instance's
|
||||
L{RelLib.Name} in a manner that should be used for displaying a sorted
|
||||
L{Name} in a manner that should be used for displaying a sorted
|
||||
name.
|
||||
|
||||
@param person: L{RelLib.Person} instance that contains the
|
||||
L{RelLib.Name} that is to be displayed. The primary name is used for
|
||||
L{Name} that is to be displayed. The primary name is used for
|
||||
the display.
|
||||
@type person: L{RelLib.Person}
|
||||
@returns: Returns the L{RelLib.Person} instance's name
|
||||
@rtype: str
|
||||
"""
|
||||
name = person.get_primary_name()
|
||||
if name.sort_as == RelLib.Name.FNLN:
|
||||
if name.sort_as == Name.FNLN:
|
||||
return self._fnln(name)
|
||||
elif name.sort_as == RelLib.Name.PTFN:
|
||||
elif name.sort_as == Name.PTFN:
|
||||
return self._ptfn(name)
|
||||
elif name.sort_as == RelLib.Name.FN:
|
||||
elif name.sort_as == Name.FN:
|
||||
return name.first_name
|
||||
else:
|
||||
return self._lnfn(name)
|
||||
|
||||
def sorted_name(self,name):
|
||||
"""
|
||||
Returns a text string representing the L{RelLib.Name} instance
|
||||
in a manner that should be used for displaying a sorted
|
||||
name.
|
||||
|
||||
@param name: L{RelLib.Name} instance that is to be displayed.
|
||||
@type name: L{RelLib.Name}
|
||||
@returns: Returns the L{RelLib.Name} string representation
|
||||
@rtype: str
|
||||
"""
|
||||
if name.sort_as == RelLib.Name.FNLN:
|
||||
return self._fnln(name)
|
||||
elif name.sort_as == RelLib.Name.PTFN:
|
||||
return self._ptfn(name)
|
||||
elif name.sort_as == RelLib.Name.FN:
|
||||
def _empty(self,name):
|
||||
return name.first_name
|
||||
else:
|
||||
return self._lnfn(name)
|
||||
|
||||
def display_given(self,person):
|
||||
name = person.get_primary_name()
|
||||
if name.patronymic:
|
||||
return "%s %s" % (name.first_name, name.patronymic)
|
||||
else:
|
||||
return name.first_name
|
||||
|
||||
def display(self,person):
|
||||
"""
|
||||
Returns a text string representing the L{RelLib.Person} instance's
|
||||
L{RelLib.Name} in a manner that should be used for normal displaying.
|
||||
|
||||
@param person: L{RelLib.Person} instance that contains the
|
||||
L{RelLib.Name} that is to be displayed. The primary name is used for
|
||||
the display.
|
||||
@type person: L{RelLib.Person}
|
||||
@returns: Returns the L{RelLib.Person} instance's name
|
||||
@rtype: str
|
||||
"""
|
||||
name = person.get_primary_name()
|
||||
if name.display_as == RelLib.Name.LNFN:
|
||||
return self._lnfn(name,"")
|
||||
else:
|
||||
return self._fnln(name,"")
|
||||
|
||||
def display_formal(self,person):
|
||||
"""
|
||||
Returns a text string representing the L{RelLib.Person} instance's
|
||||
L{RelLib.Name} in a manner that should be used for normal displaying.
|
||||
|
||||
@param person: L{RelLib.Person} instance that contains the
|
||||
L{RelLib.Name} that is to be displayed. The primary name is used for
|
||||
the display.
|
||||
@type person: L{RelLib.Person}
|
||||
@returns: Returns the L{RelLib.Person} instance's name
|
||||
@rtype: str
|
||||
"""
|
||||
name = person.get_primary_name()
|
||||
if name.display_as == RelLib.Name.LNFN:
|
||||
return self._lnfn(name,'')
|
||||
else:
|
||||
return self._fnln(name,'')
|
||||
|
||||
def display_name(self,name):
|
||||
"""
|
||||
Returns a text string representing the L{RelLib.Name} instance
|
||||
in a manner that should be used for normal displaying.
|
||||
|
||||
@param name: L{RelLib.Name} instance that is to be displayed.
|
||||
@type name: L{RelLib.Name}
|
||||
@returns: Returns the L{RelLib.Name} string representation
|
||||
@rtype: str
|
||||
"""
|
||||
if name == None:
|
||||
return ""
|
||||
elif name.display_as == RelLib.Name.LNFN:
|
||||
return self._lnfn(name)
|
||||
elif name.display_as == RelLib.Name.PTFN:
|
||||
return self._ptfn(name)
|
||||
else:
|
||||
return self._fnln(name)
|
||||
|
||||
def _ptfn(self,name):
|
||||
"""
|
||||
@ -224,21 +145,6 @@ class NameDisplay:
|
||||
else:
|
||||
return "%s %s, %s" % (first, last, name.suffix)
|
||||
|
||||
def name_grouping(self,db,person):
|
||||
return self.name_grouping_name(db,person.primary_name)
|
||||
|
||||
def name_grouping_name(self,db,pn):
|
||||
sv = pn.sort_as
|
||||
if pn.group_as:
|
||||
return pn.group_as
|
||||
if sv <= RelLib.Name.LNFN:
|
||||
val = pn.surname
|
||||
elif sv == RelLib.Name.PTFN:
|
||||
val = pn.patronymic
|
||||
else:
|
||||
val = pn.first_name
|
||||
return db.get_name_group_mapping(val)
|
||||
|
||||
def _lnfn(self,name,nickname=u""):
|
||||
"""
|
||||
Prints the Western style last name, first name style.
|
||||
@ -249,9 +155,6 @@ class NameDisplay:
|
||||
|
||||
first = name.first_name
|
||||
|
||||
if nickname:
|
||||
first = '%s "%s"' % (first,nickname)
|
||||
|
||||
if name.patronymic:
|
||||
first = "%s %s" % (first, name.patronymic)
|
||||
|
||||
@ -274,5 +177,103 @@ class NameDisplay:
|
||||
else:
|
||||
return "%s %s" % (last, first)
|
||||
|
||||
fn_array = { Name.FNLN : _fnln,
|
||||
Name.PTFN : _ptfn,
|
||||
Name.FN : _empty,
|
||||
}
|
||||
|
||||
def sorted_name(self,name):
|
||||
"""
|
||||
Returns a text string representing the L{Name} instance
|
||||
in a manner that should be used for displaying a sorted
|
||||
name.
|
||||
|
||||
@param name: L{Name} instance that is to be displayed.
|
||||
@type name: L{Name}
|
||||
@returns: Returns the L{Name} string representation
|
||||
@rtype: str
|
||||
"""
|
||||
return self.fn_array.get(name.sort_as,self._lnfn)(name)
|
||||
|
||||
def display_given(self,person):
|
||||
name = person.get_primary_name()
|
||||
if name.patronymic:
|
||||
return "%s %s" % (name.first_name, name.patronymic)
|
||||
else:
|
||||
return name.first_name
|
||||
|
||||
def display(self,person):
|
||||
"""
|
||||
Returns a text string representing the L{RelLib.Person} instance's
|
||||
L{Name} in a manner that should be used for normal displaying.
|
||||
|
||||
@param person: L{RelLib.Person} instance that contains the
|
||||
L{Name} that is to be displayed. The primary name is used for
|
||||
the display.
|
||||
@type person: L{RelLib.Person}
|
||||
@returns: Returns the L{RelLib.Person} instance's name
|
||||
@rtype: str
|
||||
"""
|
||||
name = person.get_primary_name()
|
||||
if name.display_as == Name.LNFN:
|
||||
return self._lnfn(name,"")
|
||||
else:
|
||||
return self._fnln(name,"")
|
||||
|
||||
def display_formal(self,person):
|
||||
"""
|
||||
Returns a text string representing the L{RelLib.Person} instance's
|
||||
L{Name} in a manner that should be used for normal displaying.
|
||||
|
||||
@param person: L{RelLib.Person} instance that contains the
|
||||
L{Name} that is to be displayed. The primary name is used for
|
||||
the display.
|
||||
@type person: L{RelLib.Person}
|
||||
@returns: Returns the L{RelLib.Person} instance's name
|
||||
@rtype: str
|
||||
"""
|
||||
name = person.get_primary_name()
|
||||
if name.display_as == Name.LNFN:
|
||||
return self._lnfn(name,'')
|
||||
else:
|
||||
return self._fnln(name,'')
|
||||
|
||||
def display_name(self,name):
|
||||
"""
|
||||
Returns a text string representing the L{Name} instance
|
||||
in a manner that should be used for normal displaying.
|
||||
|
||||
@param name: L{Name} instance that is to be displayed.
|
||||
@type name: L{Name}
|
||||
@returns: Returns the L{Name} string representation
|
||||
@rtype: str
|
||||
"""
|
||||
if name == None:
|
||||
return ""
|
||||
elif name.display_as == Name.LNFN:
|
||||
return self._lnfn(name)
|
||||
elif name.display_as == Name.PTFN:
|
||||
return self._ptfn(name)
|
||||
else:
|
||||
return self._fnln(name)
|
||||
|
||||
def name_grouping(self,db,person):
|
||||
return self.name_grouping_name(db,person.primary_name)
|
||||
|
||||
|
||||
sort_field = (Name.get_surname, Name.get_surname,
|
||||
Name.get_first_name, Name.get_patronymic,
|
||||
Name.get_first_name)
|
||||
|
||||
def name_grouping_name(self,db,pn):
|
||||
if pn.group_as:
|
||||
return pn.group_as
|
||||
sv = pn.sort_as
|
||||
if sv <= Name.LNFN:
|
||||
return db.get_name_group_mapping(pn.surname)
|
||||
elif sv == Name.PTFN:
|
||||
return db.get_name_group_mapping(pn.patronymic)
|
||||
else:
|
||||
return db.get_name_group_mapping(pn.first_name)
|
||||
|
||||
displayer = NameDisplay()
|
||||
|
@ -28,11 +28,15 @@
|
||||
from gettext import gettext as _
|
||||
import time
|
||||
import cgi
|
||||
import sets
|
||||
import sys
|
||||
import traceback
|
||||
import locale
|
||||
|
||||
try:
|
||||
set()
|
||||
except:
|
||||
from sets import Set as set
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GTK modules
|
||||
@ -132,7 +136,7 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
if not self.db.is_open():
|
||||
return
|
||||
|
||||
if data_filter:
|
||||
if data_filter and not data_filter.is_empty():
|
||||
keys = data_filter.apply(self.db)
|
||||
if self.invert_result:
|
||||
handle_list = self.db.get_person_handles(sort_handles=False)
|
||||
@ -142,7 +146,7 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
else:
|
||||
keys = self.db.get_person_handles(sort_handles=False)
|
||||
|
||||
flist = sets.Set(keys)
|
||||
flist = set(keys)
|
||||
if skip and skip in flist:
|
||||
flist.remove(skip)
|
||||
|
||||
@ -152,15 +156,17 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
|
||||
ngn = NameDisplay.displayer.name_grouping_name
|
||||
nsn = NameDisplay.displayer.sorted_name
|
||||
|
||||
while node:
|
||||
if node[0] in flist:
|
||||
primary_name = node[1][_NAME_COL]
|
||||
surname = unicode(ngn(self.db,primary_name))
|
||||
self.sortnames[node[0]] = unicode(nsn(primary_name))
|
||||
if self.temp_sname_sub.has_key(surname):
|
||||
self.temp_sname_sub[surname].append(node[0])
|
||||
else:
|
||||
self.temp_sname_sub[surname] = [node[0]]
|
||||
n,d = node
|
||||
if n in flist:
|
||||
primary_name = d[_NAME_COL]
|
||||
surname = ngn(self.db,primary_name)
|
||||
self.sortnames[n] = nsn(primary_name)
|
||||
try:
|
||||
self.temp_sname_sub[surname].append(n)
|
||||
except:
|
||||
self.temp_sname_sub[surname] = [n]
|
||||
node = cursor.next()
|
||||
cursor.close()
|
||||
|
||||
@ -169,11 +175,9 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
self.build_sub_entry(name)
|
||||
|
||||
def build_sub_entry(self,name):
|
||||
slist = map(lambda x: (self.sortnames[x],x),self.temp_sname_sub[name])
|
||||
slist.sort(self.byname)
|
||||
entries = map(lambda x: x[1], slist)
|
||||
self.temp_sname_sub[name].sort(locale.strcoll)
|
||||
val = 0
|
||||
for person_handle in entries:
|
||||
for person_handle in self.temp_sname_sub[name]:
|
||||
tpl = (name,val)
|
||||
self.temp_iter2path[person_handle] = tpl
|
||||
self.temp_path2iter[tpl] = person_handle
|
||||
@ -185,9 +189,6 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
self.path2iter = self.temp_path2iter
|
||||
self.sname_sub = self.temp_sname_sub
|
||||
|
||||
def byname(self,f,s):
|
||||
return locale.strcoll(f[0],s[0])
|
||||
|
||||
def on_get_flags(self):
|
||||
'''returns the GtkTreeModelFlags for this particular type of model'''
|
||||
return gtk.TREE_MODEL_ITERS_PERSIST
|
||||
|
Loading…
Reference in New Issue
Block a user