0005088: Narrated Web Site Report sort order different Windows vs Linux. Initial commit to resolve the issues on Linux and Mac (provided in both cases PyICU is installed). Windows still needs to be tested, and there may still be some other uses of strxfrm (or strcoll) that need to be fixed.

svn: r21174
This commit is contained in:
Tim G L Lyons
2013-01-20 15:10:26 +00:00
parent 1c65ab29aa
commit 421d38eb89
3 changed files with 79 additions and 34 deletions

View File

@@ -107,8 +107,8 @@ class FlatNodeMap(object):
the path, and a dictionary mapping hndl to index.
To obtain index given a path, method real_index() is available
..Note: If a string sortkey is used, apply conv_unicode_tosrtkey_ongtk
on it , so as to have localized sort
..Note: conv_unicode_tosrtkey_ongtk is applied to the underlying sort key,
so as to have localized sort
"""
def __init__(self):
@@ -381,6 +381,9 @@ class FlatBaseModel(gtk.GenericTreeModel):
"""
The base class for all flat treeview models.
It keeps a FlatNodeMap, and obtains data from database as needed
..Note: conv_unicode_tosrtkey_ongtk is applied to the underlying sort key,
so as to have localized sort
"""
def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING,
@@ -399,9 +402,9 @@ class FlatBaseModel(gtk.GenericTreeModel):
self.sort_map = [ f for f in sort_map if f[0]]
#we need the model col, that corresponds with scol
col = self.sort_map[scol][1]
self.sort_func = self.smap[col]
else:
self.sort_func = self.smap[scol]
col = scol
self.sort_func = lambda x: conv_unicode_tosrtkey_ongtk(self.smap[col](x))
self.sort_col = scol
self.skip = skip
self._in_build = False
@@ -505,15 +508,11 @@ class FlatBaseModel(gtk.GenericTreeModel):
Return the (sort_key, handle) list of all data that can maximally
be shown.
This list is sorted ascending, via localized string sort.
conv_unicode_tosrtkey_ongtk which uses strxfrm, which is apparently
broken in Win ?? --> they should fix base lib, we need strxfrm, fix it
in the Utils module.
"""
# use cursor as a context manager
with self.gen_cursor() as cursor:
#loop over database and store the sort field, and the handle
return sorted((map(conv_unicode_tosrtkey_ongtk,
self.sort_func(data)), key) for key, data in cursor)
return sorted((self.sort_func(data), key) for key, data in cursor)
def _rebuild_search(self, ignore=None):
""" function called when view must be build, given a search text
@@ -582,8 +581,7 @@ class FlatBaseModel(gtk.GenericTreeModel):
if self.node_map.get_path(handle) is not None:
return # row is already displayed
data = self.map(handle)
insert_val = (map(conv_unicode_tosrtkey_ongtk, self.sort_func(data)),
handle)
insert_val = (self.sort_func(data), handle)
if not self.search or \
(self.search and self.search.match(handle, self.db)):
#row needs to be added to the model
@@ -616,8 +614,7 @@ class FlatBaseModel(gtk.GenericTreeModel):
return # row is not currently displayed
self.clear_cache(handle)
oldsortkey = self.node_map.get_sortkey(handle)
newsortkey = map(conv_unicode_tosrtkey_ongtk, self.sort_func(self.map(
handle)))
newsortkey = self.sort_func(self.map(handle))
if oldsortkey is None or oldsortkey != newsortkey:
#or the changed object is not present in the view due to filtering
#or the order of the object must change.

View File

@@ -88,7 +88,7 @@ class Node(object):
def __init__(self, ref, parent, sortkey, handle, secondary):
self.name = sortkey
if sortkey:
self.sortkey = map(conv_unicode_tosrtkey_ongtk, sortkey)
self.sortkey = conv_unicode_tosrtkey_ongtk(sortkey)
else:
self.sortkey = None
self.ref = ref