remember custom attributes/events

svn: r6248
This commit is contained in:
Don Allingham 2006-03-31 23:46:34 +00:00
parent b80b103a88
commit e45cf453ff
9 changed files with 268 additions and 106 deletions

View File

@ -1,4 +1,12 @@
2006-03-31 Don Allingham <don@gramps-project.org>
* src/GrampsDb/_GrampsDbBase.py: handle saving of custom
attributes and event types for use in menus
* src/Editors/_EditAttribute.py: support for family vs. person
* src/Editors/_EditEventRef.py: support for family vs. person
* src/Editors/_EditEvent.py: support for family vs. person
* src/DisplayTabs: support for family vs. person attributes/events
* src/GrampsWidgets.py: initialize type value properly
* src/GrampsDb/_WriteGedcom.py: fix lds calls
* src/lds.py: restore baptism status values
* src/Editors/_EditPrimary.py: check for empty objects
* src/Editors/_EditPlace.py: check for empty objects

View File

@ -117,7 +117,8 @@ class StandardCustomSelector:
(active_key,mapping[active_key]) tuple.
"""
def __init__(self,mapping,cbe=None,custom_key=None,active_key=None):
def __init__(self,mapping,cbe=None,custom_key=None,active_key=None,
additional=None):
"""
Constructor for the StandardCustomSelector class.
@ -136,7 +137,7 @@ class StandardCustomSelector:
self.custom_key = custom_key
self.active_key = active_key
self.active_index = 0
self.additional = additional
# make model
self.store = gtk.ListStore(int,str)
@ -171,6 +172,13 @@ class StandardCustomSelector:
self.active_index = index
index = index + 1
if self.additional:
for (value,data) in self.additional:
self.store.append(row=[value,data])
if key == self.active_key:
self.active_index = index
index = index + 1
def by_value(self,f,s):
"""
Method for sorting keys based on the values.

View File

@ -640,6 +640,10 @@ class EventEmbedList(EmbeddedList):
EmbeddedList.__init__(self, dbstate, uistate, track,
_('Events'), EventRefModel, True)
def get_ref_editor(self):
from Editors import EditFamilyEventRef
return EditFamilyEventRef
def get_icon_name(self):
return 'gramps-event'
@ -650,39 +654,36 @@ class EventEmbedList(EmbeddedList):
return ((1,0),(1,1),(1,2),(1,3),(1,4),(1,5))
def handle_extra_type(self, objtype, obj):
from Editors import EditEventRef
try:
ref = RelLib.EventRef()
event = self.dbstate.db.get_event_from_handle(obj)
if self.obj.__class__.__name__ == 'Person':
event.set_type((RelLib.Event.BIRTH,''))
ref.set_role((RelLib.EventRef.PRIMARY,''))
else:
event.set_type((RelLib.Event.MARRIAGE,''))
ref.set_role((RelLib.EventRef.FAMILY,''))
EditEventRef(self.dbstate,self.uistate,self.track,
event, ref, self.obj, self.event_added)
event.set_type(self.default_type())
ref.set_role(self.default_role())
self.get_ref_editor()(
self.dbstate,self.uistate,self.track,
event, ref, self.event_added)
except Errors.WindowActiveError:
pass
def default_type(self):
return (RelLib.EventRef.FAMILY,'')
def default_role(self):
return (RelLib.Event.MARRIAGE,'')
def add_button_clicked(self,obj):
from Editors import EditEventRef
try:
ref = RelLib.EventRef()
event = RelLib.Event()
if self.obj.__class__.__name__ == 'Person':
event.set_type((RelLib.Event.BIRTH,''))
ref.set_role((RelLib.EventRef.PRIMARY,''))
else:
event.set_type((RelLib.Event.MARRIAGE,''))
ref.set_role((RelLib.EventRef.FAMILY,''))
EditEventRef(self.dbstate,self.uistate,self.track,
event, ref, self.obj, self.event_added)
ref.set_role(self.default_role())
event.set_type(self.default_type())
self.get_ref_editor()(
self.dbstate,self.uistate,self.track,
event, ref, self.event_added)
except Errors.WindowActiveError:
pass
def share_button_clicked(self,obj):
from Editors import EditEventRef
import SelectEvent
sel = SelectEvent.SelectEvent(self.dbstate.db,"Event Select")
@ -690,22 +691,20 @@ class EventEmbedList(EmbeddedList):
if event:
try:
ref = RelLib.EventRef()
if self.obj.__class__.__name__ == 'Person':
ref.set_role((RelLib.EventRef.PRIMARY,''))
else:
ref.set_role((RelLib.EventRef.FAMILY,''))
EditEventRef(self.dbstate,self.uistate,self.track,
event, ref, self.obj, self.event_added)
ref.set_role(self.default_role())
self.get_ref_editor()(
self.dbstate,self.uistate,self.track,
event, ref, self.event_added)
except Errors.WindowActiveError:
pass
def edit_button_clicked(self,obj):
ref = self.get_selected()
if ref:
from Editors import EditEventRef
event = self.dbstate.db.get_event_from_handle(ref.ref)
try:
EditEventRef(self.dbstate,self.uistate,self.track,
self.get_ref_editor()(
self.dbstate,self.uistate,self.track,
event, ref, self.obj, self.event_updated)
except Errors.WindowActiveError:
pass
@ -732,6 +731,16 @@ class PersonEventEmbedList(EventEmbedList):
def get_data(self):
return self.orig_data
def default_role(self):
return (RelLib.EventRef.PRIMARY,'')
def default_type(self):
return (RelLib.Event.BIRTH,'')
def get_ref_editor(self):
from Editors import EditEventRef
return EditEventRef
def return_info(self):
new_list = []
birth_ref = None
@ -946,6 +955,13 @@ class AttrEmbedList(EmbeddedList):
EmbeddedList.__init__(self, dbstate, uistate, track,
_('Attributes'), AttrModel)
def get_editor(self):
from Editors import EditAttribute
return EditAttribute
def get_user_values(self):
return self.dbstate.db.get_person_attribute_types()
def get_data(self):
return self.data
@ -953,14 +969,12 @@ class AttrEmbedList(EmbeddedList):
return ((1,0),(1,1))
def add_button_clicked(self,obj):
from Editors import EditAttribute
pname = ''
attr_list = []
attr = RelLib.Attribute()
try:
EditAttribute(
self.get_editor()(
self.dbstate, self.uistate, self.track, attr,
pname, attr_list, self.add_callback)
pname, self.get_user_values(), self.add_callback)
except Errors.WindowActiveError:
pass
@ -972,13 +986,11 @@ class AttrEmbedList(EmbeddedList):
def edit_button_clicked(self,obj):
attr = self.get_selected()
if attr:
from Editors import EditAttribute
pname = ''
attr_list = []
try:
EditAttribute(
self.get_editor()(
self.dbstate, self.uistate, self.track, attr,
pname, attr_list, self.edit_callback)
pname, self.get_user_values(), self.edit_callback)
except Errors.WindowActiveError:
pass
@ -986,6 +998,23 @@ class AttrEmbedList(EmbeddedList):
self.changed = True
self.rebuild()
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
class FamilyAttrEmbedList(AttrEmbedList):
def __init__(self,dbstate,uistate,track,data):
AttrEmbedList.__init__(self, dbstate, uistate, track, data)
def get_editor(self):
from Editors import EditFamilyAttribute
return EditFamilyAttribute
def get_user_values(self):
return self.dbstate.db.get_family_attribute_types()
#-------------------------------------------------------------------------
#
#
@ -1014,9 +1043,10 @@ class WebEmbedList(EmbeddedList):
return ((1,0),(1,1),(1,2))
def add_button_clicked(self,obj):
from Editors import EditUrl
url = RelLib.Url()
try:
from Editors import EditUrl
EditUrl(self.dbstate, self.uistate, self.track,
'', url, self.add_callback)
except Errors.WindowActiveError:
@ -1029,8 +1059,9 @@ class WebEmbedList(EmbeddedList):
def edit_button_clicked(self,obj):
url = self.get_selected()
if url:
from Editors import EditUrl
try:
from Editors import EditUrl
EditUrl(self.dbstate, self.uistate, self.track,
'', url, self.edit_callback)
except Errors.WindowActiveError:
@ -1066,9 +1097,10 @@ class NameEmbedList(EmbeddedList):
return ((1,0),(1,1))
def add_button_clicked(self,obj):
from Editors import EditName
name = RelLib.Name()
try:
from Editors import EditName
EditName(self.dbstate, self.uistate, self.track,
name, self.add_callback)
except Errors.WindowActiveError:
@ -1081,8 +1113,9 @@ class NameEmbedList(EmbeddedList):
def edit_button_clicked(self,obj):
name = self.get_selected()
if name:
from Editors import EditName
try:
from Editors import EditName
EditName(self.dbstate, self.uistate, self.track,
name, self.edit_callback)
except Errors.WindowActiveError:
@ -1121,9 +1154,10 @@ class AddrEmbedList(EmbeddedList):
return ((1,0),(1,1),(1,2),(1,3),(1,4))
def add_button_clicked(self,obj):
from Editors import EditAddress
addr = RelLib.Address()
try:
from Editors import EditAddress
EditAddress(self.dbstate, self.uistate, self.track,
addr, self.add_callback)
except Errors.WindowActiveError:
@ -1136,8 +1170,9 @@ class AddrEmbedList(EmbeddedList):
def edit_button_clicked(self,obj):
addr = self.get_selected()
if addr:
from Editors import EditAddress
try:
from Editors import EditAddress
EditAddress(self.dbstate, self.uistate, self.track,
addr, self.edit_callback)
except Errors.WindowActiveError:
@ -1176,9 +1211,10 @@ class LocationEmbedList(EmbeddedList):
return ((1,0),(1,1),(1,2),(1,3),(1,4))
def add_button_clicked(self,obj):
from Editors import EditLocation
loc = RelLib.Location()
try:
from Editors import EditLocation
EditLocation(self.dbstate, self.uistate, self.track,
loc, self.add_callback)
except Errors.WindowActiveError:
@ -1191,8 +1227,9 @@ class LocationEmbedList(EmbeddedList):
def edit_button_clicked(self,obj):
loc = self.get_selected()
if loc:
from Editors import EditLocation
try:
from Editors import EditLocation
EditLocation(self.dbstate, self.uistate, self.track,
loc, self.edit_callback)
except Errors.WindowActiveError:
@ -1423,7 +1460,6 @@ class GalleryTab(ButtonTab):
return None
def add_button_clicked(self,obj):
from Editors import EditMediaRef
import AddMedia
am = AddMedia.AddMediaObject(self.dbstate.db)
@ -1432,6 +1468,8 @@ class GalleryTab(ButtonTab):
sref = RelLib.MediaRef()
try:
from Editors import EditMediaRef
EditMediaRef(self.dbstate, self.uistate, self.track,
src, sref, self.add_callback)
except Errors.WindowActiveError:
@ -1471,10 +1509,10 @@ class GalleryTab(ButtonTab):
def edit_button_clicked(self,obj):
ref = self.get_selected()
if ref:
from Editors import EditMediaRef
obj = self.dbstate.db.get_object_from_handle(ref.get_reference_handle())
try:
from Editors import EditMediaRef
EditMediaRef(self.dbstate, self.uistate, self.track,
obj, ref, self.edit_callback)
except Errors.WindowActiveError:
@ -1517,24 +1555,25 @@ class SourceEmbedList(EmbeddedList):
return ((1,0),(1,1),(1,2),(1,3))
def add_button_clicked(self,obj):
from Editors import EditSourceRef
sref = RelLib.SourceRef()
src = RelLib.Source()
try:
from Editors import EditSourceRef
EditSourceRef(self.dbstate, self.uistate, self.track,
src, sref, self.add_callback)
except Errors.WindowActiveError:
pass
def share_button_clicked(self,obj):
from Editors import EditSourceRef
import SelectSource
sel = SelectSource.SelectSource(self.dbstate.db,"Source Select")
src = sel.run()
if src:
try:
from Editors import EditSourceRef
ref = RelLib.SourceRef()
EditSourceRef(self.dbstate,self.uistate,self.track,
src, ref, self.add_callback)
@ -1548,12 +1587,12 @@ class SourceEmbedList(EmbeddedList):
self.rebuild()
def edit_button_clicked(self,obj):
from Editors import EditSourceRef
sref = self.get_selected()
src = self.dbstate.db.get_source_from_handle(sref.ref)
if sref:
try:
from Editors import EditSourceRef
EditSourceRef(self.dbstate, self.uistate, self.track,
src, sref, self.edit_callback)
except Errors.WindowActiveError:
@ -1564,11 +1603,11 @@ class SourceEmbedList(EmbeddedList):
self.rebuild()
def handle_extra_type(self, objtype, obj):
from Editors import EditSourceRef
sref = RelLib.SourceRef()
src = self.dbstate.db.get_source_from_handle(obj)
try:
from Editors import EditSourceRef
EditSourceRef(self.dbstate, self.uistate, self.track,
src, sref, self.add_callback)
except Errors.WindowActiveError:
@ -1608,8 +1647,9 @@ class RepoEmbedList(EmbeddedList):
return ((1,0),(1,1),(1,2),(1,3))
def handle_extra_type(self, objtype, obj):
from Editors import EditRepoRef
try:
from Editors import EditRepoRef
ref = RelLib.RepoRef()
repo = self.dbstate.db.get_repository_from_handle(obj)
EditRepoRef(
@ -1619,11 +1659,11 @@ class RepoEmbedList(EmbeddedList):
pass
def add_button_clicked(self,obj):
from Editors import EditRepoRef
ref = RelLib.RepoRef()
repo = RelLib.Repository()
try:
from Editors import EditRepoRef
EditRepoRef(
self.dbstate, self.uistate, self.track,
repo, ref, self.add_callback)
@ -1637,12 +1677,12 @@ class RepoEmbedList(EmbeddedList):
self.rebuild()
def edit_button_clicked(self,obj):
from Editors import EditRepoRef
ref = self.get_selected()
if ref:
repo = self.dbstate.db.get_repository_from_handle(ref.ref)
try:
from Editors import EditRepoRef
EditRepoRef(
self.dbstate, self.uistate, self.track, repo,
ref, self.edit_callback)

View File

@ -53,7 +53,6 @@ import RelLib
import GrampsDisplay
from _EditSecondary import EditSecondary
from QuestionDialog import WarningDialog
from DisplayTabs import *
from GrampsWidgets import *
@ -78,6 +77,9 @@ class EditAttribute(EditSecondary):
self.alist = data_list
EditSecondary.__init__(self, state, uistate, track, attrib, callback)
def attribute_list(self):
return Utils.personal_attributes
def _local_init(self):
self.top = gtk.glade.XML(const.gladeFile, "attr_edit","gramps")
self.define_top_level(self.top.get_widget("attr_edit"),
@ -101,9 +103,12 @@ class EditAttribute(EditSecondary):
self.type_selector = MonitoredType(
self.top.get_widget("attr_menu"),
self.obj.set_type, self.obj.get_type,
dict(Utils.personal_attributes),
RelLib.Attribute.CUSTOM)
self.obj.set_type,
self.obj.get_type,
self.attribute_list(),
RelLib.Attribute.CUSTOM,
custom_values=self.alist,
)
def _create_tabbed_pages(self):
notebook = gtk.Notebook()
@ -135,18 +140,32 @@ class EditAttribute(EditSecondary):
Called when the OK button is pressed. Gets data from the
form and updates the Attribute data structure.
"""
attr_data = self.obj.get_type()
if (attr_data[0] == RelLib.Attribute.CUSTOM and
not attr_data[1] in self.alist):
WarningDialog(
_('New attribute type created'),
_('The "%s" attribute type has been added to this database.\n'
'It will now appear in the attribute menus for this database') % attr_data[1])
self.alist.append(attr_data[1])
self.alist.sort()
if self.callback:
self.callback(self.obj)
self.close_window(obj)
#-------------------------------------------------------------------------
#
# EditAttribute class
#
#-------------------------------------------------------------------------
class EditFamilyAttribute(EditAttribute):
"""
Displays a dialog that allows the user to edit an attribute.
"""
def __init__(self, state, uistate, track, attrib, title, data_list, callback):
"""
Displays the dialog box.
parent - The class that called the Address editor.
attrib - The attribute that is to be edited
title - The title of the dialog box
list - list of options for the pop down menu
"""
EditAttribute.__init__(self, state, uistate, track, attrib, title,
data_list, callback)
def attribute_list(self):
return Utils.family_attributes

