Tidy up bookmark code

svn: r21139
This commit is contained in:
Nick Hall 2013-01-15 22:30:18 +00:00
parent bd6b4ce012
commit b2ba4c3a6d
25 changed files with 71 additions and 152 deletions

View File

@ -82,7 +82,7 @@ DISABLED = -1
class Bookmarks :
"Handle the bookmarks interface for Gramps."
def __init__(self, dbstate, uistate, bookmarks, callback=None):
def __init__(self, dbstate, uistate, callback=None):
"""
Create the bookmark editor.
@ -92,7 +92,8 @@ class Bookmarks :
"""
self.dbstate = dbstate
self.uistate = uistate
self.bookmarks = bookmarks
self.bookmarks = None
self.update_bookmarks()
self.active = DISABLED
self.action_group = Gtk.ActionGroup('Bookmarks')
self.connect_signals()
@ -103,6 +104,7 @@ class Bookmarks :
Reconnect the signals on a database changed.
"""
self.connect_signals()
self.update_bookmarks()
def connect_signals(self):
"""
@ -110,11 +112,17 @@ class Bookmarks :
"""
raise NotImplementedError
def update_bookmarks(self, bookmarks):
def get_bookmarks(self):
"""
Retrieve bookmarks from the database.
"""
raise NotImplementedError
def update_bookmarks(self):
"""
Assign bookmarks
"""
self.bookmarks = bookmarks
self.bookmarks = self.get_bookmarks()
def display(self):
"""
@ -306,9 +314,9 @@ class Bookmarks :
class ListBookmarks(Bookmarks):
def __init__(self, dbstate, uistate, bookmarks, goto_handle):
def __init__(self, dbstate, uistate, goto_handle):
self.goto_handle = goto_handle
Bookmarks.__init__(self, dbstate, uistate, bookmarks)
Bookmarks.__init__(self, dbstate, uistate)
def callback(self, handle):
return make_callback(handle, self.do_callback)
@ -319,9 +327,8 @@ class ListBookmarks(Bookmarks):
class PersonBookmarks(ListBookmarks) :
"Handle the bookmarks interface for Gramps."
def __init__(self, dbstate, uistate, bookmarks, goto_handle):
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
goto_handle)
def __init__(self, dbstate, uistate, goto_handle):
ListBookmarks.__init__(self, dbstate, uistate, goto_handle)
def make_label(self, handle):
return navigation_label(self.dbstate.db, 'Person', handle)
@ -329,12 +336,14 @@ class PersonBookmarks(ListBookmarks) :
def connect_signals(self):
self.dbstate.db.connect('person-delete', self.remove_handles)
def get_bookmarks(self):
return self.dbstate.db.get_bookmarks()
class FamilyBookmarks(ListBookmarks) :
"Handle the bookmarks interface for Gramps."
def __init__(self, dbstate, uistate, bookmarks, goto_handle):
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
goto_handle)
def __init__(self, dbstate, uistate, goto_handle):
ListBookmarks.__init__(self, dbstate, uistate, goto_handle)
def make_label(self, handle):
return navigation_label(self.dbstate.db, 'Family', handle)
@ -342,12 +351,14 @@ class FamilyBookmarks(ListBookmarks) :
def connect_signals(self):
self.dbstate.db.connect('family-delete', self.remove_handles)
def get_bookmarks(self):
return self.dbstate.db.get_family_bookmarks()
class EventBookmarks(ListBookmarks) :
"Handle the bookmarks interface for Gramps."
def __init__(self, dbstate, uistate, bookmarks, goto_handle):
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
goto_handle)
def __init__(self, dbstate, uistate, goto_handle):
ListBookmarks.__init__(self, dbstate, uistate, goto_handle)
def make_label(self, handle):
return navigation_label(self.dbstate.db, 'Event', handle)
@ -355,11 +366,14 @@ class EventBookmarks(ListBookmarks) :
def connect_signals(self):
self.dbstate.db.connect('event-delete', self.remove_handles)
def get_bookmarks(self):
return self.dbstate.db.get_event_bookmarks()
class SourceBookmarks(ListBookmarks) :
"Handle the bookmarks interface for Gramps."
def __init__(self, dbstate, uistate, bookmarks, goto_handle):
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
goto_handle)
def __init__(self, dbstate, uistate, goto_handle):
ListBookmarks.__init__(self, dbstate, uistate, goto_handle)
def make_label(self, handle):
return navigation_label(self.dbstate.db, 'Source', handle)
@ -367,11 +381,14 @@ class SourceBookmarks(ListBookmarks) :
def connect_signals(self):
self.dbstate.db.connect('source-delete', self.remove_handles)
def get_bookmarks(self):
return self.dbstate.db.get_source_bookmarks()
class CitationBookmarks(ListBookmarks) :
"Handle the bookmarks interface for Gramps."
def __init__(self, dbstate, uistate, bookmarks, goto_handle):
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
goto_handle)
def __init__(self, dbstate, uistate, goto_handle):
ListBookmarks.__init__(self, dbstate, uistate, goto_handle)
def make_label(self, handle):
return navigation_label(self.dbstate.db, 'Citation', handle)
@ -379,12 +396,14 @@ class CitationBookmarks(ListBookmarks) :
def connect_signals(self):
self.dbstate.db.connect('citation-delete', self.remove_handles)
def get_bookmarks(self):
return self.dbstate.db.get_citation_bookmarks()
class MediaBookmarks(ListBookmarks) :
"Handle the bookmarks interface for Gramps."
def __init__(self, dbstate, uistate, bookmarks, goto_handle):
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
goto_handle)
def __init__(self, dbstate, uistate, goto_handle):
ListBookmarks.__init__(self, dbstate, uistate, goto_handle)
def make_label(self, handle):
return navigation_label(self.dbstate.db, 'Media', handle)
@ -392,12 +411,14 @@ class MediaBookmarks(ListBookmarks) :
def connect_signals(self):
self.dbstate.db.connect('media-delete', self.remove_handles)
def get_bookmarks(self):
return self.dbstate.db.get_media_bookmarks()
class RepoBookmarks(ListBookmarks) :
"Handle the bookmarks interface for Gramps."
def __init__(self, dbstate, uistate, bookmarks, goto_handle):
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
goto_handle)
def __init__(self, dbstate, uistate, goto_handle):
ListBookmarks.__init__(self, dbstate, uistate, goto_handle)
def make_label(self, handle):
return navigation_label(self.dbstate.db, 'Repository', handle)
@ -405,12 +426,14 @@ class RepoBookmarks(ListBookmarks) :
def connect_signals(self):
self.dbstate.db.connect('repository-delete', self.remove_handles)
def get_bookmarks(self):
return self.dbstate.db.get_repo_bookmarks()
class PlaceBookmarks(ListBookmarks) :
"Handle the bookmarks interface for Gramps."
def __init__(self, dbstate, uistate, bookmarks, goto_handle):
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
goto_handle)
def __init__(self, dbstate, uistate, goto_handle):
ListBookmarks.__init__(self, dbstate, uistate, goto_handle)
def make_label(self, handle):
return navigation_label(self.dbstate.db, 'Place', handle)
@ -418,12 +441,14 @@ class PlaceBookmarks(ListBookmarks) :
def connect_signals(self):
self.dbstate.db.connect('place-delete', self.remove_handles)
def get_bookmarks(self):
return self.dbstate.db.get_place_bookmarks()
class NoteBookmarks(ListBookmarks) :
"Handle the bookmarks interface for Gramps."
def __init__(self, dbstate, uistate, bookmarks, goto_handle):
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
goto_handle)
def __init__(self, dbstate, uistate, goto_handle):
ListBookmarks.__init__(self, dbstate, uistate, goto_handle)
def make_label(self, handle):
return navigation_label(self.dbstate.db, 'Note', handle)
@ -431,6 +456,9 @@ class NoteBookmarks(ListBookmarks) :
def connect_signals(self):
self.dbstate.db.connect('note-delete', self.remove_handles)
def get_bookmarks(self):
return self.dbstate.db.get_note_bookmarks()
def make_callback(handle, function):
"""
Build a unique call to the function with the associated handle.

View File

@ -104,10 +104,10 @@ class ListView(NavigationView):
QR_CATEGORY = -1
def __init__(self, title, pdata, dbstate, uistate, handle_col,
make_model, signal_map, get_bookmarks, bm_type, nav_group,
make_model, signal_map, bm_type, nav_group,
multiple=False, filter_class=None):
NavigationView.__init__(self, title, pdata, dbstate, uistate,
get_bookmarks, bm_type, nav_group)
bm_type, nav_group)
#default is listviews keep themself in sync with database
self._dirty_on_change_inactive = False
@ -681,7 +681,6 @@ class ListView(NavigationView):
self._change_db(db)
self.connect_signals()
self.bookmarks.update_bookmarks(self.get_bookmarks())
if self.active:
#force rebuild of the model on build of tree
self.dirty = True

View File

@ -80,10 +80,9 @@ class NavigationView(PageView):
should derive from this class.
"""
def __init__(self, title, pdata, state, uistate, bookmarks, bm_type, nav_group):
def __init__(self, title, pdata, state, uistate, bm_type, nav_group):
PageView.__init__(self, title, pdata, state, uistate)
self.bookmarks = bm_type(self.dbstate, self.uistate, bookmarks,
self.goto_handle)
self.bookmarks = bm_type(self.dbstate, self.uistate, self.goto_handle)
self.fwd_action = None
self.back_action = None

