2620: GEPS 031: Python 3 support - 3.2

* working gedcom import
  * fixes in listviews
  * fixes in db managaer and import dialog


svn: r20662
This commit is contained in:
Benny Malengier 2012-11-16 13:05:56 +00:00
parent eb09afbc99
commit 2bdf6c8b95
11 changed files with 92 additions and 28 deletions

View File

@ -119,7 +119,10 @@ class BsddbBaseCursor(object):
current = _get(db.DB_CURRENT)
first = _get(db.DB_FIRST)
##python2 iterator
next = _get(db.DB_NEXT)
##python3 iterator
__next__ = _get(db.DB_NEXT)
last = _get(db.DB_LAST)
prev = _get(db.DB_PREV)

View File

@ -129,6 +129,18 @@ class StyledText(object):
def __ne__(self, other):
return self._string != other._string or self._tags != other._tags
def __lt__(self, other):
return self._string < other._string
def __le__(self, other):
return self.__lt__(other) or self.__eq__(other)
def __gt__(self, other):
return not self.__le__(other)
def __ge__(self, other):
return self.__gt__(other) or self.__eq__(other)
def __mod__(self, other):
"""Implement '%' operation on the class."""

View File

@ -136,8 +136,10 @@ class DbLoader(CLIDbLoader):
import_dialog = Gtk.FileChooserDialog(_('Gramps: Import Family Tree'),
self.uistate.window,
Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
'gramps-import', Gtk.ResponseType.OK))
(Gtk.STOCK_CANCEL,
Gtk.ResponseType.CANCEL,
_('Import'),
Gtk.ResponseType.OK))
import_dialog.set_local_only(False)
# Always add automatic (match all files) filter

View File

@ -281,6 +281,7 @@ class DbManager(CLIDbManager):
self.column = Gtk.TreeViewColumn(_('Family tree name'), render,
text=NAME_COL)
self.column.set_sort_column_id(NAME_COL)
self.column.set_sort_indicator(True)
self.column.set_resizable(True)
self.column.set_min_width(275)
self.dblist.append_column(self.column)
@ -323,6 +324,7 @@ class DbManager(CLIDbManager):
for rdata in find_revisions(os.path.join(items[1], ARCHIVE_V)):
data = [ rdata[2], rdata[0], items[1], rdata[1], 0, False, "" ]
self.model.append(node, data)
self.model.set_sort_column_id(NAME_COL, Gtk.SortType.ASCENDING)
self.dblist.set_model(self.model)
def existing_name(self, name, skippath=None):

View File

