2620: GEPS 031: Python 3 support - 3.2

* working treeviews in python 3
   * changed conv_to_unicode on python 3 so that it decodes to unicode


svn: r20663
This commit is contained in:
Benny Malengier 2012-11-16 17:09:26 +00:00
parent 2bdf6c8b95
commit 8c4eb3d171
8 changed files with 182 additions and 158 deletions

View File

@ -480,7 +480,7 @@ def find_locker_name(dirpath):
""" """
try: try:
fname = os.path.join(dirpath, "lock") fname = os.path.join(dirpath, "lock")
ifile = open(fname) ifile = open(fname, 'rb')
username = ifile.read().strip() username = ifile.read().strip()
# Convert username to unicode according to system encoding # Convert username to unicode according to system encoding
# Otherwise problems with non ASCII characters in # Otherwise problems with non ASCII characters in

View File

@ -55,7 +55,11 @@ if sys.version_info[0] < 3:
STRTYPE = basestring STRTYPE = basestring
UNITYPE = unicode UNITYPE = unicode
else: else:
conv_to_unicode = lambda x,y: str(x) def conv_to_unicode(x, y):
if isinstance(x, str):
return x
else:
return x.decode(y)
conv_to_unicode_direct = str conv_to_unicode_direct = str
STRTYPE = str STRTYPE = str
UNITYPE = str UNITYPE = str

View File