View File

@ -135,7 +135,7 @@ class BasePersonView(ListView):
ListView.__init__(
self, title, pdata, dbstate, uistate,
len(BasePersonView.COLUMNS),
model, signal_map, dbstate.db.get_bookmarks(),
model, signal_map,
PersonBookmarks, nav_group,
multiple=True,
filter_class=PersonSidebarFilter)
@ -155,12 +155,6 @@ class BasePersonView(ListView):
"""
return 'Person'
def get_bookmarks(self):
"""
Return the bookmark object
"""
return self.dbstate.db.get_bookmarks()
def drag_info(self):
"""
Specify the drag type for a single selection

View File

@ -140,7 +140,6 @@ class PlaceBaseView(ListView):
self, title, pdata, dbstate, uistate,
15,
model, signal_map,
dbstate.db.get_place_bookmarks(),
PlaceBookmarks, nav_group,
multiple=True,
filter_class=PlaceSidebarFilter)
@ -155,9 +154,6 @@ class PlaceBaseView(ListView):
def navigation_type(self):
return 'Place'
def get_bookmarks(self):
return self.dbstate.db.get_place_bookmarks()
def define_actions(self):
ListView.define_actions(self)
self._add_toolmenu_action('MapsList', _('Loading...'),

View File

@ -126,7 +126,7 @@ class GeoGraphyView(OsmGps, NavigationView):
def __init__(self, title, pdata, dbstate, uistate,
get_bookmarks, bm_type, nav_group):
NavigationView.__init__(self, title, pdata, dbstate, uistate,
get_bookmarks, bm_type, nav_group)
bm_type, nav_group)
self.dbstate = dbstate
self.dbstate.connect('database-changed', self.change_db)
@ -224,7 +224,6 @@ class GeoGraphyView(OsmGps, NavigationView):
is no need to store the database, since we will get the value
from self.state.db
"""
self.bookmarks.update_bookmarks(self.dbstate.db.get_bookmarks())
if self.active:
self.bookmarks.redraw()

View File

@ -142,7 +142,6 @@ class CitationListView(ListView):
self, _('Citation View'), pdata, dbstate, uistate,
len(self.COLUMNS),
CitationListModel, signal_map,
dbstate.db.get_citation_bookmarks(),
CitationBookmarks, nav_group,
multiple=True,
filter_class=CitationSidebarFilter)
@ -157,9 +156,6 @@ class CitationListView(ListView):
def navigation_type(self):
return 'Citation'
def get_bookmarks(self):
return self.dbstate.db.get_citation_bookmarks()
def drag_info(self):
return DdTargets.CITATION_LINK

View File

@ -143,7 +143,6 @@ class CitationTreeView(ListView):
self, _('Citation Tree View'), pdata, dbstate, uistate,
len(self.COLUMNS),
CitationTreeModel, signal_map,
dbstate.db.get_citation_bookmarks(),
CitationBookmarks, nav_group,
multiple=True,
filter_class=SourceSidebarFilter)
@ -221,9 +220,6 @@ class CitationTreeView(ListView):
def navigation_type(self):
return 'Citation'
def get_bookmarks(self):
return self.dbstate.db.get_citation_bookmarks()
def drag_info(self):
# Since drag only needs to work when just one row is selected, ideally,
# this should just return SOURCE_LINK if one source is selected and

View File

@ -117,7 +117,7 @@ class EventView(ListView):
self, _('Events'), pdata, dbstate, uistate,
len(EventView.COLUMNS),
EventModel,
signal_map, dbstate.db.get_event_bookmarks(),
signal_map,
EventBookmarks, nav_group,
multiple=True,
filter_class=EventSidebarFilter)
@ -134,12 +134,6 @@ class EventView(ListView):
def navigation_type(self):
return 'Event'
def get_bookmarks(self):
"""
Return the bookmark object
"""
return self.dbstate.db.get_event_bookmarks()
def drag_info(self):
"""
Indicate that the drag type is an EVENT

