performance enhancements

svn: r6179
This commit is contained in:
Don Allingham 2006-03-19 23:34:23 +00:00
parent c4fcd98fdc
commit 6c198f1f5c
6 changed files with 129 additions and 27 deletions

View File

@ -1,3 +1,10 @@
2006-03-19 Don Allingham <don@gramps-project.org>
* src/Editors/_EditFamily.py: select person used for children
* src/PeopleModel.py: used raw data functions for name display
* src/NameDisplay.py: add raw functions for name display to
avoid the need to create a Name instance
* src/SelectPerson.py: fixed widths
2006-03-18 Don Allingham <don@gramps-project.org>
* src/Editors/_EditFamily.py: add add_person functionality
* src/DisplayTabs.py: add share option to sources

View File

@ -169,7 +169,6 @@ class PersonView(PageView.PersonNavView):
self.tree.connect('button-press-event', self.button_press)
self.tree.connect('drag_data_get', self.drag_data_get)
self.selection = self.tree.get_selection()
self.selection.set_mode(gtk.SELECTION_MULTIPLE)
self.selection.connect('changed',self.row_changed)

View File

@ -77,6 +77,8 @@ from GrampsWidgets import *
from ObjectSelector import PersonSelector,PersonFilterSpec
from SelectPerson import SelectPerson
class ChildEmbedList(EmbeddedList):
"""
The child embed list is specific to the Edit Family dialog, so it
@ -246,6 +248,10 @@ class ChildEmbedList(EmbeddedList):
# RelLib.Person.__name__))
# selector_window.close()
def run(self,skip):
SelectPerson(self.dbstate.db, "Select Child",
skip=[ x for x in skip if x])
def del_button_clicked(self,obj):
handle = self.get_selected()
if handle:

View File

@ -50,6 +50,14 @@ class NameDisplay:
"""
self.force_upper = use_upper
self.fn_array = [
self._lnfn, self._lnfn, self._fnln,
self._ptfn, self._empty ]
self.raw_fn_array = (
self._lnfn_raw, self._lnfn_raw, self._fnln_raw,
self._ptfn_raw, self._empty_raw )
def use_upper(self,upper):
"""
Changes the NameDisplay class to enable or display the displaying
@ -87,6 +95,9 @@ class NameDisplay:
def _empty(self,name):
return name.first_name
def _empty_raw(self,raw_data):
return raw_data[2]
def _ptfn(self,name):
"""
Prints the Western style first name, last name style.
@ -113,6 +124,36 @@ class NameDisplay:
else:
return "%s, %s" % (last, first)
def _ptfn_raw(self,raw_data):
"""
Prints the Western style first name, last name style.
Typically this is::
SurnamePrefix Patronymic SurnameSuffix, FirstName
"""
first = raw_data[2]
surname = raw_data[3]
suffix = raw_data[4]
prefix = raw_data[7]
patronymic = raw_data[8]
if self.force_upper:
last = patronymic.upper()
else:
last = patronymic
if suffix:
if prefix:
return "%s %s %s, %s" % (prefix, last, suffix, first)
else:
return "%s %s, %s" % (last, suffix, first)
else:
if name.prefix:
return "%s %s, %s" % (prefix, last, first)
else:
return "%s, %s" % (last, first)
def _fnln(self,name,nickname=""):
"""
Prints the Western style first name, last name style.
@ -141,6 +182,38 @@ class NameDisplay:
else:
return "%s %s" % (first, last)
def _fnln_raw(self,raw_data):
"""
Prints the Western style first name, last name style.
Typically this is::
FirstName Patronymic SurnamePrefix Surname SurnameSuffix
"""
first = raw_data[2]
surname = raw_data[3]
suffix = raw_data[4]
prefix = raw_data[7]
patronymic = raw_data[8]
if patronymic:
first = "%s %s" % (first, patronymic)
if self.force_upper:
last = surname.upper()
else:
last = surname
if suffix:
if prefix:
return "%s %s %s, %s" % (first, prefix, last, suffix)
else:
return "%s %s, %s" % (first, last, suffix)
else:
if prefix:
return "%s %s %s" % (first, prefix, last)
else:
return "%s %s" % (first, last)
def _lnfn(self,name,nickname=u""):
"""
Prints the Western style last name, first name style.
@ -159,11 +232,23 @@ class NameDisplay:
return " ".join([x for x in [name.prefix, last, name.first_name,
name.patronymic, name.suffix]])
fn_array = { Name.FNLN : _fnln,
Name.PTFN : _ptfn,
Name.FN : _empty,
Name.LNFN : _lnfn,
}
def _lnfn_raw(self,raw_data):
"""
Prints the Western style last name, first name style.
Typically this is::
SurnamePrefix Surname, FirstName Patronymic SurnameSuffix
"""
if self.force_upper:
last = raw_data[3].upper()
else:
last = raw_data[3]
if last:
last += ","
return " ".join([x for x in [raw_data[7], last, raw_data[2],
raw_data[8], raw_data[4]]])
def sorted_name(self,name):
"""
@ -176,7 +261,21 @@ class NameDisplay:
@returns: Returns the L{Name} string representation
@rtype: str
"""
return self.fn_array.get(name.sort_as,self._lnfn)(name)
return self.fn_array[name.sort_as](name)
#return self.fn_array.get(name.sort_as,self._lnfn)(name)
def raw_sorted_name(self,raw_data):
"""
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.raw_fn_array[raw_data[11]](raw_data)
def display_given(self,person):
name = person.get_primary_name()

View File

@ -145,7 +145,7 @@ class PeopleModel(gtk.GenericTreeModel):
return
ngn = NameDisplay.displayer.name_grouping_name
nsn = NameDisplay.displayer.sorted_name
nsn = NameDisplay.displayer.raw_sorted_name
flist = set(skip)
self.sortnames = {}
@ -157,12 +157,10 @@ class PeopleModel(gtk.GenericTreeModel):
n,d = node
d = pickle.loads(d)
handle = d[0]
primary_name = Name(data=d[_NAME_COL])
#surname = ngn(self.db,primary_name)
surname = n
if not (handle in skip or (dfilter and not dfilter.match(handle))):
self.sortnames[handle] = nsn(primary_name)
self.sortnames[handle] = nsn(d[_NAME_COL])
self.temp_sname_sub[surname] = [handle]
node = cursor.next_dup()
@ -170,9 +168,8 @@ class PeopleModel(gtk.GenericTreeModel):
n,d = node
d = pickle.loads(d)
handle = d[0]
primary_name = Name(data=d[_NAME_COL])
if not (handle in skip or (dfilter and not dfilter.match(handle))):
self.sortnames[handle] = nsn(primary_name)
self.sortnames[handle] = nsn(d[_NAME_COL])
try:
self.temp_sname_sub[surname].append(handle)
except:
@ -194,10 +191,9 @@ class PeopleModel(gtk.GenericTreeModel):
slist = [ (locale.strxfrm(self.sortnames[x]),x) \
for x in self.temp_sname_sub[name] ]
slist.sort()
entries = [ x[1] for x in slist ]
val = 0
for person_handle in entries:
for (junk,person_handle) in slist:
tpl = (name,val)
self.temp_iter2path[person_handle] = tpl
self.temp_path2iter[tpl] = person_handle

View File

@ -32,9 +32,9 @@ from TransUtils import sgettext as _
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
import gtk
import gtk.glade
import pango
#-------------------------------------------------------------------------
#
@ -55,14 +55,16 @@ class SelectPerson:
def __init__(self, db, title, filter=None, skip=[], parent_window=None):
self.renderer = gtk.CellRendererText()
self.renderer.set_property('ellipsize',pango.ELLIPSIZE_END)
self.db = db
self.glade = gtk.glade.XML(const.gladeFile,"select_person","gramps")
self.top = self.glade.get_widget('select_person')
title_label = self.glade.get_widget('title')
self.plist = self.glade.get_widget('plist')
self.notebook = self.glade.get_widget('notebook')
Utils.set_titles(self.top,title_label,title)
Utils.set_titles(self.top,
self.glade.get_widget('title'),
title)
self.model = PeopleModel.PeopleModel(self.db,
data_filter=filter,
@ -78,23 +80,16 @@ class SelectPerson:
def add_columns(self,tree):
tree.set_fixed_height_mode(True)
column = gtk.TreeViewColumn(_('Name'), self.renderer, text=0)
column.set_resizable(True)
column.set_clickable(True)
column.set_sort_column_id(0)
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
column.set_fixed_width(225)
tree.append_column(column)
column = gtk.TreeViewColumn(_('ID'), self.renderer, text=1)
column.set_resizable(True)
column.set_clickable(True)
column.set_sort_column_id(1)
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
column.set_fixed_width(75)
tree.append_column(column)
column = gtk.TreeViewColumn(_('Birth date'), self.renderer, text=3)
column.set_clickable(True)
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
column.set_fixed_width(160)
tree.append_column(column)