From 55610b6f0a63bcdbe50b38a0d2ae7da299290cba Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sun, 20 Apr 2014 16:35:22 -0700 Subject: [PATCH] Remove get_unicode_path_from_env_var(), get_unicode_path_from_file_chooser() Two very cumbersome ways of saying conv_to_unicode(). --- gramps/cli/arghandler.py | 12 +++++------- gramps/cli/argparser.py | 10 ++++++---- gramps/gen/plug/utils.py | 4 ++-- gramps/gen/utils/file.py | 22 ---------------------- gramps/gen/utils/image.py | 4 ++-- gramps/gui/configure.py | 16 +++++++--------- gramps/gui/dbloader.py | 7 +++---- gramps/gui/dbman.py | 1 - gramps/gui/editors/addmedia.py | 10 +++++----- gramps/gui/editors/editmedia.py | 5 ++--- gramps/gui/editors/editmediaref.py | 6 +++--- gramps/gui/plug/_guioptions.py | 5 ++--- gramps/gui/plug/_windows.py | 5 ++--- gramps/gui/plug/export/_exportassistant.py | 17 ++++++++--------- gramps/gui/plug/report/_fileentry.py | 7 ++++--- gramps/gui/plug/report/_reportdialog.py | 7 +++---- gramps/gui/viewmanager.py | 17 +++++++---------- gramps/gui/views/listview.py | 5 ++--- gramps/plugins/export/exportpkg.py | 6 +++--- gramps/plugins/tool/check.py | 5 ++--- gramps/plugins/tool/eventcmp.py | 3 +-- 21 files changed, 69 insertions(+), 105 deletions(-) diff --git a/gramps/cli/arghandler.py b/gramps/cli/arghandler.py index f6409e84d..862bd3c34 100644 --- a/gramps/cli/arghandler.py +++ b/gramps/cli/arghandler.py @@ -44,8 +44,7 @@ import sys # #------------------------------------------------------------------------- from gramps.gen.recentfiles import recent_files -from gramps.gen.utils.file import (rm_tempdir, get_empty_tempdir, - get_unicode_path_from_env_var) +from gramps.gen.utils.file import rm_tempdir, get_empty_tempdir from gramps.gen.db import DbBsddb from .clidbman import CLIDbManager, NAME_FILE, find_locker_name @@ -54,6 +53,7 @@ from gramps.gen.plug.report import CATEGORY_BOOK, CATEGORY_CODE, BookList from .plug import cl_report, cl_book from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext +from gramps.gen.constfunc import conv_to_unicode #------------------------------------------------------------------------- # @@ -214,7 +214,7 @@ class ArgHandler(object): """ if value is None: return None - value = get_unicode_path_from_env_var(value) + value = conv_to_unicode(value, sys.stdin.encoding) db_path = self.__deduce_db_path(value) if db_path: @@ -244,8 +244,7 @@ class ArgHandler(object): """ # Need to convert path/filename to unicode before opening # For non latin characters in Windows path/file/user names - value = get_unicode_path_from_env_var(value) - fname = value + fname = conv_to_unicode(value, sys.stdin.encoding) fullpath = os.path.abspath(os.path.expanduser(fname)) if fname != '-' and not os.path.exists(fullpath): self.__error(_('Error: Import file %s not found.') % fname) @@ -282,8 +281,7 @@ class ArgHandler(object): return # Need to convert path/filename to unicode before opening # For non latin characters in Windows path/file/user names - value = get_unicode_path_from_env_var(value) - fname = value + fname = conv_to_unicode(value, sys.stdin.encoding) if fname == '-': fullpath = '-' else: diff --git a/gramps/cli/argparser.py b/gramps/cli/argparser.py index 0fbfce4c3..1fce653a0 100644 --- a/gramps/cli/argparser.py +++ b/gramps/cli/argparser.py @@ -34,7 +34,7 @@ Module responsible for handling the command line arguments for Gramps. # Standard python modules # #------------------------------------------------------------------------- -from __future__ import print_function +from __future__ import print_function, unicode_literals import sys import getopt import logging @@ -47,9 +47,9 @@ import logging from gramps.gen.const import LONGOPTS, SHORTOPTS from gramps.gen.config import config from gramps.gen.utils.cast import get_type_converter -from gramps.gen.utils.file import get_unicode_path_from_env_var from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext +from gramps.gen.constfunc import conv_to_unicode _HELP = _(""" Usage: gramps.py [OPTION...] @@ -227,7 +227,8 @@ class ArgParser(object): # -Ärik is '-\xc3\x84rik' and getopt will respond : # option -\xc3 not recognized for arg in range(len(self.args) - 1): - self.args[arg+1] = get_unicode_path_from_env_var(self.args[arg + 1]) + self.args[arg+1] = conv_to_unicode(self.args[arg + 1], + sys.stdin.encoding) options, leftargs = getopt.getopt(self.args[1:], SHORTOPTS, LONGOPTS) except getopt.GetoptError as msg: @@ -377,7 +378,8 @@ class ArgParser(object): # but not for non-latin characters in list elements cliargs = "[ " for arg in range(len(self.args) - 1): - cliargs += get_unicode_path_from_env_var(self.args[arg + 1]) + " " + cliargs += conv_to_unicode(self.args[arg + 1], + sys.stdin.encoding) + ' ' cliargs += "]" self.errors += [(_('Error parsing the arguments'), _("Error parsing the arguments: %s \n" diff --git a/gramps/gen/plug/utils.py b/gramps/gen/plug/utils.py index 9e260f67d..94ef348e8 100644 --- a/gramps/gen/plug/utils.py +++ b/gramps/gen/plug/utils.py @@ -52,11 +52,11 @@ from ._pluginreg import make_environment from ..const import USER_PLUGINS from ...version import VERSION_TUPLE from . import BasePluginManager -from ..utils.file import get_unicode_path_from_file_chooser from ..utils.configmanager import safe_eval from ..config import config from ..const import GRAMPS_LOCALE as glocale _ = glocale.translation.sgettext +from ..constfunc import conv_to_unicode #------------------------------------------------------------------------- # @@ -367,7 +367,7 @@ def load_addon_file(path, callback=None): gpr_files = set([os.path.split(os.path.join(USER_PLUGINS, name))[0] for name in good_gpr]) for gpr_file in gpr_files: - u_gpr_file = get_unicode_path_from_file_chooser(gpr_file) + u_gpr_file = conv_to_unicode(gpr_file) if callback: callback(" " + (_("Registered '%s'") % u_gpr_file) + "\n") file_obj.close() diff --git a/gramps/gen/utils/file.py b/gramps/gen/utils/file.py index 5eb438bd4..36114d397 100644 --- a/gramps/gen/utils/file.py +++ b/gramps/gen/utils/file.py @@ -60,7 +60,6 @@ _NEW_NAME_PATTERN = '%s%sUntitled_%d.%s' def find_file( filename): # try the filename we got try: - fname = filename if os.path.isfile(filename): return(filename) except UnicodeError: @@ -72,7 +71,6 @@ def find_file( filename): def find_folder( filename): # try the filename we got try: - fname = filename if os.path.isdir(filename): return(filename) except UnicodeError: @@ -82,26 +80,6 @@ def find_folder( filename): repr(filename)) return '' -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. - """ - # make only unicode of path of type 'str' - return conv_to_unicode(path) - - -def get_unicode_path_from_env_var(path): - ''' - Environment variables should always return unicodes. - ''' - assert isinstance(path, UNITYPE) - return path - def get_new_filename(ext, folder='~/'): ix = 1 while os.path.isfile(os.path.expanduser(_NEW_NAME_PATTERN % diff --git a/gramps/gen/utils/image.py b/gramps/gen/utils/image.py index f38c3cf91..eec5abfd8 100644 --- a/gramps/gen/utils/image.py +++ b/gramps/gen/utils/image.py @@ -43,7 +43,7 @@ import tempfile # Gramps modules # #------------------------------------------------------------------------- -from .file import get_unicode_path_from_env_var +from ..constfunc import conv_to_unicode def crop_percentage_to_subpixel(width, height, crop): """ @@ -281,7 +281,7 @@ def resize_to_jpeg_buffer(source, size, crop=None): scaled = img.scale_simple(int(size[0]), int(size[1]), GdkPixbuf.InterpType.BILINEAR) os.close(filed) - dest = get_unicode_path_from_env_var(dest) + dest = conv_to_unicode(dest, None) scaled.savev(dest, "jpeg", "", "") ofile = open(dest, mode='rb') data = ofile.read() diff --git a/gramps/gui/configure.py b/gramps/gui/configure.py index d609be503..af6d32296 100644 --- a/gramps/gui/configure.py +++ b/gramps/gui/configure.py @@ -30,8 +30,6 @@ from __future__ import print_function import random -from gramps.gen.const import GRAMPS_LOCALE as glocale -_ = glocale.translation.gettext import os from xml.sax.saxutils import escape import collections @@ -51,17 +49,16 @@ from gi.repository import Gtk # #------------------------------------------------------------------------- from gramps.gen.config import config -from gramps.gen.const import HOME_DIR +from gramps.gen.const import HOME_DIR, GRAMPS_LOCALE as glocale from gramps.gen.datehandler import get_date_formats from gramps.gen.display.name import displayer as _nd from gramps.gen.display.name import NameDisplayError -from gramps.gen.utils.file import get_unicode_path_from_file_chooser from gramps.gen.utils.alive import update_constants from gramps.gen.utils.keyword import (get_keywords, get_translation_from_keyword, get_translations, get_keyword_from_translation) from gramps.gen.lib import Date, FamilyRelType from gramps.gen.lib import Name, Surname, NameOriginType -from gramps.gen.constfunc import cuni +from gramps.gen.constfunc import conv_to_unicode from .managedwindow import ManagedWindow from .widgets import MarkupLabel, BasicLabel from .dialog import ErrorDialog, QuestionDialog2, OkDialog @@ -70,6 +67,7 @@ from gramps.gen.plug.utils import available_updates from .plug import PluginWindows from gramps.gen.errors import WindowActiveError from .spell import HAVE_GTKSPELL +_ = glocale.translation.gettext #------------------------------------------------------------------------- # @@ -249,7 +247,7 @@ class ConfigureDialog(ManagedWindow): :param constant: the config setting to which the text value must be saved """ - self.__config.set(constant, cuni(obj.get_text())) + self.__config.set(constant, conv_to_unicode(obj.get_text())) def update_color(self, obj, constant, color_hex_label): color = obj.get_color() @@ -1386,7 +1384,7 @@ class GrampsPreferences(ConfigureDialog): status = f.run() if status == Gtk.ResponseType.OK: - val = get_unicode_path_from_file_chooser(f.get_filename()) + val = conv_to_unicode(f.get_filename()) if val: self.path_entry.set_text(val) f.destroy() @@ -1410,13 +1408,13 @@ class GrampsPreferences(ConfigureDialog): status = f.run() if status == Gtk.ResponseType.OK: - val = get_unicode_path_from_file_chooser(f.get_filename()) + val = conv_to_unicode(f.get_filename()) if val: self.dbpath_entry.set_text(val) f.destroy() def update_idformat_entry(self, obj, constant): - config.set(constant, cuni(obj.get_text())) + config.set(constant, conv_to_unicode(obj.get_text())) self.dbstate.db.set_prefixes( config.get('preferences.iprefix'), config.get('preferences.oprefix'), diff --git a/gramps/gui/dbloader.py b/gramps/gui/dbloader.py index c81a66b00..71f8d6a5f 100644 --- a/gramps/gui/dbloader.py +++ b/gramps/gui/dbloader.py @@ -64,8 +64,7 @@ from gramps.gen.db.exceptions import (DbUpgradeRequiredError, BsddbDowngradeRequiredError, PythonUpgradeRequiredError, PythonDowngradeError) -from gramps.gen.constfunc import STRTYPE -from gramps.gen.utils.file import get_unicode_path_from_file_chooser +from gramps.gen.constfunc import STRTYPE, UNITYPE, conv_to_unicode from .pluginmanager import GuiPluginManager from .dialog import (DBErrorDialog, ErrorDialog, QuestionDialog2, WarningDialog) @@ -172,7 +171,7 @@ class DbLoader(CLIDbLoader): if response == Gtk.ResponseType.CANCEL: break elif response == Gtk.ResponseType.OK: - filename = get_unicode_path_from_file_chooser(import_dialog.get_filename()) + filename = conv_to_unicode(import_dialog.get_filename()) if self.check_errors(filename): # displays errors if any continue @@ -211,7 +210,7 @@ class DbLoader(CLIDbLoader): In this process, a warning dialog can pop up. """ - if not isinstance(filename, STRTYPE): + if not isinstance(filename, (STRTYPE, UNITYPE)): return True filename = os.path.normpath(os.path.abspath(filename)) diff --git a/gramps/gui/dbman.py b/gramps/gui/dbman.py index 3f58490a6..b3e1d31e5 100644 --- a/gramps/gui/dbman.py +++ b/gramps/gui/dbman.py @@ -84,7 +84,6 @@ from gramps.gen.recentfiles import rename_filename, remove_filename from .glade import Glade from gramps.gen.db.backup import restore from gramps.gen.db.exceptions import DbException -from gramps.gen.utils.file import get_unicode_path_from_env_var _RETURN = Gdk.keyval_from_name("Return") diff --git a/gramps/gui/editors/addmedia.py b/gramps/gui/editors/addmedia.py index 84ff8e10c..6dd68acd1 100644 --- a/gramps/gui/editors/addmedia.py +++ b/gramps/gui/editors/addmedia.py @@ -36,7 +36,7 @@ import os #------------------------------------------------------------------------- from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext -from gramps.gen.constfunc import cuni +from gramps.gen.constfunc import cuni, conv_to_unicode #------------------------------------------------------------------------- # @@ -52,8 +52,8 @@ from gi.repository import GdkPixbuf #------------------------------------------------------------------------- from gramps.gen.const import ICON, THUMBSCALE, USER_HOME from gramps.gen.config import config -from gramps.gen.utils.file import (media_path_full, media_path, relative_path, - find_file, get_unicode_path_from_file_chooser) +from gramps.gen.utils.file import (media_path_full, media_path, relative_path, + find_file) from gramps.gen.mime import get_type from ..thumbnails import find_mime_type_pixbuf from ..display import display_help @@ -150,7 +150,7 @@ class AddMediaObject(ManagedWindow): ErrorDialog(msgstr, msgstr2) return - filename = get_unicode_path_from_file_chooser(self.file_text.get_filename()) + filename = conv_to_unicode(self.file_text.get_filename()) full_file = filename if self.relpath.get_active(): @@ -187,7 +187,7 @@ class AddMediaObject(ManagedWindow): fname = self.file_text.get_filename() if not fname: return - filename = get_unicode_path_from_file_chooser(fname) + filename = conv_to_unicode(fname) basename = os.path.basename(filename) (root, ext) = os.path.splitext(basename) old_title = cuni(self.description.get_text()) diff --git a/gramps/gui/editors/editmedia.py b/gramps/gui/editors/editmedia.py index 341c4c67f..2a7d06d0b 100644 --- a/gramps/gui/editors/editmedia.py +++ b/gramps/gui/editors/editmedia.py @@ -48,8 +48,7 @@ from gramps.gen.lib import MediaObject, NoteType from gramps.gen.db import DbTxn from gramps.gen.mime import get_description, get_type from ..thumbnails import get_thumbnail_image, find_mime_type_pixbuf -from gramps.gen.utils.file import (media_path_full, find_file, create_checksum, - get_unicode_path_from_file_chooser) +from gramps.gen.utils.file import (media_path_full, find_file, create_checksum) from .editprimary import EditPrimary from ..widgets import (MonitoredDate, MonitoredEntry, PrivacyButton, MonitoredTagList) @@ -312,7 +311,7 @@ class EditMedia(EditPrimary): self.ok_button.set_sensitive(True) return - self.obj.set_path(get_unicode_path_from_file_chooser(path)) + self.obj.set_path(conv_to_unicode(path)) with DbTxn('', self.db) as trans: if not self.obj.get_handle(): diff --git a/gramps/gui/editors/editmediaref.py b/gramps/gui/editors/editmediaref.py index d83cc643b..11f9dd01d 100644 --- a/gramps/gui/editors/editmediaref.py +++ b/gramps/gui/editors/editmediaref.py @@ -45,12 +45,12 @@ from gi.repository import Gdk #------------------------------------------------------------------------- from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.translation.sgettext +from gramps.gen.constfunc import conv_to_unicode from ..utils import open_file_with_default_application from gramps.gen.const import THUMBSCALE from gramps.gen.mime import get_description, get_type from ..thumbnails import get_thumbnail_image, find_mime_type_pixbuf -from gramps.gen.utils.file import (media_path_full, find_file, create_checksum, - get_unicode_path_from_file_chooser) +from gramps.gen.utils.file import (media_path_full, find_file, create_checksum) from gramps.gen.lib import NoteType from gramps.gen.db import DbTxn from ..glade import Glade @@ -425,7 +425,7 @@ class EditMediaRef(EditReference): def select_file(self, val): self.determine_mime() path = self.file_path.get_text() - self.source.set_path(get_unicode_path_from_file_chooser(path)) + self.source.set_path(conv_to_unicode(path)) AddMediaObject(self.dbstate, self.uistate, self.track, self.source, self._update_addmedia) diff --git a/gramps/gui/plug/_guioptions.py b/gramps/gui/plug/_guioptions.py index b06b3be5f..613c064cc 100644 --- a/gramps/gui/plug/_guioptions.py +++ b/gramps/gui/plug/_guioptions.py @@ -51,7 +51,6 @@ from gi.repository import GObject # gramps modules # #------------------------------------------------------------------------- -from gramps.gen.utils.file import get_unicode_path_from_file_chooser from ..utils import ProgressMeter from ..pluginmanager import GuiPluginManager from .. import widgets @@ -1701,12 +1700,12 @@ class GuiDestinationOption(Gtk.HBox): status = fcd.run() if status == Gtk.ResponseType.OK: - path = get_unicode_path_from_file_chooser(fcd.get_filename()) + path = conv_to_unicode(fcd.get_filename()) if path: if not self.__option.get_directory_entry() and \ not path.endswith(self.__option.get_extension()): path = path + self.__option.get_extension() - self.__entry.set_text(path) + self.__entry.set_text(uni_to_gui(path)) self.__option.set_value(path) fcd.destroy() diff --git a/gramps/gui/plug/_windows.py b/gramps/gui/plug/_windows.py index f25042a30..e90c3ba0b 100644 --- a/gramps/gui/plug/_windows.py +++ b/gramps/gui/plug/_windows.py @@ -69,9 +69,8 @@ from ..dialog import InfoDialog, OkDialog from ..editors import EditPerson from ..glade import Glade from ..listmodel import ListModel, NOSORT, TOGGLE -from gramps.gen.utils.file import get_unicode_path_from_file_chooser from gramps.gen.const import URL_WIKISTRING, USER_HOME, WIKI_EXTRAPLUGINS_RAWDATA -from gramps.gen.constfunc import win +from gramps.gen.constfunc import win, conv_to_unicode from gramps.gen.config import config from ..widgets.progressdialog import (LongOpStatus, ProgressMonitor, GtkProgressDialog) @@ -450,7 +449,7 @@ class PluginStatus(ManagedWindow): status = fcd.run() if status == Gtk.ResponseType.OK: - path = get_unicode_path_from_file_chooser(fcd.get_filename()) + path = conv_to_unicode(fcd.get_filename()) if path: self.install_addon_path.set_text(path) fcd.destroy() diff --git a/gramps/gui/plug/export/_exportassistant.py b/gramps/gui/plug/export/_exportassistant.py index 6d49a0a32..e1f89da93 100644 --- a/gramps/gui/plug/export/_exportassistant.py +++ b/gramps/gui/plug/export/_exportassistant.py @@ -31,8 +31,6 @@ #------------------------------------------------------------------------- import os import sys -from gramps.gen.const import GRAMPS_LOCALE as glocale -_ = glocale.translation.gettext #------------------------------------------------------------------------- # @@ -57,11 +55,12 @@ from gi.repository import GdkPixbuf # #------------------------------------------------------------------------- -from gramps.gen.const import USER_HOME, ICON, SPLASH +from gramps.gen.const import USER_HOME, ICON, SPLASH, GRAMPS_LOCALE as glocale +_ = glocale.translation.gettext +from gramps.gen.constfunc import conv_to_unicode from gramps.gen.config import config from ...pluginmanager import GuiPluginManager -from gramps.gen.utils.file import (find_folder, get_new_filename, - get_unicode_path_from_file_chooser) +from gramps.gen.utils.file import (find_folder, get_new_filename) from ...managedwindow import ManagedWindow from ...dialog import ErrorDialog from ...user import User @@ -313,11 +312,11 @@ class ExportAssistant(Gtk.Assistant, ManagedWindow) : Used as normal callback and event callback. For callback, we will have show=True """ - filename = filechooser.get_filename() + filename = conv_to_unicode(filechooser.get_filename()) if not filename: self.set_page_complete(filechooser, False) else: - folder = filechooser.get_current_folder() + folder = conv_to_unicode(filechooser.get_current_folder()) if not folder: folder = find_folder(filename) else: @@ -451,7 +450,7 @@ class ExportAssistant(Gtk.Assistant, 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 = get_unicode_path_from_file_chooser(self.chooser.get_filename()) + filename = conv_to_unicode(self.chooser.get_filename()) name = os.path.split(filename)[1] folder = os.path.split(filename)[0] confirm_text = _( @@ -584,7 +583,7 @@ class ExportAssistant(Gtk.Assistant, ManagedWindow) : hasattr(self.option_box_instance, "no_fileselect")): filename = "" else: - filename = get_unicode_path_from_file_chooser(self.chooser.get_filename()) + filename = conv_to_unicode(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/gramps/gui/plug/report/_fileentry.py b/gramps/gui/plug/report/_fileentry.py index 16ecdcba2..c8d501c75 100644 --- a/gramps/gui/plug/report/_fileentry.py +++ b/gramps/gui/plug/report/_fileentry.py @@ -60,7 +60,7 @@ class FileEntry(Gtk.HBox): Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) - name = os.path.basename(self.entry.get_text()) + name = os.path.basename(conv_to_unicode(self.entry.get_text())) if self.dir: if os.path.isdir(name): dialog.set_current_name(name) @@ -72,7 +72,7 @@ class FileEntry(Gtk.HBox): dialog.present() status = dialog.run() if status == Gtk.ResponseType.OK: - self.set_filename(get_unicode_path_from_file_chooser(dialog.get_filename())) + self.set_filename(conv_to_unicode(dialog.get_filename())) dialog.destroy() def set_filename(self, path): @@ -85,7 +85,8 @@ class FileEntry(Gtk.HBox): else: self.__base_path = get_curr_dir() self.__file_name = path - self.entry.set_text(os.path.join(self.__base_path, self.__file_name)) + self.entry.set_text(uni_to_gui(os.path.join(self.__base_path, + self.__file_name))) def get_full_path(self, val): """ Get the full path of the currently selected file. """ diff --git a/gramps/gui/plug/report/_reportdialog.py b/gramps/gui/plug/report/_reportdialog.py index 5fd5342dc..b331f2736 100644 --- a/gramps/gui/plug/report/_reportdialog.py +++ b/gramps/gui/plug/report/_reportdialog.py @@ -45,7 +45,7 @@ from gi.repository import Gtk # GRAMPS modules # #------------------------------------------------------------------------- -from gramps.gen.const import GRAMPS_LOCALE as glocale +from gramps.gen.const import GRAMPS_LOCALE as glocale, URL_MANUAL_PAGE _ = glocale.translation.gettext from gramps.gen.config import config from gramps.gen.errors import DatabaseError, FilterError, ReportError, WindowActiveError @@ -61,8 +61,7 @@ from ...managedwindow import ManagedWindow from ._stylecombobox import StyleComboBox from ._styleeditor import StyleListDisplay from ._fileentry import FileEntry -from gramps.gen.const import URL_MANUAL_PAGE -from gramps.gen.utils.file import get_unicode_path_from_file_chooser +from gramps.gen.constfunc import conv_to_unicode #------------------------------------------------------------------------- # # Private Constants @@ -492,7 +491,7 @@ class ReportDialog(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 = get_unicode_path_from_file_chooser(self.target_fileentry.get_full_path(0)) + self.target_path = conv_to_unicode(self.target_fileentry.get_full_path(0)) if not self.target_path: return None diff --git a/gramps/gui/viewmanager.py b/gramps/gui/viewmanager.py index ea079a341..ee12601f5 100644 --- a/gramps/gui/viewmanager.py +++ b/gramps/gui/viewmanager.py @@ -89,8 +89,7 @@ from gramps.gen.errors import WindowActiveError from .dialog import ErrorDialog, WarningDialog, QuestionDialog2, InfoDialog from .widgets import Statusbar from .undohistory import UndoHistory -from gramps.gen.utils.file import (media_path_full, get_unicode_path_from_env_var, - get_unicode_path_from_file_chooser) +from gramps.gen.utils.file import media_path_full from .dbloader import DbLoader from .display import display_help, display_url from .configure import GrampsPreferences @@ -1103,7 +1102,7 @@ class ViewManager(CLIManager): value = dialog.run() if value: (filename, title) = value - filename = conv_to_unicode(filename, 'utf8') + filename = conv_to_unicode(filename) self.db_loader.read_file(filename) self._post_load_newdb(filename, 'x-directory/normal', title) @@ -1302,9 +1301,10 @@ class ViewManager(CLIManager): window.hide() if d == Gtk.ResponseType.APPLY: # if file exists, ask if overwrite; else abort - basefile = file_entry.get_text() + basefile = conv_to_unicode(file_entry.get_text()) basefile = basefile.replace("/", r"-") - filename = os.path.join(path_entry.get_text(), basefile) + filename = os.path.join(conv_to_unicode(path_entry.get_text()), + basefile) if os.path.exists(filename): question = QuestionDialog2( _("Backup file already exists! Overwrite?"), @@ -1329,7 +1329,6 @@ class ViewManager(CLIManager): writer.write(filename) self.uistate.set_busy_cursor(False) self.uistate.progress.hide() - filename = 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: @@ -1352,14 +1351,12 @@ class ViewManager(CLIManager): if not mpath: mpath = HOME_DIR f.set_current_folder(os.path.dirname(mpath)) - f.set_filename(os.path.join(mpath, ".")) + f.set_filename(uni_to_gui(os.path.join(mpath, "."))) status = f.run() if status == Gtk.ResponseType.OK: filename = f.get_filename() if filename: - val = get_unicode_path_from_file_chooser(filename) - if val: - path_entry.set_text(val) + path_entry.set_text(val) f.destroy() return True diff --git a/gramps/gui/views/listview.py b/gramps/gui/views/listview.py index de6a228bb..831f3d4e2 100644 --- a/gramps/gui/views/listview.py +++ b/gramps/gui/views/listview.py @@ -60,11 +60,10 @@ from gramps.gen.config import config from gramps.gen.errors import WindowActiveError from ..filters import SearchBar from ..widgets.menuitem import add_menuitem -from gramps.gen.constfunc import UNITYPE +from gramps.gen.constfunc import UNITYPE, conv_to_unicode from gramps.gen.const import CUSTOM_FILTERS from gramps.gen.utils.debug import profile from gramps.gen.utils.string import data_recover_msg -from gramps.gen.utils.file import get_unicode_path_from_file_chooser from ..dialog import QuestionDialog, QuestionDialog2 from ..editors import FilterEditor from gramps.gen.const import GRAMPS_LOCALE as glocale @@ -1016,7 +1015,7 @@ class ListView(NavigationView): while True: value = chooser.run() fn = chooser.get_filename() - fn = get_unicode_path_from_file_chooser(fn) + fn = conv_to_unicode(fn) fl = combobox.get_active() if value == Gtk.ResponseType.OK: if fn: diff --git a/gramps/plugins/export/exportpkg.py b/gramps/plugins/export/exportpkg.py index 21c1ae500..593ed43cc 100644 --- a/gramps/plugins/export/exportpkg.py +++ b/gramps/plugins/export/exportpkg.py @@ -63,8 +63,8 @@ from gi.repository import Gtk #------------------------------------------------------------------------- from gramps.gui.plug.export import WriterOptionBox from gramps.plugins.export.exportxml import XmlWriter -from gramps.gen.utils.file import media_path_full, get_unicode_path_from_file_chooser -from gramps.gen.constfunc import win +from gramps.gen.utils.file import media_path_full +from gramps.gen.constfunc import win, conv_to_unicode #------------------------------------------------------------------------- # @@ -159,7 +159,7 @@ class PackageWriter(object): # pass # def fs_ok_clicked(obj): - # name = get_unicode_path_from_file_chooser(fs_top.get_filename()) + # name = conv_to_unicode(fs_top.get_filename()) # if os.path.isfile(name): # archive.add(name) diff --git a/gramps/plugins/tool/check.py b/gramps/plugins/tool/check.py index c27fe7a83..ab251c8a1 100644 --- a/gramps/plugins/tool/check.py +++ b/gramps/plugins/tool/check.py @@ -69,8 +69,7 @@ from gramps.gen.config import config from gramps.gen.utils.id import create_id from gramps.gen.utils.db import family_name from gramps.gen.utils.unknown import make_unknown -from gramps.gen.utils.file import (media_path_full, find_file, fix_encoding, - get_unicode_path_from_file_chooser) +from gramps.gen.utils.file import (media_path_full, find_file, fix_encoding) from gramps.gui.managedwindow import ManagedWindow from gramps.gen.utils.file import create_checksum from gramps.gui.plug import tool @@ -673,7 +672,7 @@ class CheckIntegrity(object): logging.warning(' FAIL: references to missing file kept') def fs_ok_clicked(obj): - name = get_unicode_path_from_file_chooser(fs_top.get_filename()) + name = conv_to_unicode(fs_top.get_filename()) if os.path.isfile(name): obj = self.db.get_object_from_handle(ObjectId) obj.set_path(name) diff --git a/gramps/plugins/tool/eventcmp.py b/gramps/plugins/tool/eventcmp.py index eb8f0914b..e7ed6fe72 100644 --- a/gramps/plugins/tool/eventcmp.py +++ b/gramps/plugins/tool/eventcmp.py @@ -45,7 +45,6 @@ from gi.repository import Gtk from gramps.gen.filters import GenericFilter, rules from gramps.gui.filters import build_filter_model from gramps.gen.sort import Sort -from gramps.gen.utils.file import get_unicode_path_from_file_chooser from gramps.gui.utils import ProgressMeter from gramps.gen.utils.docgen import ODSTab from gramps.gen.const import CUSTOM_FILTERS, URL_MANUAL_PAGE @@ -402,7 +401,7 @@ class DisplayChart(ManagedWindow): f.hide() if status == Gtk.ResponseType.OK: - name = get_unicode_path_from_file_chooser(f.get_filename()) + name = conv_to_unicode(f.get_filename()) doc = ODSTab(len(self.row_data)) doc.creator(self.db.get_researcher().get_name())