Add bookmark-list-changed signal
This commit is contained in:
parent
7b5c381b8f
commit
caa2560b11
@ -20,35 +20,86 @@
|
||||
# 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)
|
||||
"""
|
||||
DbBookmarks Class
|
||||
"""
|
||||
|
||||
def set(self, new_list):
|
||||
from ..utils.callback import Callback
|
||||
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
#
|
||||
# DbBookmarks class
|
||||
#
|
||||
# -------------------------------------------------------------------------
|
||||
class DbBookmarks(Callback):
|
||||
"""
|
||||
Simple class for tracking a list of bookmarked objects
|
||||
"""
|
||||
|
||||
__signals__ = {"bookmark-list-changed": None}
|
||||
|
||||
def __init__(self, default=None):
|
||||
super().__init__()
|
||||
self.bookmarks = default or []
|
||||
|
||||
def load(self, new_list):
|
||||
"""
|
||||
Quietly load the bookmark list.
|
||||
"""
|
||||
self.bookmarks = list(new_list)
|
||||
|
||||
def set(self, new_list):
|
||||
"""
|
||||
Set the bookmark list.
|
||||
"""
|
||||
self.bookmarks = list(new_list)
|
||||
self.emit("bookmark-list-changed")
|
||||
|
||||
def get(self):
|
||||
"""
|
||||
Return the bookmark list.
|
||||
"""
|
||||
return self.bookmarks
|
||||
|
||||
def append(self, item):
|
||||
"""
|
||||
Append an item to the end of the list.
|
||||
"""
|
||||
self.bookmarks.append(item)
|
||||
self.emit("bookmark-list-changed")
|
||||
|
||||
def append_list(self, blist):
|
||||
"""
|
||||
Append a list of items to the end of the list.
|
||||
"""
|
||||
self.bookmarks += blist
|
||||
self.emit("bookmark-list-changed")
|
||||
|
||||
def remove(self, item):
|
||||
"""
|
||||
Remove an item from the list.
|
||||
"""
|
||||
self.bookmarks.remove(item)
|
||||
self.emit("bookmark-list-changed")
|
||||
|
||||
def pop(self, item):
|
||||
return self.bookmarks.pop(item)
|
||||
def pop(self, index):
|
||||
"""
|
||||
Pop an item from the list.
|
||||
"""
|
||||
item = self.bookmarks.pop(index)
|
||||
self.emit("bookmark-list-changed")
|
||||
return item
|
||||
|
||||
def insert(self, pos, item):
|
||||
"""
|
||||
Insert a new item into the list.
|
||||
"""
|
||||
self.bookmarks.insert(pos, item)
|
||||
self.emit("bookmark-list-changed")
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
Close the list by deleting it.
|
||||
"""
|
||||
del self.bookmarks
|
||||
|
@ -63,6 +63,7 @@ from functools import wraps
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from .base import DbReadBase
|
||||
from .bookmarks import DbBookmarks
|
||||
from .dbconst import DBLOGNAME
|
||||
from ..errors import HandleError
|
||||
from ..utils.callback import Callback
|
||||
@ -72,71 +73,6 @@ from ..const import GRAMPS_LOCALE as glocale
|
||||
LOG = logging.getLogger(DBLOGNAME)
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# class DbBookmarks
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class Bookmarks:
|
||||
"""
|
||||
Dummy Bookmarks class. This needs to be defined here, because get is used to
|
||||
return the bookmark.
|
||||
"""
|
||||
def __init__(self, default=[]):
|
||||
"""
|
||||
Initialise the bookmark, either with a copy of the passed list, or with
|
||||
an empty list.
|
||||
"""
|
||||
self.bookmarks = list(default) # want a copy (not an alias)
|
||||
|
||||
def set(self, new_list):
|
||||
"""
|
||||
Set the bookmark to a new list
|
||||
"""
|
||||
self.bookmarks = list(new_list)
|
||||
|
||||
def get(self):
|
||||
"""
|
||||
Get the current bookmark list
|
||||
"""
|
||||
return self.bookmarks
|
||||
|
||||
def append(self, item):
|
||||
"""
|
||||
Append a bookmark to the list
|
||||
"""
|
||||
self.bookmarks.append(item)
|
||||
|
||||
def append_list(self, blist):
|
||||
"""
|
||||
Append a list of bookmarks to the bookmark
|
||||
"""
|
||||
self.bookmarks += blist
|
||||
|
||||
def remove(self, item):
|
||||
"""
|
||||
Remove an item from the bookmark
|
||||
"""
|
||||
self.bookmarks.remove(item)
|
||||
|
||||
def pop(self, item):
|
||||
"""
|
||||
Pop an item off the bookmark list, returning the popped item
|
||||
"""
|
||||
return self.bookmarks.pop(item)
|
||||
|
||||
def insert(self, pos, item):
|
||||
"""
|
||||
Insert an item at a specified place in thebookmark list
|
||||
"""
|
||||
self.bookmarks.insert(pos, item)
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
Close the bookmark, deleting the data.
|
||||
"""
|
||||
del self.bookmarks
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# some magic, see http://stackoverflow.com/questions/11349183/how-to-wrap-every-
|
||||
@ -224,15 +160,15 @@ class DummyDb(M_A_M_B("NewBaseClass", (DbReadBase, Callback, object,), {})):
|
||||
self.db_is_open = False
|
||||
self.readonly = True
|
||||
self.name_formats = []
|
||||
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.owner = Researcher()
|
||||
|
||||
def get_feature(self, feature):
|
||||
|
@ -592,15 +592,15 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
||||
self.owner = self._get_metadata('researcher', default=Researcher())
|
||||
|
||||
# Load bookmarks
|
||||
self.bookmarks.set(self._get_metadata('bookmarks'))
|
||||
self.family_bookmarks.set(self._get_metadata('family_bookmarks'))
|
||||
self.event_bookmarks.set(self._get_metadata('event_bookmarks'))
|
||||
self.source_bookmarks.set(self._get_metadata('source_bookmarks'))
|
||||
self.citation_bookmarks.set(self._get_metadata('citation_bookmarks'))
|
||||
self.repo_bookmarks.set(self._get_metadata('repo_bookmarks'))
|
||||
self.media_bookmarks.set(self._get_metadata('media_bookmarks'))
|
||||
self.place_bookmarks.set(self._get_metadata('place_bookmarks'))
|
||||
self.note_bookmarks.set(self._get_metadata('note_bookmarks'))
|
||||
self.bookmarks.load(self._get_metadata('bookmarks'))
|
||||
self.family_bookmarks.load(self._get_metadata('family_bookmarks'))
|
||||
self.event_bookmarks.load(self._get_metadata('event_bookmarks'))
|
||||
self.source_bookmarks.load(self._get_metadata('source_bookmarks'))
|
||||
self.citation_bookmarks.load(self._get_metadata('citation_bookmarks'))
|
||||
self.repo_bookmarks.load(self._get_metadata('repo_bookmarks'))
|
||||
self.media_bookmarks.load(self._get_metadata('media_bookmarks'))
|
||||
self.place_bookmarks.load(self._get_metadata('place_bookmarks'))
|
||||
self.note_bookmarks.load(self._get_metadata('note_bookmarks'))
|
||||
|
||||
# Custom type values
|
||||
self.event_names = self._get_metadata('event_names', set())
|
||||
|
Loading…
Reference in New Issue
Block a user