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.
This commit is contained in:
John Ralls 2014-04-19 17:49:25 -07:00
parent 74336a7ca8
commit 8f4aebe4c6
2 changed files with 11 additions and 2 deletions

View File

@ -64,6 +64,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:

View File

@ -47,7 +47,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
#------------------------------------------------------------------------
#
@ -122,7 +122,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