@ -35,67 +35,71 @@ strftime.
Since these routines return values encoded into selected character Since these routines return values encoded into selected character
set, we have to convert to unicode. set, we have to convert to unicode.
""" """
if sys.version_info[0] < 3:
to_uni = conv_to_unicode
else:
#locale returns unicode in python 3
to_uni = lambda x, y: x
try: try:
codeset = locale.nl_langinfo(locale.CODESET) codeset = locale.nl_langinfo(locale.CODESET)
month_to_int = { month_to_int = {
conv_to_unicode(locale.nl_langinfo(locale.MON_1),codeset).lower() : 1, to_uni(locale.nl_langinfo(locale.MON_1), codeset).lower() : 1,
conv_to_unicode(locale.nl_langinfo(locale.ABMON_1),codeset).lower() : 1, to_uni(locale.nl_langinfo(locale.ABMON_1), codeset).lower() : 1,
conv_to_unicode(locale.nl_langinfo(locale.MON_2),codeset).lower() : 2, to_uni(locale.nl_langinfo(locale.MON_2), codeset).lower() : 2,
conv_to_unicode(locale.nl_langinfo(locale.ABMON_2),codeset).lower() : 2, to_uni(locale.nl_langinfo(locale.ABMON_2), codeset).lower() : 2,
conv_to_unicode(locale.nl_langinfo(locale.MON_3),codeset).lower() : 3, to_uni(locale.nl_langinfo(locale.MON_3), codeset).lower() : 3,
conv_to_unicode(locale.nl_langinfo(locale.ABMON_3),codeset).lower() : 3, to_uni(locale.nl_langinfo(locale.ABMON_3), codeset).lower() : 3,
conv_to_unicode(locale.nl_langinfo(locale.MON_4),codeset).lower() : 4, to_uni(locale.nl_langinfo(locale.MON_4), codeset).lower() : 4,
conv_to_unicode(locale.nl_langinfo(locale.ABMON_4),codeset).lower() : 4, to_uni(locale.nl_langinfo(locale.ABMON_4), codeset).lower() : 4,
conv_to_unicode(locale.nl_langinfo(locale.MON_5),codeset).lower() : 5, to_uni(locale.nl_langinfo(locale.MON_5), codeset).lower() : 5,
conv_to_unicode(locale.nl_langinfo(locale.ABMON_5),codeset).lower() : 5, to_uni(locale.nl_langinfo(locale.ABMON_5), codeset).lower() : 5,
conv_to_unicode(locale.nl_langinfo(locale.MON_6),codeset).lower() : 6, to_uni(locale.nl_langinfo(locale.MON_6), codeset).lower() : 6,
conv_to_unicode(locale.nl_langinfo(locale.ABMON_6),codeset).lower() : 6, to_uni(locale.nl_langinfo(locale.ABMON_6), codeset).lower() : 6,
conv_to_unicode(locale.nl_langinfo(locale.MON_7),codeset).lower() : 7, to_uni(locale.nl_langinfo(locale.MON_7), codeset).lower() : 7,
conv_to_unicode(locale.nl_langinfo(locale.ABMON_7),codeset).lower() : 7, to_uni(locale.nl_langinfo(locale.ABMON_7), codeset).lower() : 7,
conv_to_unicode(locale.nl_langinfo(locale.MON_8),codeset).lower() : 8, to_uni(locale.nl_langinfo(locale.MON_8), codeset).lower() : 8,
conv_to_unicode(locale.nl_langinfo(locale.ABMON_8),codeset).lower() : 8, to_uni(locale.nl_langinfo(locale.ABMON_8), codeset).lower() : 8,
conv_to_unicode(locale.nl_langinfo(locale.MON_9),codeset).lower() : 9, to_uni(locale.nl_langinfo(locale.MON_9), codeset).lower() : 9,
conv_to_unicode(locale.nl_langinfo(locale.ABMON_9),codeset).lower() : 9, to_uni(locale.nl_langinfo(locale.ABMON_9), codeset).lower() : 9,
conv_to_unicode(locale.nl_langinfo(locale.MON_10),codeset).lower() : 10, to_uni(locale.nl_langinfo(locale.MON_10), codeset).lower() : 10,
conv_to_unicode(locale.nl_langinfo(locale.ABMON_10),codeset).lower(): 10, to_uni(locale.nl_langinfo(locale.ABMON_10), codeset).lower(): 10,
conv_to_unicode(locale.nl_langinfo(locale.MON_11),codeset).lower() : 11, to_uni(locale.nl_langinfo(locale.MON_11), codeset).lower() : 11,
conv_to_unicode(locale.nl_langinfo(locale.ABMON_11),codeset).lower(): 11, to_uni(locale.nl_langinfo(locale.ABMON_11), codeset).lower(): 11,
conv_to_unicode(locale.nl_langinfo(locale.MON_12),codeset).lower() : 12, to_uni(locale.nl_langinfo(locale.MON_12), codeset).lower() : 12,
conv_to_unicode(locale.nl_langinfo(locale.ABMON_12),codeset).lower(): 12, to_uni(locale.nl_langinfo(locale.ABMON_12), codeset).lower(): 12,
} }
long_months = ( long_months = (
"", "",
conv_to_unicode(locale.nl_langinfo(locale.MON_1),codeset), to_uni(locale.nl_langinfo(locale.MON_1), codeset),
conv_to_unicode(locale.nl_langinfo(locale.MON_2),codeset), to_uni(locale.nl_langinfo(locale.MON_2), codeset),
conv_to_unicode(locale.nl_langinfo(locale.MON_3),codeset), to_uni(locale.nl_langinfo(locale.MON_3), codeset),
conv_to_unicode(locale.nl_langinfo(locale.MON_4),codeset), to_uni(locale.nl_langinfo(locale.MON_4), codeset),
conv_to_unicode(locale.nl_langinfo(locale.MON_5),codeset), to_uni(locale.nl_langinfo(locale.MON_5), codeset),
conv_to_unicode(locale.nl_langinfo(locale.MON_6),codeset), to_uni(locale.nl_langinfo(locale.MON_6), codeset),
conv_to_unicode(locale.nl_langinfo(locale.MON_7),codeset), to_uni(locale.nl_langinfo(locale.MON_7), codeset),
conv_to_unicode(locale.nl_langinfo(locale.MON_8),codeset), to_uni(locale.nl_langinfo(locale.MON_8), codeset),
conv_to_unicode(locale.nl_langinfo(locale.MON_9),codeset), to_uni(locale.nl_langinfo(locale.MON_9), codeset),
conv_to_unicode(locale.nl_langinfo(locale.MON_10),codeset), to_uni(locale.nl_langinfo(locale.MON_10), codeset),
conv_to_unicode(locale.nl_langinfo(locale.MON_11),codeset), to_uni(locale.nl_langinfo(locale.MON_11), codeset),
conv_to_unicode(locale.nl_langinfo(locale.MON_12),codeset), to_uni(locale.nl_langinfo(locale.MON_12), codeset),
) )
short_months = ( short_months = (
"", "",
conv_to_unicode(locale.nl_langinfo(locale.ABMON_1),codeset), to_uni(locale.nl_langinfo(locale.ABMON_1), codeset),
conv_to_unicode(locale.nl_langinfo(locale.ABMON_2),codeset), to_uni(locale.nl_langinfo(locale.ABMON_2), codeset),
conv_to_unicode(locale.nl_langinfo(locale.ABMON_3),codeset), to_uni(locale.nl_langinfo(locale.ABMON_3), codeset),
conv_to_unicode(locale.nl_langinfo(locale.ABMON_4),codeset), to_uni(locale.nl_langinfo(locale.ABMON_4), codeset),
conv_to_unicode(locale.nl_langinfo(locale.ABMON_5),codeset), to_uni(locale.nl_langinfo(locale.ABMON_5), codeset),
conv_to_unicode(locale.nl_langinfo(locale.ABMON_6),codeset), to_uni(locale.nl_langinfo(locale.ABMON_6), codeset),
conv_to_unicode(locale.nl_langinfo(locale.ABMON_7),codeset), to_uni(locale.nl_langinfo(locale.ABMON_7), codeset),
conv_to_unicode(locale.nl_langinfo(locale.ABMON_8),codeset), to_uni(locale.nl_langinfo(locale.ABMON_8), codeset),
conv_to_unicode(locale.nl_langinfo(locale.ABMON_9),codeset), to_uni(locale.nl_langinfo(locale.ABMON_9), codeset),
conv_to_unicode(locale.nl_langinfo(locale.ABMON_10),codeset), to_uni(locale.nl_langinfo(locale.ABMON_10), codeset),
conv_to_unicode(locale.nl_langinfo(locale.ABMON_11),codeset), to_uni(locale.nl_langinfo(locale.ABMON_11), codeset),
conv_to_unicode(locale.nl_langinfo(locale.ABMON_12),codeset), to_uni(locale.nl_langinfo(locale.ABMON_12), codeset),
) )
# Gramps day number: Sunday => 1, Monday => 2, etc # Gramps day number: Sunday => 1, Monday => 2, etc
@ -106,24 +110,24 @@ try:
# see http://docs.python.org/library/locale.html # see http://docs.python.org/library/locale.html
long_days = ( long_days = (
"", "",
conv_to_unicode(locale.nl_langinfo(locale.DAY_1),codeset), # Sunday to_uni(locale.nl_langinfo(locale.DAY_1), codeset), # Sunday
conv_to_unicode(locale.nl_langinfo(locale.DAY_2),codeset), # Monday to_uni(locale.nl_langinfo(locale.DAY_2), codeset), # Monday
conv_to_unicode(locale.nl_langinfo(locale.DAY_3),codeset), # Tuesday to_uni(locale.nl_langinfo(locale.DAY_3), codeset), # Tuesday
conv_to_unicode(locale.nl_langinfo(locale.DAY_4),codeset), # Wednesday to_uni(locale.nl_langinfo(locale.DAY_4), codeset), # Wednesday
conv_to_unicode(locale.nl_langinfo(locale.DAY_5),codeset), # Thursday to_uni(locale.nl_langinfo(locale.DAY_5), codeset), # Thursday
conv_to_unicode(locale.nl_langinfo(locale.DAY_6),codeset), # Friday to_uni(locale.nl_langinfo(locale.DAY_6), codeset), # Friday
conv_to_unicode(locale.nl_langinfo(locale.DAY_7),codeset), # Saturday to_uni(locale.nl_langinfo(locale.DAY_7), codeset), # Saturday
) )
short_days = ( short_days = (
"", "",
conv_to_unicode(locale.nl_langinfo(locale.ABDAY_1),codeset), # Sunday to_uni(locale.nl_langinfo(locale.ABDAY_1), codeset), # Sunday
conv_to_unicode(locale.nl_langinfo(locale.ABDAY_2),codeset), # Monday to_uni(locale.nl_langinfo(locale.ABDAY_2), codeset), # Monday
conv_to_unicode(locale.nl_langinfo(locale.ABDAY_3),codeset), # Tuesday to_uni(locale.nl_langinfo(locale.ABDAY_3), codeset), # Tuesday
conv_to_unicode(locale.nl_langinfo(locale.ABDAY_4),codeset), # Wednesday to_uni(locale.nl_langinfo(locale.ABDAY_4), codeset), # Wednesday
conv_to_unicode(locale.nl_langinfo(locale.ABDAY_5),codeset), # Thursday to_uni(locale.nl_langinfo(locale.ABDAY_5), codeset), # Thursday
conv_to_unicode(locale.nl_langinfo(locale.ABDAY_6),codeset), # Friday to_uni(locale.nl_langinfo(locale.ABDAY_6), codeset), # Friday
conv_to_unicode(locale.nl_langinfo(locale.ABDAY_7),codeset), # Saturday to_uni(locale.nl_langinfo(locale.ABDAY_7), codeset), # Saturday
) )
tformat = locale.nl_langinfo(locale.D_FMT).replace('%y','%Y') tformat = locale.nl_langinfo(locale.D_FMT).replace('%y','%Y')
@ -140,62 +144,62 @@ except:
codeset = locale.getpreferredencoding() codeset = locale.getpreferredencoding()
month_to_int = { month_to_int = {
conv_to_unicode(time.strftime('%B',(0,1,1,1,1,1,1,1,1)),codeset).lower() : 1, to_uni(time.strftime('%B',(0,1,1,1,1,1,1,1,1)), codeset).lower() : 1,
conv_to_unicode(time.strftime('%b',(0,1,1,1,1,1,1,1,1)),codeset).lower() : 1, to_uni(time.strftime('%b',(0,1,1,1,1,1,1,1,1)), codeset).lower() : 1,
conv_to_unicode(time.strftime('%B',(0,2,1,1,1,1,1,1,1)),codeset).lower() : 2, to_uni(time.strftime('%B',(0,2,1,1,1,1,1,1,1)), codeset).lower() : 2,
conv_to_unicode(time.strftime('%b',(0,2,1,1,1,1,1,1,1)),codeset).lower() : 2, to_uni(time.strftime('%b',(0,2,1,1,1,1,1,1,1)), codeset).lower() : 2,
conv_to_unicode(time.strftime('%B',(0,3,1,1,1,1,1,1,1)),codeset).lower() : 3, to_uni(time.strftime('%B',(0,3,1,1,1,1,1,1,1)), codeset).lower() : 3,
conv_to_unicode(time.strftime('%b',(0,3,1,1,1,1,1,1,1)),codeset).lower() : 3, to_uni(time.strftime('%b',(0,3,1,1,1,1,1,1,1)), codeset).lower() : 3,
conv_to_unicode(time.strftime('%B',(0,4,1,1,1,1,1,1,1)),codeset).lower() : 4, to_uni(time.strftime('%B',(0,4,1,1,1,1,1,1,1)), codeset).lower() : 4,
conv_to_unicode(time.strftime('%b',(0,4,1,1,1,1,1,1,1)),codeset).lower() : 4, to_uni(time.strftime('%b',(0,4,1,1,1,1,1,1,1)), codeset).lower() : 4,
conv_to_unicode(time.strftime('%B',(0,5,1,1,1,1,1,1,1)),codeset).lower() : 5, to_uni(time.strftime('%B',(0,5,1,1,1,1,1,1,1)), codeset).lower() : 5,
conv_to_unicode(time.strftime('%b',(0,5,1,1,1,1,1,1,1)),codeset).lower() : 5, to_uni(time.strftime('%b',(0,5,1,1,1,1,1,1,1)), codeset).lower() : 5,
conv_to_unicode(time.strftime('%B',(0,6,1,1,1,1,1,1,1)),codeset).lower() : 6, to_uni(time.strftime('%B',(0,6,1,1,1,1,1,1,1)), codeset).lower() : 6,
conv_to_unicode(time.strftime('%b',(0,6,1,1,1,1,1,1,1)),codeset).lower() : 6, to_uni(time.strftime('%b',(0,6,1,1,1,1,1,1,1)), codeset).lower() : 6,
conv_to_unicode(time.strftime('%B',(0,7,1,1,1,1,1,1,1)),codeset).lower() : 7, to_uni(time.strftime('%B',(0,7,1,1,1,1,1,1,1)), codeset).lower() : 7,
conv_to_unicode(time.strftime('%b',(0,7,1,1,1,1,1,1,1)),codeset).lower() : 7, to_uni(time.strftime('%b',(0,7,1,1,1,1,1,1,1)), codeset).lower() : 7,
conv_to_unicode(time.strftime('%B',(0,8,1,1,1,1,1,1,1)),codeset).lower() : 8, to_uni(time.strftime('%B',(0,8,1,1,1,1,1,1,1)), codeset).lower() : 8,
conv_to_unicode(time.strftime('%b',(0,8,1,1,1,1,1,1,1)),codeset).lower() : 8, to_uni(time.strftime('%b',(0,8,1,1,1,1,1,1,1)), codeset).lower() : 8,
conv_to_unicode(time.strftime('%B',(0,9,1,1,1,1,1,1,1)),codeset).lower() : 9, to_uni(time.strftime('%B',(0,9,1,1,1,1,1,1,1)), codeset).lower() : 9,
conv_to_unicode(time.strftime('%b',(0,9,1,1,1,1,1,1,1)),codeset).lower() : 9, to_uni(time.strftime('%b',(0,9,1,1,1,1,1,1,1)), codeset).lower() : 9,
conv_to_unicode(time.strftime('%B',(0,10,1,1,1,1,1,1,1)),codeset).lower() : 10, to_uni(time.strftime('%B',(0,10,1,1,1,1,1,1,1)), codeset).lower() : 10,
conv_to_unicode(time.strftime('%b',(0,10,1,1,1,1,1,1,1)),codeset).lower() : 10, to_uni(time.strftime('%b',(0,10,1,1,1,1,1,1,1)), codeset).lower() : 10,
conv_to_unicode(time.strftime('%B',(0,11,1,1,1,1,1,1,1)),codeset).lower() : 11, to_uni(time.strftime('%B',(0,11,1,1,1,1,1,1,1)), codeset).lower() : 11,
conv_to_unicode(time.strftime('%b',(0,11,1,1,1,1,1,1,1)),codeset).lower() : 11, to_uni(time.strftime('%b',(0,11,1,1,1,1,1,1,1)), codeset).lower() : 11,
conv_to_unicode(time.strftime('%B',(0,12,1,1,1,1,1,1,1)),codeset).lower() : 12, to_uni(time.strftime('%B',(0,12,1,1,1,1,1,1,1)), codeset).lower() : 12,
conv_to_unicode(time.strftime('%b',(0,12,1,1,1,1,1,1,1)),codeset).lower() : 12, to_uni(time.strftime('%b',(0,12,1,1,1,1,1,1,1)), codeset).lower() : 12,
} }
long_months = ( long_months = (
"", "",
conv_to_unicode(time.strftime('%B',(0,1,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%B',(0,1,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%B',(0,2,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%B',(0,2,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%B',(0,3,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%B',(0,3,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%B',(0,4,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%B',(0,4,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%B',(0,5,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%B',(0,5,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%B',(0,6,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%B',(0,6,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%B',(0,7,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%B',(0,7,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%B',(0,8,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%B',(0,8,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%B',(0,9,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%B',(0,9,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%B',(0,10,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%B',(0,10,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%B',(0,11,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%B',(0,11,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%B',(0,12,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%B',(0,12,1,1,1,1,1,1,1)), codeset),
) )
short_months = ( short_months = (
"", "",
conv_to_unicode(time.strftime('%b',(0,1,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%b',(0,1,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%b',(0,2,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%b',(0,2,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%b',(0,3,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%b',(0,3,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%b',(0,4,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%b',(0,4,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%b',(0,5,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%b',(0,5,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%b',(0,6,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%b',(0,6,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%b',(0,7,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%b',(0,7,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%b',(0,8,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%b',(0,8,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%b',(0,9,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%b',(0,9,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%b',(0,10,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%b',(0,10,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%b',(0,11,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%b',(0,11,1,1,1,1,1,1,1)), codeset),
conv_to_unicode(time.strftime('%b',(0,12,1,1,1,1,1,1,1)),codeset), to_uni(time.strftime('%b',(0,12,1,1,1,1,1,1,1)), codeset),
) )
# Gramps day number: Sunday => 1, Monday => 2, etc # Gramps day number: Sunday => 1, Monday => 2, etc
@ -209,24 +213,24 @@ except:
# just a dummy. # just a dummy.
long_days = ( long_days = (
"", "",
conv_to_unicode(time.strftime('%A',(0,1,1,1,1,1,6,1,1)),codeset), # Sunday to_uni(time.strftime('%A',(0,1,1,1,1,1,6,1,1)), codeset), # Sunday
conv_to_unicode(time.strftime('%A',(0,1,1,1,1,1,0,1,1)),codeset), # Monday to_uni(time.strftime('%A',(0,1,1,1,1,1,0,1,1)), codeset), # Monday
conv_to_unicode(time.strftime('%A',(0,1,1,1,1,1,1,1,1)),codeset), # Tuesday to_uni(time.strftime('%A',(0,1,1,1,1,1,1,1,1)), codeset), # Tuesday
conv_to_unicode(time.strftime('%A',(0,1,1,1,1,1,2,1,1)),codeset), # Wednesday to_uni(time.strftime('%A',(0,1,1,1,1,1,2,1,1)), codeset), # Wednesday
conv_to_unicode(time.strftime('%A',(0,1,1,1,1,1,3,1,1)),codeset), # Thursday to_uni(time.strftime('%A',(0,1,1,1,1,1,3,1,1)), codeset), # Thursday
conv_to_unicode(time.strftime('%A',(0,1,1,1,1,1,4,1,1)),codeset), # Friday to_uni(time.strftime('%A',(0,1,1,1,1,1,4,1,1)), codeset), # Friday
conv_to_unicode(time.strftime('%A',(0,1,1,1,1,1,5,1,1)),codeset), # Saturday to_uni(time.strftime('%A',(0,1,1,1,1,1,5,1,1)), codeset), # Saturday
) )
short_days = ( short_days = (
"", "",
conv_to_unicode(time.strftime('%a',(0,1,1,1,1,1,6,1,1)),codeset), # Sunday to_uni(time.strftime('%a',(0,1,1,1,1,1,6,1,1)), codeset), # Sunday
conv_to_unicode(time.strftime('%a',(0,1,1,1,1,1,0,1,1)),codeset), # Monday to_uni(time.strftime('%a',(0,1,1,1,1,1,0,1,1)), codeset), # Monday
conv_to_unicode(time.strftime('%a',(0,1,1,1,1,1,1,1,1)),codeset), # Tuesday to_uni(time.strftime('%a',(0,1,1,1,1,1,1,1,1)), codeset), # Tuesday
conv_to_unicode(time.strftime('%a',(0,1,1,1,1,1,2,1,1)),codeset), # Wednesday to_uni(time.strftime('%a',(0,1,1,1,1,1,2,1,1)), codeset), # Wednesday
conv_to_unicode(time.strftime('%a',(0,1,1,1,1,1,3,1,1)),codeset), # Thursday to_uni(time.strftime('%a',(0,1,1,1,1,1,3,1,1)), codeset), # Thursday
conv_to_unicode(time.strftime('%a',(0,1,1,1,1,1,4,1,1)),codeset), # Friday to_uni(time.strftime('%a',(0,1,1,1,1,1,4,1,1)), codeset), # Friday
conv_to_unicode(time.strftime('%a',(0,1,1,1,1,1,5,1,1)),codeset), # Saturday to_uni(time.strftime('%a',(0,1,1,1,1,1,5,1,1)), codeset), # Saturday
) )
# depending on the locale, the value returned for 20th Feb 2009 could be # depending on the locale, the value returned for 20th Feb 2009 could be

View File

@ -61,7 +61,7 @@ import re
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from ..constfunc import cuni, conv_to_unicode from ..constfunc import cuni, conv_to_unicode, UNITYPE
from ..lib.name import Name from ..lib.name import Name
from ..lib.nameorigintype import NameOriginType from ..lib.nameorigintype import NameOriginType
@ -986,7 +986,8 @@ class NameDisplay(object):
# if in double quotes, just use % codes # if in double quotes, just use % codes
for (code, keyword) in d_keys: for (code, keyword) in d_keys:
exp, keyword, ikeyword = d[code] exp, keyword, ikeyword = d[code]
keyword = conv_to_unicode(keyword, "utf8") if not isinstance(keyword, UNITYPE):
keyword = conv_to_unicode(keyword, "utf-8")
format_str = format_str.replace(keyword, "%"+ code) format_str = format_str.replace(keyword, "%"+ code)
format_str = format_str.replace(keyword.title(), "%"+ code) format_str = format_str.replace(keyword.title(), "%"+ code)
format_str = format_str.replace(keyword.upper(), "%"+ code.upper()) format_str = format_str.replace(keyword.upper(), "%"+ code.upper())

View File

@ -44,7 +44,7 @@ from gi.repository import Gtk
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gen.datehandler import displayer, format_time from gramps.gen.datehandler import displayer, format_time
from gramps.gen.lib import Date, MediaObject from gramps.gen.lib import Date, MediaObject
from gramps.gen.constfunc import cuni, conv_to_unicode from gramps.gen.constfunc import cuni, conv_to_unicode, UNITYPE
from .flatbasemodel import FlatBaseModel from .flatbasemodel import FlatBaseModel
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -107,21 +107,30 @@ class MediaModel(FlatBaseModel):
def do_get_n_columns(self): def do_get_n_columns(self):
return len(self.fmap)+1 return len(self.fmap)+1
def column_description(self,data): def column_description(self, data):
descr = data[4]
if isinstance(descr, UNITYPE):
return descr
try: try:
return cuni(data[4]) return cuni(descr)
except: except:
return conv_to_unicode(data[4], 'latin1') return conv_to_unicode(descr, 'latin1')
def column_path(self,data): def column_path(self, data):
path = data[2]
if isinstance(path, UNITYPE):
return path
try: try:
return cuni(data[2]) return cuni(path)
except: except:
return cuni(data[2].encode('iso-8859-1')) return cuni(path.encode('iso-8859-1'))
def column_mime(self,data): def column_mime(self, data):
if data[3]: mime = data[3]
return cuni(data[3]) if mime and isinstance(mime, UNITYPE):
return mime
if mime:
return cuni(mime)
else: else:
return _('Note') return _('Note')

View File

@ -194,8 +194,8 @@ class PeopleBaseModel(object):
def sort_name(self, data): def sort_name(self, data):
name = name_displayer.raw_sorted_name(data[COLUMN_NAME]) name = name_displayer.raw_sorted_name(data[COLUMN_NAME])
# internally we work with utf-8 # internally we work with utf-8
if isinstance(name, UNITYPE): if not isinstance(name, UNITYPE):
name = name.encode('utf-8') name = name.decode('utf-8')
return name return name
def column_name(self, data): def column_name(self, data):
@ -209,7 +209,6 @@ class PeopleBaseModel(object):
name = name.encode('utf-8') name = name.encode('utf-8')
if not self._in_build: if not self._in_build:
self.lru_name[handle] = name self.lru_name[handle] = name
return name return name
def column_spouse(self, data): def column_spouse(self, data):
@ -537,8 +536,8 @@ class PersonTreeModel(PeopleBaseModel, TreeBaseModel):
name_data = data[COLUMN_NAME] name_data = data[COLUMN_NAME]
group_name = ngn(self.db, name_data) group_name = ngn(self.db, name_data)
if isinstance(group_name, UNITYPE): #if isinstance(group_name, UNITYPE):
group_name = group_name.encode('utf-8') # group_name = group_name.encode('utf-8')
sort_key = self.sort_func(data) sort_key = self.sort_func(data)
#if group_name not in self.group_list: #if group_name not in self.group_list:

View File

@ -37,6 +37,7 @@ This module provides the model that is used for all hierarchical treeviews.
import time import time
import locale import locale
import sys
from gramps.gen.ggettext import gettext as _ from gramps.gen.ggettext import gettext as _
import logging import logging
@ -90,13 +91,16 @@ class Node(object):
def __init__(self, ref, parent, sortkey, handle, secondary): def __init__(self, ref, parent, sortkey, handle, secondary):
if sortkey: if sortkey:
if isinstance(sortkey, UNITYPE): if isinstance(sortkey, UNITYPE):
self.name = sortkey.encode('utf-8') self.name = sortkey
#sortkey must be localized sort, so #sortkey must be localized sort, so
self.sortkey = conv_unicode_tosrtkey(sortkey) self.sortkey = conv_unicode_tosrtkey(sortkey)
else: else:
self.name = sortkey self.name = sortkey.decode('utf-8')
#sortkey must be localized sort, so #sortkey must be localized sort, so
self.sortkey = conv_str_tosrtkey(sortkey) if sys.version_info[0] < 3:
self.sortkey = conv_str_tosrtkey(sortkey)
else:
self.sortkey = conv_unicode_tosrtkey(self.name)
else: else:
self.name = '' self.name = ''
self.sortkey = None self.sortkey = None
@ -832,7 +836,7 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel):
not correspond to a gramps object. not correspond to a gramps object.
""" """
handle = node.handle handle = node.handle
if not isinstance(handle, UNITYPE): if handle and not isinstance(handle, UNITYPE):
handle = handle.decode('utf-8') handle = handle.decode('utf-8')
return handle return handle
@ -881,24 +885,25 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel):
if node.handle is None: if node.handle is None:
# Header rows dont get the foreground color set # Header rows dont get the foreground color set
if col == self.color_column(): if col == self.color_column():
#color must not be utf-8
return "#000000000000" return "#000000000000"
# Return the node name for the first column # Return the node name for the first column
if col == 0: if col == 0:
return self.column_header(node) val = self.column_header(node)
else: else:
#no value to show in other header column #no value to show in other header column
return '' val = ''
else: else:
# return values for 'data' row, calling a function # return values for 'data' row, calling a function
# according to column_defs table # according to column_defs table
val = self._get_value(node.handle, col, node.secondary) val = self._get_value(node.handle, col, node.secondary)
#GTK 3 should convert unicode objects automatically, but this #GTK 3 should convert unicode objects automatically, but this
# gives wrong column values, so we convert, so we convert for python 2.7 # gives wrong column values, so we convert, so we convert for python 2.7
if not isinstance(val, str): if not isinstance(val, str):
return val.encode('utf-8') return val.encode('utf-8')
else: else:
return val return val
def _get_value(self, handle, col, secondary=False): def _get_value(self, handle, col, secondary=False):
""" """

View File

@ -48,7 +48,7 @@ from gi.repository import Gtk
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gen.constfunc import conv_to_unicode from gramps.gen.constfunc import conv_to_unicode, UNITYPE
from .undoablebuffer import Stack from .undoablebuffer import Stack
class UndoableInsertEntry(object): class UndoableInsertEntry(object):
@ -57,7 +57,9 @@ class UndoableInsertEntry(object):
self.offset = position self.offset = position
self.text = str(text) self.text = str(text)
#unicode char can have length > 1 as it points in the buffer #unicode char can have length > 1 as it points in the buffer
charlength = len(conv_to_unicode(text, 'utf-8')) if not isinstance(text, UNITYPE):
text = conv_to_unicode(text, 'utf-8')
charlength = len(text)
self.length = charlength self.length = charlength
if charlength > 1 or self.text in ("\r", "\n", " "): if charlength > 1 or self.text in ("\r", "\n", " "):
self.mergeable = False self.mergeable = False