@ -67,7 +67,7 @@ from .managedwindow import GrampsWindowManager
from gramps.gen.relationship import get_relationship_calculator
from .glade import Glade
from gramps.gen.utils.db import navigation_label
from gramps.gen.constfunc import UNITYPE
from gramps.gen.constfunc import UNITYPE, cuni
DISABLED = -1
@ -83,7 +83,7 @@ class History(Callback):
"""
__signals__ = {
'active-changed' : (str, ),
'active-changed' : (UNITYPE, ),
'mru-changed' : (list, )
}
@ -138,7 +138,10 @@ class History(Callback):
self.mru.remove(del_id)
self.emit('mru-changed', (self.mru, ))
if self.history:
self.emit('active-changed', (self.history[self.index],))
newact = self.history[self.index]
if not isinstance(newact, UNITYPE):
newact = cuni(newact)
self.emit('active-changed', (newact,))
def push(self, handle):
"""
@ -146,14 +149,17 @@ class History(Callback):
"""
self.prune()
if len(self.history) == 0 or handle != self.history[-1]:
self.history.append(str(handle))
self.history.append(handle)
if handle in self.mru:
self.mru.remove(handle)
self.mru.append(handle)
self.emit('mru-changed', (self.mru, ))
self.index += 1
if self.history:
self.emit('active-changed', (self.history[self.index],))
newact = self.history[self.index]
if not isinstance(newact, UNITYPE):
newact = cuni(newact)
self.emit('active-changed', (newact,))
def forward(self, step=1):
"""
@ -165,9 +171,11 @@ class History(Callback):
self.mru.remove(handle)
self.mru.append(handle)
self.emit('mru-changed', (self.mru, ))
if self.history:
self.emit('active-changed', (self.history[self.index],))
return str(self.history[self.index])
newact = self.history[self.index]
if not isinstance(newact, UNITYPE):
newact = cuni(newact)
self.emit('active-changed', (newact,))
return newact
def back(self, step=1):
"""
@ -180,9 +188,11 @@ class History(Callback):
self.mru.remove(handle)
self.mru.append(handle)
self.emit('mru-changed', (self.mru, ))
if self.history:
self.emit('active-changed', (self.history[self.index],))
return str(self.history[self.index])
newact = self.history[self.index]
if not isinstance(newact, UNITYPE):
newact = cuni(newact)
self.emit('active-changed', (newact,))
return newact
except IndexError:
return ""

View File

@ -30,6 +30,7 @@ Handles generation and access to thumbnails used in GRAMPS.
#
#-------------------------------------------------------------------------
import os
import sys
import logging
try:
from hashlib import md5
@ -145,7 +146,10 @@ def __build_thumb_path(path, rectangle=None, size=SIZE_NORMAL):
extra = ""
if rectangle is not None:
extra = "?" + str(rectangle)
md5_hash = md5(path+extra)
prehash = path+extra
if sys.version_info[0] >= 3:
prehash =prehash.encode('utf-8')
md5_hash = md5(prehash)
if size == SIZE_LARGE:
base_dir = THUMB_LARGE
else:

View File

@ -62,6 +62,7 @@ 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.const import CUSTOM_FILTERS, USE_TIPS
from gramps.gen.utils.debug import profile
from gramps.gen.utils.string import data_recover_msg

View File

@ -305,8 +305,12 @@ class FlatNodeMap(object):
:param path: path as it appears in the treeview
:type path: integer
:return handle: unicode form of the handle
"""
return self._index2hndl[self.real_index(path)][1]
handle = self._index2hndl[self.real_index(path)][1]
if not isinstance(handle, UNITYPE):
handle = handle.decode('utf-8')
return handle
def find_next_handle(self, iter):
"""

View File

@ -831,7 +831,10 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel):
Get the gramps handle for a node. Return None if the node does
not correspond to a gramps object.
"""
return node.handle
handle = node.handle
if not isinstance(handle, UNITYPE):
handle = handle.decode('utf-8')
return handle
def get_node(self, handle):
"""

View File

@ -104,7 +104,10 @@ def importData(database, filename, user):
assert(isinstance(code_set, STRTYPE))
try:
ifile = open(filename, "rU")
if sys.version_info[0] < 3:
ifile = open(filename, "rU")
else:
ifile = open(filename, "rb")
stage_one = libgedcom.GedcomStageOne(ifile)
stage_one.parse()

View File

@ -123,7 +123,12 @@ LOG = logging.getLogger(".libgedcom")
#-------------------------------------------------------------------------
from gramps.gen.errors import GedcomError
from gramps.gen.const import DATA_DIR
from gramps.gen.lib import Address, Attribute, AttributeType, ChildRef, ChildRefType, Citation, Date, Event, EventRef, EventRoleType, EventType, Family, FamilyRelType, LdsOrd, Location, MediaObject, MediaRef, Name, NameType, Note, NoteType, Person, PersonRef, Place, RepoRef, Repository, RepositoryType, Researcher, Source, SourceMediaType, Surname, Url, UrlType
from gramps.gen.lib import (Address, Attribute, AttributeType, ChildRef,
ChildRefType, Citation, Date, Event, EventRef, EventRoleType,
EventType, Family, FamilyRelType, LdsOrd, Location, MediaObject,
MediaRef, Name, NameType, Note, NoteType, Person, PersonRef, Place,
RepoRef, Repository, RepositoryType, Researcher, Source,
SourceMediaType, Surname, Url, UrlType)
from gramps.gen.db import DbTxn
from gramps.gen.updatecallback import UpdateCallback
from gramps.gen.mime import get_type
@ -135,7 +140,7 @@ from gramps.gen.db.dbconst import EVENT_KEY
from gramps.gui.dialog import WarningDialog
from gramps.gen.lib.const import IDENTICAL, DIFFERENT
from gramps.gen.lib import (StyledText, StyledTextTag, StyledTextTagType)
from gramps.gen.constfunc import cuni, conv_to_unicode, STRTYPE
from gramps.gen.constfunc import cuni, conv_to_unicode, STRTYPE, UNITYPE
#-------------------------------------------------------------------------
#
@ -1206,9 +1211,13 @@ class BaseReader(object):
self.ifile.seek(0)
def readline(self):
line = cuni(self.ifile.readline(),
encoding=self.enc,
errors='replace')
if sys.version_info[0] < 3:
line = unicode(self.ifile.readline(),
encoding=self.enc,
errors='replace')
else:
line = self.ifile.readline()
line = line.decode(self.enc, errors='replace')
return line.translate(STRIP_DICT)
class UTF8Reader(BaseReader):
@ -1224,9 +1233,13 @@ class UTF8Reader(BaseReader):
self.ifile.seek(0)
def readline(self):
line = cuni(self.ifile.readline(),
encoding=self.enc,
errors='replace')
line = self.ifile.readline()
if sys.version_info[0] < 3:
line = unicode(line,
encoding=self.enc,
errors='replace')
else:
line = line.decode(self.enc, errors='replace')
return line.translate(STRIP_DICT)
class UTF16Reader(BaseReader):
@ -1497,7 +1510,10 @@ class AnselReader(BaseReader):
head = '\ufffd' # "Replacement Char"
s = s[1:]
buff.write(head.encode("utf-8"))
ans = conv_to_unicode(buff.getvalue(), "utf-8")
if sys.version_info[0] < 3:
ans = unicode(buff.getvalue(), "utf-8")
else:
ans = buff.getvalue().decode("utf-8")
buff.close()
return ans
@ -1703,7 +1719,10 @@ class IdMapper(object):
# have found it. If we had already encountered I0001 and we are
# now looking for I1, it wouldn't be in self.swap, and we now
# find that I0001 is in use, so we have to create a new id.
if self.trans.get(str(formatted_gid)) or \
bformatted_gid = formatted_gid
if isinstance(bformatted_gid, UNITYPE):
bformatted_gid = bformatted_gid.encode('utf-8')
if self.trans.get(bformatted_gid) or \
(formatted_gid in list(self.swap.values())):
new_val = self.find_next()
while new_val in list(self.swap.values()):
@ -2938,7 +2957,8 @@ class GedcomParser(UpdateCallback):
def __check(map, trans, class_func, commit_func, gramps_id2handle, msg):
for input_id, gramps_id in map.map().items():
# Check whether an object exists for the mapped gramps_id
if not trans.get(str(gramps_id)):
bgramps_id = gramps_id.encode('utf-8')
if not trans.get(bgramps_id):
handle = self.__find_from_handle(gramps_id,
gramps_id2handle)
if msg == "FAM":