2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2003-09-08 17:44:34 +05:30
|
|
|
# Copyright (C) 2000-2003 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-12-06 05:44:25 +05:30
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
2003-12-06 05:44:25 +05:30
|
|
|
import gnome
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import Utils
|
|
|
|
import const
|
|
|
|
import GrampsCfg
|
2003-08-17 07:44:33 +05:30
|
|
|
from gettext import gettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# DbPrompter
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class DbPrompter:
|
|
|
|
"""Make sure a database is opened"""
|
|
|
|
|
2003-09-08 09:42:43 +05:30
|
|
|
def __init__(self,db,want_new,parent=None):
|
2002-10-20 19:55:16 +05:30
|
|
|
self.db = db
|
|
|
|
self.want_new = want_new
|
2003-09-08 09:42:43 +05:30
|
|
|
self.parent = parent
|
2002-10-20 19:55:16 +05:30
|
|
|
self.show()
|
|
|
|
|
|
|
|
def show(self):
|
2003-08-17 07:44:33 +05:30
|
|
|
opendb = gtk.glade.XML(const.gladeFile, "opendb","gramps")
|
2003-03-06 11:42:51 +05:30
|
|
|
top = opendb.get_widget('opendb')
|
2003-09-08 17:44:34 +05:30
|
|
|
if self.parent:
|
|
|
|
top.set_transient_for(self.parent)
|
2003-03-06 11:42:51 +05:30
|
|
|
title = opendb.get_widget('title')
|
2003-03-05 11:31:31 +05:30
|
|
|
|
2003-03-06 11:42:51 +05:30
|
|
|
Utils.set_titles(top,title,_('Open a database'))
|
2003-03-05 11:31:31 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
opendb.signal_autoconnect({
|
|
|
|
"on_open_ok_clicked" : self.open_ok_clicked,
|
2003-12-06 05:44:25 +05:30
|
|
|
"on_open_help_clicked" : self.open_help_clicked,
|
2002-10-20 19:55:16 +05:30
|
|
|
"on_open_cancel_clicked" : self.open_cancel_clicked,
|
|
|
|
"on_opendb_delete_event": self.open_delete_event,
|
|
|
|
})
|
2003-03-06 11:42:51 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.new = opendb.get_widget("new")
|
|
|
|
if self.want_new:
|
|
|
|
self.new.set_active(1)
|
|
|
|
|
|
|
|
def open_ok_clicked(self,obj):
|
|
|
|
if self.new.get_active():
|
2003-11-02 22:11:29 +05:30
|
|
|
self.db.clear_database()
|
2002-10-20 19:55:16 +05:30
|
|
|
self.save_as_activate()
|
|
|
|
else:
|
|
|
|
self.open_activate()
|
|
|
|
Utils.destroy_passed_object(obj)
|
|
|
|
|
2003-12-06 05:44:25 +05:30
|
|
|
def open_help_clicked(self,obj):
|
|
|
|
"""Display the GRAMPS manual"""
|
|
|
|
gnome.help_display('gramps-manual','choose-db-start')
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def save_as_activate(self):
|
2004-04-19 08:45:05 +05:30
|
|
|
if gtk.pygtk_version[1] >= 3:
|
|
|
|
choose = gtk.FileChooserDialog('Create GRAMPS database',
|
|
|
|
None,
|
|
|
|
gtk.FILE_CHOOSER_ACTION_SAVE,
|
|
|
|
(gtk.STOCK_CANCEL,
|
|
|
|
gtk.RESPONSE_CANCEL,
|
|
|
|
gtk.STOCK_OPEN,
|
|
|
|
gtk.RESPONSE_OK))
|
|
|
|
filter = gtk.FileFilter()
|
|
|
|
filter.set_name(_('GRAMPS databases'))
|
|
|
|
filter.add_pattern('*.grdb')
|
|
|
|
choose.add_filter(filter)
|
|
|
|
|
|
|
|
filter = gtk.FileFilter()
|
|
|
|
filter.set_name(_('All files'))
|
|
|
|
filter.add_pattern('*')
|
|
|
|
choose.add_filter(filter)
|
|
|
|
|
|
|
|
response = choose.run()
|
|
|
|
if response == gtk.RESPONSE_OK:
|
|
|
|
filename = choose.get_filename()
|
|
|
|
self.db.read_file(filename)
|
|
|
|
choose.destroy()
|
|
|
|
else:
|
|
|
|
wFs = gtk.glade.XML (const.gladeFile, "fileselection","gramps")
|
|
|
|
wFs.signal_autoconnect({
|
|
|
|
"on_ok_button1_clicked": self.save_ok_button_clicked,
|
|
|
|
"destroy_passed_object": self.cancel_button_clicked,
|
|
|
|
})
|
|
|
|
filesel = wFs.get_widget('fileselection')
|
|
|
|
filesel.set_title('%s - GRAMPS' % _('Create database'))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def save_ok_button_clicked(self,obj):
|
2003-03-21 09:55:55 +05:30
|
|
|
filename = obj.get_filename().encode('iso8859-1')
|
2002-10-20 19:55:16 +05:30
|
|
|
if filename:
|
2004-04-10 09:08:48 +05:30
|
|
|
if self.db.read_file(filename) == 1:
|
|
|
|
Utils.destroy_passed_object(obj)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def open_activate(self):
|
2004-04-19 08:45:05 +05:30
|
|
|
if gtk.pygtk_version[1] >= 3:
|
|
|
|
choose = gtk.FileChooserDialog('Open GRAMPS database',
|
|
|
|
None,
|
|
|
|
gtk.FILE_CHOOSER_ACTION_OPEN,
|
|
|
|
(gtk.STOCK_CANCEL,
|
|
|
|
gtk.RESPONSE_CANCEL,
|
|
|
|
gtk.STOCK_OPEN,
|
|
|
|
gtk.RESPONSE_OK))
|
|
|
|
filter = gtk.FileFilter()
|
|
|
|
filter.set_name(_('GRAMPS databases'))
|
|
|
|
filter.add_pattern('*.grdb')
|
|
|
|
choose.add_filter(filter)
|
|
|
|
|
|
|
|
filter = gtk.FileFilter()
|
|
|
|
filter.set_name(_('All files'))
|
|
|
|
filter.add_pattern('*')
|
|
|
|
choose.add_filter(filter)
|
|
|
|
|
|
|
|
if GrampsCfg.lastfile:
|
|
|
|
choose.set_filename(GrampsCfg.lastfile)
|
|
|
|
|
|
|
|
response = choose.run()
|
|
|
|
if response == gtk.RESPONSE_OK:
|
|
|
|
filename = choose.get_filename()
|
|
|
|
self.db.read_file(filename)
|
|
|
|
choose.destroy()
|
|
|
|
else:
|
|
|
|
wFs = gtk.glade.XML (const.gladeFile, "fileselection","gramps")
|
|
|
|
wFs.signal_autoconnect({
|
|
|
|
"on_ok_button1_clicked": self.ok_button_clicked,
|
|
|
|
"destroy_passed_object": self.cancel_button_clicked,
|
|
|
|
})
|
|
|
|
self.filesel = wFs.get_widget('fileselection')
|
|
|
|
self.filesel.set_title('%s - GRAMPS' % _('Open database'))
|
|
|
|
if GrampsCfg.lastfile:
|
|
|
|
self.filesel.set_filename(GrampsCfg.lastfile)
|
2004-03-30 10:20:24 +05:30
|
|
|
return
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def cancel_button_clicked(self,obj):
|
|
|
|
Utils.destroy_passed_object(obj)
|
|
|
|
self.show()
|
|
|
|
|
|
|
|
def ok_button_clicked(self,obj):
|
2004-03-30 10:20:24 +05:30
|
|
|
filename = self.filesel.get_filename()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
if not filename:
|
|
|
|
return
|
2004-04-10 09:08:48 +05:30
|
|
|
if self.db.read_file(filename) == 1:
|
|
|
|
Utils.destroy_passed_object(obj)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def open_delete_event(self,obj,event):
|
2004-04-28 09:36:25 +05:30
|
|
|
gtk.main_quit()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def open_cancel_clicked(self,obj):
|
2004-04-28 09:36:25 +05:30
|
|
|
gtk.main_quit()
|
2002-10-20 19:55:16 +05:30
|
|
|
|