View File

@ -116,7 +116,7 @@ class FamilyView(ListView):
self, _('Families'), pdata, dbstate, uistate,
len(FamilyView.COLUMNS),
FamilyModel,
signal_map, dbstate.db.get_family_bookmarks(),
signal_map,
FamilyBookmarks, nav_group,
multiple=True,
filter_class=FamilySidebarFilter)
@ -227,9 +227,6 @@ class FamilyView(ListView):
ListView.set_inactive(self)
self.uistate.viewmanager.tags.tag_disable()
def get_bookmarks(self):
return self.dbstate.db.get_family_bookmarks()
def add_bookmark(self, obj):
mlist = self.selected_handles()
if mlist:

View File

@ -72,7 +72,6 @@ class FanChartDescView(fanchartdesc.FanChartDescGrampsGUI, NavigationView):
NavigationView.__init__(self, _('Descendant Fan Chart'),
pdata, dbstate, uistate,
dbstate.db.get_bookmarks(),
PersonBookmarks,
nav_group)
fanchartdesc.FanChartDescGrampsGUI.__init__(self, self.on_childmenu_changed)
@ -200,7 +199,6 @@ class FanChartDescView(fanchartdesc.FanChartDescGrampsGUI, NavigationView):
def change_db(self, db):
self._change_db(db)
self.bookmarks.update_bookmarks(self.dbstate.db.get_bookmarks())
if self.active:
self.bookmarks.redraw()
self.update()

