From b0e285abfb9db88ee81faa0fd6a610adefeaa8a1 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Fri, 1 Jun 2012 17:55:58 +0000 Subject: [PATCH] EditObject can now create a new object svn: r19737 --- src/gui/editors/__init__.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/gui/editors/__init__.py b/src/gui/editors/__init__.py index 475671cd5..097da4054 100644 --- a/src/gui/editors/__init__.py +++ b/src/gui/editors/__init__.py @@ -57,21 +57,27 @@ EDITORS = { 'Note': EditNote, } -def EditObject(dbstate, uistate, track, obj_class, prop, value): +def EditObject(dbstate, uistate, track, obj_class, prop=None, value=None, callback=None): """ Generic Object Editor. obj_class is Person, Source, Repository, etc. - prop is 'handle' or 'gramps_id' - value is string handle or string gramps_id + prop is 'handle', 'gramps_id', or None (for new object) + value is string handle, string gramps_id, or None (for new object) """ import logging LOG = logging.getLogger(".Edit") if obj_class in dbstate.db.get_table_names(): - if prop in ("gramps_id", "handle"): + if value is None: + obj = dbstate.db.get_table_metadata(obj_class)["class_func"]() + try: + EDITORS[obj_class](dbstate, uistate, track, obj, callback=callback) + except Exception as msg: + LOG.warn(str(msg)) + elif prop in ("gramps_id", "handle"): obj = dbstate.db.get_table_metadata(obj_class)[prop + "_func"](value) if obj: try: - EDITORS[obj_class](dbstate, uistate, track, obj) + EDITORS[obj_class](dbstate, uistate, track, obj, callback=callback) except Exception as msg: LOG.warn(str(msg)) else: