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> 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/lds.py: restore baptism status values
* src/Editors/_EditPrimary.py: check for empty objects * src/Editors/_EditPrimary.py: check for empty objects
* src/Editors/_EditPlace.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. (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. Constructor for the StandardCustomSelector class.
@ -136,7 +137,7 @@ class StandardCustomSelector:
self.custom_key = custom_key self.custom_key = custom_key
self.active_key = active_key self.active_key = active_key
self.active_index = 0 self.active_index = 0
self.additional = additional
# make model # make model
self.store = gtk.ListStore(int,str) self.store = gtk.ListStore(int,str)
@ -171,6 +172,13 @@ class StandardCustomSelector:
self.active_index = index self.active_index = index
index = index + 1 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): def by_value(self,f,s):
""" """
Method for sorting keys based on the values. Method for sorting keys based on the values.

View File

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

View File

@ -53,7 +53,6 @@ import RelLib
import GrampsDisplay import GrampsDisplay
from _EditSecondary import EditSecondary from _EditSecondary import EditSecondary
from QuestionDialog import WarningDialog
from DisplayTabs import * from DisplayTabs import *
from GrampsWidgets import * from GrampsWidgets import *
@ -78,6 +77,9 @@ class EditAttribute(EditSecondary):
self.alist = data_list self.alist = data_list
EditSecondary.__init__(self, state, uistate, track, attrib, callback) EditSecondary.__init__(self, state, uistate, track, attrib, callback)
def attribute_list(self):
return Utils.personal_attributes
def _local_init(self): def _local_init(self):
self.top = gtk.glade.XML(const.gladeFile, "attr_edit","gramps") self.top = gtk.glade.XML(const.gladeFile, "attr_edit","gramps")
self.define_top_level(self.top.get_widget("attr_edit"), self.define_top_level(self.top.get_widget("attr_edit"),
@ -101,9 +103,12 @@ class EditAttribute(EditSecondary):
self.type_selector = MonitoredType( self.type_selector = MonitoredType(
self.top.get_widget("attr_menu"), self.top.get_widget("attr_menu"),
self.obj.set_type, self.obj.get_type, self.obj.set_type,
dict(Utils.personal_attributes), self.obj.get_type,
RelLib.Attribute.CUSTOM) self.attribute_list(),
RelLib.Attribute.CUSTOM,
custom_values=self.alist,
)
def _create_tabbed_pages(self): def _create_tabbed_pages(self):
notebook = gtk.Notebook() notebook = gtk.Notebook()
@ -135,18 +140,32 @@ class EditAttribute(EditSecondary):
Called when the OK button is pressed. Gets data from the Called when the OK button is pressed. Gets data from the
form and updates the Attribute data structure. 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: if self.callback:
self.callback(self.obj) self.callback(self.obj)
self.close_window(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 # 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, EditPrimary.__init__(self, dbstate, uistate, track,
event, dbstate.db.get_event_from_handle) 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): def empty_object(self):
return RelLib.Event() 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): def _local_init(self):
self.top = gtk.glade.XML(const.gladeFile, "event_edit","gramps") self.top = gtk.glade.XML(const.gladeFile, "event_edit","gramps")
self.window = self.top.get_widget("event_edit") self.window = self.top.get_widget("event_edit")
@ -122,8 +135,9 @@ class EditEvent(EditPrimary):
self.top.get_widget("personal_events"), self.top.get_widget("personal_events"),
self.obj.set_type, self.obj.set_type,
self.obj.get_type, self.obj.get_type,
dict(total_events), self.get_base_events(),
RelLib.Event.CUSTOM) RelLib.Event.CUSTOM,
custom_values=self.get_custom_events())
self.date_field = MonitoredDate( self.date_field = MonitoredDate(
self.top.get_widget("eventDate"), self.top.get_widget("eventDate"),
@ -209,18 +223,13 @@ class EditEvent(EditPrimary):
trans = self.db.transaction_begin() trans = self.db.transaction_begin()
if need_new: if need_new:
self.db.add_place(place_obj,trans) 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")) self.db.transaction_commit(trans,_("Edit Event"))
if self.callback: if self.callback:
self.callback(self.obj) self.callback(self.obj)
self.close(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): def data_has_changed(self):
if self.db.readonly: if self.db.readonly:
return False return False
@ -230,6 +239,36 @@ class EditEvent(EditPrimary):
else: else:
return True 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 # Delete Query class
@ -262,3 +301,4 @@ class DelEventQuery:
self.db.remove_event(self.event.get_handle(),trans) self.db.remove_event(self.event.get_handle(),trans)
self.db.transaction_commit( self.db.transaction_commit(
trans,_("Delete Event (%s)") % self.event.get_gramps_id()) 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): class EditEventRef(EditReference):
def __init__(self, state, uistate, track, event, event_ref, referent, update): def __init__(self, state, uistate, track, event, event_ref, update):
self.referent = referent
EditReference.__init__(self, state, uistate, track, event, event_ref, EditReference.__init__(self, state, uistate, track, event, event_ref,
update) update)
self._init_event()
def _local_init(self): def _local_init(self):
@ -85,10 +84,18 @@ class EditEventRef(EditReference):
self.define_warn_box(self.top.get_widget("eer_warning")) self.define_warn_box(self.top.get_widget("eer_warning"))
self.define_expander(self.top.get_widget("eer_expander")) self.define_expander(self.top.get_widget("eer_expander"))
if self.referent.__class__.__name__ == 'Person': def _init_event(self):
self.role_dict = Utils.event_roles self.commit_event = self.db.commit_personal_event
elif self.referent.__class__.__name__ == 'Family': self.add_event = self.db.add_person_event
self.role_dict = Utils.family_event_roles
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): def _connect_signals(self):
self.define_ok_button(self.top.get_widget('ok'),self.ok_clicked) 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.top.get_widget('eer_role_combo'),
self.source_ref.set_role, self.source_ref.set_role,
self.source_ref.get_role, self.source_ref.get_role,
self.role_dict, self.get_roles(),
RelLib.EventRef.CUSTOM) RelLib.EventRef.CUSTOM)
self.event_menu = MonitoredType( self.event_menu = MonitoredType(
self.top.get_widget("eer_type_combo"), self.top.get_widget("eer_type_combo"),
self.source.set_type, self.source.set_type,
self.source.get_type, self.source.get_type,
dict(total_events), self.get_event_types(),
RelLib.Event.CUSTOM) RelLib.Event.CUSTOM,
custom_values=self.get_custom_events())
self.date_check = MonitoredDate( self.date_check = MonitoredDate(
self.top.get_widget("eer_date"), self.top.get_widget("eer_date"),
@ -206,12 +214,12 @@ class EditEventRef(EditReference):
if self.source.handle: if self.source.handle:
if need_new: if need_new:
self.db.add_place(place_obj,trans) 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")) self.db.transaction_commit(trans,_("Modify Event"))
else: else:
if need_new: if need_new:
self.db.add_place(place_obj,trans) 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.db.transaction_commit(trans,_("Add Event"))
self.source_ref.ref = self.source.handle self.source_ref.ref = self.source.handle
@ -220,6 +228,26 @@ class EditEventRef(EditReference):
self.close_window(None) 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( self.attr_list = self._add_tab(
notebook, notebook,
AttrEmbedList(self.dbstate, self.uistate, self.track, FamilyAttrEmbedList(self.dbstate, self.uistate, self.track,
self.obj.get_attribute_list())) self.obj.get_attribute_list()))
self.note_tab = self._add_tab( self.note_tab = self._add_tab(

View File

@ -859,6 +859,24 @@ class GrampsDbBase(GrampsDBCallback):
self.find_next_event_gramps_id, self.find_next_event_gramps_id,
self.commit_event) 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): def add_place(self,place,transaction):
""" """
Adds a Place to the database, assigning internal IDs if they have Adds a Place to the database, assigning internal IDs if they have

View File

@ -316,7 +316,8 @@ class MonitoredText:
class MonitoredType: 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.set_val = set_val
self.get_val = get_val self.get_val = get_val
@ -329,7 +330,7 @@ class MonitoredType:
default = None default = None
self.sel = AutoComp.StandardCustomSelector( self.sel = AutoComp.StandardCustomSelector(
mapping, obj, custom, default) mapping, obj, custom, default, additional=custom_values)
self.set_val(self.sel.get_values()) self.set_val(self.sel.get_values())
self.obj.set_sensitive(not readonly) self.obj.set_sensitive(not readonly)