View File

@ -71,7 +71,6 @@ class FanChartView(fanchart.FanChartGrampsGUI, NavigationView):
NavigationView.__init__(self, _('Fan Chart'),
pdata, dbstate, uistate,
dbstate.db.get_bookmarks(),
PersonBookmarks,
nav_group)
fanchart.FanChartGrampsGUI.__init__(self, self.on_childmenu_changed)
@ -198,7 +197,6 @@ class FanChartView(fanchart.FanChartGrampsGUI, NavigationView):
def change_db(self, db):
self._change_db(db)
self.bookmarks.update_bookmarks(self.dbstate.db.get_bookmarks())
if self.active:
self.bookmarks.redraw()
self.update()

View File

@ -130,7 +130,6 @@ class GeoClose(GeoGraphyView):
def __init__(self, pdata, dbstate, uistate, nav_group=0):
GeoGraphyView.__init__(self, _("Have they been able to meet?"),
pdata, dbstate, uistate,
dbstate.db.get_bookmarks(),
PersonBookmarks,
nav_group)
self.dbstate = dbstate
@ -188,12 +187,6 @@ class GeoClose(GeoGraphyView):
"""
return 'Person'
def get_bookmarks(self):
"""
Return the bookmark object
"""
return self.dbstate.db.get_bookmarks()
def goto_handle(self, handle=None):
"""
Rebuild the tree with the given person handle as the root.

