svn: r8622
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2004-2006 Donald N. Allingham
|
||||
# Copyright (C) 2004-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
|
||||
@@ -38,6 +38,7 @@ import re
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from RelLib import Name
|
||||
from Errors import NameDisplayError
|
||||
|
||||
try:
|
||||
import Config
|
||||
@@ -383,7 +384,7 @@ class NameDisplay:
|
||||
# for each one we find the variable name that is needed to
|
||||
# replace it and add this to a list. This list will be used
|
||||
# generate the replacement tuple.
|
||||
pat = re.compile("%.")
|
||||
pat = re.compile('|'.join(d.keys()))
|
||||
|
||||
param = ()
|
||||
mat = pat.search(format_str)
|
||||
@@ -443,7 +444,11 @@ class NameDisplay:
|
||||
func = self._gen_cooked_func(format_str)
|
||||
self.__class__.format_funcs[format_str] = func
|
||||
|
||||
try:
|
||||
s = func(first,surname,prefix,suffix,patronymic,title,call)
|
||||
except (ValueError,TypeError,):
|
||||
raise NameDisplayError, "Incomplete format string"
|
||||
|
||||
return ' '.join(s.split())
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2006 Donald N. Allingham
|
||||
# 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
|
||||
@@ -383,8 +383,6 @@ class EditFamily(EditPrimary):
|
||||
EditPrimary.__init__(self, dbstate, uistate, track,
|
||||
family, dbstate.db.get_family_from_handle)
|
||||
|
||||
self.in_save = False
|
||||
|
||||
# look for the scenerio of a child and no parents on a new
|
||||
# family
|
||||
|
||||
@@ -433,7 +431,7 @@ class EditFamily(EditPrimary):
|
||||
def check_for_family_change(self, handles):
|
||||
|
||||
# check to see if the handle matches the current object
|
||||
if not self.in_save and self.obj.get_handle() in handles:
|
||||
if self.obj.get_handle() in handles:
|
||||
|
||||
self.obj = self.dbstate.db.get_family_from_handle(self.obj.get_handle())
|
||||
self.reload_people()
|
||||
@@ -802,7 +800,6 @@ class EditFamily(EditPrimary):
|
||||
|
||||
def __do_save(self):
|
||||
self.ok_button.set_sensitive(False)
|
||||
self.in_save = True
|
||||
|
||||
if not self.added:
|
||||
original = self.db.get_family_from_handle(self.obj.handle)
|
||||
@@ -834,6 +831,20 @@ class EditFamily(EditPrimary):
|
||||
self.ok_button.set_sensitive(True)
|
||||
return
|
||||
|
||||
if not original and self.object_is_empty():
|
||||
QuestionDialog.ErrorDialog(
|
||||
_("Cannot save family"),
|
||||
_("No data exists for this family. "
|
||||
"Please enter data or cancel the edit."))
|
||||
self.ok_button.set_sensitive(True)
|
||||
return
|
||||
|
||||
# We disconnect the callbacks to all signals we connected earlier.
|
||||
# This prevents the signals originating in any of the following
|
||||
# commits from being caught by us again.
|
||||
for key in self.signal_keys:
|
||||
self.db.disconnect(key)
|
||||
self.signal_keys = []
|
||||
|
||||
if not original and not self.object_is_empty():
|
||||
trans = self.db.transaction_begin()
|
||||
@@ -861,12 +872,6 @@ class EditFamily(EditPrimary):
|
||||
|
||||
self.db.add_family(self.obj,trans)
|
||||
self.db.transaction_commit(trans,_("Add Family"))
|
||||
elif not original and self.object_is_empty():
|
||||
QuestionDialog.ErrorDialog(_("Cannot save family"),
|
||||
_("No data exists for this family. Please "
|
||||
"enter data or cancel the edit."))
|
||||
self.ok_button.set_sensitive(True)
|
||||
return
|
||||
elif original and self.object_is_empty():
|
||||
trans = self.db.transaction_begin()
|
||||
self.db.remove_family(self.obj.handle,trans)
|
||||
@@ -901,7 +906,6 @@ class EditFamily(EditPrimary):
|
||||
self.db.commit_family(self.obj,trans)
|
||||
self.db.transaction_commit(trans,_("Edit Family"))
|
||||
|
||||
self.in_save = False
|
||||
self.close()
|
||||
|
||||
def _cleanup_on_exit(self):
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2003-2006 Donald N. Allingham
|
||||
# Copyright (C) 2003-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
|
||||
@@ -151,3 +151,14 @@ class DbError(Exception):
|
||||
def __str__(self):
|
||||
"Return string representation"
|
||||
return self.value
|
||||
|
||||
class NameDisplayError(Exception):
|
||||
"""
|
||||
Error used to report that the name display format string is invalid.
|
||||
"""
|
||||
def __init__(self,value):
|
||||
Exception.__init__(self)
|
||||
self.value = value
|
||||
|
||||
def __str__(self):
|
||||
return self.value
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gettext import gettext as _
|
||||
from xml.sax.saxutils import escape
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@@ -46,6 +47,7 @@ from RelLib import Name
|
||||
import ManagedWindow
|
||||
from GrampsWidgets import *
|
||||
import QuestionDialog
|
||||
from Errors import NameDisplayError
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@@ -379,12 +381,12 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
||||
Name format editor Edit button callback
|
||||
"""
|
||||
num,name,fmt = self.selected_fmt[COL_NUM:COL_EXPL]
|
||||
dlg = NameFormatEditDlg(name,fmt,self.examplename)
|
||||
dlg = NameFormatEditDlg(name, fmt, self.examplename)
|
||||
dlg.dlg.set_transient_for(self.window)
|
||||
(res,name,fmt) = dlg.run()
|
||||
|
||||
if name != self.selected_fmt[COL_NAME] or \
|
||||
fmt != self.selected_fmt[COL_FMT]:
|
||||
if res == gtk.RESPONSE_OK and (name != self.selected_fmt[COL_NAME] or
|
||||
fmt != self.selected_fmt[COL_FMT]):
|
||||
exmpl = _nd.format_str(self.examplename,fmt)
|
||||
self.fmt_model.set(self.iter,COL_NAME,name,
|
||||
COL_FMT,fmt,
|
||||
@@ -586,12 +588,13 @@ class NameFormatEditDlg:
|
||||
"""
|
||||
"""
|
||||
|
||||
def __init__(self,fmt_name,fmt_str,name):
|
||||
def __init__(self, fmt_name, fmt_str, name):
|
||||
self.fmt_name = fmt_name
|
||||
self.fmt_str = fmt_str
|
||||
self.name = name
|
||||
self.valid = True
|
||||
|
||||
self.top = gtk.glade.XML(const.gladeFile,'namefmt_edit','gramps')
|
||||
self.top = gtk.glade.XML(const.gladeFile, 'namefmt_edit','gramps')
|
||||
self.dlg = self.top.get_widget('namefmt_edit')
|
||||
ManagedWindow.set_titles(self.dlg, None, _('Name Format Editor'))
|
||||
|
||||
@@ -601,7 +604,7 @@ class NameFormatEditDlg:
|
||||
self.nameentry.set_text(self.fmt_name)
|
||||
|
||||
self.formatentry = self.top.get_widget('format_entry')
|
||||
self.formatentry.connect('changed',self.cb_format_changed)
|
||||
self.formatentry.connect('changed', self.cb_format_changed)
|
||||
self.formatentry.set_text(self.fmt_str)
|
||||
|
||||
def run(self):
|
||||
@@ -614,7 +617,15 @@ class NameFormatEditDlg:
|
||||
self.fmt_str = self.formatentry.get_text()
|
||||
|
||||
if self.response == gtk.RESPONSE_OK:
|
||||
if self.fmt_name == '' and self.fmt_str == '':
|
||||
if not self.valid:
|
||||
q = QuestionDialog.QuestionDialog2(
|
||||
_('The format definition is invalid'),
|
||||
_('What would you like to do?'),
|
||||
_('_Continue anyway'), _('_Modify format'),
|
||||
parent=self.dlg)
|
||||
running = not q.run()
|
||||
self.response = gtk.RESPONSE_CANCEL
|
||||
elif self.fmt_name == '' and self.fmt_str == '':
|
||||
self.response = gtk.RESPONSE_CANCEL
|
||||
elif (self.fmt_name == '') ^ (self.fmt_str == ''):
|
||||
QuestionDialog.ErrorDialog(
|
||||
@@ -625,11 +636,15 @@ class NameFormatEditDlg:
|
||||
self.dlg.destroy()
|
||||
return (self.response, self.fmt_name, self.fmt_str)
|
||||
|
||||
def cb_format_changed(self,obj):
|
||||
def cb_format_changed(self, obj):
|
||||
try:
|
||||
t = (_nd.format_str(self.name,obj.get_text()))
|
||||
except ValueError, msg:
|
||||
t = _("Invalid format string: %s") % msg
|
||||
self.examplelabel.set_text(
|
||||
'<span weight="bold" style="italic">%s</span>' % t)
|
||||
t = (_nd.format_str(self.name, escape(obj.get_text())))
|
||||
sample = '<span weight="bold" style="italic">%s</span>' % t
|
||||
self.valid = True
|
||||
except NameDisplayError:
|
||||
t = _("Invalid or incomplete format definition")
|
||||
sample = '<span foreground="#FF0000">%s</span>' % t
|
||||
self.valid = False
|
||||
|
||||
self.examplelabel.set_text(sample)
|
||||
self.examplelabel.set_use_markup(True)
|
||||
|
Reference in New Issue
Block a user