Create new module for DbBookmarks

This commit is contained in:
Nick Hall 2016-11-29 19:34:57 +00:00
parent 3bf40f9921
commit 98950a89a3
4 changed files with 66 additions and 71 deletions

View File

@ -0,0 +1,54 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2010 Nick Hall
# Copyright (C) 2011 Tim G L Lyons
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
#-------------------------------------------------------------------------
#
# class DbBookmarks
#
#-------------------------------------------------------------------------
class DbBookmarks:
def __init__(self, default=[]):
self.bookmarks = list(default) # want a copy (not an alias)
def set(self, new_list):
self.bookmarks = list(new_list)
def get(self):
return self.bookmarks
def append(self, item):
self.bookmarks.append(item)
def append_list(self, blist):
self.bookmarks += blist
def remove(self, item):
self.bookmarks.remove(item)
def pop(self, item):
return self.bookmarks.pop(item)
def insert(self, pos, item):
self.bookmarks.insert(pos, item)
def close(self):
del self.bookmarks

View File

@ -56,6 +56,7 @@ from gramps.gen.errors import HandleError
from gramps.gen.utils.callback import Callback
from gramps.gen.updatecallback import UpdateCallback
from gramps.gen.db.dbconst import *
from gramps.gen.db.bookmarks import DbBookmarks
from gramps.gen.db import exceptions
from gramps.gen.utils.id import create_id
@ -302,34 +303,6 @@ class TreeCursor(Cursor):
for handle in handles:
yield (handle, self.db.get_raw_place_data(handle))
class Bookmarks:
def __init__(self, default=[]):
self.handles = list(default)
def set(self, handles):
self.handles = list(handles)
def get(self):
return self.handles
def append(self, handle):
self.handles.append(handle)
def append_list(self, handles):
self.handles += handles
def remove(self, handle):
self.handles.remove(handle)
def pop(self, item):
return self.handles.pop(item)
def insert(self, pos, item):
self.handles.insert(pos, item)
def close(self):
del self.handles
class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
"""
A Gramps Database Backend. This replicates the grampsdb functions.
@ -548,15 +521,15 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.db_is_open = False
self.name_formats = []
# Bookmarks:
self.bookmarks = Bookmarks()
self.family_bookmarks = Bookmarks()
self.event_bookmarks = Bookmarks()
self.place_bookmarks = Bookmarks()
self.citation_bookmarks = Bookmarks()
self.source_bookmarks = Bookmarks()
self.repo_bookmarks = Bookmarks()
self.media_bookmarks = Bookmarks()
self.note_bookmarks = Bookmarks()
self.bookmarks = DbBookmarks()
self.family_bookmarks = DbBookmarks()
self.event_bookmarks = DbBookmarks()
self.place_bookmarks = DbBookmarks()
self.citation_bookmarks = DbBookmarks()
self.source_bookmarks = DbBookmarks()
self.repo_bookmarks = DbBookmarks()
self.media_bookmarks = DbBookmarks()
self.note_bookmarks = DbBookmarks()
self.set_person_id_prefix('I%04d')
self.set_media_id_prefix('O%04d')
self.set_family_id_prefix('F%04d')

View File

@ -72,6 +72,7 @@ from gramps.gen.lib.nameorigintype import NameOriginType
from gramps.gen.utils.callback import Callback
from . import BsddbBaseCursor
from gramps.gen.db.base import DbReadBase
from gramps.gen.db.bookmarks import DbBookmarks
from gramps.gen.utils.id import create_id
from gramps.gen.errors import DbError, HandleError
from gramps.gen.constfunc import get_env_var
@ -164,40 +165,6 @@ def __index_surname(surn_list):
surn = ""
return surn
#-------------------------------------------------------------------------
#
# class DbBookmarks
#
#-------------------------------------------------------------------------
class DbBookmarks:
def __init__(self, default=[]):
self.bookmarks = list(default) # want a copy (not an alias)
def set(self, new_list):
self.bookmarks = list(new_list)
def get(self):
return self.bookmarks
def append(self, item):
self.bookmarks.append(item)
def append_list(self, blist):
self.bookmarks += blist
def remove(self, item):
self.bookmarks.remove(item)
def pop(self, item):
return self.bookmarks.pop(item)
def insert(self, pos, item):
self.bookmarks.insert(pos, item)
def close(self):
del self.bookmarks
#-------------------------------------------------------------------------
#
# GrampsDBReadCursor

View File

@ -55,6 +55,7 @@ gramps/gen/datehandler/_grampslocale.py
#
gramps/gen/db/__init__.py
gramps/gen/db/backup.py
gramps/gen/db/bookmarks.py
gramps/gen/db/bsddbtxn.py
gramps/gen/db/cursor.py
gramps/gen/db/dbconst.py