From 63614a2740107069b82818559284b4f36710a650 Mon Sep 17 00:00:00 2001 From: Zsolt Foldvari Date: Sun, 4 Feb 2007 17:37:36 +0000 Subject: [PATCH] 2007-02-04 Zsolt Foldvari * src/GrampsLocale: set svn:ignore propery * src/BasicUtils: set svn:ignore propery * src/GrampsDbUtils: set svn:ignore propery * src/RelLib/_Researcher.py: add missing get/set methods * src/GrampsDbUtils/_WriteGedcom.py: db owner handling, warn for missing * src/GrampsCfg.py: db owner handling, new warning pref * src/Config/_GrampsConfigKeys.py: db owner handling, new warning pref * data/gramps.schemas.in: db owner handling, new warning pref * src/plugins/OwnerEditor.py: db owner handling, plugin tool * src/plugins/ownereditor.glade: db owner handling, plugin tool svn: r8051 --- ChangeLog | 12 + data/gramps.schemas.in | 13 + src/Config/_GrampsConfigKeys.py | 2 + src/GrampsCfg.py | 9 +- src/GrampsDbUtils/_WriteGedcom.py | 32 +- src/RelLib/_Researcher.py | 22 ++ src/plugins/OwnerEditor.py | 192 ++++++++++ src/plugins/ownereditor.glade | 586 ++++++++++++++++++++++++++++++ 8 files changed, 848 insertions(+), 20 deletions(-) create mode 100644 src/plugins/OwnerEditor.py create mode 100644 src/plugins/ownereditor.glade diff --git a/ChangeLog b/ChangeLog index 901a696f1..406213320 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2007-02-04 Zsolt Foldvari + * src/GrampsLocale: set svn:ignore propery + * src/BasicUtils: set svn:ignore propery + * src/GrampsDbUtils: set svn:ignore propery + * src/RelLib/_Researcher.py: add missing get/set methods + * src/GrampsDbUtils/_WriteGedcom.py: db owner handling, warn for missing + * src/GrampsCfg.py: db owner handling, new warning pref + * src/Config/_GrampsConfigKeys.py: db owner handling, new warning pref + * data/gramps.schemas.in: db owner handling, new warning pref + * src/plugins/OwnerEditor.py: db owner handling, plugin tool + * src/plugins/ownereditor.glade: db owner handling, plugin tool + 2007-02-04 Richard Taylor * src/GrampsDb/_GrampsGEDDB.py: fix reader/writer import * ChangeLog: fix the commit of a conflit (Brian ?) diff --git a/data/gramps.schemas.in b/data/gramps.schemas.in index d5edbdd74..55776b07d 100644 --- a/data/gramps.schemas.in +++ b/data/gramps.schemas.in @@ -1153,5 +1153,18 @@ + + /schemas/apps/gramps/behavior/owner-warn + /apps/gramps/behavior/owner-warn + gramps + bool + 0 + + Hide warning on missing database owner. + If set to 1, the warning about missing database owner will not + be displayed when GEDCOM export is done. + + + diff --git a/src/Config/_GrampsConfigKeys.py b/src/Config/_GrampsConfigKeys.py index 3ba8ecc0f..d833985aa 100644 --- a/src/Config/_GrampsConfigKeys.py +++ b/src/Config/_GrampsConfigKeys.py @@ -114,6 +114,7 @@ WEBSITE_DIRECTORY = ('paths','website-directory', 2) PORT_WARN = ('preferences','port-warn', 0) TRANSACTIONS = ('behavior','transactions', 0) RELEDITBTN = ('interface','editbutton', 1) +OWNER_WARN = ('preferences','owner-warn', 0) default_value = { @@ -211,4 +212,5 @@ default_value = { WEBSITE_DIRECTORY : './', PORT_WARN : False, TRANSACTIONS : True, + OWNER_WARN : False, } diff --git a/src/GrampsCfg.py b/src/GrampsCfg.py index 885c0e60c..1c5bdbfe9 100644 --- a/src/GrampsCfg.py +++ b/src/GrampsCfg.py @@ -163,7 +163,7 @@ class GrampsPreferences(ManagedWindow.ManagedWindow): return table def add_advanced_panel(self): - table = gtk.Table(3,8) + table = gtk.Table(4,8) table.set_border_width(12) table.set_col_spacings(6) table.set_row_spacings(6) @@ -175,9 +175,14 @@ class GrampsPreferences(ManagedWindow.ManagedWindow): table, _('Suppress warning when cancelling with changed data'), 1, Config.DONT_ASK) + self.add_checkbox( + table, _('Suppress warning about missing researcher when' + ' exporting to GEDCOM'), + 2, Config.OWNER_WARN) + self.add_checkbox( table, _('Show plugin status dialog on plugin load error'), - 2, Config.POP_PLUGIN_STATUS) + 3, Config.POP_PLUGIN_STATUS) return table diff --git a/src/GrampsDbUtils/_WriteGedcom.py b/src/GrampsDbUtils/_WriteGedcom.py index 5caad27a2..9b13c52b2 100644 --- a/src/GrampsDbUtils/_WriteGedcom.py +++ b/src/GrampsDbUtils/_WriteGedcom.py @@ -60,12 +60,10 @@ from BasicUtils import UpdateCallback try: import Config - STARTUP = Config.STARTUP - STARTUP_VAL = Config.get(Config.STARTUP) + HAVE_CONFIG = True except: log.warn("No Config module available using defaults.") - STARTUP = ('behavior','startup', 1) - STARTUP_VAL = 0 + HAVE_CONFIG = False #------------------------------------------------------------------------ # @@ -78,12 +76,6 @@ def keep_utf8(s): def iso8859(s): return s.encode('iso-8859-1','replace') -def researcher_info_missing(): - val = STARTUP_VAL - if val < const.startup: - return True - return False - #------------------------------------------------------------------------- # # GEDCOM tags representing attributes that may take a parameter, value or @@ -471,14 +463,18 @@ class GedcomWriter(UpdateCallback): self.cnvtxt = self.option_box.cnvtxt self.nl = self.option_box.nl - if researcher_info_missing(): - MessageHideDialog( - _('Researcher information'), - _('A valid GEDCOM file is required to contain researcher ' - 'information. You need to fill these data in the ' - 'Preferences dialog.\n\n' - 'However, most programs do not require it. ' - 'You may leave this empty if you want.'),STARTUP) + if HAVE_CONFIG: + show_owner_missing_warning = not Config.get(Config.OWNER_WARN) + owner_name_empty = self.db.get_researcher().get_name() == '' + + if show_owner_missing_warning and owner_name_empty: + MessageHideDialog( + _('Researcher information'), + _('A valid GEDCOM file is required to contain researcher ' + 'information. You need to fill these data in the ' + 'Preferences dialog.\n\n' + 'However, most programs do not require it. You may ' + 'leave this empty if you want.'),Config.OWNER_WARN) if self.option_box.cfilter == None: self.plist = set(self.db.get_person_handles(sort_handles=False)) diff --git a/src/RelLib/_Researcher.py b/src/RelLib/_Researcher.py index 97d221404..5f33ff59b 100644 --- a/src/RelLib/_Researcher.py +++ b/src/RelLib/_Researcher.py @@ -49,14 +49,26 @@ class Researcher(LocationBase): self.addr = "" self.email = "" + def set_name(self, data): + """sets the database owner's name""" + self.name = data + def get_name(self): """returns the database owner's name""" return self.name + def set_address(self, data): + """sets the database owner's address""" + self.addr = data + def get_address(self): """returns the database owner's address""" return self.addr + def set_email(self, data): + """ sets the database owner's email""" + self.email = data + def get_email(self): """returns the database owner's email""" return self.email @@ -80,3 +92,13 @@ class Researcher(LocationBase): if email: self.email = email.strip() + def get(self): + """gets the information about the database owner""" + return (self.name, + self.addr, + self.city, + self.state, + self.country, + self.postal, + self.phone, + self.email) diff --git a/src/plugins/OwnerEditor.py b/src/plugins/OwnerEditor.py new file mode 100644 index 000000000..936d00976 --- /dev/null +++ b/src/plugins/OwnerEditor.py @@ -0,0 +1,192 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2007 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 +# + +# $Id: + +"Database Processing/Edit database owner information" + +#------------------------------------------------------------------------- +# +# python modules +# +#------------------------------------------------------------------------- +import os +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# gnome/gtk +# +#------------------------------------------------------------------------- +import gtk +import gtk.glade + +#------------------------------------------------------------------------- +# +# gramps modules +# +#------------------------------------------------------------------------- +import Config +import GrampsCfg +import GrampsDisplay +from GrampsWidgets import MonitoredEntry +import ManagedWindow +from PluginUtils import Tool, register_tool + +#------------------------------------------------------------------------- +# +# constants +# +#------------------------------------------------------------------------- +config_keys = ( + Config.RESEARCHER_NAME, + Config.RESEARCHER_ADDR, + Config.RESEARCHER_CITY, + Config.RESEARCHER_STATE, + Config.RESEARCHER_COUNTRY, + Config.RESEARCHER_POSTAL, + Config.RESEARCHER_PHONE, + Config.RESEARCHER_EMAIL, +) + +#------------------------------------------------------------------------- +# +# OwnerEditor +# +#------------------------------------------------------------------------- +class OwnerEditor(Tool.Tool, ManagedWindow.ManagedWindow): + """ + Allow editing database owner information. + + Provides a possibility to direcly verify and edit the owner data of the + current database. It also allows copying data from/to the preferences. + """ + def __init__(self, dbstate, uistate, options_class, name, callback=None): + ManagedWindow.ManagedWindow.__init__(self, uistate, [], self.__class__) + Tool.Tool.__init__(self, dbstate, options_class, name) + + self.display() + + def display(self): + base = os.path.dirname(__file__) + glade_file = os.path.join(base, "ownereditor.glade") + + # get the main window from glade + top_xml = gtk.glade.XML(glade_file, "top", "gramps") + + # set gramps style title for the window + window = top_xml.get_widget("top") + self.set_window(window, + top_xml.get_widget("title"), + _("Database owner editor")) + + # move help button to the left side + action_area = top_xml.get_widget("action_area") + help_button = top_xml.get_widget("help_button") + action_area.set_child_secondary(help_button, True) + + # connect signals + top_xml.signal_autoconnect({ + "on_ok_button_clicked": self.on_ok_button_clicked, + "on_cancel_button_clicked": self.close, + "on_help_button_clicked": self.on_help_button_clicked, + "on_eventbox_button_press_event": self.on_button_press_event, + }) + + # fetch the popup menu + popup_xml = gtk.glade.XML(glade_file, "popup-menu", "gramps") + self.menu = popup_xml.get_widget("popup-menu") + popup_xml.signal_connect("on_menu_activate", self.on_menu_activate) + + # get current db owner and attach it to the entries of the window + self.owner = self.db.get_researcher() + + self.entries = [] + entry = [ + ("entry1", self.owner.set_name, self.owner.get_name), + ("entry2", self.owner.set_address, self.owner.get_address), + ("entry3", self.owner.set_city, self.owner.get_city), + ("entry4", self.owner.set_state, self.owner.get_state), + ("entry5", self.owner.set_country, self.owner.get_country), + ("entry6", self.owner.set_postal_code, self.owner.get_postal_code), + ("entry7", self.owner.set_phone, self.owner.get_phone), + ("entry8", self.owner.set_email, self.owner.get_email), + ] + + for (name,set_fn,get_fn) in entry: + self.entries.append(MonitoredEntry(top_xml.get_widget(name), + set_fn, + get_fn, + self.db.readonly)) + # ok, let's see what we've done + self.show() + + def on_ok_button_clicked(self, obj): + """Update the current db's owner information from editor""" + self.db.set_researcher(self.owner) + self.close() + + def on_help_button_clicked(self, obj): + """Display the relevant portion of GRAMPS manual""" + GrampsDisplay.help('tools-db') + + def on_button_press_event(self, obj, event): + """Shows popup-menu for db <-> preferences copying""" + if event.button == 3 and event.type == gtk.gdk.BUTTON_PRESS: + self.menu.popup(None,None,None,0,0) + + def on_menu_activate(self, menuitem): + """Copies the owner information from/to the preferences""" + if menuitem.name == 'copy_from_preferences_to_db': + self.owner.set(*GrampsCfg.get_researcher().get()) + for entry in self.entries: + entry.update() + + elif menuitem.name == 'copy_from_db_to_preferences': + for i in range(len(config_keys)): + Config.set(config_keys[i], self.owner.get()[i]) + +#------------------------------------------------------------------------- +# +# OwnerEditorOptions (None at the moment) +# +#------------------------------------------------------------------------- +class OwnerEditorOptions(Tool.ToolOptions): + """Defines options and provides handling interface.""" + def __init__(self,name,person_id=None): + Tool.ToolOptions.__init__(self,name,person_id) + +#------------------------------------------------------------------------- +# +# Register the plugin tool to plugin manager +# +#------------------------------------------------------------------------- +register_tool( + name = 'editowner', + category = Tool.TOOL_DBPROC, + tool_class = OwnerEditor, + options_class = OwnerEditorOptions, + modes = Tool.MODE_GUI, + translated_name = _("Edit database owner information"), + status = _("Beta"), + author_name = "Zsolt Foldvari", + author_email = "zfoldvar@users.sourceforge.net", + description = _("Allow editing database owner information.") +) diff --git a/src/plugins/ownereditor.glade b/src/plugins/ownereditor.glade new file mode 100644 index 000000000..ba1d3f449 --- /dev/null +++ b/src/plugins/ownereditor.glade @@ -0,0 +1,586 @@ + + + + + + + + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER + False + 500 + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + True + False + + + + + True + True + False + + + + + 6 + True + False + 0 + + + + True + GTK_BUTTONBOX_END + 0 + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + + + + + + + True + True + True + gtk-help + True + GTK_RELIEF_NORMAL + True + + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + + + 3 + False + True + GTK_PACK_END + + + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 6 + False + False + + + + + + 6 + True + 8 + 2 + False + 6 + 6 + + + + True + Name: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + Address: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + City: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 2 + 3 + fill + + + + + + + True + State/Province: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 3 + 4 + fill + + + + + + + True + Country: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 4 + 5 + fill + + + + + + + True + ZIP/Postal Code: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 5 + 6 + fill + + + + + + + True + Phone: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 6 + 7 + fill + + + + + + + True + Email: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 7 + 8 + fill + + + + + + + True + True + True + True + 0 + + True + + False + + + 1 + 2 + 0 + 1 + + + + + + + True + True + True + True + 0 + + True + + False + + + 1 + 2 + 1 + 2 + + + + + + + True + True + True + True + 0 + + True + + False + + + 1 + 2 + 2 + 3 + + + + + + + True + True + True + True + 0 + + True + + False + + + 1 + 2 + 3 + 4 + + + + + + + True + True + True + True + 0 + + True + + False + + + 1 + 2 + 4 + 5 + + + + + + + True + True + True + True + 0 + + True + + False + + + 1 + 2 + 5 + 6 + + + + + + + True + True + True + True + 0 + + True + + False + + + 1 + 2 + 6 + 7 + + + + + + + True + True + True + True + 0 + + True + + False + + + 1 + 2 + 7 + 8 + + + + + + 0 + False + True + + + + + + + + + + + + + True + Copy from DB to Preferences + True + + + + + True + gtk-go-back + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + True + Copy from Preferences to DB + True + + + + + True + gtk-go-forward + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + +