Correct localized sort in windows using os encoding in the flat views
svn: r12761
This commit is contained in:
parent
f7454de7fd
commit
c8ef93f120
68
src/Utils.py
68
src/Utils.py
@ -20,6 +20,10 @@
|
|||||||
|
|
||||||
# $Id$
|
# $Id$
|
||||||
|
|
||||||
|
"""
|
||||||
|
Non GUI/GTK related utility functions
|
||||||
|
"""
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Standard python modules
|
# Standard python modules
|
||||||
@ -30,15 +34,8 @@ import sys
|
|||||||
import locale
|
import locale
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
|
import shutil
|
||||||
from TransUtils import sgettext as _
|
import platform
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
#
|
|
||||||
# GNOME/GTK
|
|
||||||
#
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
import gtk
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -48,10 +45,10 @@ import gtk
|
|||||||
from BasicUtils import name_displayer
|
from BasicUtils import name_displayer
|
||||||
import gen.lib
|
import gen.lib
|
||||||
import Errors
|
import Errors
|
||||||
from QuestionDialog import WarningDialog, ErrorDialog
|
from GrampsLocale import codeset
|
||||||
|
|
||||||
from const import TEMP_DIR, USER_HOME
|
from const import TEMP_DIR, USER_HOME, WINDOWS
|
||||||
import shutil
|
from TransUtils import sgettext as _
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -213,6 +210,53 @@ def family_upper_name(family, db):
|
|||||||
name = mother.get_primary_name().get_upper_name()
|
name = mother.get_primary_name().get_upper_name()
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# String Encoding functions
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
def encodingdefs():
|
||||||
|
"""
|
||||||
|
4 functions are defined to obtain a byte string that can be used as
|
||||||
|
sort key and is locale aware. Do not print the sortkey, it is a sortable
|
||||||
|
string, but is not a human readable correct string!
|
||||||
|
When gtk is defined, one can avoid some function calls as then the default
|
||||||
|
python encoding is not ascii but utf-8, so use the gtk functions in those
|
||||||
|
cases.
|
||||||
|
|
||||||
|
conv_utf8_tosrtkey: convert a utf8 encoded string to sortkey usable string
|
||||||
|
|
||||||
|
conv_unicode_tosrtkey: convert a unicode object to sortkey usable string
|
||||||
|
|
||||||
|
conv_utf8_tosrtkey_ongtk: convert a utf8 encoded string to sortkey usable
|
||||||
|
string when gtk is loaded or utf-8 is default python encoding
|
||||||
|
|
||||||
|
conv_unicode_tosrtkey_ongtk: convert a unicode object to sortkey usable
|
||||||
|
string when gtk is loaded or utf-8 is default python encoding
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
if platform in WINDOWS:
|
||||||
|
# python encoding is ascii, but C functions need to recieve the
|
||||||
|
# windows codeset, so convert over to it
|
||||||
|
conv_utf8_tosrtkey = lambda x: locale.strxfrm(x.decode("utf-8").encode(
|
||||||
|
codeset))
|
||||||
|
conv_unicode_tosrtkey = lambda x: locale.strxfrm(x.encode(codeset))
|
||||||
|
#when gtk is imported the python defaultencoding is utf-8,
|
||||||
|
#so no need to specify it
|
||||||
|
conv_utf8_tosrtkey_ongtk = lambda x: locale.strxfrm(unicode(x).encode(
|
||||||
|
codeset))
|
||||||
|
conv_unicode_tosrtkey_ongtk = lambda x: locale.strxfrm(x.encode(codeset))
|
||||||
|
else:
|
||||||
|
# on unix C functions need to recieve utf-8. Default conversion would
|
||||||
|
# use ascii, so it is needed to be explicit about the resulting encoding
|
||||||
|
conv_utf8_tosrtkey = lambda x: locale.strxfrm(x)
|
||||||
|
conv_unicode_tosrtkey = lambda x: locale.strxfrm(x.encode("utf-8"))
|
||||||
|
# when gtk loaded, default encoding (sys.getdefaultencoding ) is utf-8,
|
||||||
|
# so default conversion happens with utf-8
|
||||||
|
conv_utf8_tosrtkey_ongtk = lambda x: locale.strxfrm(x)
|
||||||
|
conv_unicode_tosrtkey_ongtk = lambda x: locale.strxfrm(x)
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
|
@ -74,6 +74,7 @@ import gtk
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from Filters import SearchFilter
|
from Filters import SearchFilter
|
||||||
import Config
|
import Config
|
||||||
|
from Utils import conv_unicode_tosrtkey_ongtk
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -449,6 +450,7 @@ class FlatBaseModel(gtk.GenericTreeModel):
|
|||||||
"""
|
"""
|
||||||
Total number of items that maximally can be shown
|
Total number of items that maximally can be shown
|
||||||
"""
|
"""
|
||||||
|
print 'total asked', self.node_map.max_rows()
|
||||||
return self.node_map.max_rows()
|
return self.node_map.max_rows()
|
||||||
|
|
||||||
def displayed(self):
|
def displayed(self):
|
||||||
@ -475,8 +477,8 @@ class FlatBaseModel(gtk.GenericTreeModel):
|
|||||||
# use cursor as a context manager
|
# use cursor as a context manager
|
||||||
with self.gen_cursor() as cursor:
|
with self.gen_cursor() as cursor:
|
||||||
#loop over database and store the sort field, and the handle
|
#loop over database and store the sort field, and the handle
|
||||||
return sorted( (locale.strxfrm(self.sort_func(data)), key)
|
return sorted( (conv_unicode_tosrtkey_ongtk(self.sort_func(data)),
|
||||||
for key, data in cursor )
|
key) for key, data in cursor )
|
||||||
|
|
||||||
def _rebuild_search(self, ignore=None):
|
def _rebuild_search(self, ignore=None):
|
||||||
""" function called when view must be build, given a search text
|
""" function called when view must be build, given a search text
|
||||||
|
Loading…
Reference in New Issue
Block a user