From 1d8a776cd3daf429ac52b9e883983b306d200af9 Mon Sep 17 00:00:00 2001 From: Peter Landgren Date: Sat, 9 Oct 2010 12:33:47 +0000 Subject: [PATCH] Part 1 of issue 4276. I principle same patch as for branch, but adapeted to trunk. svn: r15959 --- src/ExportAssistant.py | 4 +-- src/Filters/_FilterList.py | 4 +-- src/ImgManip.py | 8 +++++ src/TransUtils.py | 5 +++ src/Utils.py | 32 ++++++++++++++++++-- src/cli/clidbman.py | 2 ++ src/const.py.in | 5 +-- src/gen/plug/_pluginreg.py | 2 -- src/gen/plug/utils.py | 3 +- src/gui/configure.py | 2 +- src/gui/dbloader.py | 14 +++++++-- src/gui/dbman.py | 9 +++--- src/gui/editors/addmedia.py | 4 +-- src/gui/editors/editmedia.py | 4 +-- src/gui/plug/_guioptions.py | 2 +- src/gui/plug/_windows.py | 2 +- src/gui/plug/report/_fileentry.py | 2 +- src/gui/plug/report/_graphvizreportdialog.py | 32 +++++++++++++++----- src/gui/plug/report/_reportdialog.py | 4 +-- src/gui/viewmanager.py | 6 +++- src/gui/views/listview.py | 1 + src/plugins/docgen/PdfDoc.py | 4 ++- src/plugins/export/ExportPkg.py | 3 +- src/plugins/tool/Check.py | 2 +- src/plugins/tool/EventCmp.py | 2 +- src/plugins/view/geoview.py | 2 +- src/plugins/view/pedigreeview.py | 3 ++ 27 files changed, 118 insertions(+), 45 deletions(-) diff --git a/src/ExportAssistant.py b/src/ExportAssistant.py index 29defb12c..dec6a3271 100644 --- a/src/ExportAssistant.py +++ b/src/ExportAssistant.py @@ -478,7 +478,7 @@ class ExportAssistant(gtk.Assistant, ManagedWindow.ManagedWindow) : #Allow for exotic error: file is still not correct self.check_fileselect(self.chooser, show=False) if self.get_page_complete(self.chooser) : - filename = Utils.get_unicode_path(self.chooser.get_filename()) + filename = Utils.get_unicode_path_from_file_chooser(self.chooser.get_filename()) name = os.path.split(filename)[1] folder = os.path.split(filename)[0] confirm_text = _( @@ -612,7 +612,7 @@ class ExportAssistant(gtk.Assistant, ManagedWindow.ManagedWindow) : hasattr(self.option_box_instance, "no_fileselect")): filename = "" else: - filename = Utils.get_unicode_path(self.chooser.get_filename()) + filename = Utils.get_unicode_path_from_file_chooser(self.chooser.get_filename()) config.set('paths.recent-export-dir', os.path.split(filename)[0]) ix = self.get_selected_format_index() config.set('behavior.recent-export-type', ix) diff --git a/src/Filters/_FilterList.py b/src/Filters/_FilterList.py index b936aea28..1cd8e67bc 100644 --- a/src/Filters/_FilterList.py +++ b/src/Filters/_FilterList.py @@ -27,6 +27,7 @@ #------------------------------------------------------------------------- from xml.sax import make_parser, SAXParseException import os +import sys #------------------------------------------------------------------------- # @@ -114,8 +115,7 @@ class FilterList(object): return l.replace('"', '"') def save(self): - f = open(self.file.encode('utf-8'), 'w') - + f = open(self.file.encode(sys.getfilesystemencoding()), 'w') f.write("\n") f.write('\n') for namespace in self.filter_namespaces: diff --git a/src/ImgManip.py b/src/ImgManip.py index 6898831ec..aeaf22de7 100644 --- a/src/ImgManip.py +++ b/src/ImgManip.py @@ -38,6 +38,13 @@ import tempfile # #------------------------------------------------------------------------- +#------------------------------------------------------------------------- +# +# Gramps modules +# +#------------------------------------------------------------------------- +import Utils + #------------------------------------------------------------------------- # # resize_to_jpeg @@ -111,6 +118,7 @@ def resize_to_jpeg_buffer(source, width, height): img = gtk.gdk.pixbuf_new_from_file(source) scaled = img.scale_simple(int(width), int(height), gtk.gdk.INTERP_BILINEAR) os.close(filed) + dest = Utils.get_unicode_path_from_env_var(dest) scaled.save(dest, 'jpeg') ofile = open(dest, mode='rb') data = ofile.read() diff --git a/src/TransUtils.py b/src/TransUtils.py index 0570fee92..6ad88562b 100644 --- a/src/TransUtils.py +++ b/src/TransUtils.py @@ -234,6 +234,11 @@ def get_addon_translator(filename=None, domain="addon", languages=None): gramps_translator = gettext.translation(LOCALEDOMAIN, LOCALEDIR, fallback=True) path = os.path.dirname(os.path.abspath(filename)) + # Check if path is of type str. Do import and conversion if so. + # The import cannot be done at the top as that will conflict with the translation system. + if type(path) == str: + from Utils import get_unicode_path_from_env_var + path = get_unicode_path_from_env_var(path) if languages: addon_translator = gettext.translation(domain, os.path.join(path,"locale"), languages=languages, diff --git a/src/Utils.py b/src/Utils.py index b6744544a..e2fa9f071 100644 --- a/src/Utils.py +++ b/src/Utils.py @@ -326,14 +326,14 @@ def find_folder( filename): # not found return '' -def get_unicode_path(path): +def get_unicode_path_from_file_chooser(path): """ Return the Unicode version of a path string. :type path: str :param path: The path to be converted to Unicode :rtype: unicode - :returns: The Unicode version of path. + :returns: The Unicode version of path. """ # Don't make unicode of unicode if isinstance(path, unicode): @@ -353,6 +353,33 @@ def get_unicode_path(path): LOG.warn("Problem encountered converting string: %s." % path) return unicode(path, sys.getfilesystemencoding(), errors='replace') +def get_unicode_path_from_env_var(path): + """ + Return the Unicode version of a path string. + + :type path: str + :param path: The path to be converted to Unicode + :rtype: unicode + :returns: The Unicode version of path. + """ + if isinstance(path, unicode): + return path + + if constfunc.win(): + # In Windows path/filename returned from a emvironment variable is in filesystemencoding + try: + new_path = unicode(path, sys.getfilesystemencoding()) + return new_path + except: + LOG.warn("Problem encountered converting string: %s." % path) + return unicode(path, sys.getfilesystemencoding(), errors='replace') + else: + try: + return unicode(path) + except: + LOG.warn("Problem encountered converting string: %s." % path) + return unicode(path, sys.getfilesystemencoding(), errors='replace') + #------------------------------------------------------------------------- @@ -962,6 +989,7 @@ def get_empty_tempdir(dirname): if os.path.isdir(dirpath): shutil.rmtree(dirpath) os.makedirs(dirpath) + dirpath = get_unicode_path_from_env_var(dirpath) return dirpath def rm_tempdir(path): diff --git a/src/cli/clidbman.py b/src/cli/clidbman.py index 32edf56ec..629ee31d7 100644 --- a/src/cli/clidbman.py +++ b/src/cli/clidbman.py @@ -167,6 +167,7 @@ class CLIDbManager(object): """ # make the default directory if it does not exist dbdir = os.path.expanduser(config.get('behavior.database-path')) + dbdir = dbdir.encode(sys.getfilesystemencoding()) make_dbdir(dbdir) self.current_names = [] @@ -354,6 +355,7 @@ def find_next_db_dir(): while True: base = "%x" % int(time.time()) dbdir = os.path.expanduser(config.get('behavior.database-path')) + dbdir = dbdir.encode(sys.getfilesystemencoding()) new_path = os.path.join(dbdir, base) if not os.path.isdir(new_path): break diff --git a/src/const.py.in b/src/const.py.in index 47434b7c9..62db53e5d 100644 --- a/src/const.py.in +++ b/src/const.py.in @@ -117,10 +117,7 @@ else: # Conversion of USER_HOME to unicode was needed to have better # support for non ASCII path names in Windows for the Gramps database. USER_HOME = unicode(USER_HOME, sys.getfilesystemencoding()) - -# Tried also coversion of HOME_DIR, but that caused a lot of problems -# in Windows. Leave it unconverted for now. -#HOME_DIR = unicode(HOME_DIR, sys.getfilesystemencoding()) +HOME_DIR = unicode(HOME_DIR, sys.getfilesystemencoding()) #------------------------------------------------------------------------- # diff --git a/src/gen/plug/_pluginreg.py b/src/gen/plug/_pluginreg.py index f0def694e..4941c5832 100644 --- a/src/gen/plug/_pluginreg.py +++ b/src/gen/plug/_pluginreg.py @@ -1052,8 +1052,6 @@ class PluginRegister(object): lenpd = len(self.__plugindata) full_filename = os.path.join(dir, filename) local_gettext = get_addon_translator(full_filename).gettext - if type(full_filename) == str: - full_filename = unicode(full_filename, sys.getfilesystemencoding()) try: #execfile(full_filename, execfile(full_filename.encode(sys.getfilesystemencoding()), diff --git a/src/gen/plug/utils.py b/src/gen/plug/utils.py index 21419b3d0..0bb034461 100644 --- a/src/gen/plug/utils.py +++ b/src/gen/plug/utils.py @@ -40,6 +40,7 @@ import os #------------------------------------------------------------------------- from gen.plug._pluginreg import make_environment import const +import Utils #------------------------------------------------------------------------- # @@ -278,7 +279,7 @@ def load_addon_file(path, callback=None): gpr_files = set([os.path.split(os.path.join(const.USER_PLUGINS, name))[0] for name in good_gpr]) for gpr_file in gpr_files: - u_gpr_file = unicode(gpr_file, sys.getfilesystemencoding()) + u_gpr_file = Utils.get_unicode_path_from_file_chooser(gpr_file) if callback: callback(" " + (_("Registered '%s'") % u_gpr_file) + "\n") file_obj.close() diff --git a/src/gui/configure.py b/src/gui/configure.py index 87fffa84a..aca534d54 100644 --- a/src/gui/configure.py +++ b/src/gui/configure.py @@ -1138,7 +1138,7 @@ class GrampsPreferences(ConfigureDialog): status = f.run() if status == gtk.RESPONSE_OK: - val = Utils.get_unicode_path(f.get_filename()) + val = Utils.get_unicode_path_from_file_chooser(f.get_filename()) if val: self.path_entry.set_text(val) f.destroy() diff --git a/src/gui/dbloader.py b/src/gui/dbloader.py index b79c20f46..24ebbdf68 100644 --- a/src/gui/dbloader.py +++ b/src/gui/dbloader.py @@ -86,7 +86,14 @@ class DbLoader(CLIDbLoader): return 1 def _dberrordialog(self, msg): - DBErrorDialog(str(msg.value)) + import traceback + exc = traceback.format_exc() + try: + DBErrorDialog(str(msg.value)) + _LOG.error(str(msg.value)) + except: + DBErrorDialog(str(msg)) + _LOG.error(str(msg) +"\n" + exc) def _begin_progress(self): self.uistate.set_busy_cursor(1) @@ -154,7 +161,7 @@ class DbLoader(CLIDbLoader): if response == gtk.RESPONSE_CANCEL: break elif response == gtk.RESPONSE_OK: - filename = Utils.get_unicode_path(import_dialog.get_filename()) + filename = Utils.get_unicode_path_from_file_chooser(import_dialog.get_filename()) if self.check_errors(filename): # displays errors if any continue @@ -312,8 +319,9 @@ class DbLoader(CLIDbLoader): except Errors.DbError, msg: self.dbstate.no_database() self._dberrordialog(msg) - except Exception: + except Exception as newerror: self.dbstate.no_database() + self._dberrordialog(str(newerror)) self._end_progress() return True diff --git a/src/gui/dbman.py b/src/gui/dbman.py index bc1ec6cbc..917ab93ed 100644 --- a/src/gui/dbman.py +++ b/src/gui/dbman.py @@ -77,6 +77,7 @@ import RecentFiles from glade import Glade from gen.db.backup import restore from gen.db.exceptions import DbException +from Utils import get_unicode_path_from_env_var _RETURN = gtk.gdk.keyval_from_name("Return") @@ -233,7 +234,7 @@ class DbManager(CLIDbManager): self.rcs.set_sensitive(False) if store.get_value(node, STOCK_COL) == gtk.STOCK_DIALOG_ERROR: - path = store.get_value(node, PATH_COL) + path = get_unicode_path_from_env_var(store.get_value(node, PATH_COL)) backup = os.path.join(path, "person.gbkp") self.repair.set_sensitive(os.path.isfile(backup)) else: @@ -346,8 +347,8 @@ class DbManager(CLIDbManager): self.top.destroy() del self.selection del self.name_renderer - return (store.get_value(node, PATH_COL), - store.get_value(node, NAME_COL)) + path = get_unicode_path_from_env_var(store.get_value(node, PATH_COL)) + return (path, store.get_value(node, NAME_COL)) else: self.top.destroy() del self.selection @@ -381,7 +382,7 @@ class DbManager(CLIDbManager): try: self.break_lock(self.lock_file) store, node = self.selection.get_selected() - dbpath = store.get_value(node, PATH_COL) + dbpath = get_unicode_path_from_env_var(store.get_value(node, PATH_COL)) (tval, last) = time_val(dbpath) store.set_value(node, OPEN_COL, 0) store.set_value(node, STOCK_COL, "") diff --git a/src/gui/editors/addmedia.py b/src/gui/editors/addmedia.py index 95f77ca70..92d9ddf34 100644 --- a/src/gui/editors/addmedia.py +++ b/src/gui/editors/addmedia.py @@ -149,7 +149,7 @@ class AddMediaObject(ManagedWindow.ManagedWindow): ErrorDialog(msgstr, msgstr2) return - filename = Utils.get_unicode_path(self.file_text.get_filename()) + filename = Utils.get_unicode_path_from_file_chooser(self.file_text.get_filename()) full_file = filename if self.relpath.get_active(): @@ -186,7 +186,7 @@ class AddMediaObject(ManagedWindow.ManagedWindow): fname = self.file_text.get_filename() if not fname: return - filename = Utils.get_unicode_path(fname) + filename = Utils.get_unicode_path_from_file_chooser(fname) basename = os.path.basename(filename) (root, ext) = os.path.splitext(basename) old_title = unicode(self.description.get_text()) diff --git a/src/gui/editors/editmedia.py b/src/gui/editors/editmedia.py index 1ffaa50e2..5667bb131 100644 --- a/src/gui/editors/editmedia.py +++ b/src/gui/editors/editmedia.py @@ -231,7 +231,7 @@ class EditMedia(EditPrimary): def select_file(self, val): self.determine_mime() path = self.file_path.get_text() - self.obj.set_path(Utils.get_unicode_path(path)) + self.obj.set_path(Utils.get_unicode_path_from_file_chooser(path)) AddMediaObject(self.dbstate, self.uistate, self.track, self.obj, self._update_addmedia) @@ -275,7 +275,7 @@ class EditMedia(EditPrimary): path = self.file_path.get_text() self.determine_mime() - self.obj.set_path(Utils.get_unicode_path(path)) + self.obj.set_path(Utils.get_unicode_path_from_file_chooser(path)) trans = self.db.transaction_begin() if not self.obj.get_handle(): diff --git a/src/gui/plug/_guioptions.py b/src/gui/plug/_guioptions.py index 9bc34d360..3f29e5021 100644 --- a/src/gui/plug/_guioptions.py +++ b/src/gui/plug/_guioptions.py @@ -1276,7 +1276,7 @@ class GuiDestinationOption(gtk.HBox): status = fcd.run() if status == gtk.RESPONSE_OK: - path = Utils.get_unicode_path(fcd.get_filename()) + path = Utils.get_unicode_path_from_file_chooser(fcd.get_filename()) if path: if not self.__option.get_directory_entry() and \ not path.endswith(self.__option.get_extension()): diff --git a/src/gui/plug/_windows.py b/src/gui/plug/_windows.py index 6158ca09e..8abc8306c 100644 --- a/src/gui/plug/_windows.py +++ b/src/gui/plug/_windows.py @@ -430,7 +430,7 @@ class PluginStatus(ManagedWindow.ManagedWindow): status = fcd.run() if status == gtk.RESPONSE_OK: - path = Utils.get_unicode_path(fcd.get_filename()) + path = Utils.get_unicode_path_from_file_chooser(fcd.get_filename()) if path: self.install_addon_path.set_text(path) fcd.destroy() diff --git a/src/gui/plug/report/_fileentry.py b/src/gui/plug/report/_fileentry.py index 80a8e99f0..0e045e1f1 100644 --- a/src/gui/plug/report/_fileentry.py +++ b/src/gui/plug/report/_fileentry.py @@ -74,7 +74,7 @@ class FileEntry(gtk.HBox): dialog.present() status = dialog.run() if status == gtk.RESPONSE_OK: - self.set_filename(Utils.get_unicode_path(dialog.get_filename())) + self.set_filename(Utils.get_unicode_path_from_file_chooser(dialog.get_filename())) dialog.destroy() def set_filename(self, path): diff --git a/src/gui/plug/report/_graphvizreportdialog.py b/src/gui/plug/report/_graphvizreportdialog.py index bb3424e18..ad39b4509 100644 --- a/src/gui/plug/report/_graphvizreportdialog.py +++ b/src/gui/plug/report/_graphvizreportdialog.py @@ -36,6 +36,7 @@ import time from types import ClassType, InstanceType from gen.ggettext import gettext as _ from subprocess import Popen, PIPE +import sys #------------------------------------------------------------------------------- # @@ -448,8 +449,10 @@ class GVPsDoc(GVDocBase): # but the output is clipped, some margins have disappeared. I used 1 inch margins always. # See bug tracker issue 2815 # :cairo does not work with Graphviz 2.26.3 See issue 4164 + # Covert filename to str using file system encoding. + fname = self._filename.encode(sys.getfilesystemencoding()) - command = 'dot -Tps:cairo -o"%s" "%s"' % (self._filename, tmp_dot) + command = 'dot -Tps:cairo -o"%s" "%s"' % (fname, tmp_dot) dotversion = Popen(['dot', '-V'], stderr=PIPE).communicate(input=None)[1] # Problem with dot 2.26.3 and multiple pages, which gives "cairo: out of memory" # If the :cairo is skipped for these cases it gives acceptable result. @@ -498,9 +501,11 @@ class GVSvgDoc(GVDocBase): dotfile = os.fdopen(handle,"w") dotfile.write(self._dot.getvalue()) dotfile.close() + # Covert filename to str using file system encoding. + fname = self._filename.encode(sys.getfilesystemencoding()) # Generate the SVG file. - os.system( 'dot -Tsvg -o"%s" "%s"' % (self._filename, tmp_dot) ) + os.system( 'dot -Tsvg -o"%s" "%s"' % (fname, tmp_dot) ) # Delete the temporary dot file os.remove(tmp_dot) @@ -544,9 +549,11 @@ class GVSvgzDoc(GVDocBase): dotfile = os.fdopen(handle,"w") dotfile.write(self._dot.getvalue()) dotfile.close() + # Covert filename to str using file system encoding. + fname = self._filename.encode(sys.getfilesystemencoding()) # Generate the SVGZ file. - os.system( 'dot -Tsvgz -o"%s" "%s"' % (self._filename, tmp_dot) ) + os.system( 'dot -Tsvgz -o"%s" "%s"' % (fname, tmp_dot) ) # Delete the temporary dot file os.remove(tmp_dot) @@ -590,9 +597,11 @@ class GVPngDoc(GVDocBase): dotfile = os.fdopen(handle,"w") dotfile.write(self._dot.getvalue()) dotfile.close() + # Covert filename to str using file system encoding. + fname = self._filename.encode(sys.getfilesystemencoding()) # Generate the PNG file. - os.system( 'dot -Tpng -o"%s" "%s"' % (self._filename, tmp_dot) ) + os.system( 'dot -Tpng -o"%s" "%s"' % (fname, tmp_dot) ) # Delete the temporary dot file os.remove(tmp_dot) @@ -636,9 +645,11 @@ class GVJpegDoc(GVDocBase): dotfile = os.fdopen(handle,"w") dotfile.write(self._dot.getvalue()) dotfile.close() + # Covert filename to str using file system encoding. + fname = self._filename.encode(sys.getfilesystemencoding()) # Generate the JPEG file. - os.system( 'dot -Tjpg -o"%s" "%s"' % (self._filename, tmp_dot) ) + os.system( 'dot -Tjpg -o"%s" "%s"' % (fname, tmp_dot) ) # Delete the temporary dot file os.remove(tmp_dot) @@ -682,9 +693,11 @@ class GVGifDoc(GVDocBase): dotfile = os.fdopen(handle,"w") dotfile.write(self._dot.getvalue()) dotfile.close() + # Covert filename to str using file system encoding. + fname = self._filename.encode(sys.getfilesystemencoding()) # Generate the GIF file. - os.system( 'dot -Tgif -o"%s" "%s"' % (self._filename, tmp_dot) ) + os.system( 'dot -Tgif -o"%s" "%s"' % (fname, tmp_dot) ) # Delete the temporary dot file os.remove(tmp_dot) @@ -731,9 +744,11 @@ class GVPdfGvDoc(GVDocBase): dotfile = os.fdopen(handle,"w") dotfile.write(self._dot.getvalue()) dotfile.close() + # Covert filename to str using file system encoding. + fname = self._filename.encode(sys.getfilesystemencoding()) # Generate the PDF file. - os.system( 'dot -Tpdf -o"%s" "%s"' % (self._filename, tmp_dot) ) + os.system( 'dot -Tpdf -o"%s" "%s"' % (fname, tmp_dot) ) # Delete the temporary dot file os.remove(tmp_dot) @@ -799,9 +814,10 @@ class GVPdfGsDoc(GVDocBase): height_pt = int( (paper_size.get_height_inches() * 72) + 0.5 ) # Convert to PDF using ghostscript + fname = self._filename.encode(sys.getfilesystemencoding()) command = '%s -q -sDEVICE=pdfwrite -dNOPAUSE -dDEVICEWIDTHPOINTS=%d' \ ' -dDEVICEHEIGHTPOINTS=%d -sOutputFile="%s" "%s" -c quit' \ - % ( _GS_CMD, width_pt, height_pt, self._filename, tmp_ps ) + % ( _GS_CMD, width_pt, height_pt, fname, tmp_ps ) os.system(command) os.remove(tmp_ps) diff --git a/src/gui/plug/report/_reportdialog.py b/src/gui/plug/report/_reportdialog.py index ed05d2e4a..b2982bcaf 100644 --- a/src/gui/plug/report/_reportdialog.py +++ b/src/gui/plug/report/_reportdialog.py @@ -58,7 +58,7 @@ from _stylecombobox import StyleComboBox from _styleeditor import StyleListDisplay from _fileentry import FileEntry from const import URL_MANUAL_PAGE - +import Utils #------------------------------------------------------------------------- # # Private Constants @@ -467,7 +467,7 @@ class ReportDialog(ManagedWindow.ManagedWindow): to tell the calling routine to give up. This function also saves the current directory so that any future reports will default to the most recently used directory.""" - self.target_path = self.target_fileentry.get_full_path(0) + self.target_path = Utils.get_unicode_path_from_file_chooser(self.target_fileentry.get_full_path(0)) if not self.target_path: return None diff --git a/src/gui/viewmanager.py b/src/gui/viewmanager.py index e9bdb26c3..b6bd5acf4 100644 --- a/src/gui/viewmanager.py +++ b/src/gui/viewmanager.py @@ -41,6 +41,7 @@ from gen.ggettext import gettext as _ from gen.ggettext import ngettext from cStringIO import StringIO from collections import defaultdict +import sys #------------------------------------------------------------------------- # @@ -1206,6 +1207,7 @@ class ViewManager(CLIManager): value = dialog.run() if value: (filename, title) = value + filename = filename.encode(sys.getfilesystemencoding()) self.db_loader.read_file(filename) self._post_load_newdb(filename, 'x-directory/normal', title) @@ -1393,6 +1395,7 @@ class ViewManager(CLIManager): basefile = file_entry.get_text() basefile = basefile.replace("/", r"-") filename = os.path.join(path_entry.get_text(), basefile) + filename = filename.encode(sys.getfilesystemencoding()) if include.get_active(): from ExportPkg import PackageWriter writer = PackageWriter(self.dbstate.db, filename, @@ -1408,6 +1411,7 @@ class ViewManager(CLIManager): writer.write(filename) self.uistate.set_busy_cursor(0) self.uistate.progress.hide() + filename = Utils.get_unicode_path_from_env_var(filename) self.uistate.push_message(self.dbstate, _("Backup saved to '%s'" % filename)) config.set('paths.quick-backup-directory', path_entry.get_text()) else: @@ -1444,7 +1448,7 @@ class ViewManager(CLIManager): if status == gtk.RESPONSE_OK: filename = f.get_filename() if filename: - val = Utils.get_unicode_path(filename) + val = Utils.get_unicode_path_from_file_chooser(filename) if val: path_entry.set_text(val) f.destroy() diff --git a/src/gui/views/listview.py b/src/gui/views/listview.py index 3318fc4ff..b9037250f 100644 --- a/src/gui/views/listview.py +++ b/src/gui/views/listview.py @@ -945,6 +945,7 @@ class ListView(NavigationView): while True: value = chooser.run() fn = chooser.get_filename() + fn = Utils.get_unicode_path_from_file_chooser(fn) fl = combobox.get_active() if value == gtk.RESPONSE_OK: if fn: diff --git a/src/plugins/docgen/PdfDoc.py b/src/plugins/docgen/PdfDoc.py index e656f4eb7..7e63d4801 100644 --- a/src/plugins/docgen/PdfDoc.py +++ b/src/plugins/docgen/PdfDoc.py @@ -30,6 +30,7 @@ # #------------------------------------------------------------------------ from gen.ggettext import gettext as _ +import sys #------------------------------------------------------------------------ # @@ -85,7 +86,8 @@ class PdfDoc(libcairodoc.CairoDoc): top_margin = self.paper.get_top_margin() * DPI / 2.54 # create cairo context and pango layout - surface = cairo.PDFSurface(self._backend.filename, paper_width, paper_height) + filename = self._backend.filename.encode(sys.getfilesystemencoding()) + surface = cairo.PDFSurface(filename, paper_width, paper_height) surface.set_fallback_resolution(300, 300) cr = pangocairo.CairoContext(cairo.Context(surface)) diff --git a/src/plugins/export/ExportPkg.py b/src/plugins/export/ExportPkg.py index be5c46a7a..535a14834 100644 --- a/src/plugins/export/ExportPkg.py +++ b/src/plugins/export/ExportPkg.py @@ -159,8 +159,7 @@ class PackageWriter(object): pass def fs_ok_clicked(obj): - name = unicode(fs_top.get_filename(), - sys.getfilesystemencoding()) + name = Utils.get_unicode_path_from_file_chooser(fs_top.get_filename()) if os.path.isfile(name): archive.add(name) diff --git a/src/plugins/tool/Check.py b/src/plugins/tool/Check.py index fbba915f6..a8a15e716 100644 --- a/src/plugins/tool/Check.py +++ b/src/plugins/tool/Check.py @@ -526,7 +526,7 @@ class CheckIntegrity(object): self.bad_photo.append(ObjectId) def fs_ok_clicked(obj): - name = Utils.get_unicode_path(fs_top.get_filename()) + name = Utils.get_unicode_path_from_file_chooser(fs_top.get_filename()) if os.path.isfile(name): obj = self.db.get_object_from_handle(ObjectId) obj.set_path(name) diff --git a/src/plugins/tool/EventCmp.py b/src/plugins/tool/EventCmp.py index 3bd74c349..4e3cb89f3 100644 --- a/src/plugins/tool/EventCmp.py +++ b/src/plugins/tool/EventCmp.py @@ -396,7 +396,7 @@ class DisplayChart(ManagedWindow.ManagedWindow): f.hide() if status == gtk.RESPONSE_OK: - name = Utils.get_unicode_path(f.get_filename()) + name = Utils.get_unicode_path_from_file_chooser(f.get_filename()) doc = ODSTab(len(self.row_data)) doc.creator(self.db.get_researcher().get_name()) diff --git a/src/plugins/view/geoview.py b/src/plugins/view/geoview.py index 2ce91ae86..b47a44195 100644 --- a/src/plugins/view/geoview.py +++ b/src/plugins/view/geoview.py @@ -118,7 +118,7 @@ from htmlrenderer import HtmlView # #------------------------------------------------------------------------- #covert to unicode for better hadnling of path in Windows -GEOVIEW_SUBPATH = Utils.get_unicode_path(Utils.get_empty_tempdir('geoview')) +GEOVIEW_SUBPATH = Utils.get_empty_tempdir('geoview') DISABLED = -1 MRU_SIZE = 10 diff --git a/src/plugins/view/pedigreeview.py b/src/plugins/view/pedigreeview.py index 2c352dd81..5ed5d4077 100644 --- a/src/plugins/view/pedigreeview.py +++ b/src/plugins/view/pedigreeview.py @@ -33,6 +33,7 @@ from gen.ggettext import sgettext as _ from gen.ggettext import ngettext from cgi import escape import math +import sys #------------------------------------------------------------------------- # @@ -200,6 +201,8 @@ class PersonBoxWidgetCairo(_PersonWidgetBase): self.img_surf = None if image: image_path = self.get_image(dbstate, person) + if isinstance(image_path, unicode): + image_path = image_path.encode(sys.getfilesystemencoding()) if image_path: self.img_surf = cairo.ImageSurface.create_from_png(image_path)