* src/EditEventRef.py: switch to monitored widgets, place selector
* src/EventEdit.py: switch to monitored widgets, place selector * src/GrampsWidgets.py: place selection widget * src/GrampsDb/_GrampsDbBase.py: move completion widget, handle place lists svn: r5980
This commit is contained in:
parent
e3eb6c6ab5
commit
c157f3e50f
@ -1,3 +1,10 @@
|
||||
2006-02-23 Don Allingham <don@gramps-project.org>
|
||||
* src/EditEventRef.py: switch to monitored widgets, place selector
|
||||
* src/EventEdit.py: switch to monitored widgets, place selector
|
||||
* src/GrampsWidgets.py: place selection widget
|
||||
* src/GrampsDb/_GrampsDbBase.py: move completion widget, handle
|
||||
place lists
|
||||
|
||||
2006-02-22 Don Allingham <don@gramps-project.org>
|
||||
* src/EditPlace.py: use monitored widgets
|
||||
* src/EditSource.py: use monitored widgets
|
||||
|
@ -69,26 +69,6 @@ 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]
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# helper function
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def get_place(field,pmap,db):
|
||||
text = unicode(field.get_text().strip())
|
||||
if text:
|
||||
if pmap.has_key(text):
|
||||
return db.get_place_from_handle(pmap[text])
|
||||
else:
|
||||
place = RelLib.Place()
|
||||
place.set_title(text)
|
||||
trans = db.transaction_begin()
|
||||
db.add_place(place,trans)
|
||||
db.transaction_commit(trans,_("Add Place"))
|
||||
return place
|
||||
else:
|
||||
return None
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# EditEventRef class
|
||||
@ -110,27 +90,16 @@ class EditEventRef(DisplayState.ManagedWindow):
|
||||
|
||||
self.update = update
|
||||
|
||||
self.pmap = {}
|
||||
for key in self.db.get_place_handles():
|
||||
title = self.db.get_place_from_handle(key).get_title()
|
||||
self.pmap[title] = key
|
||||
|
||||
self.title = _('Event Reference Editor')
|
||||
|
||||
self.top = gtk.glade.XML(const.gladeFile, "event_eref_edit","gramps")
|
||||
self.window = self.top.get_widget('event_eref_edit')
|
||||
self.ref_note_field = self.top.get_widget('eer_ref_note')
|
||||
self.role_combo = self.top.get_widget('eer_role_combo')
|
||||
self.date_field = self.top.get_widget("eer_date")
|
||||
self.place_field = self.top.get_widget("eer_place")
|
||||
self.cause_field = self.top.get_widget("eer_cause")
|
||||
self.ev_note_field = self.top.get_widget("eer_ev_note")
|
||||
self.type_combo = self.top.get_widget("eer_type_combo")
|
||||
self.general_label = self.top.get_widget("eer_general_tab")
|
||||
self.ok = self.top.get_widget('ok')
|
||||
self.expander = self.top.get_widget("eer_expander")
|
||||
self.warning = self.top.get_widget("eer_warning")
|
||||
self.notebook = self.top.get_widget('notebook')
|
||||
self.notebook_ref = self.top.get_widget('notebook_ref')
|
||||
|
||||
if self.referent.__class__.__name__ == 'Person':
|
||||
default_type = RelLib.Event.BIRTH
|
||||
@ -143,9 +112,12 @@ class EditEventRef(DisplayState.ManagedWindow):
|
||||
ev_dict = Utils.family_events
|
||||
role_dict = Utils.family_event_roles
|
||||
|
||||
Utils.set_titles(self.window,
|
||||
self.top.get_widget('eer_title'),
|
||||
self.title)
|
||||
|
||||
if self.event:
|
||||
self.event_added = False
|
||||
self.date = RelLib.Date(self.event.get_date_object())
|
||||
if self.event_ref:
|
||||
if self.event_ref.get_role()[0] == default_role:
|
||||
self.expander.set_expanded(True)
|
||||
@ -159,7 +131,6 @@ class EditEventRef(DisplayState.ManagedWindow):
|
||||
self.event.set_handle(self.db.create_id())
|
||||
self.event.set_gramps_id(self.db.find_next_event_gramps_id())
|
||||
self.event_added = True
|
||||
self.date = RelLib.Date(None)
|
||||
self.expander.set_expanded(True)
|
||||
self.warning.hide()
|
||||
|
||||
@ -168,67 +139,77 @@ class EditEventRef(DisplayState.ManagedWindow):
|
||||
self.event_ref.set_role((default_role,role_dict[default_role]))
|
||||
self.event_ref.set_reference_handle(self.event.get_handle())
|
||||
|
||||
self.cause_monitor = MonitoredEntry(self.cause_field,self.event.set_cause,
|
||||
self.event.get_cause, False)
|
||||
self.ref_privacy = PrivacyButton(self.top.get_widget('eer_ref_priv'),
|
||||
self.event_ref)
|
||||
|
||||
self.descr_field = MonitoredEntry(self.top.get_widget("eer_description"),
|
||||
self.event.set_description,
|
||||
self.event.get_description, False)
|
||||
|
||||
self.ev_privacy = PrivacyButton(self.top.get_widget("eer_ev_priv"),
|
||||
self.event)
|
||||
|
||||
Utils.set_titles(self.window,
|
||||
self.top.get_widget('eer_title'),
|
||||
self.title)
|
||||
|
||||
self.top.signal_autoconnect({
|
||||
"on_eer_help_clicked" : self.on_help_clicked,
|
||||
"on_eer_ok_clicked" : self.on_ok_clicked,
|
||||
"on_eer_cancel_clicked" : self.close,
|
||||
"on_eer_delete_event" : self.close,
|
||||
})
|
||||
|
||||
self.role_selector = AutoComp.StandardCustomSelector(
|
||||
role_dict,self.role_combo,
|
||||
RelLib.EventRef.CUSTOM,default_role)
|
||||
|
||||
AutoComp.fill_entry(self.place_field,self.pmap.keys())
|
||||
|
||||
self.type_selector = AutoComp.StandardCustomSelector(
|
||||
ev_dict,self.type_combo,
|
||||
RelLib.Event.CUSTOM,default_type)
|
||||
|
||||
self.date_check = DateEdit.DateEdit(self.date,
|
||||
self.date_field,
|
||||
self.top.get_widget("eer_date_stat"),
|
||||
self.window)
|
||||
|
||||
# set event_ref values
|
||||
self.role_selector.set_values(self.event_ref.get_role())
|
||||
self.ref_note_field.get_buffer().set_text(self.event_ref.get_note())
|
||||
|
||||
# set event values
|
||||
self.type_selector.set_values(self.event.get_type())
|
||||
place_handle = self.event.get_place_handle()
|
||||
if not place_handle:
|
||||
place_name = u""
|
||||
else:
|
||||
place_name = self.db.get_place_from_handle(place_handle).get_title()
|
||||
self.place_field.set_text(place_name)
|
||||
self.date_field.set_text(_dd.display(self.date))
|
||||
|
||||
self._create_tabbed_pages()
|
||||
|
||||
self._setup_fields(self.state.get_place_completion(),role_dict)
|
||||
self._connect_signals()
|
||||
|
||||
self.show()
|
||||
|
||||
def _setup_fields(self,place_values,role_dict):
|
||||
|
||||
self.cause_monitor = MonitoredEntry(
|
||||
self.top.get_widget("eer_cause"),
|
||||
self.event.set_cause,
|
||||
self.event.get_cause,
|
||||
self.db.readonly)
|
||||
|
||||
self.ref_privacy = PrivacyButton(
|
||||
self.top.get_widget('eer_ref_priv'),
|
||||
self.event_ref)
|
||||
|
||||
self.descr_field = MonitoredEntry(
|
||||
self.top.get_widget("eer_description"),
|
||||
self.event.set_description,
|
||||
self.event.get_description,
|
||||
self.db.readonly)
|
||||
|
||||
self.place_field = PlaceEntry(
|
||||
self.top.get_widget("eer_place"),
|
||||
self.event.get_place_handle(),
|
||||
place_values,
|
||||
self.db.readonly)
|
||||
|
||||
self.ev_privacy = PrivacyButton(
|
||||
self.top.get_widget("eer_ev_priv"),
|
||||
self.event)
|
||||
|
||||
self.role_selector = MonitoredType(
|
||||
self.top.get_widget('eer_role_combo'),
|
||||
self.event_ref.set_role,
|
||||
self.event_ref.get_role,
|
||||
role_dict,
|
||||
RelLib.EventRef.CUSTOM)
|
||||
|
||||
self.event_menu = MonitoredType(
|
||||
self.top.get_widget("eer_type_combo"),
|
||||
self.event.set_type,
|
||||
self.event.get_type,
|
||||
dict(total_events),
|
||||
RelLib.Event.CUSTOM)
|
||||
|
||||
self.date_check = DateEdit.DateEdit(
|
||||
self.event.get_date_object(),
|
||||
self.top.get_widget("eer_date"),
|
||||
self.top.get_widget("eer_date_stat"),
|
||||
self.window)
|
||||
|
||||
def _connect_signals(self):
|
||||
self.top.get_widget('ok').connect('clicked',self.ok_clicked)
|
||||
self.top.get_widget('cancel').connect('clicked',self.close)
|
||||
self.top.get_widget('help').connect('clicked',self.help_clicked)
|
||||
self.window.connect('delete-event',self.close)
|
||||
|
||||
def _add_page(self,page):
|
||||
self.notebook.insert_page(page)
|
||||
self.notebook.set_tab_label(page,page.get_tab_widget())
|
||||
return page
|
||||
|
||||
def _add_ref_page(self,page):
|
||||
self.notebook_ref.insert_page(page)
|
||||
self.notebook_ref.set_tab_label(page,page.get_tab_widget())
|
||||
return page
|
||||
|
||||
def _create_tabbed_pages(self):
|
||||
"""
|
||||
Creates the notebook tabs and inserts them into the main
|
||||
@ -242,6 +223,9 @@ class EditEventRef(DisplayState.ManagedWindow):
|
||||
self.note_tab = self._add_page(NoteTab(
|
||||
self.state, self.uistate, self.track,
|
||||
self.event.get_note_object()))
|
||||
self.note_ref_tab = self._add_ref_page(NoteTab(
|
||||
self.state, self.uistate, self.track,
|
||||
self.event_ref.get_note_object()))
|
||||
self.gallery_tab = self._add_page(GalleryTab(
|
||||
self.state, self.uistate, self.track,
|
||||
self.event.get_media_list()))
|
||||
@ -266,46 +250,35 @@ class EditEventRef(DisplayState.ManagedWindow):
|
||||
else:
|
||||
return id(self)
|
||||
|
||||
def on_help_clicked(self,obj):
|
||||
def help_clicked(self,obj):
|
||||
pass
|
||||
|
||||
def on_ok_clicked(self,obj):
|
||||
def ok_clicked(self,obj):
|
||||
|
||||
(need_new, handle) = self.place_field.get_place_info()
|
||||
if need_new:
|
||||
place_obj = RelLib.Place()
|
||||
place_obj.set_title(handle)
|
||||
self.event.set_place_handle(place_obj.get_handle())
|
||||
else:
|
||||
self.event.set_place_handle(handle)
|
||||
|
||||
# first, save event if changed
|
||||
etype = self.type_selector.get_values()
|
||||
eplace_obj = get_place(self.place_field,self.pmap,self.db)
|
||||
self.update_event(etype,self.date,eplace_obj)
|
||||
|
||||
trans = self.db.transaction_begin()
|
||||
self.db.commit_event(self.event,trans)
|
||||
if self.event_added:
|
||||
if need_new:
|
||||
self.db.add_place(place_obj,trans)
|
||||
self.db.transaction_commit(trans,_("Add Event"))
|
||||
else:
|
||||
if need_new:
|
||||
self.db.add_place(place_obj,trans)
|
||||
self.db.transaction_commit(trans,_("Modify Event"))
|
||||
|
||||
# then, set properties of the event_ref
|
||||
self.event_ref.set_role(self.role_selector.get_values())
|
||||
self.event_ref.set_privacy(self.ref_privacy.get_active())
|
||||
self.close(None)
|
||||
|
||||
if self.update:
|
||||
self.update((self.event_ref,self.event))
|
||||
|
||||
def update_event(self,the_type,date,place):
|
||||
if place:
|
||||
if self.event.get_place_handle() != place.get_handle():
|
||||
self.event.set_place_handle(place.get_handle())
|
||||
else:
|
||||
if self.event.get_place_handle():
|
||||
self.event.set_place_handle("")
|
||||
|
||||
if self.event.get_type() != the_type:
|
||||
self.event.set_type(the_type)
|
||||
|
||||
dobj = self.event.get_date_object()
|
||||
|
||||
if not dobj.is_equal(date):
|
||||
self.event.set_date_object(date)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
|
@ -67,26 +67,6 @@ 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]
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# helper function
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def get_place(field,pmap,db):
|
||||
text = unicode(field.get_text().strip())
|
||||
if text:
|
||||
if pmap.has_key(text):
|
||||
return db.get_place_from_handle(pmap[text])
|
||||
else:
|
||||
place = RelLib.Place()
|
||||
place.set_title(text)
|
||||
trans = db.transaction_begin()
|
||||
db.add_place(place,trans)
|
||||
db.transaction_commit(trans,_("Add Place"))
|
||||
return place
|
||||
else:
|
||||
return None
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# EventEditor class
|
||||
@ -122,17 +102,6 @@ class EventEditor(DisplayState.ManagedWindow):
|
||||
Utils.set_titles(self.window,title_label, etitle,
|
||||
_('Event Editor'))
|
||||
|
||||
self.place_field = self.top.get_widget("eventPlace")
|
||||
self.place_field.set_editable(not self.db.readonly)
|
||||
|
||||
place_handle = event.get_place_handle()
|
||||
if not place_handle:
|
||||
place_name = u""
|
||||
else:
|
||||
place_name = self.db.get_place_from_handle(place_handle).get_title()
|
||||
self.place_field.set_text(place_name)
|
||||
self.place_field.set_completion(self.dbstate.get_place_completion())
|
||||
|
||||
self._create_tabbed_pages()
|
||||
self._setup_fields()
|
||||
self._connect_signals()
|
||||
@ -147,6 +116,12 @@ class EventEditor(DisplayState.ManagedWindow):
|
||||
ok.connect('clicked',self.on_event_edit_ok_clicked)
|
||||
|
||||
def _setup_fields(self):
|
||||
self.place_field = PlaceEntry(
|
||||
self.top.get_widget("eventPlace"),
|
||||
self.event.get_place_handle(),
|
||||
self.dbstate.get_place_completion(),
|
||||
self.db.readonly)
|
||||
|
||||
self.cause_monitor = MonitoredEntry(
|
||||
self.top.get_widget("eventCause"),
|
||||
self.event.set_cause,
|
||||
@ -157,7 +132,6 @@ class EventEditor(DisplayState.ManagedWindow):
|
||||
self.event.set_description,
|
||||
self.event.get_description, self.db.readonly)
|
||||
|
||||
|
||||
self.priv = PrivacyButton(
|
||||
self.top.get_widget("private"),
|
||||
self.event, self.db.readonly)
|
||||
@ -234,18 +208,26 @@ class EventEditor(DisplayState.ManagedWindow):
|
||||
|
||||
def on_event_edit_ok_clicked(self,obj):
|
||||
|
||||
eplace_obj = get_place(self.place_field,self.pmap,self.db)
|
||||
|
||||
self.update_event(eplace_obj)
|
||||
|
||||
(need_new, handle) = self.place_field.get_place_info()
|
||||
if need_new:
|
||||
place_obj = RelLib.Place()
|
||||
place_obj.set_title(handle)
|
||||
self.event.set_place_handle(place_obj.get_handle())
|
||||
else:
|
||||
self.event.set_place_handle(handle)
|
||||
|
||||
if self.event.handle == None:
|
||||
trans = self.db.transaction_begin()
|
||||
if need_new:
|
||||
self.db.add_place(place_obj,trans)
|
||||
self.db.add_event(self.event,trans)
|
||||
self.db.transaction_commit(trans,_("Add Event"))
|
||||
else:
|
||||
orig = self.dbstate.db.get_event_from_handle(self.event.handle)
|
||||
if cmp(self.event.serialize(),orig.serialize()):
|
||||
trans = self.db.transaction_begin()
|
||||
if need_new:
|
||||
self.db.add_place(place_obj,trans)
|
||||
self.db.commit_event(self.event,trans)
|
||||
self.db.transaction_commit(trans,_("Edit Event"))
|
||||
|
||||
@ -253,15 +235,6 @@ class EventEditor(DisplayState.ManagedWindow):
|
||||
self.callback(self.event)
|
||||
self.close(obj)
|
||||
|
||||
def update_event(self,place):
|
||||
# FIXME: commented because we no longer have parent
|
||||
if place:
|
||||
if self.event.get_place_handle() != place.get_handle():
|
||||
self.event.set_place_handle(place.get_handle())
|
||||
else:
|
||||
if self.event.get_place_handle():
|
||||
self.event.set_place_handle("")
|
||||
|
||||
def commit(self,event,trans):
|
||||
self.db.commit_event(event,trans)
|
||||
|
||||
|
@ -1999,20 +1999,23 @@ class DbState(GrampsDBCallback):
|
||||
data = cursor.next()
|
||||
while data:
|
||||
if data[1][2]:
|
||||
self.places[data[1][2]] = data[0]
|
||||
self.places[data[0]] = data[1][2]
|
||||
data = cursor.next()
|
||||
cursor.close()
|
||||
|
||||
def _place_add(self,handle):
|
||||
place = self.db.get_place_from_handle(handle)
|
||||
self.places[place.get_title()] = handle
|
||||
def _place_add(self,handle_list):
|
||||
for handle in handle_list:
|
||||
place = self.db.get_place_from_handle(handle)
|
||||
self.places[place.get_title()] = handle
|
||||
|
||||
def _place_update(self,handle):
|
||||
place = self.db.get_place_from_handle(handle)
|
||||
self.places[handle] = place.get_title()
|
||||
def _place_update(self,handle_list):
|
||||
for handle in handle_list:
|
||||
place = self.db.get_place_from_handle(handle)
|
||||
self.places[handle] = place.get_title()
|
||||
|
||||
def _place_delete(self,handle):
|
||||
del self.places[handle]
|
||||
def _place_delete(self,handle_list):
|
||||
for handle in handle_list:
|
||||
del self.places[handle]
|
||||
|
||||
def change_active_person(self,person):
|
||||
self.active = person
|
||||
@ -2047,16 +2050,5 @@ class DbState(GrampsDBCallback):
|
||||
self.emit('no-database')
|
||||
|
||||
def get_place_completion(self):
|
||||
import locale
|
||||
|
||||
store = gtk.ListStore(str,str)
|
||||
foo = []
|
||||
for val in self.places.keys():
|
||||
foo.append((locale.strxform(self.places[val]),val))
|
||||
foo.sort()
|
||||
for val in foo:
|
||||
self.store.append(row=[val[1],val[0]])
|
||||
self.completion = gtk.EntryCompletion()
|
||||
self.completion.set_text_column(0)
|
||||
self.completion.set_model(store)
|
||||
return self.completion
|
||||
return self.places
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
# $Id$
|
||||
|
||||
import cgi
|
||||
import locale
|
||||
from gettext import gettext as _
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -334,3 +335,42 @@ class MonitoredDate:
|
||||
|
||||
field.set_text(DateHandler.displayer.display(self.date))
|
||||
|
||||
class PlaceEntry:
|
||||
|
||||
def __init__(self, obj, handle, place_map, read_only=False):
|
||||
self.obj = obj
|
||||
self.handle = handle
|
||||
self.places = place_map
|
||||
|
||||
if handle:
|
||||
name = place_map[handle]
|
||||
else:
|
||||
name = u""
|
||||
|
||||
if read_only:
|
||||
self.obj.set_editable(False)
|
||||
else:
|
||||
self.obj.set_editable(True)
|
||||
|
||||
store = gtk.ListStore(str)
|
||||
foo = self.places.values()
|
||||
foo.sort(locale.strcoll)
|
||||
for val in foo:
|
||||
store.append(row=[val[0]])
|
||||
completion = gtk.EntryCompletion()
|
||||
completion.set_text_column(0)
|
||||
completion.set_model(store)
|
||||
obj.set_completion(completion)
|
||||
|
||||
obj.set_text(name)
|
||||
|
||||
def get_place_info(self):
|
||||
text = unicode(self.obj.get_text().strip())
|
||||
if text:
|
||||
for key in self.places.keys():
|
||||
if text == self.places[key]:
|
||||
return (False,key)
|
||||
return (True,text)
|
||||
else:
|
||||
return (False,u"")
|
||||
|
||||
|
1189
src/gramps.glade
1189
src/gramps.glade
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user