gramps/src/gramps_main.py

240 lines
9.4 KiB
Python
Raw Normal View History

#
2002-10-20 19:55:16 +05:30
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2001-2006 Donald N. Allingham
2002-10-20 19:55:16 +05:30
#
# 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
#
# $Id$
#-------------------------------------------------------------------------
#
# GTK+/GNOME modules
#
#-------------------------------------------------------------------------
2002-10-20 19:55:16 +05:30
import gtk
import logging
2006-04-26 07:14:03 +05:30
import os
log = logging.getLogger(".")
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
import ViewManager
import GrampsDb
import ArgHandler
2006-03-03 05:40:52 +05:30
import Config
2002-10-20 19:55:16 +05:30
import GrampsCfg
import const
import Errors
import TipOfDay
2006-03-04 21:07:04 +05:30
import DataViews
2006-03-03 05:53:04 +05:30
from Mime import mime_type_is_defined
from QuestionDialog import ErrorDialog
from gettext import gettext as _
2002-10-20 19:55:16 +05:30
2006-03-04 05:18:11 +05:30
iconpaths = [const.image_dir,"."]
def register_stock_icons ():
import os
2005-08-12 08:05:27 +05:30
items = [
2006-03-04 05:18:11 +05:30
(os.path.join(const.image_dir,'person.svg'),
2006-03-05 04:23:46 +05:30
('gramps-person',_('Person'),gtk.gdk.CONTROL_MASK,0,'')),
2006-03-04 05:18:11 +05:30
(os.path.join(const.image_dir,'relation.svg'),
2006-03-05 04:23:46 +05:30
('gramps-family',_('Relationships'),gtk.gdk.CONTROL_MASK,0,'')),
2006-03-04 05:18:11 +05:30
(os.path.join(const.image_dir,'flist.svg'),
2006-03-05 04:23:46 +05:30
('gramps-family-list',_('Family List'),gtk.gdk.CONTROL_MASK,0,'')),
(os.path.join(const.image_dir,'media.svg'),
('gramps-media',_('Media'),gtk.gdk.CONTROL_MASK,0,'')),
2006-03-04 05:18:11 +05:30
(os.path.join(const.image_dir,'ped24.png'),
2006-03-05 04:23:46 +05:30
('gramps-pedigree',_('Pedigree'),gtk.gdk.CONTROL_MASK,0,'')),
2006-03-04 05:18:11 +05:30
(os.path.join(const.image_dir,'repos.png'),
2006-03-05 04:23:46 +05:30
('gramps-repository',_('Repositories'),gtk.gdk.CONTROL_MASK,0,'')),
2006-03-04 05:18:11 +05:30
(os.path.join(const.image_dir,'sources.png'),
2006-03-05 04:23:46 +05:30
('gramps-source',_('Sources'),gtk.gdk.CONTROL_MASK,0,'')),
2006-03-04 05:18:11 +05:30
(os.path.join(const.image_dir,'events.png'),
2006-03-05 04:23:46 +05:30
('gramps-event',_('Events'),gtk.gdk.CONTROL_MASK,0,'')),
2006-03-04 05:18:11 +05:30
(os.path.join(const.image_dir,'place.png'),
2006-03-05 04:23:46 +05:30
('gramps-place',_('Places'),gtk.gdk.CONTROL_MASK,0,'')),
2006-03-04 05:18:11 +05:30
(os.path.join(const.image_dir,'place.png'),
2006-03-05 04:23:46 +05:30
('gramps-map',_('Map'),gtk.gdk.CONTROL_MASK,0,'')),
2005-08-12 08:05:27 +05:30
]
# Register our stock items
2005-08-12 08:05:27 +05:30
gtk.stock_add (map(lambda x: x[1],items))
# Add our custom icon factory to the list of defaults
factory = gtk.IconFactory ()
factory.add_default ()
2005-08-12 08:05:27 +05:30
for (key,data) in items:
for dirname in iconpaths:
icon_file = os.path.expanduser(os.path.join(dirname,key))
if os.path.isfile(icon_file):
2006-03-05 04:23:46 +05:30
try:
pixbuf = gtk.gdk.pixbuf_new_from_file (icon_file)
break
except:
pass
else:
2006-03-04 05:18:11 +05:30
icon_file = os.path.join(const.image_dir,'gramps.png')
2006-03-05 04:23:46 +05:30
pixbuf = gtk.gdk.pixbuf_new_from_file (icon_file)
pixbuf = pixbuf.add_alpha(True, chr(0xff), chr(0xff), chr(0xff))
2006-03-05 04:23:46 +05:30
icon_set = gtk.IconSet (pixbuf)
factory.add (data[0], icon_set)
2006-04-26 07:14:03 +05:30
def build_user_paths():
user_paths = [const.home_dir,
os.path.join(const.home_dir,"filters"),
os.path.join(const.home_dir,"plugins"),
os.path.join(const.home_dir,"templates"),
os.path.join(const.home_dir,"thumb")]
for path in user_paths:
if not os.path.isdir(path):
os.mkdir(path)
class Gramps:
"""
Main class corresponding to a running gramps process.
There can be only one instance of this class per gramps application
process. It may spawn several windows and control several databases.
"""
2002-10-20 19:55:16 +05:30
2003-05-17 09:44:13 +05:30
def __init__(self,args):
try:
2006-04-26 07:14:03 +05:30
build_user_paths()
self.welcome()
except OSError, msg:
ErrorDialog(_("Configuration error"),str(msg))
return
except Errors.GConfSchemaError, val:
ErrorDialog(_("Configuration error"),str(val) +
_("\n\nPossibly the installation of GRAMPS "
"was incomplete. Make sure the GConf schema "
"of GRAMPS is properly installed."))
gtk.main_quit()
return
except:
log.error("Error reading configuration.", exc_info=True)
return
if not mime_type_is_defined(const.app_gramps):
ErrorDialog(_("Configuration error"),
_("A definition for the MIME-type %s could not "
"be found \n\nPossibly the installation of GRAMPS "
"was incomplete. Make sure the MIME-types "
"of GRAMPS are properly installed.")
% const.app_gramps)
gtk.main_quit()
return
2002-10-20 19:55:16 +05:30
register_stock_icons()
state = GrampsDb.DbState()
self.vm = ViewManager.ViewManager(state)
2006-03-04 21:07:04 +05:30
for view in DataViews.get_views():
self.vm.register_view(view)
ArgHandler.ArgHandler(state,self.vm,args)
self.vm.init_interface()
state.db.request_rebuild()
2005-08-13 00:30:43 +05:30
state.change_active_person(state.db.get_default_person())
# Don't show main window until ArgHandler is done.
2004-06-22 04:54:51 +05:30
# This prevents a window from annoyingly popping up when
# the command line args are sufficient to operate without it.
2006-03-03 05:40:52 +05:30
Config.client.notify_add("/apps/gramps/researcher",
self.researcher_key_update)
2006-03-03 05:40:52 +05:30
Config.client.notify_add("/apps/gramps/interface/statusbar",
self.statusbar_key_update)
Config.client.notify_add("/apps/gramps/interface/toolbar",
self.toolbar_key_update)
2006-03-03 05:40:52 +05:30
# Config.client.notify_add("/apps/gramps/interface/toolbar-on",
# self.toolbar_on_key_update)
2006-03-03 05:40:52 +05:30
# Config.client.notify_add("/apps/gramps/interface/filter",
# self.filter_key_update)
2006-03-03 05:40:52 +05:30
# Config.client.notify_add("/apps/gramps/interface/view",
# self.sidebar_key_update)
2006-03-03 05:40:52 +05:30
# Config.client.notify_add("/apps/gramps/preferences/name-format",
# self.familyview_key_update)
2006-03-03 05:40:52 +05:30
# Config.client.notify_add("/apps/gramps/preferences/date-format",
# self.date_format_key_update)
2006-04-25 02:34:01 +05:30
if Config.get(Config.USE_TIPS):
TipOfDay.TipOfDay(self.vm.uistate)
## # FIXME: THESE will have to be added (ViewManager?)
## # once bookmarks work again
## self.db.set_researcher(GrampsCfg.get_researcher())
## self.db.connect('person-delete',self.on_remove_bookmark)
## self.db.connect('person-update',self.on_update_bookmark)
def welcome(self):
2006-04-30 06:55:56 +05:30
if not Config.get(Config.BETAWARN):
from QuestionDialog import WarningDialog
WarningDialog(
_('Danger: This is unstable code!'),
_("The GRAMPS 2.1 release is an early, experimental "
"branch of the future 2.2 release. This version is "
"not meant for normal usage. Use at your own risk.\n\n"
"This version may:\n1) Fail to run properly\n"
"2) Corrupt your data\n3) Cause your hair to turn "
"pink and fall out.\n\nAny databases opened by this "
"version will <b>NO LONGER WORK</b> in older versions of "
"GRAMPS, and <b>MAY NOT WORK</b> in with future "
"releases of GRAMPS. <b>BACKUP</b> your existing databases "
"before opening them with this version, and make "
"sure to export your data to XML every now and then."))
Config.set(Config.AUTOLOAD,False)
Config.set(Config.BETAWARN,True)
2006-03-29 10:18:50 +05:30
return
def researcher_key_update(self,client,cnxn_id,entry,data):
pass
2006-04-25 02:34:01 +05:30
# self.db.set_person_id_prefix(Config.get(Config.IPREFIX))
# self.db.set_family_id_prefix(Config.get(Config.FPREFIX))
# self.db.set_source_id_prefix(Config.get(Config.SPREFIX))
# self.db.set_object_id_prefix(Config.get(Config.OPREFIX))
# self.db.set_place_id_prefix(Config.get(Config.PPREFIX))
# self.db.set_event_id_prefix(Config.get(Config.EPREFIX))
* src/data/gramps.schemas: Cleanup. * src/data/Makefile.am: Clen up install rule. Add uninstall rule. * src/StartupDialog.py: Correct use of keys. * src/GrampsCfg.py: Correct usage of gconf. * src/DbPrompter.py: Remove unused module. * src/SelectChild.py: Remove unused module. * src/SelectObject.py: Remove unused module. * src/WriteXML.py: Remove unused module. * src/gramps_main.py: Convert to new gconf usage. * src/FamilyView.py: Convert to new gconf usage. * src/AddSpouse.py: Convert to new gconf usage. * src/ChooseParents.py: Convert to new gconf usage. * src/EditPerson.py: Convert to new gconf usage. * src/EditPlace.py: Convert to new gconf usage. * src/EditSource.py: Convert to new gconf usage. * src/EventEdit.py: Convert to new gconf usage. * src/ImageSelect.py: Convert to new gconf usage. * src/Marriage.py: Convert to new gconf usage. * src/MediaView.py: Convert to new gconf usage. * src/MergeData.py: Convert to new gconf usage. * src/PedView.py: Convert to new gconf usage. * src/Plugins.py: Convert to new gconf usage. * src/RelLib.py: Convert to new gconf usage. * src/TipOfDay.py: Convert to new gconf usage. * src/plugins/AncestorChart2.py: Remove unused module. * src/plugins/AncestorChart.py: Remove unused module. * src/plugins/BookReport.py: Remove unused module. * src/plugins/FanChart.py: Remove unused module. * src/plugins/Partition.py: Remove unused module. * src/plugins/Desbrowser.py: Convert to new gconf usage. * src/plugins/Merge.py: Convert to new gconf usage. * src/plugins/RelCalc.py: Convert to new gconf usage. * src/plugins/WebPage.py: Convert to new gconf usage. svn: r3274
2004-07-15 08:24:04 +05:30
def statusbar_key_update(self,client,cnxn_id,entry,data):
self.vm.uistate.modify_statusbar()
def toolbar_key_update(self,client,cnxn_id,entry,data):
2006-04-25 02:34:01 +05:30
the_style = Config.get(Config.TOOLBAR)
if the_style == -1:
self.vm.toolbar.unset_style()
else:
self.vm.toolbar.set_style(the_style)
# def toolbar_on_key_update(self,client,cnxn_id,entry,data):
# is_on = COnfig.get_toolbar_on()
# self.enable_toolbar(is_on)