* src/GrampsDb/_GrampsDbBase.py: convert DbState to its own file

* src/GrampsDb/__init__.py: convert DbState to its own file
	* src/DbState.py: convert DbState to its own file
	* src/gramps_main.py: convert DbState to its own file
	* src/Makefile.am: convert DbState to its own file


svn: r8041
This commit is contained in:
Don Allingham 2007-02-04 01:18:17 +00:00
parent 0113bb454a
commit 798a975bce
6 changed files with 113 additions and 77 deletions

View File

@ -1,4 +1,9 @@
2007-02-03 Don Allingham <don@gramps-project.org>
* src/GrampsDb/_GrampsDbBase.py: convert DbState to its own file
* src/GrampsDb/__init__.py: convert DbState to its own file
* src/DbState.py: convert DbState to its own file
* src/gramps_main.py: convert DbState to its own file
* src/Makefile.am: convert DbState to its own file
* configure.in: update version, process new Makefile.am files
* src/GrampsDb/Makefile.am: update
* src/Makefile.am: update

88
src/DbState.py Normal file
View File

@ -0,0 +1,88 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""
Provides the database state class
"""
__author__ = "Donald N. Allingham"
__revision__ = "$Revision: 8032 $"
from GrampsDb import GrampsDBCallback, GrampsDbBase
import Config
class DbState(GrampsDBCallback):
__signals__ = {
'database-changed' : (GrampsDbBase, ),
'active-changed' : (str, ),
'no-database' : None,
}
def __init__(self):
GrampsDBCallback.__init__(self)
self.db = GrampsDbBase()
self.open = False
self.active = None
def change_active_person(self, person):
self.active = person
if person:
try:
self.emit('active-changed', (person.handle, ))
except:
self.emit('active-changed', ("", ))
def change_active_handle(self, handle):
self.change_active_person(self.db.get_person_from_handle(handle))
def get_active_person(self):
if self.active: # Fetch a fresh version from DB to not return a stale one
self.active = self.db.get_person_from_handle(self.active.handle)
return self.active
def change_database(self, database):
self.db.close()
self.change_database_noclose(database)
def change_database_noclose(self, database):
self.db = database
self.db.set_prefixes(
Config.get(Config.IPREFIX),
Config.get(Config.OPREFIX),
Config.get(Config.FPREFIX),
Config.get(Config.SPREFIX),
Config.get(Config.PPREFIX),
Config.get(Config.EPREFIX),
Config.get(Config.RPREFIX))
self.active = None
self.open = True
def signal_change(self):
self.emit('database-changed', (self.db, ))
def no_database(self):
self.db.close()
self.db = GrampsDbBase()
self.active = None
self.open = False
self.emit('no-database')

View File

@ -215,25 +215,13 @@ class GrampsDbBase(GrampsDBCallback):
GrampsDBCallback.__init__(self)
# If we have the gramps Config module available
# then use it to get the prefix values, if
# not then just use the default values.
if self.__class__.__config__ != None:
IPREFIX = Config.get(Config.IPREFIX)
OPREFIX = Config.get(Config.OPREFIX)
FPREFIX = Config.get(Config.FPREFIX)
SPREFIX = Config.get(Config.SPREFIX)
PPREFIX = Config.get(Config.PPREFIX)
EPREFIX = Config.get(Config.EPREFIX)
RPREFIX = Config.get(Config.RPREFIX)
else:
FPREFIX = 'F%04d'
EPREFIX = 'E%04d'
RPREFIX = 'R%04d'
IPREFIX = 'I%04d'
OPREFIX = 'O%04d'
PPREFIX = 'P%04d'
SPREFIX = 'S%04d'
self.set_person_id_prefix('I%04d')
self.set_object_id_prefix('O%04d')
self.set_family_id_prefix('F%04d')
self.set_source_id_prefix('S%04d')
self.set_place_id_prefix('P%04d')
self.set_event_id_prefix('E%04d')
self.set_repository_id_prefix('R%04d')
self.readonly = False
self.rand = random.Random(time.time())
@ -260,14 +248,6 @@ class GrampsDbBase(GrampsDBCallback):
self.url_types = set()
self.media_attributes = set()
self.set_person_id_prefix(IPREFIX)
self.set_object_id_prefix(OPREFIX)
self.set_family_id_prefix(FPREFIX)
self.set_source_id_prefix(SPREFIX)
self.set_place_id_prefix(PPREFIX)
self.set_event_id_prefix(EPREFIX)
self.set_repository_id_prefix(RPREFIX)
self.open = 0
self.genderStats = GenderStats()
@ -312,6 +292,15 @@ class GrampsDbBase(GrampsDBCallback):
self.name_group = {}
self.surname_list = []
def set_prefixes(self, person, media, family, source, place, event, repository):
self.iprefix = person
self.oprefix = media
self.fprefix = family
self.sprefix = source
self.pprefix = place
self.eprefix = event
self.rprefix = repository
def rebuild_secondary(self, callback):
pass
@ -2307,51 +2296,3 @@ class Transaction:
return self.last - self.first + 1
return 0
class DbState(GrampsDBCallback):
__signals__ = {
'database-changed' : (GrampsDbBase, ),
'active-changed' : (str, ),
'no-database' : None,
}
def __init__(self):
GrampsDBCallback.__init__(self)
self.db = GrampsDbBase()
self.open = False
self.active = None
def change_active_person(self, person):
self.active = person
if person:
try:
self.emit('active-changed', (person.handle, ))
except:
self.emit('active-changed', ("", ))
def change_active_handle(self, handle):
self.change_active_person(self.db.get_person_from_handle(handle))
def get_active_person(self):
if self.active: # Fetch a fresh version from DB to not return a stale one
self.active = self.db.get_person_from_handle(self.active.handle)
return self.active
def change_database(self, database):
self.db.close()
self.change_database_noclose(database)
def change_database_noclose(self, database):
self.db = database
self.active = None
self.open = True
def signal_change(self):
self.emit('database-changed', (self.db, ))
def no_database(self):
self.db.close()
self.db = GrampsDbBase()
self.active = None
self.open = False
self.emit('no-database')

View File

@ -38,7 +38,7 @@ the database objects. Read the comments in _GrampsDBCallback.py for more
information.
"""
from _GrampsDbBase import DbState, GrampsDbBase
from _GrampsDbBase import GrampsDbBase
from _GrampsDbFactories import \
gramps_db_factory

View File

@ -42,6 +42,7 @@ gdir_PYTHON = \
DateEdit.py\
Date.py\
DbLoader.py\
DbState.py\
DdTargets.py\
DisplayState.py\
Errors.py\

View File

@ -52,6 +52,7 @@ import const
import Errors
import TipOfDay
import DataViews
import DbState
from Mime import mime_type_is_defined
from QuestionDialog import ErrorDialog
@ -218,7 +219,7 @@ class Gramps:
register_stock_icons()
state = GrampsDb.DbState()
state = DbState.DbState()
self.vm = ViewManager.ViewManager(state)
for view in DataViews.get_views():
self.vm.register_view(view)