2563: Add signals for all objects when active object changes
svn: r13960
This commit is contained in:
		
							
								
								
									
										170
									
								
								src/DbState.py
									
									
									
									
									
								
							
							
						
						
									
										170
									
								
								src/DbState.py
									
									
									
									
									
								
							@@ -25,6 +25,18 @@ Provide the database state class
 | 
			
		||||
from gen.db import DbBsddbRead
 | 
			
		||||
from gen.utils import Callback
 | 
			
		||||
import config
 | 
			
		||||
from gui.views.navigationview import (NAVIGATION_PERSON, NAVIGATION_FAMILY,
 | 
			
		||||
                                      NAVIGATION_EVENT, NAVIGATION_PLACE,
 | 
			
		||||
                                      NAVIGATION_SOURCE, NAVIGATION_REPOSITORY,
 | 
			
		||||
                                      NAVIGATION_MEDIA, NAVIGATION_NOTE)
 | 
			
		||||
ACTIVE_SIGNALS = ['person-active',
 | 
			
		||||
                  'family-active',
 | 
			
		||||
                  'event-active',
 | 
			
		||||
                  'place-active',
 | 
			
		||||
                  'source-active',
 | 
			
		||||
                  'repository-active',
 | 
			
		||||
                  'media-active',
 | 
			
		||||
                  'note-active']
 | 
			
		||||
 | 
			
		||||
class DbState(Callback):
 | 
			
		||||
    """
 | 
			
		||||
@@ -32,10 +44,17 @@ class DbState(Callback):
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    __signals__ = {
 | 
			
		||||
        'database-changed' : (DbBsddbRead, ), 
 | 
			
		||||
        'active-changed'   : (str, ), 
 | 
			
		||||
        'media-changed'    : (str, ),
 | 
			
		||||
        'no-database'      :  None, 
 | 
			
		||||
        'database-changed'  : (DbBsddbRead, ), 
 | 
			
		||||
        'active-changed'    : (str, ), 
 | 
			
		||||
        'person-active'     : (str, ),
 | 
			
		||||
        'family-active'     : (str, ),
 | 
			
		||||
        'event-active'      : (str, ),
 | 
			
		||||
        'place-active'      : (str, ),
 | 
			
		||||
        'source-active'     : (str, ),
 | 
			
		||||
        'repository-active' : (str, ),
 | 
			
		||||
        'media-active'      : (str, ),
 | 
			
		||||
        'note-active'       : (str, ),
 | 
			
		||||
        'no-database'       :  None, 
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
@@ -46,7 +65,8 @@ class DbState(Callback):
 | 
			
		||||
        Callback.__init__(self)
 | 
			
		||||
        self.db      = DbBsddbRead()
 | 
			
		||||
        self.open    = False
 | 
			
		||||
        self.active  = None
 | 
			
		||||
        self.active  = None # Retained for backward compatibility.
 | 
			
		||||
        self.__active_objects = [None] * 8
 | 
			
		||||
        self.sighndl = None
 | 
			
		||||
 | 
			
		||||
    def change_active_person(self, person):
 | 
			
		||||
@@ -54,35 +74,23 @@ class DbState(Callback):
 | 
			
		||||
        Change the active person and emits a signal to notify those who
 | 
			
		||||
        are interested.
 | 
			
		||||
        """
 | 
			
		||||
        previous_active_person = self.active
 | 
			
		||||
        self.active = person
 | 
			
		||||
        print 'DbState: change_active_person is deprecated, ' + \
 | 
			
		||||
                'use set_active_person instead.'
 | 
			
		||||
        if person:
 | 
			
		||||
            if previous_active_person and previous_active_person.handle == person.handle:
 | 
			
		||||
                pass # don't change to same!
 | 
			
		||||
            else:
 | 
			
		||||
                try:
 | 
			
		||||
                    self.emit('active-changed', (person.handle, ))
 | 
			
		||||
                except:
 | 
			
		||||
                    self.emit('active-changed', ("", ))
 | 
			
		||||
            self.set_active_person(person.get_handle())
 | 
			
		||||
 | 
			
		||||
    def change_active_handle(self, handle):
 | 
			
		||||
        """
 | 
			
		||||
        Change the active person based on the person's handle
 | 
			
		||||
        """
 | 
			
		||||
        self.change_active_person(self.db.get_person_from_handle(handle))
 | 
			
		||||
 | 
			
		||||
    def get_active_person(self):
 | 
			
		||||
        """
 | 
			
		||||
        Get the current active person. Creates a new instance to make sure that
 | 
			
		||||
        the data is active.
 | 
			
		||||
        """
 | 
			
		||||
        if self.active: 
 | 
			
		||||
            self.active = self.db.get_person_from_handle(self.active.handle)
 | 
			
		||||
        return self.active
 | 
			
		||||
        print 'DbState: change_active_handle is deprecated, ' + \
 | 
			
		||||
                'use set_active_person instead.'
 | 
			
		||||
        self.set_active_person(handle)
 | 
			
		||||
 | 
			
		||||
    def change_database(self, database):
 | 
			
		||||
        """
 | 
			
		||||
        Closes the existing db, and opens a new one.
 | 
			
		||||
        Retained for backward compatibility.
 | 
			
		||||
        """
 | 
			
		||||
        self.db.close()
 | 
			
		||||
        self.change_database_noclose(database)
 | 
			
		||||
