From 2d5e249839788556dece33ea979d8355a9bc2d9c Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sat, 8 May 2004 04:48:59 +0000 Subject: [PATCH] * src/DbPrompter.py: handle open dialog in a clean manner * src/gramps.py: handle open dialog in a clean manner * src/gramps_main.py: handle open dialog in a clean manner * src/gramps.glade: handle open dialog in a clean manner svn: r3143 --- gramps2/ChangeLog | 6 ++ gramps2/src/DbPrompter.py | 133 ++++++++++++++++--------------------- gramps2/src/gramps.glade | 4 +- gramps2/src/gramps.py | 23 ++++--- gramps2/src/gramps_main.py | 11 ++- 5 files changed, 84 insertions(+), 93 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 44cbb2c76..7321fa975 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,9 @@ +2004-05-07 Don Allingham + * src/DbPrompter.py: handle open dialog in a clean manner + * src/gramps.py: handle open dialog in a clean manner + * src/gramps_main.py: handle open dialog in a clean manner + * src/gramps.glade: handle open dialog in a clean manner + 2004-05-07 Alex Roitman * src/plugins/soundgen.py: Convert to db. * src/plugins/GraphViz.py: Typo. diff --git a/gramps2/src/DbPrompter.py b/gramps2/src/DbPrompter.py index fca3630d3..de904eac9 100644 --- a/gramps2/src/DbPrompter.py +++ b/gramps2/src/DbPrompter.py @@ -27,6 +27,7 @@ #------------------------------------------------------------------------- import gtk import gtk.glade +import gobject #------------------------------------------------------------------------- # @@ -36,6 +37,8 @@ import gtk.glade import Utils import const import GrampsCfg +import gnome +import QuestionDialog from gettext import gettext as _ #------------------------------------------------------------------------- @@ -48,91 +51,73 @@ class DbPrompter: def __init__(self,db,want_new,parent=None): self.db = db - self.want_new = want_new - self.parent = parent - self.show() - - def show(self): opendb = gtk.glade.XML(const.gladeFile, "opendb","gramps") top = opendb.get_widget('opendb') - if self.parent: - top.set_transient_for(self.parent) + if parent: + top.set_transient_for(parent) title = opendb.get_widget('title') Utils.set_titles(top,title,_('Open a database')) - - opendb.signal_autoconnect({ - "on_open_ok_clicked" : self.open_ok_clicked, - "on_open_help_clicked" : self.open_help_clicked, - "on_open_cancel_clicked" : gtk.main_quit, - "on_opendb_delete_event": gtk.main_quit, - }) - self.new = opendb.get_widget("new") - if self.want_new: - self.new.set_active(1) + new = opendb.get_widget("new") + new.set_active(want_new) - def open_ok_clicked(self,obj): - if self.new.get_active(): + while 1: + response = top.run() + if response == gtk.RESPONSE_OK: + if self.chooser(new.get_active()): + break + elif response == gtk.RESPONSE_CANCEL: + break + elif response == gtk.RESPONSE_HELP: + try: + gnome.help_display('gramps-manual','choose-db-start') + except gobject.GError,msg: + QuestionDialog.ErrorDialog(_('Help not available'),msg) + + top.destroy() + if response == gtk.RESPONSE_CANCEL: + gtk.main_quit() + + def chooser(self,save): + if save: + choose = gtk.FileChooserDialog('Create GRAMPS database', + None, + gtk.FILE_CHOOSER_ACTION_SAVE, + (gtk.STOCK_CANCEL, + gtk.RESPONSE_CANCEL, + gtk.STOCK_OPEN, + gtk.RESPONSE_OK)) self.db.clear_database() - self.save_as_activate() else: - self.open_activate() - Utils.destroy_passed_object(obj) - - def open_help_clicked(self,obj): - """Display the GRAMPS manual""" - import gnome - gnome.help_display('gramps-manual','choose-db-start') - - def save_as_activate(self): - 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() - - def open_activate(self): - 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) + 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 save and 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() - + choose.destroy() + return 1 + else: + choose.destroy() + return 0 + diff --git a/gramps2/src/gramps.glade b/gramps2/src/gramps.glade index 0cd86d16f..302139484 100644 --- a/gramps2/src/gramps.glade +++ b/gramps2/src/gramps.glade @@ -6589,7 +6589,7 @@ True GTK_RELIEF_NORMAL True - 0 + -6 @@ -6604,7 +6604,7 @@ True GTK_RELIEF_NORMAL True - 0 + -5 diff --git a/gramps2/src/gramps.py b/gramps2/src/gramps.py index af6a5a27f..f7836ab1f 100755 --- a/gramps2/src/gramps.py +++ b/gramps2/src/gramps.py @@ -78,20 +78,23 @@ gettext.install("gramps",loc,unicode=1) # #------------------------------------------------------------------------- import gramps_main +import gobject signal.signal(signal.SIGCHLD, signal.SIG_DFL) args = sys.argv[1:] -try: - import StartupDialog - - if StartupDialog.need_to_run(): - StartupDialog.StartupDialog(gramps_main.Gramps,args) - else: - gramps_main.Gramps(args) -except: - import DisplayTrace - DisplayTrace.DisplayTrace() +def run(): + try: + import StartupDialog + + if StartupDialog.need_to_run(): + StartupDialog.StartupDialog(gramps_main.Gramps,args) + else: + gramps_main.Gramps(args) + except: + import DisplayTrace + DisplayTrace.DisplayTrace() +gobject.timeout_add(100, run, priority=100) gtk.main() diff --git a/gramps2/src/gramps_main.py b/gramps2/src/gramps_main.py index 9e3d7f7f5..7813f4f2a 100755 --- a/gramps2/src/gramps_main.py +++ b/gramps2/src/gramps_main.py @@ -59,9 +59,6 @@ import FamilyView import SourceView import PeopleView import GenericFilter - -from QuestionDialog import * - import DisplayTrace import const import Plugins @@ -72,9 +69,11 @@ import EditPerson import Find import DbPrompter -try: # First try python2.3 and later: this is the future +from QuestionDialog import * + +try: # First try python2.3 and later: this is the future from bsddb import db -except ImportError: # try python2.2 +except ImportError: # try python2.2 from bsddb3 import db #------------------------------------------------------------------------- @@ -894,7 +893,6 @@ class Gramps: self.new_database_response,self.topWindow) def new_database_response(self): - import DbPrompter DbPrompter.DbPrompter(self,1,self.topWindow) def clear_database(self): @@ -1175,7 +1173,6 @@ class Gramps: if os.path.exists(filename): if not os.path.isdir(filename): - import DbPrompter DbPrompter.DbPrompter(self,0,self.topWindow) self.displayError(_("Database could not be opened"), _("%s is not a directory.") % filename + ' ' + \