View File

@ -111,7 +111,6 @@ class GeoEvents(GeoGraphyView):
def __init__(self, pdata, dbstate, uistate, nav_group=0):
GeoGraphyView.__init__(self, _('Events places map'),
pdata, dbstate, uistate,
dbstate.db.get_event_bookmarks(),
EventBookmarks,
nav_group)
self.dbstate = dbstate
@ -161,12 +160,6 @@ class GeoEvents(GeoGraphyView):
"""
return 'Event'
def get_bookmarks(self):
"""
Return the bookmark object
"""
return self.dbstate.db.get_event_bookmarks()
def goto_handle(self, handle=None):
"""
Rebuild the tree with the given events handle as the root.

View File

@ -128,7 +128,6 @@ class GeoFamClose(GeoGraphyView):
def __init__(self, pdata, dbstate, uistate, nav_group=0):
GeoGraphyView.__init__(self, _("Have these two families been able to meet?"),
pdata, dbstate, uistate,
dbstate.db.get_bookmarks(),
FamilyBookmarks,
nav_group)
self.dbstate = dbstate
@ -186,12 +185,6 @@ class GeoFamClose(GeoGraphyView):
"""
return 'Family'
def get_bookmarks(self):
"""
Return the bookmark object
"""
return self.dbstate.db.get_bookmarks()
def family_label(self,family):
if family is None:
return "Unknown"

View File

@ -111,7 +111,6 @@ class GeoFamily(GeoGraphyView):
def __init__(self, pdata, dbstate, uistate, nav_group=0):
GeoGraphyView.__init__(self, _('Family places map'),
pdata, dbstate, uistate,
dbstate.db.get_family_bookmarks(),
FamilyBookmarks,
nav_group)
self.dbstate = dbstate
@ -160,12 +159,6 @@ class GeoFamily(GeoGraphyView):
"""
return 'Family'
def get_bookmarks(self):
"""
Return the bookmark object
"""
return self.dbstate.db.get_family_bookmarks()
def goto_handle(self, handle=None):
"""
Rebuild the tree with the given person handle as the root.

View File

@ -131,7 +131,6 @@ class GeoMoves(GeoGraphyView):
def __init__(self, pdata, dbstate, uistate, nav_group=0):
GeoGraphyView.__init__(self, _("Descendance of the active person."),
pdata, dbstate, uistate,
dbstate.db.get_bookmarks(),
PersonBookmarks,
nav_group)
self.dbstate = dbstate
@ -189,12 +188,6 @@ class GeoMoves(GeoGraphyView):
"""
return 'Person'
def get_bookmarks(self):
"""
Return the bookmark object
"""
return self.dbstate.db.get_bookmarks()
def goto_handle(self, handle=None):
"""
Rebuild the tree with the given family handle as reference.

View File

@ -140,7 +140,6 @@ class GeoPerson(GeoGraphyView):
def __init__(self, pdata, dbstate, uistate, nav_group=0):
GeoGraphyView.__init__(self, _("Person places map"),
pdata, dbstate, uistate,
dbstate.db.get_bookmarks(),
PersonBookmarks,
nav_group)
self.dbstate = dbstate
@ -189,12 +188,6 @@ class GeoPerson(GeoGraphyView):
"""
return 'Person'
def get_bookmarks(self):
"""
Return the bookmark object
"""
return self.dbstate.db.get_bookmarks()
def goto_handle(self, handle=None):
"""
Rebuild the tree with the given person handle as the root.

View File

@ -111,7 +111,6 @@ class GeoPlaces(GeoGraphyView):
def __init__(self, pdata, dbstate, uistate, nav_group=0):
GeoGraphyView.__init__(self, _('Places places map'),
pdata, dbstate, uistate,
dbstate.db.get_place_bookmarks(),
PlaceBookmarks,
nav_group)
self.dbstate = dbstate
@ -161,12 +160,6 @@ class GeoPlaces(GeoGraphyView):
"""
return 'Place'
def get_bookmarks(self):
"""
Return the bookmark object
"""
return self.dbstate.db.get_place_bookmarks()
def goto_handle(self, handle=None):
"""
Rebuild the tree with the given places handle as the root.

View File

@ -139,7 +139,7 @@ class MediaView(ListView):
self, _('Media'), pdata, dbstate, uistate,
len(MediaView.COLUMNS),
MediaModel,
signal_map, dbstate.db.get_media_bookmarks(),
signal_map,
MediaBookmarks, nav_group,
filter_class=MediaSidebarFilter,
multiple=True)
@ -212,12 +212,6 @@ class MediaView(ListView):
self.dbstate.db.add_object(photo, trans)
widget.emit_stop_by_name('drag_data_received')
def get_bookmarks(self):
"""
Return the bookmarks associated with this view
"""
return self.dbstate.db.get_media_bookmarks()
def define_actions(self):
"""
Defines the UIManager actions specific to Media View. We need to make

View File

@ -111,7 +111,6 @@ class NoteView(ListView):
ListView.__init__(
self, _('Notes'), pdata, dbstate, uistate,
len(NoteView.COLUMNS), NoteModel, signal_map,
dbstate.db.get_note_bookmarks(),
NoteBookmarks, nav_group,
filter_class=NoteSidebarFilter,
multiple=True)
@ -126,12 +125,6 @@ class NoteView(ListView):
def navigation_type(self):
return 'Note'
def get_bookmarks(self):
"""
Return the bookmark object
"""
return self.dbstate.db.get_note_bookmarks()
def drag_info(self):
"""
Indicate that the drag type is an EVENT

View File

@ -520,9 +520,7 @@ class PedigreeView(NavigationView):
def __init__(self, pdata, dbstate, uistate, nav_group=0):
NavigationView.__init__(self, _('Pedigree'), pdata, dbstate, uistate,
dbstate.db.get_bookmarks(),
PersonBookmarks,
nav_group)
PersonBookmarks, nav_group)
self.func_list.update({
'F2' : self.kb_goto_home,
@ -715,7 +713,6 @@ class PedigreeView(NavigationView):
from self.state.db
"""
self._change_db(db)
self.bookmarks.update_bookmarks(self.dbstate.db.get_bookmarks())
if self.active:
self.bookmarks.redraw()
self.build_tree()

View File

@ -148,7 +148,6 @@ class RelationshipView(NavigationView):
def __init__(self, pdata, dbstate, uistate, nav_group=0):
NavigationView.__init__(self, _('Relationships'),
pdata, dbstate, uistate,
dbstate.db.get_bookmarks(),
PersonBookmarks,
nav_group)
@ -454,7 +453,6 @@ class RelationshipView(NavigationView):
list(map(self.vbox.remove, self.vbox.get_children()))
list(map(self.header.remove, self.header.get_children()))
self.child = None
self.bookmarks.update_bookmarks(db.get_bookmarks())
if self.active:
self.bookmarks.redraw()
self.redraw()

View File

@ -127,7 +127,6 @@ class RepositoryView(ListView):
self, _('Repositories'), pdata, dbstate, uistate,
len(RepositoryView.COLUMNS),
RepositoryModel, signal_map,
dbstate.db.get_repo_bookmarks(),
RepoBookmarks, nav_group,
multiple=True,
filter_class=RepoSidebarFilter)
@ -142,9 +141,6 @@ class RepositoryView(ListView):
def navigation_type(self):
return 'Repository'
def get_bookmarks(self):
return self.dbstate.db.get_repo_bookmarks()
def drag_info(self):
return DdTargets.REPO_LINK

View File

@ -114,7 +114,6 @@ class SourceView(ListView):
self, _('Sources'), pdata, dbstate, uistate,
len(SourceView.COLUMNS),
SourceModel, signal_map,
dbstate.db.get_source_bookmarks(),
SourceBookmarks, nav_group,
multiple=True,
filter_class=SourceSidebarFilter)
@ -129,9 +128,6 @@ class SourceView(ListView):
def navigation_type(self):
return 'Source'
def get_bookmarks(self):
return self.dbstate.db.get_source_bookmarks()
def drag_info(self):
return DdTargets.SOURCE_LINK