@@ -118,7 +126,8 @@ class DbState(Callback):
 | 
			
		||||
        self.db.close()
 | 
			
		||||
        self.db = DbBsddbRead()
 | 
			
		||||
        self.db.db_is_open = False
 | 
			
		||||
        self.active = None
 | 
			
		||||
        self.active = None # Retained for backward compatibility.
 | 
			
		||||
        self.__active_objects = [None] * 8
 | 
			
		||||
        self.open = False
 | 
			
		||||
        self.emit('database-changed', (self.db, ))
 | 
			
		||||
        
 | 
			
		||||
@@ -127,3 +136,114 @@ class DbState(Callback):
 | 
			
		||||
        Get a reference to the current database.
 | 
			
		||||
        """
 | 
			
		||||
        return self.db
 | 
			
		||||
 | 
			
		||||
    def set_active(self, navigation_type, handle):
 | 
			
		||||
        """
 | 
			
		||||
        Set the active handle for the given navigation type.
 | 
			
		||||
        """
 | 
			
		||||
        handle = str(handle) # This is sometimes unicode.
 | 
			
		||||
        old_handle = self.__active_objects[navigation_type]
 | 
			
		||||
        if old_handle != handle:
 | 
			
		||||
            self.__active_objects[navigation_type] = handle
 | 
			
		||||
            signal = ACTIVE_SIGNALS[navigation_type]
 | 
			
		||||
            try:
 | 
			
		||||
                self.emit(signal, (handle, ))
 | 
			
		||||
            except:
 | 
			
		||||
                self.emit(signal, ("", ))
 | 
			
		||||
 | 
			
		||||
            # Retained for backward compatibility.
 | 
			
		||||
            if navigation_type == NAVIGATION_PERSON:
 | 
			
		||||
                self.active = self.db.get_person_from_handle(handle)
 | 
			
		||||
                try:
 | 
			
		||||
                    self.emit('active-changed', (handle, ))
 | 
			
		||||
                except:
 | 
			
		||||
                    self.emit('active-changed', ("", ))
 | 
			
		||||
 | 
			
		||||
    def get_active(self, navigation_type):
 | 
			
		||||
        """
 | 
			
		||||
        Return the active handle for the given navigation type.
 | 
			
		||||
        """
 | 
			
		||||
        handle = self.__active_objects[navigation_type]
 | 
			
		||||
        if navigation_type == NAVIGATION_PERSON:
 | 
			
		||||
            return self.db.get_person_from_handle(handle)
 | 
			
		||||
        elif navigation_type == NAVIGATION_FAMILY:
 | 
			
		||||
            return self.db.get_family_from_handle(handle)
 | 
			
		||||
        elif navigation_type == NAVIGATION_EVENT:
 | 
			
		||||
            return self.db.get_event_from_handle(handle)
 | 
			
		||||
        elif navigation_type == NAVIGATION_PLACE:
 | 
			
		||||
            return self.db.get_place_from_handle(handle)
 | 
			
		||||
        elif navigation_type == NAVIGATION_SOURCE:
 | 
			
		||||
            return self.db.get_source_from_handle(handle)
 | 
			
		||||
        elif navigation_type == NAVIGATION_REPOSITORY:
 | 
			
		||||
            return self.db.get_repository_from_handle(handle)
 | 
			
		||||
        elif navigation_type == NAVIGATION_MEDIA:
 | 
			
		||||
            return self.db.get_object_from_handle(handle)
 | 
			
		||||
        elif navigation_type == NAVIGATION_NOTE:
 | 
			
		||||
            return self.db.get_note_from_handle(handle)
 | 
			
		||||
            
 | 
			
		||||
    ###########################################################################
 | 
			
		||||
    # Convenience functions
 | 
			
		||||
    ###########################################################################
 | 
			
		||||
    def set_active_person(self, handle):
 | 
			
		||||
        """Set the active person to the given handle."""
 | 
			
		||||
        self.set_active(NAVIGATION_PERSON, handle)
 | 
			
		||||
 | 
			
		||||
    def get_active_person(self):
 | 
			
		||||
        """Return the handle for the active person."""
 | 
			
		||||
        return self.get_active(NAVIGATION_PERSON)
 | 
			
		||||
        
 | 
			
		||||
    def set_active_family(self, handle):
 | 
			
		||||
        """Set the active family to the given handle."""
 | 
			
		||||
        self.set_active(NAVIGATION_FAMILY, handle)
 | 
			
		||||
 | 
			
		||||
    def get_active_family(self):
 | 
			
		||||
        """Return the handle for the active family."""
 | 
			
		||||
        return self.get_active(NAVIGATION_FAMILY)
 | 
			
		||||
        
 | 
			
		||||
    def set_active_event(self, handle):
 | 
			
		||||
        """Set the active event to the given handle."""
 | 
			
		||||
        self.set_active(NAVIGATION_EVENT, handle)
 | 
			
		||||
 | 
			
		||||
    def get_active_event(self):
 | 
			
		||||
        """Return the handle for the active event."""
 | 
			
		||||
        return self.get_active(NAVIGATION_EVENT)
 | 
			
		||||
        
 | 
			
		||||
    def set_active_place(self, handle):
 | 
			
		||||
        """Set the active place to the given handle."""
 | 
			
		||||
        self.set_active(NAVIGATION_PLACE, handle)
 | 
			
		||||
 | 
			
		||||
    def get_active_place(self):
 | 
			
		||||
        """Return the handle for the active place."""
 | 
			
		||||
        return self.get_active(NAVIGATION_PLACE)
 | 
			
		||||
        
 | 
			
		||||
    def set_active_source(self, handle):
 | 
			
		||||
        """Set the active source to the given handle."""
 | 
			
		||||
        self.set_active(NAVIGATION_SOURCE, handle)
 | 
			
		||||
 | 
			
		||||
    def get_active_source(self):
 | 
			
		||||
        """Return the handle for the active source."""
 | 
			
		||||
        return self.get_active(NAVIGATION_SOURCE)
 | 
			
		||||
        
 | 
			
		||||
    def set_active_repository(self, handle):
 | 
			
		||||
        """Set the active repository to the given handle."""
 | 
			
		||||
        self.set_active(NAVIGATION_REPOSITORY, handle)
 | 
			
		||||
 | 
			
		||||
    def get_active_repository(self):
 | 
			
		||||
        """Return the handle for the active repository."""
 | 
			
		||||
        return self.get_active(NAVIGATION_REPOSITORY)
 | 
			
		||||
        
 | 
			
		||||
    def set_active_media(self, handle):
 | 
			
		||||
        """Set the active media to the given handle."""
 | 
			
		||||
        self.set_active(NAVIGATION_MEDIA, handle)
 | 
			
		||||
 | 
			
		||||
    def get_active_media(self):
 | 
			
		||||
        """Return the handle for the active media."""
 | 
			
		||||
        return self.get_active(NAVIGATION_MEDIA)
 | 
			
		||||
        
 | 
			
		||||
    def set_active_note(self, handle):
 | 
			
		||||
        """Set the active note to the given handle."""
 | 
			
		||||
        self.set_active(NAVIGATION_NOTE, handle)
 | 
			
		||||
 | 
			
		||||
    def get_active_note(self):
 | 
			
		||||
        """Return the handle for the active note."""
 | 
			
		||||
        return self.get_active(NAVIGATION_NOTE)
 | 
			
		||||
 
 | 
			
		||||
@@ -160,12 +160,7 @@ class NavigationView(PageView):
 | 
			
		||||
        """
 | 
			
		||||
        Changes the active object.
 | 
			
		||||
        """
 | 
			
		||||
        if self.navigation_type() == NAVIGATION_PERSON:
 | 
			
		||||
            if handle is None:
 | 
			
		||||
                self.dbstate.change_active_person(None)
 | 
			
		||||
            else:
 | 
			
		||||
                person = self.dbstate.db.get_person_from_handle(handle)
 | 
			
		||||
                self.dbstate.change_active_person(person)
 | 
			
		||||
        self.dbstate.set_active(self.navigation_type(), handle)
 | 
			
		||||
 | 
			
		||||
    def goto_handle(self, handle):
 | 
			
		||||
        """
 | 
			
		||||
 
 | 
			
		||||
@@ -336,7 +336,6 @@ class MediaView(ListView):
 | 
			
		||||
            pix = ThumbNails.get_thumbnail_image(
 | 
			
		||||
                        Utils.media_path_full(self.dbstate.db, obj.get_path()))
 | 
			
		||||
            self.image.set_from_pixbuf(pix)
 | 
			
		||||
            self.dbstate.emit('media-changed', (handle, ))
 | 
			
		||||
 | 
			
		||||
    def ui_definition(self):
 | 
			
		||||
        """
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user