View File

@ -61,10 +61,6 @@ from GrampsWidgets import *
# Constants
#
#-------------------------------------------------------------------------
total_events = dict(Utils.personal_events)
for event_type in Utils.family_events.keys():
if not total_events.has_key(event_type):
total_events[event_type] = Utils.family_events[event_type]
#-------------------------------------------------------------------------
#
@ -78,9 +74,26 @@ class EditEvent(EditPrimary):
EditPrimary.__init__(self, dbstate, uistate, track,
event, dbstate.db.get_event_from_handle)
self._init_event()
def _init_event(self):
self.commit_event = self.db.commit_event
def empty_object(self):
return RelLib.Event()
def get_base_events(self):
new_batch = {}
for key in Utils.personal_events:
new_batch[key] = Utils.personal_events[key]
for key in Utils.family_events:
new_batch[key] = Utils.family_events[key]
return new_batch
def get_custom_events(self):
return self.dbstate.db.get_person_event_type_list() + \
self.dbstate.db.get_family_event_types()
def _local_init(self):
self.top = gtk.glade.XML(const.gladeFile, "event_edit","gramps")
self.window = self.top.get_widget("event_edit")
@ -122,8 +135,9 @@ class EditEvent(EditPrimary):
self.top.get_widget("personal_events"),
self.obj.set_type,
self.obj.get_type,
dict(total_events),
RelLib.Event.CUSTOM)
self.get_base_events(),
RelLib.Event.CUSTOM,
custom_values=self.get_custom_events())
self.date_field = MonitoredDate(
self.top.get_widget("eventDate"),
@ -209,18 +223,13 @@ class EditEvent(EditPrimary):
trans = self.db.transaction_begin()
if need_new:
self.db.add_place(place_obj,trans)
self.db.commit_event(self.obj,trans)
self.commit_event(self.obj,trans)
self.db.transaction_commit(trans,_("Edit Event"))
if self.callback:
self.callback(self.obj)
self.close(obj)
def get_event_names(self):
data = set(self.db.get_family_event_types())
data.union(self.db.get_person_event_types())
return list(data)
def data_has_changed(self):
if self.db.readonly:
return False
@ -230,6 +239,36 @@ class EditEvent(EditPrimary):
else:
return True
class EditPersonEvent(EditEvent):
def __init__(self, event, dbstate, uistate, track=[], callback=None):
EditEvent.__init__(self, event, dbstate, uistate, track,
callback)
def _init_event(self):
self.commit_event = self.db.commit_personal_event
def get_base_events(self):
return Utils.personal_events
def get_custom_events(self):
return self.dbstate.db.get_person_event_type_list()
class EditFamilyEvent(EditEvent):
def __init__(self, event, dbstate, uistate, track=[], callback=None):
EditEvent.__init__(self, event, dbstate, uistate, track,
callback)
def _init_event(self):
self.commit_event = self.db.commit_family_event
def get_base_events(self):
return Utils.family_events
def get_custom_events(self):
return self.dbstate.db.get_family_event_types()
#-------------------------------------------------------------------------
#
# Delete Query class
@ -262,3 +301,4 @@ class DelEventQuery:
self.db.remove_event(self.event.get_handle(),trans)
self.db.transaction_commit(
trans,_("Delete Event (%s)") % self.event.get_gramps_id())

View File

@ -70,11 +70,10 @@ for event_type in Utils.family_events.keys():
#
#-------------------------------------------------------------------------
class EditEventRef(EditReference):
def __init__(self, state, uistate, track, event, event_ref, referent, update):
self.referent = referent
def __init__(self, state, uistate, track, event, event_ref, update):
EditReference.__init__(self, state, uistate, track, event, event_ref,
update)
self._init_event()
def _local_init(self):
@ -85,10 +84,18 @@ class EditEventRef(EditReference):
self.define_warn_box(self.top.get_widget("eer_warning"))
self.define_expander(self.top.get_widget("eer_expander"))
if self.referent.__class__.__name__ == 'Person':
self.role_dict = Utils.event_roles
elif self.referent.__class__.__name__ == 'Family':
self.role_dict = Utils.family_event_roles
def _init_event(self):
self.commit_event = self.db.commit_personal_event
self.add_event = self.db.add_person_event
def get_roles(self):
return Utils.event_roles
def get_event_types(self):
return Utils.personal_events
def get_custom_events(self):
return [ (RelLib.Event.CUSTOM,val) for val in self.dbstate.db.get_person_event_types()]
def _connect_signals(self):
self.define_ok_button(self.top.get_widget('ok'),self.ok_clicked)
@ -126,15 +133,16 @@ class EditEventRef(EditReference):
self.top.get_widget('eer_role_combo'),
self.source_ref.set_role,
self.source_ref.get_role,
self.role_dict,
self.get_roles(),
RelLib.EventRef.CUSTOM)
self.event_menu = MonitoredType(
self.top.get_widget("eer_type_combo"),
self.source.set_type,
self.source.get_type,
dict(total_events),
RelLib.Event.CUSTOM)
self.get_event_types(),
RelLib.Event.CUSTOM,
custom_values=self.get_custom_events())
self.date_check = MonitoredDate(
self.top.get_widget("eer_date"),
@ -206,12 +214,12 @@ class EditEventRef(EditReference):
if self.source.handle:
if need_new:
self.db.add_place(place_obj,trans)
self.db.commit_event(self.source,trans)
self.commit_event(self.source,trans)
self.db.transaction_commit(trans,_("Modify Event"))
else:
if need_new:
self.db.add_place(place_obj,trans)
self.db.add_event(self.source,trans)
self.add_event(self.source,trans)
self.db.transaction_commit(trans,_("Add Event"))
self.source_ref.ref = self.source.handle
@ -220,6 +228,26 @@ class EditEventRef(EditReference):
self.close_window(None)
class EditFamilyEventRef(EditEventRef):
def __init__(self, state, uistate, track, event, event_ref, update):
EditEventRef.__init__(self, state, uistate, track, event,
event_ref, update)
def _init_event(self):
self.commit_event = self.db.commit_family_event
self.add_event = self.db.add_family_event
def get_roles(self):
return Utils.event_roles
def get_event_types(self):
return Utils.family_events
def get_custom_events(self):
return [ (RelLib.Event.CUSTOM,val) for val in self.dbstate.db.get_family_event_types()]
#-------------------------------------------------------------------------
#

View File

@ -473,7 +473,7 @@ class EditFamily(EditPrimary):
self.attr_list = self._add_tab(
notebook,
AttrEmbedList(self.dbstate, self.uistate, self.track,
FamilyAttrEmbedList(self.dbstate, self.uistate, self.track,
self.obj.get_attribute_list()))
self.note_tab = self._add_tab(

View File

@ -859,6 +859,24 @@ class GrampsDbBase(GrampsDBCallback):
self.find_next_event_gramps_id,
self.commit_event)
def add_person_event(self,event,transaction):
"""
Adds an Event to the database, assigning internal IDs if they have
not already been defined.
"""
if event.type[0] == Event.CUSTOM:
self.individual_event_names.add(event.type[1])
return self.add_event(event,transaction)
def add_family_event(self,event,transaction):
"""
Adds an Event to the database, assigning internal IDs if they have
not already been defined.
"""
if event.type[0] == Event.CUSTOM:
self.family_event_names.add(event.type[1])
return self.add_event(event,transaction)
def add_place(self,place,transaction):
"""
Adds a Place to the database, assigning internal IDs if they have

View File

@ -316,7 +316,8 @@ class MonitoredText:
class MonitoredType:
def __init__(self,obj,set_val,get_val,mapping,custom,readonly=False):
def __init__(self,obj,set_val,get_val,mapping,custom,readonly=False,
custom_values=None):
self.set_val = set_val
self.get_val = get_val
@ -329,7 +330,7 @@ class MonitoredType:
default = None
self.sel = AutoComp.StandardCustomSelector(
mapping, obj, custom, default)
mapping, obj, custom, default, additional=custom_values)
self.set_val(self.sel.get_values())
self.obj.set_sensitive(not readonly)