Unicode conversion not required for other Gtk methods

This commit is contained in:
Nick Hall 2015-11-29 00:01:05 +00:00
parent 415540e4a6
commit b34b257d33
9 changed files with 28 additions and 38 deletions

View File

@ -58,7 +58,6 @@ from gramps.gen.utils.keyword import (get_keywords, get_translation_from_keyword
get_translations, get_keyword_from_translation) get_translations, get_keyword_from_translation)
from gramps.gen.lib import Date, FamilyRelType from gramps.gen.lib import Date, FamilyRelType
from gramps.gen.lib import Name, Surname, NameOriginType from gramps.gen.lib import Name, Surname, NameOriginType
from gramps.gen.constfunc import conv_to_unicode
from .managedwindow import ManagedWindow from .managedwindow import ManagedWindow
from .widgets import MarkupLabel, BasicLabel from .widgets import MarkupLabel, BasicLabel
from .dialog import ErrorDialog, QuestionDialog2, OkDialog from .dialog import ErrorDialog, QuestionDialog2, OkDialog
@ -236,7 +235,7 @@ class ConfigureDialog(ManagedWindow):
obj.get_text(), parent=self.window) obj.get_text(), parent=self.window)
obj.set_text('<b>%s</b>') obj.set_text('<b>%s</b>')
self.__config.set(constant, unicode(obj.get_text())) self.__config.set(constant, obj.get_text())
def update_entry(self, obj, constant): def update_entry(self, obj, constant):
""" """
@ -244,7 +243,7 @@ class ConfigureDialog(ManagedWindow):
:param constant: the config setting to which the text value must be :param constant: the config setting to which the text value must be
saved saved
""" """
self.__config.set(constant, conv_to_unicode(obj.get_text())) self.__config.set(constant, obj.get_text())
def update_color(self, obj, constant, color_hex_label): def update_color(self, obj, constant, color_hex_label):
rgba = obj.get_rgba() rgba = obj.get_rgba()
@ -1472,7 +1471,7 @@ class GrampsPreferences(ConfigureDialog):
f.destroy() f.destroy()
def set_dbpath(self, *obj): def set_dbpath(self, *obj):
path = conv_to_unicode(self.dbpath_entry.get_text().strip()) path = self.dbpath_entry.get_text().strip()
config.set('behavior.database-path', path) config.set('behavior.database-path', path)
def select_dbpath(self, *obj): def select_dbpath(self, *obj):
@ -1491,13 +1490,13 @@ class GrampsPreferences(ConfigureDialog):
status = f.run() status = f.run()
if status == Gtk.ResponseType.OK: if status == Gtk.ResponseType.OK:
val = conv_to_unicode(f.get_filename()) val = f.get_filename()
if val: if val:
self.dbpath_entry.set_text(val) self.dbpath_entry.set_text(val)
f.destroy() f.destroy()
def update_idformat_entry(self, obj, constant): def update_idformat_entry(self, obj, constant):
config.set(constant, conv_to_unicode(obj.get_text())) config.set(constant, obj.get_text())
self.dbstate.db.set_prefixes( self.dbstate.db.set_prefixes(
config.get('preferences.iprefix'), config.get('preferences.iprefix'),
config.get('preferences.oprefix'), config.get('preferences.oprefix'),

View File

@ -44,7 +44,7 @@ from urllib.parse import urlparse
import logging import logging
LOG = logging.getLogger(".DbManager") LOG = logging.getLogger(".DbManager")
from gramps.gen.constfunc import win, conv_to_unicode from gramps.gen.constfunc import win
if win(): if win():
_RCS_FOUND = os.system("rcs -V >nul 2>nul") == 0 _RCS_FOUND = os.system("rcs -V >nul 2>nul") == 0
if _RCS_FOUND and "TZ" not in os.environ: if _RCS_FOUND and "TZ" not in os.environ:
@ -282,7 +282,7 @@ class DbManager(CLIDbManager):
self.rcs.set_sensitive(False) self.rcs.set_sensitive(False)
if store.get_value(node, ICON_COL) == 'dialog-error': if store.get_value(node, ICON_COL) == 'dialog-error':
path = conv_to_unicode(store.get_value(node, PATH_COL), 'utf8') path = store.get_value(node, PATH_COL)
backup = os.path.join(path, "person.gbkp") backup = os.path.join(path, "person.gbkp")
self.repair.set_sensitive(os.path.isfile(backup)) self.repair.set_sensitive(os.path.isfile(backup))
else: else:
@ -399,7 +399,7 @@ class DbManager(CLIDbManager):
self.top.destroy() self.top.destroy()
del self.selection del self.selection
del self.name_renderer del self.name_renderer
path = conv_to_unicode(store.get_value(node, PATH_COL), 'utf8') path = store.get_value(node, PATH_COL)
return (path, store.get_value(node, NAME_COL)) return (path, store.get_value(node, NAME_COL))
else: else:
self.top.destroy() self.top.destroy()
@ -434,7 +434,7 @@ class DbManager(CLIDbManager):
try: try:
self.break_lock(self.lock_file) self.break_lock(self.lock_file)
store, node = self.selection.get_selected() store, node = self.selection.get_selected()
dbpath = conv_to_unicode(store.get_value(node, PATH_COL), 'utf8') dbpath = store.get_value(node, PATH_COL)
(tval, last) = time_val(dbpath) (tval, last) = time_val(dbpath)
store.set_value(node, OPEN_COL, 0) store.set_value(node, OPEN_COL, 0)
store.set_value(node, ICON_COL, "") store.set_value(node, ICON_COL, "")
@ -472,7 +472,6 @@ class DbManager(CLIDbManager):
#path is a string, convert to TreePath first #path is a string, convert to TreePath first
path = Gtk.TreePath(path=path) path = Gtk.TreePath(path=path)
if len(new_text) > 0: if len(new_text) > 0:
new_text = conv_to_unicode(new_text, 'utf8')
node = self.model.get_iter(path) node = self.model.get_iter(path)
old_text = self.model.get_value(node, NAME_COL) old_text = self.model.get_value(node, NAME_COL)
if not old_text.strip() == new_text.strip(): if not old_text.strip() == new_text.strip():
@ -622,13 +621,13 @@ class DbManager(CLIDbManager):
store, node = self.selection.get_selected() store, node = self.selection.get_selected()
path = store.get_path(node) path = store.get_path(node)
node = self.model.get_iter(path) node = self.model.get_iter(path)
filename = conv_to_unicode(self.model.get_value(node, FILE_COL), 'utf8') filename = self.model.get_value(node, FILE_COL)
try: try:
name_file = open(filename, "r") name_file = open(filename, "r")
file_name_to_delete=name_file.read() file_name_to_delete=name_file.read()
name_file.close() name_file.close()
remove_filename(file_name_to_delete) remove_filename(file_name_to_delete)
directory = conv_to_unicode(self.data_to_delete[1], 'utf8') directory = self.data_to_delete[1]
for (top, dirs, files) in os.walk(directory): for (top, dirs, files) in os.walk(directory):
for filename in files: for filename in files:
os.unlink(os.path.join(top, filename)) os.unlink(os.path.join(top, filename))
@ -804,8 +803,7 @@ class DbManager(CLIDbManager):
""" """
Create a new database, append to model Create a new database, append to model
""" """
new_path, title = self.create_new_db_cli(conv_to_unicode(title, 'utf8'), new_path, title = self.create_new_db_cli(title, create_db, dbid)
create_db, dbid)
path_name = os.path.join(new_path, NAME_FILE) path_name = os.path.join(new_path, NAME_FILE)
(tval, last) = time_val(new_path) (tval, last) = time_val(new_path)
node = self.model.append(None, [title, new_path, path_name, node = self.model.append(None, [title, new_path, path_name,

View File

@ -49,7 +49,6 @@ from gi.repository import GdkPixbuf
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext _ = glocale.translation.sgettext
from gramps.gen.constfunc import conv_to_unicode
from gramps.gen.const import ICON, THUMBSCALE, USER_HOME from gramps.gen.const import ICON, THUMBSCALE, USER_HOME
from gramps.gen.config import config from gramps.gen.config import config
from gramps.gen.utils.file import (media_path_full, media_path, relative_path, from gramps.gen.utils.file import (media_path_full, media_path, relative_path,
@ -161,7 +160,7 @@ class AddMediaObject(ManagedWindow):
ErrorDialog(msgstr, msgstr2) ErrorDialog(msgstr, msgstr2)
return return
filename = conv_to_unicode(self.file_text.get_filename()) filename = self.file_text.get_filename()
full_file = filename full_file = filename
if self.relpath.get_active(): if self.relpath.get_active():
@ -198,10 +197,10 @@ class AddMediaObject(ManagedWindow):
fname = self.file_text.get_filename() fname = self.file_text.get_filename()
if not fname: if not fname:
return return
filename = conv_to_unicode(fname) filename = fname
basename = os.path.basename(filename) basename = os.path.basename(filename)
(root, ext) = os.path.splitext(basename) (root, ext) = os.path.splitext(basename)
old_title = str(self.description.get_text()) old_title = self.description.get_text()
if old_title == '' or old_title == self.temp_name: if old_title == '' or old_title == self.temp_name:
self.description.set_text(root) self.description.set_text(root)

View File

@ -48,7 +48,6 @@ from .surnamemodel import SurnameModel
from .embeddedlist import EmbeddedList, TEXT_COL, MARKUP_COL, ICON_COL from .embeddedlist import EmbeddedList, TEXT_COL, MARKUP_COL, ICON_COL
from ...ddtargets import DdTargets from ...ddtargets import DdTargets
from gramps.gen.lib import Surname, NameOriginType from gramps.gen.lib import Surname, NameOriginType
from gramps.gen.constfunc import conv_to_unicode
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -176,10 +175,10 @@ class SurnameTab(EmbeddedList):
for idx in range(len(self.model)): for idx in range(len(self.model)):
node = self.model.get_iter(idx) node = self.model.get_iter(idx)
surn = self.model.get_value(node, 5) surn = self.model.get_value(node, 5)
surn.set_prefix(conv_to_unicode(self.model.get_value(node, 0), 'UTF-8')) surn.set_prefix(self.model.get_value(node, 0))
surn.set_surname(conv_to_unicode(self.model.get_value(node, 1), 'UTF-8')) surn.set_surname(self.model.get_value(node, 1))
surn.set_connector(conv_to_unicode(self.model.get_value(node, 2), 'UTF-8')) surn.set_connector(self.model.get_value(node, 2))
surn.get_origintype().set(conv_to_unicode(self.model.get_value(node, 3), 'UTF-8')) surn.get_origintype().set(self.model.get_value(node, 3))
surn.set_primary(self.model.get_value(node, 4)) surn.set_primary(self.model.get_value(node, 4))
new_list += [surn] new_list += [surn]
return new_list return new_list

View File

@ -42,7 +42,6 @@ from gi.repository import Gdk
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext _ = glocale.translation.sgettext
from gramps.gen.constfunc import conv_to_unicode
from ..utils import open_file_with_default_application from ..utils import open_file_with_default_application
from gramps.gen.lib import MediaObject, NoteType from gramps.gen.lib import MediaObject, NoteType
from gramps.gen.db import DbTxn from gramps.gen.db import DbTxn
@ -258,7 +257,7 @@ class EditMedia(EditPrimary):
def select_file(self, val): def select_file(self, val):
self.determine_mime() self.determine_mime()
path = self.file_path.get_text() path = self.file_path.get_text()
self.obj.set_path(conv_to_unicode(path)) self.obj.set_path(path)
AddMediaObject(self.dbstate, self.uistate, self.track, self.obj, AddMediaObject(self.dbstate, self.uistate, self.track, self.obj,
self._update_addmedia) self._update_addmedia)
@ -306,7 +305,7 @@ class EditMedia(EditPrimary):
self.ok_button.set_sensitive(True) self.ok_button.set_sensitive(True)
return return
path = conv_to_unicode(self.file_path.get_text()) path = self.file_path.get_text()
full_path = media_path_full(self.db, path) full_path = media_path_full(self.db, path)
if os.path.isfile(full_path): if os.path.isfile(full_path):
self.determine_mime() self.determine_mime()

View File

@ -45,7 +45,6 @@ from gi.repository import Gdk
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext _ = glocale.translation.sgettext
from gramps.gen.constfunc import conv_to_unicode
from ..utils import open_file_with_default_application from ..utils import open_file_with_default_application
from gramps.gen.const import THUMBSCALE from gramps.gen.const import THUMBSCALE
from gramps.gen.mime import get_description, get_type from gramps.gen.mime import get_description, get_type
@ -435,7 +434,7 @@ class EditMediaRef(EditReference):
def select_file(self, val): def select_file(self, val):
self.determine_mime() self.determine_mime()
path = self.file_path.get_text() path = self.file_path.get_text()
self.source.set_path(conv_to_unicode(path)) self.source.set_path(path)
AddMediaObject(self.dbstate, self.uistate, self.track, self.source, AddMediaObject(self.dbstate, self.uistate, self.track, self.source,
self._update_addmedia) self._update_addmedia)

View File

@ -23,7 +23,7 @@
import os import os
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import GObject from gi.repository import GObject
from gramps.gen.constfunc import conv_to_unicode, get_curr_dir from gramps.gen.constfunc import get_curr_dir
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext _ = glocale.translation.gettext
@ -65,7 +65,7 @@ class FileEntry(Gtk.Box):
_('_Open'), _('_Open'),
Gtk.ResponseType.OK)) Gtk.ResponseType.OK))
name = os.path.basename(conv_to_unicode(self.entry.get_text())) name = os.path.basename(self.entry.get_text())
if self.dir: if self.dir:
if os.path.isdir(name): if os.path.isdir(name):
dialog.set_current_name(name) dialog.set_current_name(name)

View File

@ -61,7 +61,6 @@ from ...managedwindow import ManagedWindow
from ._stylecombobox import StyleComboBox from ._stylecombobox import StyleComboBox
from ._styleeditor import StyleListDisplay from ._styleeditor import StyleListDisplay
from ._fileentry import FileEntry from ._fileentry import FileEntry
from gramps.gen.constfunc import conv_to_unicode
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Private Constants # Private Constants
@ -483,7 +482,7 @@ class ReportDialog(ManagedWindow):
to tell the calling routine to give up. This function also to tell the calling routine to give up. This function also
saves the current directory so that any future reports will saves the current directory so that any future reports will
default to the most recently used directory.""" default to the most recently used directory."""
self.target_path = conv_to_unicode(self.target_fileentry.get_full_path(0)) self.target_path = self.target_fileentry.get_full_path(0)
if not self.target_path: if not self.target_path:
return None return None

View File

@ -77,7 +77,7 @@ from .displaystate import DisplayState, RecentDocsMenu
from gramps.gen.const import (HOME_DIR, ICON, URL_BUGTRACKER, URL_HOMEPAGE, from gramps.gen.const import (HOME_DIR, ICON, URL_BUGTRACKER, URL_HOMEPAGE,
URL_MAILINGLIST, URL_MANUAL_PAGE, URL_WIKISTRING, URL_MAILINGLIST, URL_MANUAL_PAGE, URL_WIKISTRING,
WIKI_EXTRAPLUGINS, URL_BUGHOME) WIKI_EXTRAPLUGINS, URL_BUGHOME)
from gramps.gen.constfunc import is_quartz, conv_to_unicode from gramps.gen.constfunc import is_quartz
from gramps.gen.config import config from gramps.gen.config import config
from gramps.gen.errors import WindowActiveError from gramps.gen.errors import WindowActiveError
from .dialog import ErrorDialog, WarningDialog, QuestionDialog2, InfoDialog from .dialog import ErrorDialog, WarningDialog, QuestionDialog2, InfoDialog
@ -1095,7 +1095,6 @@ class ViewManager(CLIManager):
value = dialog.run() value = dialog.run()
if value: if value:
(filename, title) = value (filename, title) = value
filename = conv_to_unicode(filename)
self.db_loader.read_file(filename) self.db_loader.read_file(filename)
self._post_load_newdb(filename, 'x-directory/normal', title) self._post_load_newdb(filename, 'x-directory/normal', title)
@ -1295,10 +1294,9 @@ class ViewManager(CLIManager):
window.hide() window.hide()
if d == Gtk.ResponseType.APPLY: if d == Gtk.ResponseType.APPLY:
# if file exists, ask if overwrite; else abort # if file exists, ask if overwrite; else abort
basefile = conv_to_unicode(file_entry.get_text()) basefile = file_entry.get_text()
basefile = basefile.replace("/", r"-") basefile = basefile.replace("/", r"-")
filename = os.path.join(conv_to_unicode(path_entry.get_text()), filename = os.path.join(path_entry.get_text(), basefile)
basefile)
if os.path.exists(filename): if os.path.exists(filename):
question = QuestionDialog2( question = QuestionDialog2(
_("Backup file already exists! Overwrite?"), _("Backup file already exists! Overwrite?"),