Start with fix up of connects to db in relationview.
Fix calling method of signals to a shorter algorithm based on lambda func svn: r13115
This commit is contained in:
parent
3d13046fa0
commit
43663bbee7
@ -123,7 +123,6 @@ class RelationshipView(PageView.PersonNavView):
|
||||
dbstate.connect('database-changed', self.change_db)
|
||||
self.show_siblings = Config.get(Config.FAMILY_SIBLINGS)
|
||||
self.show_details = Config.get(Config.FAMILY_DETAILS)
|
||||
self.connect_to_db(dbstate.db)
|
||||
self.redrawing = False
|
||||
self.use_shade = Config.get(Config.RELATION_SHADE)
|
||||
self.toolbar_visible = Config.get(Config.TOOLBAR_ON)
|
||||
@ -141,6 +140,23 @@ class RelationshipView(PageView.PersonNavView):
|
||||
self.reorder_sensitive = False
|
||||
self.collapsed_items = {}
|
||||
|
||||
def _connect_db_signals(self):
|
||||
"""
|
||||
implement from base class DbGUIElement
|
||||
Register the callbacks we need.
|
||||
"""
|
||||
# Add a signal to pick up event changes, bug #1416
|
||||
self.callman.add_db_signal('event-update', self.family_update)
|
||||
|
||||
self.callman.add_db_signal('person-update', self.person_update)
|
||||
self.callman.add_db_signal('person-rebuild', self.person_rebuild)
|
||||
self.callman.add_db_signal('family-update', self.family_update)
|
||||
self.callman.add_db_signal('family-add', self.family_add)
|
||||
self.callman.add_db_signal('family-delete', self.family_delete)
|
||||
self.callman.add_db_signal('family-rebuild', self.family_rebuild)
|
||||
|
||||
self.callman.add_db_signal('person-delete', self.redraw)
|
||||
|
||||
def set_active(self):
|
||||
PageView.PersonNavView.set_active(self)
|
||||
self.key_active_changed = self.dbstate.connect('active-changed',
|
||||
@ -162,17 +178,6 @@ class RelationshipView(PageView.PersonNavView):
|
||||
|
||||
def build_tree(self):
|
||||
self.redraw()
|
||||
|
||||
def connect_to_db(self, db):
|
||||
# Add a signal to pick up event changes, bug #1416
|
||||
db.connect('event-update', self.family_update)
|
||||
|
||||
db.connect('person-update', self.person_update)
|
||||
db.connect('person-rebuild', self.person_rebuild)
|
||||
db.connect('family-update', self.family_update)
|
||||
db.connect('family-add', self.family_add)
|
||||
db.connect('family-delete', self.family_delete)
|
||||
db.connect('family-rebuild', self.family_rebuild)
|
||||
|
||||
def person_update(self, handle_list):
|
||||
if self.dbstate.active:
|
||||
@ -372,19 +377,14 @@ class RelationshipView(PageView.PersonNavView):
|
||||
Config.set(Config.FAMILY_DETAILS, self.show_details)
|
||||
|
||||
def change_db(self, db):
|
||||
self.connect_to_db(db)
|
||||
#reset the connects
|
||||
self._change_db(db)
|
||||
if self.child:
|
||||
for old_child in self.vbox.get_children():
|
||||
self.vbox.remove(old_child)
|
||||
for old_child in self.header.get_children():
|
||||
self.header.remove(old_child)
|
||||
self.child = None
|
||||
self.dbstate.db.connect('family-update', self.redraw)
|
||||
self.dbstate.db.connect('family-add', self.redraw)
|
||||
self.dbstate.db.connect('family-delete', self.redraw)
|
||||
self.dbstate.db.connect('person-update', self.redraw)
|
||||
self.dbstate.db.connect('person-add', self.redraw)
|
||||
self.dbstate.db.connect('person-delete', self.redraw)
|
||||
self.bookmarks.update_bookmarks(db.get_bookmarks())
|
||||
if self.active:
|
||||
self.bookmarks.redraw()
|
||||
|
@ -55,6 +55,7 @@ import Errors
|
||||
from Filters import SearchBar
|
||||
import Utils
|
||||
from gui.utils import add_menuitem
|
||||
from gui.dbguielement import DbGUIElement
|
||||
import const
|
||||
from widgets.menutoolbuttonaction import MenuToolButtonAction
|
||||
|
||||
@ -69,7 +70,7 @@ NAVIGATION_PERSON = 0
|
||||
# PageView
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
class PageView(object):
|
||||
class PageView(DbGUIElement):
|
||||
"""
|
||||
The PageView class is the base class for all Data Views in GRAMPS. All
|
||||
Views should derive from this class. The ViewManager understands the public
|
||||
@ -97,6 +98,7 @@ class PageView(object):
|
||||
self.handle_col = 0
|
||||
self.selection = None
|
||||
self.func_list = {}
|
||||
DbGUIElement.__init__(self, dbstate.db)
|
||||
|
||||
def call_function(self, key):
|
||||
"""
|
||||
@ -1006,8 +1008,9 @@ class ListView(BookMarkView):
|
||||
return
|
||||
|
||||
def change_db(self, db):
|
||||
self._cleanup_callbacks()
|
||||
for sig in self.signal_map:
|
||||
db.connect(sig, self.signal_map[sig])
|
||||
self.callman.add_db_signal(sig, self.signal_map[sig])
|
||||
self.bookmarks.update_bookmarks(self.get_bookmarks())
|
||||
if self.active:
|
||||
#force rebuild of the model on build of tree
|
||||
|
@ -242,12 +242,19 @@ class CallbackManager(object):
|
||||
if keys is None:
|
||||
return
|
||||
for key in keys:
|
||||
for method in METHODS:
|
||||
for method in METHODS_LIST:
|
||||
signal = key + method
|
||||
self.__do_unconnect(signal)
|
||||
self.__callbacks[signal][1] = self.database.connect(
|
||||
signal,
|
||||
self.__callbackcreator(key, signal))
|
||||
self.__callbackcreator(signal))
|
||||
for method in METHODS_NONE:
|
||||
signal = key + method
|
||||
self.__do_unconnect(signal)
|
||||
self.__callbacks[signal][1] = self.database.connect(
|
||||
signal,
|
||||
self.__callbackcreator(signal,
|
||||
noarg=True))
|
||||
|
||||
def __do_callback(self, signal, *arg):
|
||||
"""
|
||||
@ -291,107 +298,33 @@ class CallbackManager(object):
|
||||
"""
|
||||
self.custom_signal_keys.append(self.database.connect(name, callback))
|
||||
|
||||
def __callbackcreator(self, key, signal):
|
||||
def __callbackcreator(self, signal, noarg=False):
|
||||
"""
|
||||
helper function, a lambda function needs a string to be defined
|
||||
explicitly. This function creates the correct lambda function to use
|
||||
as callback based on the key/signal one needs to connect to.
|
||||
AttributeError is raised for unknown key or signal.
|
||||
"""
|
||||
if key == PERSONKEY:
|
||||
if signal == 'person-update':
|
||||
return lambda arg: self.__do_callback('person-update', *(arg,))
|
||||
elif signal == 'person-add':
|
||||
return lambda arg: self.__do_callback('person-add', *(arg,))
|
||||
elif signal == 'person-delete':
|
||||
return lambda arg: self.__do_callback('person-delete', *(arg,))
|
||||
elif signal == 'person-rebuild':
|
||||
return lambda *arg: self.__do_callback('person-rebuild')
|
||||
def gen(self, signal):
|
||||
"""
|
||||
Generate lambda function that does call with an argument
|
||||
"""
|
||||
return lambda arg: self.__do_callback(signal, *(arg,))
|
||||
|
||||
def gen_noarg(self, signal):
|
||||
"""
|
||||
Generate lambda function that does call without argument
|
||||
"""
|
||||
return lambda *arg: self.__do_callback(signal)
|
||||
|
||||
if signal in self.__callbacks:
|
||||
if noarg:
|
||||
return gen_noarg(self, signal)
|
||||
else:
|
||||
raise AttributeError, 'Signal ' + signal + 'not supported.'
|
||||
elif key == FAMILYKEY:
|
||||
if signal == 'family-update':
|
||||
return lambda arg: self.__do_callback('family-update', *(arg,))
|
||||
elif signal == 'family-add':
|
||||
return lambda arg: self.__do_callback('family-add', *(arg,))
|
||||
elif signal == 'family-delete':
|
||||
return lambda arg: self.__do_callback('family-delete', *(arg,))
|
||||
elif signal == 'family-rebuild':
|
||||
return lambda *arg: self.__do_callback('family-rebuild')
|
||||
else:
|
||||
raise AttributeError, 'Signal ' + signal + 'not supported.'
|
||||
elif key == EVENTKEY:
|
||||
if signal == 'event-update':
|
||||
return lambda arg: self.__do_callback('event-update', *(arg,))
|
||||
elif signal == 'event-add':
|
||||
return lambda arg: self.__do_callback('event-add', *(arg,))
|
||||
elif signal == 'event-delete':
|
||||
return lambda arg: self.__do_callback('event-delete', *(arg,))
|
||||
elif signal == 'event-rebuild':
|
||||
return lambda *arg: self.__do_callback('event-rebuild')
|
||||
else:
|
||||
raise AttributeError, 'Signal ' + signal + 'not supported.'
|
||||
elif key == PLACEKEY:
|
||||
if signal == 'place-update':
|
||||
return lambda arg: self.__do_callback('place-update', *(arg,))
|
||||
elif signal == 'place-add':
|
||||
return lambda arg: self.__do_callback('place-add', *(arg,))
|
||||
elif signal == 'place-delete':
|
||||
return lambda arg: self.__do_callback('place-delete', *(arg,))
|
||||
elif signal == 'place-rebuild':
|
||||
return lambda *arg: self.__do_callback('place-rebuild')
|
||||
else:
|
||||
raise AttributeError, 'Signal ' + signal + 'not supported.'
|
||||
elif key == SOURCEKEY:
|
||||
if signal == 'source-update':
|
||||
return lambda arg: self.__do_callback('source-update', *(arg,))
|
||||
elif signal == 'source-add':
|
||||
return lambda arg: self.__do_callback('source-add', *(arg,))
|
||||
elif signal == 'source-delete':
|
||||
return lambda arg: self.__do_callback('source-delete', *(arg,))
|
||||
elif signal == 'source-rebuild':
|
||||
return lambda *arg: self.__do_callback('source-rebuild')
|
||||
else:
|
||||
raise AttributeError, 'Signal ' + signal + 'not supported.'
|
||||
elif key == REPOKEY:
|
||||
if signal == 'repository-update':
|
||||
return lambda arg: self.__do_callback('repository-update',
|
||||
*(arg,))
|
||||
elif signal == 'repository-add':
|
||||
return lambda arg: self.__do_callback('repository-add',
|
||||
*(arg,))
|
||||
elif signal == 'repository-delete':
|
||||
return lambda arg: self.__do_callback('repository-delete',
|
||||
*(arg,))
|
||||
elif signal == 'repository-rebuild':
|
||||
return lambda *arg: self.__do_callback('repository-rebuild')
|
||||
else:
|
||||
raise AttributeError, 'Signal ' + signal + 'not supported.'
|
||||
elif key == MEDIAKEY:
|
||||
if signal == 'media-update':
|
||||
return lambda arg: self.__do_callback('media-update', *(arg,))
|
||||
elif signal == 'media-add':
|
||||
return lambda arg: self.__do_callback('media-add', *(arg,))
|
||||
elif signal == 'media-delete':
|
||||
return lambda arg: self.__do_callback('media-delete', *(arg,))
|
||||
elif signal == 'media-rebuild':
|
||||
return lambda *arg: self.__do_callback('media-rebuild')
|
||||
else:
|
||||
raise AttributeError, 'Signal ' + signal + 'not supported.'
|
||||
elif key == NOTEKEY:
|
||||
if signal == 'note-update':
|
||||
return lambda arg: self.__do_callback('note-update', *(arg,))
|
||||
elif signal == 'note-add':
|
||||
return lambda arg: self.__do_callback('note-add', *(arg,))
|
||||
elif signal == 'note-delete':
|
||||
return lambda arg: self.__do_callback('note-delete', *(arg,))
|
||||
elif signal == 'note-rebuild':
|
||||
return lambda *arg: self.__do_callback('note-rebuild')
|
||||
else:
|
||||
raise AttributeError, 'Signal ' + signal + 'not supported.'
|
||||
return gen(self, signal)
|
||||
else:
|
||||
raise AttributeError, 'Signal ' + signal + 'not supported.'
|
||||
|
||||
|
||||
def directhandledict(baseobj):
|
||||
"""
|
||||
Build a handledict from baseobj with all directly referenced objects
|
||||
|
@ -74,7 +74,8 @@ class DbGUIElement(object):
|
||||
def _connect_db_signals(self):
|
||||
"""
|
||||
Convenience method that is called on initialization of DbGUIElement.
|
||||
Use this to group setup of the callman attribute
|
||||
Use this to group setup of the callman attribute.
|
||||
Also called in _change_db method
|
||||
"""
|
||||
pass
|
||||
|
||||
@ -85,5 +86,23 @@ class DbGUIElement(object):
|
||||
normally needed earlier, calling this method does so.
|
||||
"""
|
||||
database = self.callman.database
|
||||
self.callman.disconnect_all()
|
||||
if database.is_open():
|
||||
#a closed database has disconnected all signals
|
||||
self.callman.disconnect_all()
|
||||
#set a new callback manager
|
||||
self.callman = CallbackManager(database)
|
||||
|
||||
def _change_db(self, database):
|
||||
"""
|
||||
Change the database the GUI element works on to database.
|
||||
This removes all callbacks and all registered handles.
|
||||
|
||||
:param database: the new database to connect to
|
||||
"""
|
||||
dbold = self.callman.database
|
||||
if dbold.is_open():
|
||||
#a closed database has disconnected all signals
|
||||
self.callman.disconnect_all()
|
||||
#set a new callback manager on new database
|
||||
self.callman = CallbackManager(database)
|
||||
self._connect_db_signals()
|
||||
|
Loading…
Reference in New Issue
Block a user