2004-08-28 19:49:34 +00:00
|
|
|
#
|
2002-10-20 14:25:16 +00:00
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-03-02 23:37:16 +00:00
|
|
|
# Copyright (C) 2001-2006 Donald N. Allingham
|
2002-10-20 14:25:16 +00:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2007-10-07 03:19:35 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
2002-10-20 14:25:16 +00:00
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2008-02-18 15:52:40 +00:00
|
|
|
# $Id:gramps_main.py 9912 2008-01-22 09:17:46Z acraphae $
|
2003-10-13 01:55:56 +00:00
|
|
|
|
2005-08-12 16:25:43 +00:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2006-05-22 18:07:12 +00:00
|
|
|
# Python modules
|
2005-08-12 16:25:43 +00:00
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-05-22 18:07:12 +00:00
|
|
|
from gettext import gettext as _
|
2006-04-26 01:44:03 +00:00
|
|
|
import os
|
2006-05-22 18:07:12 +00:00
|
|
|
import platform
|
2006-01-06 15:23:28 +00:00
|
|
|
|
2006-05-22 18:07:12 +00:00
|
|
|
import logging
|
2006-01-06 15:23:28 +00:00
|
|
|
log = logging.getLogger(".")
|
2005-08-12 16:25:43 +00:00
|
|
|
|
2006-05-22 18:07:12 +00:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK+/GNOME modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
|
2005-08-12 16:25:43 +00:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-08-09 04:41:20 +00:00
|
|
|
import ViewManager
|
|
|
|
import ArgHandler
|
2006-03-03 00:10:52 +00:00
|
|
|
import Config
|
2005-08-09 04:41:20 +00:00
|
|
|
import const
|
2005-03-30 01:45:14 +00:00
|
|
|
import Errors
|
2005-08-09 10:18:56 +00:00
|
|
|
import TipOfDay
|
2006-03-04 15:37:04 +00:00
|
|
|
import DataViews
|
2007-02-04 01:18:17 +00:00
|
|
|
import DbState
|
2006-03-03 00:23:04 +00:00
|
|
|
from Mime import mime_type_is_defined
|
2005-08-09 04:41:20 +00:00
|
|
|
from QuestionDialog import ErrorDialog
|
2002-10-20 14:25:16 +00:00
|
|
|
|
2006-05-22 18:07:12 +00:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# helper functions
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-04-04 01:11:50 +00:00
|
|
|
|
2006-11-17 05:17:13 +00:00
|
|
|
|
2005-08-09 04:41:20 +00:00
|
|
|
def register_stock_icons ():
|
2008-02-18 15:52:40 +00:00
|
|
|
"""
|
2007-02-25 21:36:42 +00:00
|
|
|
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
|
2008-02-18 15:52:40 +00:00
|
|
|
"""
|
2007-02-20 19:58:47 +00:00
|
|
|
|
2007-02-25 21:36:42 +00:00
|
|
|
#iconpath to the base image. The front of the list has highest priority
|
2007-02-20 19:58:47 +00:00
|
|
|
if platform.system() == "Windows":
|
2007-02-25 21:36:42 +00:00
|
|
|
iconpaths = [
|
2007-10-07 03:19:35 +00:00
|
|
|
(os.path.join(const.IMAGE_DIR, '48x48'), '.png'),
|
|
|
|
(const.IMAGE_DIR, '.png'),
|
2007-02-25 21:36:42 +00:00
|
|
|
]
|
2007-02-20 19:58:47 +00:00
|
|
|
else :
|
2007-02-25 21:36:42 +00:00
|
|
|
iconpaths = [
|
2007-10-07 03:19:35 +00:00
|
|
|
(os.path.join(const.IMAGE_DIR, 'scalable'), '.svg'),
|
|
|
|
(const.IMAGE_DIR, '.svg'), (const.IMAGE_DIR, '.png'),
|
2007-02-25 21:36:42 +00:00
|
|
|
]
|
2007-02-20 19:58:47 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
#sizes: menu=16, small_toolbar=18, large_toolbar=24,
|
2007-02-25 21:36:42 +00:00
|
|
|
# button=20, dnd=32, dialog=48
|
|
|
|
#add to the back of this list to overrule images set at beginning of list
|
|
|
|
extraiconsize = [
|
2007-10-07 03:19:35 +00:00
|
|
|
(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-20 19:58:47 +00:00
|
|
|
]
|
|
|
|
|
2005-08-12 02:35:27 +00:00
|
|
|
items = [
|
2007-10-07 03:19:35 +00:00
|
|
|
('gramps-db', _('Family Trees'), gtk.gdk.CONTROL_MASK, 0, ''),
|
|
|
|
('gramps-address', _('Address'), gtk.gdk.CONTROL_MASK, 0, ''),
|
|
|
|
('gramps-attribute', _('Attribute'), gtk.gdk.CONTROL_MASK, 0, ''),
|
2008-01-01 06:44:58 +00:00
|
|
|
#('gramps-bookmark', _('Bookmarks'), gtk.gdk.CONTROL_MASK, 0, ''),
|
2007-10-07 03:19:35 +00:00
|
|
|
#('gramps-bookmark-delete', _('Delete bookmark'), gtk.gdk.CONTROL_MASK, 0, ''),
|
2008-02-19 09:18:47 +00:00
|
|
|
('gramps-bookmark-edit', _('Organize Bookmarks'), gtk.gdk.CONTROL_MASK, 0, ''),
|
2007-10-07 03:19:35 +00:00
|
|
|
('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-font', _('Font'), gtk.gdk.CONTROL_MASK, 0, ''),
|
|
|
|
('gramps-font-color', _('Font Color'), gtk.gdk.CONTROL_MASK, 0, ''),
|
|
|
|
('gramps-font-bgcolor', _('Font Background Color'), gtk.gdk.CONTROL_MASK, 0, ''),
|
2008-01-07 21:44:41 +00:00
|
|
|
('gramps-gramplet', _('Gramplets'), gtk.gdk.CONTROL_MASK, 0, ''),
|
2008-12-07 22:48:30 +00:00
|
|
|
('gramps-geo', _('GeoView'), gtk.gdk.CONTROL_MASK, 0, ''),
|
2007-10-07 03:19:35 +00:00
|
|
|
('gramps-lock', _('Public'), gtk.gdk.CONTROL_MASK, 0, ''),
|
|
|
|
('gramps-media', _('Media'), gtk.gdk.CONTROL_MASK, 0, ''),
|
|
|
|
('gramps-notes', _('Notes'), gtk.gdk.CONTROL_MASK, 0, ''),
|
|
|
|
('gramps-parents', _('Parents'), gtk.gdk.CONTROL_MASK, 0, ''),
|
|
|
|
('gramps-parents-add', _('Add Parents'), gtk.gdk.CONTROL_MASK, 0, ''),
|
|
|
|
('gramps-parents-open', _('Select 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, ''),
|
|
|
|
('gramps-unlock', _('Private'), gtk.gdk.CONTROL_MASK, 0, ''),
|
|
|
|
('gramps-viewmedia', _('View'), gtk.gdk.CONTROL_MASK, 0, ''),
|
|
|
|
('gramps-zoom-in', _('Zoom In'), gtk.gdk.CONTROL_MASK, 0, ''),
|
|
|
|
('gramps-zoom-out', _('Zoom Out'), gtk.gdk.CONTROL_MASK, 0, ''),
|
|
|
|
('gramps-zoom-fit-width', _('Fit Width'), gtk.gdk.CONTROL_MASK, 0, ''),
|
|
|
|
('gramps-zoom-best-fit', _('Fit Page'), gtk.gdk.CONTROL_MASK, 0, ''),
|
2007-02-20 19:58:47 +00:00
|
|
|
]
|
|
|
|
# the following icons are not yet in new directory structure
|
|
|
|
# they should be ported in the near future
|
|
|
|
items_legacy = [
|
2007-10-07 03:19:35 +00:00
|
|
|
('gramps-export', _('Export'), gtk.gdk.CONTROL_MASK, 0, ''),
|
2007-11-12 15:44:15 +00:00
|
|
|
('gramps-import', _('Import'), gtk.gdk.CONTROL_MASK, 0, ''),
|
2007-10-07 03:19:35 +00:00
|
|
|
('gramps-undo-history', _('Undo History'), gtk.gdk.CONTROL_MASK, 0, ''),
|
|
|
|
('gramps-url', _('URL'), gtk.gdk.CONTROL_MASK, 0, ''),
|
2005-08-12 02:35:27 +00:00
|
|
|
]
|
2005-08-09 04:41:20 +00:00
|
|
|
|
|
|
|
# Register our stock items
|
2007-02-20 19:58:47 +00:00
|
|
|
gtk.stock_add (items+items_legacy)
|
2005-08-09 04:41:20 +00:00
|
|
|
|
|
|
|
# Add our custom icon factory to the list of defaults
|
|
|
|
factory = gtk.IconFactory ()
|
|
|
|
factory.add_default ()
|
|
|
|
|
2007-02-20 19:58:47 +00:00
|
|
|
for data in items+items_legacy:
|
|
|
|
pixbuf = 0
|
2007-10-07 03:19:35 +00:00
|
|
|
for (dirname, ext) in iconpaths:
|
|
|
|
icon_file = os.path.expanduser(os.path.join(dirname, data[0]+ext))
|
2005-08-09 04:41:20 +00:00
|
|
|
if os.path.isfile(icon_file):
|
2006-03-04 22:53:46 +00:00
|
|
|
try:
|
|
|
|
pixbuf = gtk.gdk.pixbuf_new_from_file (icon_file)
|
|
|
|
break
|
|
|
|
except:
|
|
|
|
pass
|
2007-02-20 19:58:47 +00:00
|
|
|
|
|
|
|
if not pixbuf :
|
2007-10-07 03:19:35 +00:00
|
|
|
icon_file = os.path.join(const.IMAGE_DIR, 'gramps.png')
|
2006-03-04 22:53:46 +00:00
|
|
|
pixbuf = gtk.gdk.pixbuf_new_from_file (icon_file)
|
2005-08-09 04:41:20 +00:00
|
|
|
|
|
|
|
pixbuf = pixbuf.add_alpha(True, chr(0xff), chr(0xff), chr(0xff))
|
2006-03-04 22:53:46 +00:00
|
|
|
icon_set = gtk.IconSet (pixbuf)
|
2007-02-20 19:58:47 +00:00
|
|
|
#add different sized icons, always png type!
|
|
|
|
for size in extraiconsize :
|
|
|
|
pixbuf = 0
|
|
|
|
icon_file = os.path.expanduser(
|
2007-02-25 21:36:42 +00:00
|
|
|
os.path.join(size[0], data[0]+'.png'))
|
2007-02-20 19:58:47 +00:00
|
|
|
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-04 22:53:46 +00:00
|
|
|
factory.add (data[0], icon_set)
|
2005-08-09 04:41:20 +00:00
|
|
|
|
2006-04-26 01:44:03 +00:00
|
|
|
|
|
|
|
def build_user_paths():
|
2007-11-26 05:11:19 +00:00
|
|
|
""" check/make user-dirs on each Gramps session"""
|
|
|
|
for path in const.USER_DIRLIST:
|
2006-04-26 01:44:03 +00:00
|
|
|
if not os.path.isdir(path):
|
|
|
|
os.mkdir(path)
|
2008-01-13 04:58:11 +00:00
|
|
|
|
|
|
|
def _display_welcome_message():
|
|
|
|
"""
|
|
|
|
Display a welcome message to the user.
|
|
|
|
"""
|
|
|
|
if not Config.get(Config.BETAWARN):
|
|
|
|
from QuestionDialog import WarningDialog
|
|
|
|
WarningDialog(
|
|
|
|
_('Danger: This is unstable code!'),
|
2008-05-05 04:52:51 +00:00
|
|
|
_("This GRAMPS 3.x-trunk is a development release. "
|
|
|
|
"This version is not meant for normal usage. Use "
|
|
|
|
"at your own risk.\n"
|
|
|
|
"\n"
|
2008-01-13 04:58:11 +00:00
|
|
|
"This version may:\n"
|
|
|
|
"1) Work differently than you expect.\n"
|
2008-01-13 15:05:41 +00:00
|
|
|
"2) Fail to run at all.\n"
|
|
|
|
"3) Crash often.\n"
|
|
|
|
"4) Corrupt your data.\n"
|
2008-01-13 04:58:11 +00:00
|
|
|
"5) Save data in a format that is incompatible with the "
|
2008-05-05 04:52:51 +00:00
|
|
|
"official release.\n"
|
|
|
|
"\n"
|
|
|
|
"<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."))
|
2008-01-13 04:58:11 +00:00
|
|
|
Config.set(Config.AUTOLOAD, False)
|
|
|
|
# Config.set(Config.BETAWARN, True)
|
|
|
|
Config.set(Config.BETAWARN, Config.get(Config.BETAWARN))
|
2006-04-26 01:44:03 +00:00
|
|
|
|
2006-05-22 18:07:12 +00:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Main Gramps class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-08-09 04:41:20 +00:00
|
|
|
class Gramps:
|
2005-08-12 02:50:56 +00:00
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
2007-10-20 18:14:02 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def __init__(self, args):
|
2007-10-20 18:14:02 +00:00
|
|
|
stopload = False
|
2005-03-17 19:28:00 +00:00
|
|
|
try:
|
2006-04-26 01:44:03 +00:00
|
|
|
build_user_paths()
|
2008-01-13 04:58:11 +00:00
|
|
|
_display_welcome_message()
|
2005-05-07 02:41:08 +00:00
|
|
|
except OSError, msg:
|
2007-10-07 03:19:35 +00:00
|
|
|
ErrorDialog(_("Configuration error"), str(msg))
|
2005-03-30 01:45:14 +00:00
|
|
|
except Errors.GConfSchemaError, val:
|
2007-10-07 03:19:35 +00:00
|
|
|
ErrorDialog(_("Configuration error"), str(val) +
|
2005-08-12 02:50:56 +00:00
|
|
|
_("\n\nPossibly the installation of GRAMPS "
|
|
|
|
"was incomplete. Make sure the GConf schema "
|
|
|
|
"of GRAMPS is properly installed."))
|
2005-03-17 19:28:00 +00:00
|
|
|
gtk.main_quit()
|
2007-10-20 18:14:02 +00:00
|
|
|
stopload = True
|
2005-05-07 02:41:08 +00:00
|
|
|
except:
|
2006-01-09 11:28:44 +00:00
|
|
|
log.error("Error reading configuration.", exc_info=True)
|
2005-03-17 19:28:00 +00:00
|
|
|
|
2007-09-08 05:54:02 +00:00
|
|
|
if not mime_type_is_defined(const.APP_GRAMPS):
|
2007-10-07 03:19:35 +00:00
|
|
|
ErrorDialog(_("Configuration error"),
|
2005-08-12 02:50:56 +00:00
|
|
|
_("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.")
|
2007-09-08 05:54:02 +00:00
|
|
|
% const.APP_GRAMPS)
|
2005-03-17 19:28:00 +00:00
|
|
|
gtk.main_quit()
|
2007-10-20 18:14:02 +00:00
|
|
|
stopload = True
|
2002-10-20 14:25:16 +00:00
|
|
|
|
2005-08-12 16:25:43 +00:00
|
|
|
register_stock_icons()
|
|
|
|
|
2007-02-04 01:18:17 +00:00
|
|
|
state = DbState.DbState()
|
2006-04-22 22:09:16 +00:00
|
|
|
self.vm = ViewManager.ViewManager(state)
|
2006-03-04 15:37:04 +00:00
|
|
|
for view in DataViews.get_views():
|
2006-04-22 22:09:16 +00:00
|
|
|
self.vm.register_view(view)
|
2005-08-12 16:25:43 +00:00
|
|
|
|
2007-10-20 18:14:02 +00:00
|
|
|
if stopload:
|
2007-10-20 21:24:32 +00:00
|
|
|
# We stop further loading so family tree manager is not shown
|
|
|
|
# before the exit of GRAMPS
|
2007-10-20 18:14:02 +00:00
|
|
|
return
|
|
|
|
|
2006-05-21 04:13:34 +00:00
|
|
|
self.vm.init_interface()
|
2006-05-22 18:07:12 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
# Depending on the nature of this session,
|
2006-05-22 18:07:12 +00:00
|
|
|
# we may need to change the order of operation
|
2007-10-07 03:19:35 +00:00
|
|
|
ah = ArgHandler.ArgHandler(state, self.vm, args)
|
2006-05-22 18:07:12 +00:00
|
|
|
if ah.need_gui():
|
2008-11-04 04:12:51 +00:00
|
|
|
filename = ah.handle_args()
|
|
|
|
if filename:
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 15:09:01 +00:00
|
|
|
self.vm.post_init_interface(show_manager=False)
|
|
|
|
self.vm.open_activate(filename)
|
|
|
|
else:
|
|
|
|
self.vm.post_init_interface()
|
2006-05-22 18:07:12 +00:00
|
|
|
else:
|
|
|
|
ah.handle_args()
|
|
|
|
self.vm.post_init_interface()
|
2005-08-12 16:25:43 +00:00
|
|
|
|
2006-04-24 21:04:01 +00:00
|
|
|
if Config.get(Config.USE_TIPS):
|
2006-04-22 22:09:16 +00:00
|
|
|
TipOfDay.TipOfDay(self.vm.uistate)
|
2004-05-18 07:00:34 +00:00
|
|
|
|
2006-10-30 14:44:04 +00:00
|
|
|
|