2004-08-29 01:19:34 +05:30
|
|
|
#
|
2002-10-20 19:55:16 +05:30
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-03-03 05:07:16 +05:30
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2003-10-13 07:25:56 +05:30
|
|
|
# $Id$
|
|
|
|
|
2005-08-12 21:55:43 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2006-05-22 23:37:12 +05:30
|
|
|
# Python modules
|
2005-08-12 21:55:43 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-05-22 23:37:12 +05:30
|
|
|
from gettext import gettext as _
|
2006-04-26 07:14:03 +05:30
|
|
|
import os
|
2006-05-22 23:37:12 +05:30
|
|
|
import platform
|
2006-01-06 20:53:28 +05:30
|
|
|
|
2006-05-22 23:37:12 +05:30
|
|
|
import logging
|
2006-01-06 20:53:28 +05:30
|
|
|
log = logging.getLogger(".")
|
2005-08-12 21:55:43 +05:30
|
|
|
|
2006-05-22 23:37:12 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK+/GNOME modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
|
2005-08-12 21:55:43 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-08-09 10:11:20 +05:30
|
|
|
import ViewManager
|
2005-12-21 16:57:05 +05:30
|
|
|
import GrampsDb
|
2005-08-09 10:11:20 +05:30
|
|
|
import ArgHandler
|
2006-03-03 05:40:52 +05:30
|
|
|
import Config
|
2005-08-09 10:11:20 +05:30
|
|
|
import const
|
2005-03-30 07:15:14 +05:30
|
|
|
import Errors
|
2005-08-09 15:48:56 +05:30
|
|
|
import TipOfDay
|
2006-03-04 21:07:04 +05:30
|
|
|
import DataViews
|
2007-02-04 06:48:17 +05:30
|
|
|
import DbState
|
2006-03-03 05:53:04 +05:30
|
|
|
from Mime import mime_type_is_defined
|
2005-08-09 10:11:20 +05:30
|
|
|
from QuestionDialog import ErrorDialog
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-05-22 23:37:12 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# helper functions
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-04-04 06:41:50 +05:30
|
|
|
|
2006-11-17 10:47:13 +05:30
|
|
|
|
2005-08-09 10:11:20 +05:30
|
|
|
def register_stock_icons ():
|
2007-02-26 03:06:42 +05:30
|
|
|
'''
|
|
|
|
Add the gramps names for its icons (eg gramps-person) to the GTK icon
|
|
|
|
factory. This allows all gramps modules to call up the icons by their name
|
|
|
|
'''
|
2007-02-21 01:28:47 +05:30
|
|
|
|
2007-02-26 03:06:42 +05:30
|
|
|
#iconpath to the base image. The front of the list has highest priority
|
2007-02-21 01:28:47 +05:30
|
|
|
if platform.system() == "Windows":
|
2007-02-26 03:06:42 +05:30
|
|
|
iconpaths = [
|
|
|
|
(os.path.join(const.image_dir,'48x48'),'.png'),
|
|
|
|
(const.image_dir,'.png'),
|
|
|
|
]
|
2007-02-21 01:28:47 +05:30
|
|
|
else :
|
2007-02-26 03:06:42 +05:30
|
|
|
iconpaths = [
|
|
|
|
(os.path.join(const.image_dir,'scalable'),'.svg'),
|
|
|
|
(const.image_dir,'.svg'), (const.image_dir,'.png'),
|
|
|
|
]
|
2007-02-21 01:28:47 +05:30
|
|
|
|
2007-02-26 03:06:42 +05:30
|
|
|
#sizes: menu=16, small_toolbar=18, large_toolbar=24,
|
|
|
|
# button=20, dnd=32, dialog=48
|
|
|
|
#add to the back of this list to overrule images set at beginning of list
|
|
|
|
extraiconsize = [
|
|
|
|
(os.path.join(const.image_dir, '22x22'),
|
|
|
|
gtk.ICON_SIZE_LARGE_TOOLBAR),
|
|
|
|
(os.path.join(const.image_dir, '16x16'),
|
|
|
|
gtk.ICON_SIZE_MENU),
|
|
|
|
(os.path.join(const.image_dir, '22x22'),
|
|
|
|
gtk.ICON_SIZE_BUTTON),
|
2007-02-21 01:28:47 +05:30
|
|
|
]
|
|
|
|
|
2005-08-12 08:05:27 +05:30
|
|
|
items = [
|
2007-02-26 03:06:42 +05:30
|
|
|
('gramps-address',_('Address'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-attribute',_('Attribute'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
#('gramps-bookmark',_('Bookmarks'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
#('gramps-bookmark-delete',_('Delete bookmark'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-bookmark-edit',_('Edit Bookmarks'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-bookmark-new',_('Add Bookmark'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-date',_('Date'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-date-edit',_('Edit Date'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-event',_('Events'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-family',_('Family'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-media',_('Media'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-notes',_('Notes'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-parents',_('Add Parents'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-pedigree',_('Pedigree'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-person',_('Person'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-place',_('Places'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-relation',_('Relationships'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-reports',_('Reports'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-repository',_('Repositories'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-source',_('Sources'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-spouse',_('Add Spouse'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-tools',_('Tools'),gtk.gdk.CONTROL_MASK,0,''),
|
2007-02-21 01:28:47 +05:30
|
|
|
]
|
|
|
|
# the following icons are not yet in new directory structure
|
|
|
|
# they should be ported in the near future
|
|
|
|
items_legacy = [
|
|
|
|
('gramps-export',_('Export'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-undo-history',_('Undo History'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-url',_('URL'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-sharefamily',_('Share Family'),gtk.gdk.CONTROL_MASK,0,''),
|
|
|
|
('gramps-viewmedia',_('View'),gtk.gdk.CONTROL_MASK,0,''),
|
2005-08-12 08:05:27 +05:30
|
|
|
]
|
2005-08-09 10:11:20 +05:30
|
|
|
|
|
|
|
# Register our stock items
|
2007-02-21 01:28:47 +05:30
|
|
|
gtk.stock_add (items+items_legacy)
|
2005-08-09 10:11:20 +05:30
|
|
|
|
|
|
|
# Add our custom icon factory to the list of defaults
|
|
|
|
factory = gtk.IconFactory ()
|
|
|
|
factory.add_default ()
|
|
|
|
|
2007-02-21 01:28:47 +05:30
|
|
|
for data in items+items_legacy:
|
|
|
|
pixbuf = 0
|
|
|
|
for (dirname,ext) in iconpaths:
|
|
|
|
icon_file = os.path.expanduser(os.path.join(dirname,data[0]+ext))
|
2005-08-09 10:11:20 +05:30
|
|
|
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
|
2007-02-21 01:28:47 +05:30
|
|
|
|
|
|
|
if not pixbuf :
|
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)
|
2005-08-09 10:11:20 +05:30
|
|
|
|
|
|
|
pixbuf = pixbuf.add_alpha(True, chr(0xff), chr(0xff), chr(0xff))
|
2006-03-05 04:23:46 +05:30
|
|
|
icon_set = gtk.IconSet (pixbuf)
|
2007-02-21 01:28:47 +05:30
|
|
|
#add different sized icons, always png type!
|
|
|
|
for size in extraiconsize :
|
|
|
|
pixbuf = 0
|
|
|
|
icon_file = os.path.expanduser(
|
2007-02-26 03:06:42 +05:30
|
|
|
os.path.join(size[0], data[0]+'.png'))
|
2007-02-21 01:28:47 +05:30
|
|
|
if os.path.isfile(icon_file):
|
|
|
|
try:
|
|
|
|
pixbuf = gtk.gdk.pixbuf_new_from_file (icon_file)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if pixbuf :
|
|
|
|
source = gtk.IconSource()
|
|
|
|
source.set_size_wildcarded(False)
|
|
|
|
source.set_size(size[1])
|
|
|
|
source.set_pixbuf(pixbuf)
|
|
|
|
icon_set.add_source(source)
|
|
|
|
|
2006-03-05 04:23:46 +05:30
|
|
|
factory.add (data[0], icon_set)
|
2005-08-09 10:11:20 +05:30
|
|
|
|
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)
|
|
|
|
|
2006-05-22 23:37:12 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Main Gramps class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-08-09 10:11:20 +05:30
|
|
|
class Gramps:
|
2005-08-12 08:20:56 +05:30
|
|
|
"""
|
|
|
|
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):
|
2005-03-18 00:58:00 +05:30
|
|
|
try:
|
2006-04-26 07:14:03 +05:30
|
|
|
build_user_paths()
|
2005-05-11 19:34:47 +05:30
|
|
|
self.welcome()
|
2005-05-07 08:11:08 +05:30
|
|
|
except OSError, msg:
|
|
|
|
ErrorDialog(_("Configuration error"),str(msg))
|
|
|
|
return
|
2005-03-30 07:15:14 +05:30
|
|
|
except Errors.GConfSchemaError, val:
|
2005-08-12 08:20:56 +05:30
|
|
|
ErrorDialog(_("Configuration error"),str(val) +
|
|
|
|
_("\n\nPossibly the installation of GRAMPS "
|
|
|
|
"was incomplete. Make sure the GConf schema "
|
|
|
|
"of GRAMPS is properly installed."))
|
2005-03-18 00:58:00 +05:30
|
|
|
gtk.main_quit()
|
|
|
|
return
|
2005-05-07 08:11:08 +05:30
|
|
|
except:
|
2006-01-09 16:58:44 +05:30
|
|
|
log.error("Error reading configuration.", exc_info=True)
|
2005-05-07 08:11:08 +05:30
|
|
|
return
|
2005-03-18 00:58:00 +05:30
|
|
|
|
|
|
|
if not mime_type_is_defined(const.app_gramps):
|
|
|
|
ErrorDialog(_("Configuration error"),
|
2005-08-12 08:20:56 +05:30
|
|
|
_("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)
|
2005-03-18 00:58:00 +05:30
|
|
|
gtk.main_quit()
|
|
|
|
return
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-08-12 21:55:43 +05:30
|
|
|
register_stock_icons()
|
|
|
|
|
2007-02-04 06:48:17 +05:30
|
|
|
state = DbState.DbState()
|
2006-04-23 03:39:16 +05:30
|
|
|
self.vm = ViewManager.ViewManager(state)
|
2006-03-04 21:07:04 +05:30
|
|
|
for view in DataViews.get_views():
|
2006-04-23 03:39:16 +05:30
|
|
|
self.vm.register_view(view)
|
2005-08-12 21:55:43 +05:30
|
|
|
|
2006-05-21 09:43:34 +05:30
|
|
|
self.vm.init_interface()
|
2006-05-22 23:37:12 +05:30
|
|
|
|
|
|
|
# Depending on the nature of this session,
|
|
|
|
# we may need to change the order of operation
|
|
|
|
ah = ArgHandler.ArgHandler(state,self.vm,args)
|
|
|
|
if ah.need_gui():
|
|
|
|
self.vm.post_init_interface()
|
|
|
|
ah.handle_args()
|
|
|
|
else:
|
|
|
|
ah.handle_args()
|
|
|
|
self.vm.post_init_interface()
|
2005-08-12 21:55:43 +05:30
|
|
|
|
2007-01-18 09:59:52 +05:30
|
|
|
# state.db.request_rebuild()
|
|
|
|
# state.change_active_person(state.db.get_default_person())
|
2005-08-12 21:55:43 +05:30
|
|
|
|
2006-04-25 02:34:01 +05:30
|
|
|
if Config.get(Config.USE_TIPS):
|
2006-04-23 03:39:16 +05:30
|
|
|
TipOfDay.TipOfDay(self.vm.uistate)
|
2004-05-18 12:30:34 +05:30
|
|
|
|
2005-05-11 19:34:47 +05:30
|
|
|
def welcome(self):
|
2006-03-29 10:18:50 +05:30
|
|
|
return
|
2006-10-30 20:14:04 +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)
|
|
|
|
|