From aaa12567623f3abb39b2fd24bd1bb19217dd66c9 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sat, 19 Apr 2014 17:49:25 -0700 Subject: [PATCH] 7258: A consequence of forcing paths to unicode is that we sometimes need to explicitly decode a path to utf8 to pass to Gtk Only in Py2, of course, since the Py3 version of PyGObject knows what to do. --- gramps/gen/constfunc.py | 9 +++++++++ gramps/gui/glade.py | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gramps/gen/constfunc.py b/gramps/gen/constfunc.py index 40764083d..28e50b703 100644 --- a/gramps/gen/constfunc.py +++ b/gramps/gen/constfunc.py @@ -66,6 +66,15 @@ cuni = conv_to_unicode_direct def conv_to_unicode(x, y='utf8'): return x if x is None or isinstance(x, UNITYPE) else cuni(x, y) +def uni_to_gui(x): + ''' + In Py2 we need to convert strings to utf8 before passing them to + Gtk functions. + ''' + if sys.version_info[0] < 3 and isinstance(x, UNITYPE): + return x.encode('utf8') + else: + return x # handle in database is bytes, while internally Gramps wants unicode for py3 if sys.version_info[0] < 3: diff --git a/gramps/gui/glade.py b/gramps/gui/glade.py index bcb1b2bb8..bc57f00fb 100644 --- a/gramps/gui/glade.py +++ b/gramps/gui/glade.py @@ -49,7 +49,7 @@ from gi.repository import Gtk # #------------------------------------------------------------------------ from gramps.gen.const import GLADE_DIR, GRAMPS_LOCALE as glocale -from gramps.gen.constfunc import STRTYPE +from gramps.gen.constfunc import STRTYPE, uni_to_gui #------------------------------------------------------------------------ # @@ -124,7 +124,7 @@ class Glade(Gtk.Builder): # try to build Gtk objects from glade file. Let exceptions happen - self.add_from_file(path) + self.add_from_file(uni_to_gui(path)) self.__dirname, self.__filename = os.path.split(path) # try to find the toplevel widget