From f08d8961f5be05ca8dfd662aa87da462de0f4672 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Fri, 25 Jan 2002 05:37:57 +0000 Subject: [PATCH] Proper handling of startup wizard svn: r725 --- gramps/src/Config.py | 111 +++++++++++++----------------------- gramps/src/HtmlDoc.py | 2 - gramps/src/RelLib.py | 24 +++++--- gramps/src/StartupDialog.py | 63 ++++++++++++++++++++ gramps/src/gramps.py | 14 ++++- gramps/src/gramps_main.py | 11 ++-- 6 files changed, 135 insertions(+), 90 deletions(-) create mode 100644 gramps/src/StartupDialog.py diff --git a/gramps/src/Config.py b/gramps/src/Config.py index 574cfaed7..9ec7092f6 100644 --- a/gramps/src/Config.py +++ b/gramps/src/Config.py @@ -114,8 +114,6 @@ panellist = [ # #------------------------------------------------------------------------- -owner = Researcher() -prefsTop = None iprefix = "I" oprefix = "O" sprefix = "S" @@ -158,7 +156,6 @@ localprop = 1 #------------------------------------------------------------------------- _name_format = 0 _callback = None -_druid = None #------------------------------------------------------------------------- # @@ -193,7 +190,6 @@ def make_path(path): def loadConfig(call): global autoload global autosave_int - global owner global usetabs global uselds global autocomp @@ -211,7 +207,6 @@ def loadConfig(call): global nameof global display_attr global attr_name - global _druid global _name_format global _callback global paper_preference @@ -286,15 +281,6 @@ def loadConfig(call): else: db_dir = os.path.normpath(db_dir) + os.sep - name = get_string("/gramps/researcher/name") - addr = get_string("/gramps/researcher/addr") - city = get_string("/gramps/researcher/city") - state = get_string("/gramps/researcher/state") - country = get_string("/gramps/researcher/country") - postal = get_string("/gramps/researcher/postal") - phone = get_string("/gramps/researcher/phone") - email = get_string("/gramps/researcher/email") - en = get_bool("/gramps/color/enableColors") if en == None: en = 0 @@ -388,15 +374,6 @@ def loadConfig(call): else: nameof = utils.phonebook_name - if name == None: - _druid = libglade.GladeXML(const.configFile,"initDruid") - _druid.signal_autoconnect({ - "destroy_passed_object" : druid_cancel_clicked, - "on_initDruid_finish" : on_initDruid_finish - }) - else: - owner.set(name,addr,city,state,country,postal,phone,email) - make_path(os.path.expanduser("~/.gramps")) make_path(os.path.expanduser("~/.gramps/filters")) make_path(os.path.expanduser("~/.gramps/plugins")) @@ -415,37 +392,19 @@ def save_last_file(file): # # #------------------------------------------------------------------------- -def on_initDruid_finish(obj,b): - global owner - - name = _druid.get_widget("dresname").get_text() - addr = _druid.get_widget("dresaddr").get_text() - city = _druid.get_widget("drescity").get_text() - state = _druid.get_widget("dresstate").get_text() - country = _druid.get_widget("drescountry").get_text() - postal = _druid.get_widget("drespostal").get_text() - phone = _druid.get_widget("dresphone").get_text() - email = _druid.get_widget("dresemail").get_text() +def get_researcher(): + n = get_string("/gramps/researcher/name") + a = get_string("/gramps/researcher/addr") + c = get_string("/gramps/researcher/city") + s = get_string("/gramps/researcher/state") + ct = get_string("/gramps/researcher/country") + p = get_string("/gramps/researcher/postal") + ph = get_string("/gramps/researcher/phone") + e = get_string("/gramps/researcher/email") - owner.set(name,addr,city,state,country,postal,phone,email) - store_researcher(owner) - utils.destroy_passed_object(obj) - -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def store_researcher(res): - set_string("/gramps/researcher/name",res.name) - set_string("/gramps/researcher/addr",res.addr) - set_string("/gramps/researcher/city",res.city) - set_string("/gramps/researcher/state",res.state) - set_string("/gramps/researcher/country",res.country) - set_string("/gramps/researcher/postal",res.postal) - set_string("/gramps/researcher/phone",res.phone) - set_string("/gramps/researcher/email",res.email) - sync() + owner = Researcher() + owner.set(n,a,c,s,ct,p,ph,e) + return owner #------------------------------------------------------------------------- # @@ -777,14 +736,23 @@ class GrampsPreferences: name_menu.set_active(_name_format) name_option.set_menu(name_menu) - self.top.get_widget("resname").set_text(owner.getName()) - self.top.get_widget("resaddr").set_text(owner.getAddress()) - self.top.get_widget("rescity").set_text(owner.getCity()) - self.top.get_widget("resstate").set_text(owner.getState()) - self.top.get_widget("rescountry").set_text(owner.getCountry()) - self.top.get_widget("respostal").set_text(owner.getPostalCode()) - self.top.get_widget("resphone").set_text(owner.getPhone()) - self.top.get_widget("resemail").set_text(owner.getEmail()) + cname = get_string("/gramps/researcher/name") + caddr = get_string("/gramps/researcher/addr") + ccity = get_string("/gramps/researcher/city") + cstate = get_string("/gramps/researcher/state") + ccountry = get_string("/gramps/researcher/country") + cpostal = get_string("/gramps/researcher/postal") + cphone = get_string("/gramps/researcher/phone") + cemail = get_string("/gramps/researcher/email") + + self.top.get_widget("resname").set_text(cname) + self.top.get_widget("resaddr").set_text(caddr) + self.top.get_widget("rescity").set_text(ccity) + self.top.get_widget("resstate").set_text(cstate) + self.top.get_widget("rescountry").set_text(ccountry) + self.top.get_widget("respostal").set_text(cpostal) + self.top.get_widget("resphone").set_text(cphone) + self.top.get_widget("resemail").set_text(cemail) cwidget = self.top.get_widget(ODDFGCOLOR) cwidget.set_i16(ListColors.oddfg[0],ListColors.oddfg[1],\ @@ -888,10 +856,10 @@ class GrampsPreferences: def on_propertybox_apply(self,obj): global nameof - global owner global usetabs global uselds global autocomp + global autosave_int global mediaref global globalprop global localprop @@ -919,6 +887,7 @@ class GrampsPreferences: global web_dir global db_dir global lastnamegen + global autoload show_detail = self.top.get_widget("showdetail").get_active() autoload = self.top.get_widget("autoload").get_active() @@ -1075,8 +1044,14 @@ class GrampsPreferences: save_config_color(EVENBGCOLOR,ListColors.evenbg) save_config_color(ANCESTORFGCOLOR,ListColors.ancestorfg) - owner.set(name,addr,city,state,country,postal,phone,email) - store_researcher(owner) + set_string("/gramps/researcher/name",name) + set_string("/gramps/researcher/addr",addr) + set_string("/gramps/researcher/city",city) + set_string("/gramps/researcher/state",state) + set_string("/gramps/researcher/country",country) + set_string("/gramps/researcher/postal",postal) + set_string("/gramps/researcher/phone",phone) + set_string("/gramps/researcher/email",email) self.db.set_iprefix(iprefix) self.db.set_fprefix(fprefix) @@ -1154,12 +1129,4 @@ def save_sort_cols(name,col,dir): set_int("/gramps/sort/%s_dir" % name, dir) sync() -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def druid_cancel_clicked(obj,a): - utils.destroy_passed_object(obj) - diff --git a/gramps/src/HtmlDoc.py b/gramps/src/HtmlDoc.py index 01d93de2d..e4e1d4b1e 100644 --- a/gramps/src/HtmlDoc.py +++ b/gramps/src/HtmlDoc.py @@ -145,8 +145,6 @@ class HtmlDoc(TextDoc): self.top = _top def open(self,filename): - - if filename[-5:] == ".html" or filename[-4:0] == ".htm": self.filename = filename else: diff --git a/gramps/src/RelLib.py b/gramps/src/RelLib.py index b9181f190..3d62dda37 100644 --- a/gramps/src/RelLib.py +++ b/gramps/src/RelLib.py @@ -353,14 +353,22 @@ class Researcher: def set(self,name,addr,city,state,country,postal,phone,email): """sets the information about the database owner""" - self.name = strip(name) - self.addr = strip(addr) - self.city = strip(city) - self.state = strip(state) - self.country = strip(country) - self.postal = strip(postal) - self.phone = strip(phone) - self.email = strip(email) + if name: + self.name = strip(name) + if addr: + self.addr = strip(addr) + if city: + self.city = strip(city) + if state: + self.state = strip(state) + if country: + self.country = strip(country) + if postal: + self.postal = strip(postal) + if phone: + self.phone = strip(phone) + if email: + self.email = strip(email) class Location: """Provides information about a place, including city, county, state, diff --git a/gramps/src/StartupDialog.py b/gramps/src/StartupDialog.py new file mode 100644 index 000000000..1e1cab870 --- /dev/null +++ b/gramps/src/StartupDialog.py @@ -0,0 +1,63 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000 Donald N. Allingham +# +# 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 +# + +import const +import libglade +import gnome.config +import utils + +class StartupDialog: + + def __init__(self,task,arg): + self.task = task + self.arg = arg + + self.druid = libglade.GladeXML(const.configFile,"initDruid") + self.druid.signal_autoconnect({ + "destroy_passed_object" : self.on_cancel_clicked, + "on_initDruid_finish" : self.on_finish + }) + + def on_finish(self,obj,b): + + name = self.druid.get_widget("dresname").get_text() + addr = self.druid.get_widget("dresaddr").get_text() + city = self.druid.get_widget("drescity").get_text() + state = self.druid.get_widget("dresstate").get_text() + country = self.druid.get_widget("drescountry").get_text() + postal = self.druid.get_widget("drespostal").get_text() + phone = self.druid.get_widget("dresphone").get_text() + email = self.druid.get_widget("dresemail").get_text() + + gnome.config.set_string("/gramps/researcher/name",name) + gnome.config.set_string("/gramps/researcher/addr",addr) + gnome.config.set_string("/gramps/researcher/city",city) + gnome.config.set_string("/gramps/researcher/state",state) + gnome.config.set_string("/gramps/researcher/country",country) + gnome.config.set_string("/gramps/researcher/postal",postal) + gnome.config.set_string("/gramps/researcher/phone",phone) + gnome.config.set_string("/gramps/researcher/email",email) + gnome.config.sync() + utils.destroy_passed_object(obj) + self.task(self.arg) + + def on_cancel_clicked(self,obj,a): + self.task(self.arg) + utils.destroy_passed_object(obj) diff --git a/gramps/src/gramps.py b/gramps/src/gramps.py index 640f9dfd1..454814b32 100755 --- a/gramps/src/gramps.py +++ b/gramps/src/gramps.py @@ -5,6 +5,7 @@ import intl import os import gtk import gnome.ui +import gnome.config import locale if os.environ.has_key("GRAMPSI18N"): @@ -21,11 +22,17 @@ import gramps_main import sys import locale +if len(sys.argv) > 1: + arg = sys.argv[1] +else: + arg = None + try: - if len(sys.argv) > 1: - gramps_main.main(sys.argv[1]) + if gnome.config.get_string("/gramps/researcher/name") == None: + from StartupDialog import StartupDialog + StartupDialog(gramps_main.main,arg) else: - gramps_main.main(None) + gramps_main.main(arg) except: traceback.print_exc() @@ -34,4 +41,5 @@ except: traceback.print_exc(file=errfile) errfile.close() +gtk.mainloop() diff --git a/gramps/src/gramps_main.py b/gramps/src/gramps_main.py index 609aa58e5..45ea49e81 100755 --- a/gramps/src/gramps_main.py +++ b/gramps/src/gramps_main.py @@ -1702,8 +1702,10 @@ def post_load(name): database.setSavePath(name) res = database.getResearcher() - if res.getName() == "" and Config.owner.getName() != "": - database.setResearcher(Config.owner) + owner = Config.get_researcher() + + if res.getName() == "" and owner.getName() != "": + database.setResearcher(owner) utils.modified() setup_bookmarks() @@ -2168,8 +2170,7 @@ def main(arg): if Config.autosave_int != 0: utils.enable_autosave(autosave_database,Config.autosave_int) - database.setResearcher(Config.owner) - gtk.mainloop() + database.setResearcher(Config.get_researcher()) #------------------------------------------------------------------------- # @@ -2262,4 +2263,4 @@ class DbPrompter: #------------------------------------------------------------------------- if __name__ == '__main__': main(None) - + gtk.mainloop()