* src/EditPerson.py: Add support for inline editing

* src/EventEdit.py: Don't commit events here - should be commited
elsewhere
* src/ListModel.py: Add support for table callback functions
to update data after inline editing


svn: r4447
This commit is contained in:
Don Allingham 2005-04-30 23:45:17 +00:00
parent a71db16ccd
commit 5351dad9bc
4 changed files with 135 additions and 105 deletions

View File

@ -1,3 +1,10 @@
2005-04-30 Don Allingham <don@gramps-project.org>
* src/EditPerson.py: Add support for inline editing
* src/EventEdit.py: Don't commit events here - should be commited
elsewhere
* src/ListModel.py: Add support for table callback functions
to update data after inline editing
2005-04-29 Alex Roitman <shura@gramps-project.org> 2005-04-29 Alex Roitman <shura@gramps-project.org>
* src/edit_person.glade: Compact name edit button. * src/edit_person.glade: Compact name edit button.

View File

@ -28,6 +28,7 @@
import cPickle as pickle import cPickle as pickle
import os import os
import locale import locale
from sets import Set
from gettext import gettext as _ from gettext import gettext as _
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -52,7 +53,6 @@ import GrampsKeys
import GrampsMime import GrampsMime
import ImageSelect import ImageSelect
import AutoComp import AutoComp
import ListModel
import RelLib import RelLib
import Sources import Sources
import DateEdit import DateEdit
@ -68,7 +68,7 @@ import EventEdit
import AddrEdit import AddrEdit
from QuestionDialog import WarningDialog, ErrorDialog, SaveDialog, QuestionDialog2 from QuestionDialog import WarningDialog, ErrorDialog, SaveDialog, QuestionDialog2
from ListModel import ListModel, NOSORT, COMBO, TEXT, TOGGLE
from DdTargets import DdTargets from DdTargets import DdTargets
@ -413,12 +413,6 @@ class EditPerson:
self.child_windows = {} self.child_windows = {}
def close(self): def close(self):
event_list = []
#for col in self.event_list.get_columns():
# event_list.append(self.event_trans.find_key(col.get_title()))
#if not self.db.readonly:
# self.db.metadata['event_order'] = event_list
#self.gallery.close() #self.gallery.close()
self.close_child_windows() self.close_child_windows()
self.remove_itself_from_winsmenu() self.remove_itself_from_winsmenu()
@ -834,14 +828,25 @@ class EditPerson:
def update_lists(self): def update_lists(self):
"""Updates the person's lists if anything has changed""" """Updates the person's lists if anything has changed"""
if self.lists_changed: self.person.set_alternate_names(self.name_box.data)
self.person.set_alternate_names(self.nlist) self.person.set_url_list(self.url_box.data)
self.person.set_url_list(self.ulist) self.person.set_attribute_list(self.attr_box.data)
self.person.set_attribute_list(self.alist) self.person.set_address_list(self.addr_box.data)
self.person.set_address_list(self.plist)
#self.person.set_event_list(self.elist) self.person.set_birth_handle(None)
# self.person.set_birth_handle(self.birth.get_handle()) self.person.set_death_handle(None)
# self.person.set_death_handle(self.death.get_handle()) elist = self.event_box.data[:]
for event in elist:
if event.get_name() == "Birth":
self.person.set_birth_handle(event.get_handle())
self.event_box.data.remove(event)
if event.get_name() == "Death":
self.person.set_death_handle(event.get_handle())
self.event_box.data.remove(event)
elist = []
for val in self.event_box.data:
elist.append(val.get_handle())
self.person.set_event_list(elist)
def on_apply_person_clicked(self,obj): def on_apply_person_clicked(self,obj):
@ -869,7 +874,6 @@ class EditPerson:
idval = unicode(self.gid.get_text()) idval = unicode(self.gid.get_text())
name = self.pname name = self.pname
if idval != self.person.get_gramps_id(): if idval != self.person.get_gramps_id():
person = self.db.get_person_from_gramps_id(idval) person = self.db.get_person_from_gramps_id(idval)
if not person: if not person:
@ -1012,9 +1016,8 @@ class EditPerson:
if not self.lds_sealing.are_equal(lds_ord): if not self.lds_sealing.are_equal(lds_ord):
self.person.set_lds_sealing(self.lds_sealing) self.person.set_lds_sealing(self.lds_sealing)
if self.lists_changed: self.person.set_source_reference_list(self.srcreflist)
self.person.set_source_reference_list(self.srcreflist) self.update_lists()
self.update_lists()
if not self.person.get_handle(): if not self.person.get_handle():
self.db.add_person(self.person, trans) self.db.add_person(self.person, trans)
@ -1023,6 +1026,10 @@ class EditPerson:
self.person.set_gramps_id(self.db.find_next_person_gramps_id()) self.person.set_gramps_id(self.db.find_next_person_gramps_id())
self.db.commit_person(self.person, trans) self.db.commit_person(self.person, trans)
n = self.person.get_primary_name().get_regular_name() n = self.person.get_primary_name().get_regular_name()
for event in self.event_box.get_changed_objects():
self.db.commit_event(event,trans)
self.db.transaction_commit(trans,_("Edit Person (%s)") % n) self.db.transaction_commit(trans,_("Edit Person (%s)") % n)
if self.callback: if self.callback:
self.callback(self,self.retval) self.callback(self,self.retval)
@ -1272,7 +1279,7 @@ class ListBox:
self.name = NameDisplay.displayer.display(self.person) self.name = NameDisplay.displayer.display(self.person)
self.db = parent.db self.db = parent.db
self.parent = parent self.parent = parent
self.list_model = ListModel.ListModel( self.list_model = ListModel(
obj, titles, self.select_row, self.update) obj, titles, self.select_row, self.update)
self.blist = button_list self.blist = button_list
self.node_map = {} self.node_map = {}
@ -1281,9 +1288,14 @@ class ListBox:
self.blist[0].connect('clicked',self.add) self.blist[0].connect('clicked',self.add)
self.blist[1].connect('clicked',self.update) self.blist[1].connect('clicked',self.update)
self.blist[2].connect('clicked',self.delete) self.blist[2].connect('clicked',self.delete)
self.change_list = Set()
def get_changed_objects(self):
return list(self.change_list)
def add_object(self,item): def add_object(self,item):
self.data.append(item) self.data.append(item)
self.change_list.add(item)
def select_row(self,obj): def select_row(self,obj):
store, node = obj.get_selected() store, node = obj.get_selected()
@ -1305,7 +1317,7 @@ class ListBox:
self.node_map = {} self.node_map = {}
for item in self.data: for item in self.data:
node = self.list_model.add(self.display_data(item),item) node = self.list_model.add(self.display_data(item),item)
self.node_map[str(item)] = node self.node_map[item] = node
if self.data: if self.data:
self.list_model.select_row(0) self.list_model.select_row(0)
self.set_label() self.set_label()
@ -1322,12 +1334,14 @@ class ListBox:
self.redraw() self.redraw()
def edit_callback(self,data): def edit_callback(self,data):
self.data.append(data) self.changed = True
self.change_list.add(data)
if data not in self.data:
self.data.append(data)
self.redraw() self.redraw()
try: try:
self.list_model.select_iter(self.node_map[str(data)]) self.list_model.select_iter(self.node_map[data])
except: except:
print self.node_map, data
print "Edit callback failed" print "Edit callback failed"
def set_label(self): def set_label(self):
@ -1393,11 +1407,11 @@ class ReorderListBox(ListBox):
class AttrListBox(ListBox): class AttrListBox(ListBox):
titles = [ titles = [
# Title Sort Column Min Width, Type # Title Sort Col, Size, Type
(_('Attribute'), ListModel.NOSORT, 200, ListModel.TEXT), (_('Attribute'), NOSORT, 200, TEXT),
(_('Value'), ListModel.NOSORT, 350, ListModel.TEXT), (_('Value'), NOSORT, 350, TEXT),
(_('Source'), ListModel.NOSORT, 50, ListModel.TOGGLE), (_('Source'), NOSORT, 50, TOGGLE),
(_('Note'), ListModel.NOSORT, 50, ListModel.TOGGLE), (_('Note'), NOSORT, 50, TOGGLE),
] ]
def __init__(self, parent, person, obj, label, button_list): def __init__(self, parent, person, obj, label, button_list):
@ -1425,35 +1439,52 @@ class AttrListBox(ListBox):
return [const.display_pattr(attr.get_type()), attr.get_value(), return [const.display_pattr(attr.get_type()), attr.get_value(),
has_source, has_note] has_source, has_note]
class EventListBox(ReorderListBox): class EventListBox(ReorderListBox):
evalues = [
# Title Sort Column Min Width, Type
(_('Event'), ListModel.NOSORT, 125, ListModel.COMBO),
(_('Description'), ListModel.NOSORT, 150, ListModel.TEXT),
(_('Date'), ListModel.NOSORT, 100, ListModel.TEXT),
(_('Place'), ListModel.NOSORT, 100, ListModel.TEXT),
(_('Source'), ListModel.NOSORT, 50, ListModel.TOGGLE),
(_('Note'), ListModel.NOSORT, 50, ListModel.TOGGLE)
]
titles = ['Event', 'Description','Date','Place','Source','Note'] titles = ['Event', 'Description','Date','Place','Source','Note']
def __init__(self,parent,person,obj,label,button_list): def __init__(self,parent,person,obj,label,button_list):
self.trans = TransTable.TransTable(self.titles) self.trans = TransTable.TransTable(self.titles)
self.data = [] self.data = []
if person.get_birth_handle(): if person.get_birth_handle():
self.data.append(person.get_birth_handle()) event = parent.db.get_event_from_handle(person.get_birth_handle())
self.data.append(event)
if person.get_death_handle(): if person.get_death_handle():
self.data.append(person.get_death_handle()) event = parent.db.get_event_from_handle(person.get_death_handle())
self.data.append(event)
for val in person.get_event_list(): for val in person.get_event_list():
self.data.append(val) self.data.append(parent.db.get_event_from_handle(val))
evalues = [
# Title Sort Col Size, Type Argument
(_('Event'), NOSORT, 100, COMBO, const.personalEvents, self.set_name),
(_('Description'), NOSORT, 140, TEXT, None, self.set_description),
(_('Date'), NOSORT, 100, TEXT, None, self.set_date),
(_('Place'), NOSORT, 100, TEXT, None, self.set_place),
(_('Source'), NOSORT, 50, TOGGLE),
(_('Note'), NOSORT, 50, TOGGLE),
]
ReorderListBox.__init__(self, parent, person, obj, label, ReorderListBox.__init__(self, parent, person, obj, label,
button_list, self.evalues, DdTargets.EVENT) button_list, evalues, DdTargets.EVENT)
def set_name(self,index,value):
self.data[index].set_name(value)
self.change_list.add(self.data[index])
def set_description(self,index,value):
self.data[index].set_description(value)
self.change_list.add(self.data[index])
def set_place(self,index,value):
self.data[index].set_description(value)
self.change_list.add(self.data[index])
def set_date(self,index,value):
self.data[index].set_date(value)
self.change_list.add(self.data[index])
def add(self,obj): def add(self,obj):
"""Brings up the EventEditor for a new event""" """Brings up the EventEditor for a new event"""
@ -1469,34 +1500,16 @@ class EventListBox(ReorderListBox):
event = self.list_model.get_object(node) event = self.list_model.get_object(node)
EventEdit.EventEditor( EventEdit.EventEditor(
self.parent, self.name, const.personalEvents, self.parent, self.name, const.personalEvents,
const.personal_events,event, None, 0, const.personal_events, event, None, 0,
self.edit_callback, noedit=self.db.readonly) self.edit_callback, noedit=self.db.readonly)
def redraw(self): def display_data(self,event):
"""redraw_event_list - Update both the birth and death place combo pname = place_title(self.db,event)
boxes for any changes that occurred in the 'Event Edit' window. has_note = event.get_note()
Make sure not to allow the editing of a birth event to change has_source = len(event.get_source_references())> 0
any values in the death event, and vice versa. Since updating a return [const.display_pevent(event.get_name()),
combo list resets its present value, this code will have to save event.get_description(), event.get_date(),
and restore the value for the event *not* being edited.""" pname, has_source, has_note]
self.list_model.clear()
self.node_map = {}
for handle in self.data:
event = self.db.get_event_from_handle(handle)
if not event:
print "couldn't find",handle
pname = place_title(self.db,event)
has_note = event.get_note()
has_source = len(event.get_source_references())> 0
data = [const.display_pevent(event.get_name()),
event.get_description(), event.get_date(),
pname, has_source, has_note]
node = self.list_model.add(data, event)
self.node_map[handle] = node
if self.data:
self.list_model.select_row(0)
self.set_label()
def unpickle(self, data): def unpickle(self, data):
foo = pickle.loads(data); foo = pickle.loads(data);
@ -1512,14 +1525,14 @@ class EventListBox(ReorderListBox):
class NameListBox(ReorderListBox): class NameListBox(ReorderListBox):
titles = [ titles = [
# Title Sort Column Min Width, Type # Title Sort Col Size, Type
(_('Family Name'), ListModel.NOSORT, 225, ListModel.TEXT), (_('Family Name'), NOSORT, 225, TEXT),
(_('Prefix'), ListModel.NOSORT, 50, ListModel.TEXT), (_('Prefix'), NOSORT, 50, TEXT),
(_('Given Name'), ListModel.NOSORT, 200, ListModel.TEXT), (_('Given Name'), NOSORT, 200, TEXT),
(_('Suffix'), ListModel.NOSORT, 50, ListModel.TEXT), (_('Suffix'), NOSORT, 50, TEXT),
(_('Type'), ListModel.NOSORT, 100, ListModel.TEXT), (_('Type'), NOSORT, 100, TEXT),
(_('Source'), ListModel.NOSORT, 50, ListModel.TOGGLE), (_('Source'), NOSORT, 50, TOGGLE),
(_('Note'), ListModel.NOSORT, 50, ListModel.TOGGLE), (_('Note'), NOSORT, 50, TOGGLE),
] ]
def __init__(self,parent,person,obj,label,button_list): def __init__(self,parent,person,obj,label,button_list):
@ -1555,14 +1568,14 @@ class NameListBox(ReorderListBox):
class AddressListBox(ReorderListBox): class AddressListBox(ReorderListBox):
titles = [ titles = [
# Title Sort Column Min Width, Type # Title Sort Col Size, Type
(_('Date'), ListModel.NOSORT, 175, ListModel.TEXT), (_('Date'), NOSORT, 175, TEXT),
(_('Address'), ListModel.NOSORT, 150, ListModel.TEXT), (_('Address'), NOSORT, 150, TEXT),
(_('City'), ListModel.NOSORT, 100, ListModel.TEXT), (_('City'), NOSORT, 100, TEXT),
(_('State/Province'),ListModel.NOSORT, 75, ListModel.TEXT), (_('State/Province'),NOSORT, 75, TEXT),
(_('Country'), ListModel.NOSORT, 100, ListModel.TEXT), (_('Country'), NOSORT, 100, TEXT),
(_('Source'), ListModel.NOSORT, 50, ListModel.TOGGLE), (_('Source'), NOSORT, 50, TOGGLE),
(_('Note'), ListModel.NOSORT, 50, ListModel.TOGGLE), (_('Note'), NOSORT, 50, TOGGLE),
] ]
def __init__(self,parent,person,obj,label,button_list): def __init__(self,parent,person,obj,label,button_list):
@ -1599,9 +1612,9 @@ class AddressListBox(ReorderListBox):
class UrlListBox(ReorderListBox): class UrlListBox(ReorderListBox):
titles = [ titles = [
# Title Sort Column Min Width, Type # Title Sort Col Size, Type
(_('Path'), ListModel.NOSORT, 250, ListModel.TEXT), (_('Path'), NOSORT, 250, TEXT),
(_('Description'), ListModel.NOSORT, 100, ListModel.TEXT), (_('Description'), NOSORT, 100, TEXT),
] ]
def __init__(self,parent,person,obj,label,button_list): def __init__(self,parent,person,obj,label,button_list):

View File

@ -87,9 +87,8 @@ class EventEditor:
for v in elist: for v in elist:
values[v] = 1 values[v] = 1
for vv in self.db.get_person_event_type_list(): for vv in self.db.get_person_event_type_list():
if vv not in ("Birth","Death"): v = _(vv)
v = _(vv) values[v] = 1
values[v] = 1
self.elist = values.keys() self.elist = values.keys()
self.elist.sort() self.elist.sort()
@ -325,7 +324,6 @@ class EventEditor:
"before you can save the event")) "before you can save the event"))
return return
trans = self.db.transaction_begin()
#self.date = self.dp.parse(unicode(self.date_field.get_text())) #self.date = self.dp.parse(unicode(self.date_field.get_text()))
ecause = unicode(self.cause_field.get_text()) ecause = unicode(self.cause_field.get_text())
eplace_obj = self.get_place(self.place_field,trans) eplace_obj = self.get_place(self.place_field,trans)
@ -357,11 +355,10 @@ class EventEditor:
self.update_event(ename,self.date,eplace_obj,edesc,enote,eformat, self.update_event(ename,self.date,eplace_obj,edesc,enote,eformat,
epriv,ecause,trans) epriv,ecause,trans)
self.db.transaction_commit(trans,_("Edit Event"))
self.close(obj) self.close(obj)
if self.callback: if self.callback:
self.callback(self.event.get_handle()) self.callback(self.event)
def update_event(self,name,date,place,desc,note,format,priv,cause,trans): def update_event(self,name,date,place,desc,note,format,priv,cause,trans):
if place: if place:
@ -373,8 +370,7 @@ class EventEditor:
self.event.set_place_handle("") self.event.set_place_handle("")
self.parent.lists_changed = 1 self.parent.lists_changed = 1
if self.event.get_name() not in [self.trans.find_key(name), if self.event.get_name() not in [self.trans.find_key(name)]:
"Birth","Death"]:
self.event.set_name(self.trans.find_key(name)) self.event.set_name(self.trans.find_key(name))
self.parent.lists_changed = 1 self.parent.lists_changed = 1

View File

@ -48,7 +48,8 @@ class ListModel:
self.mylist.append(TYPE_STRING) self.mylist.append(TYPE_STRING)
self.data_index += 1 self.data_index += 1
self.mylist.append(TYPE_PYOBJECT) self.mylist.append(TYPE_PYOBJECT)
self.function = {}
self.tree.set_rules_hint(True) self.tree.set_rules_hint(True)
self.model = None self.model = None
self.selection = None self.selection = None
@ -73,26 +74,37 @@ class ListModel:
cnum = 0 cnum = 0
for name in dlist: for name in dlist:
if len(name) == 3: if len(name) == 3:
name = (name[0],name[1],name[2],TEXT) name = (name[0],name[1],name[2],TEXT,False, None)
elif len(name) == 4:
name = (name[0],name[1],name[2],name[3],False, None)
if name[0] and name[3] == TOGGLE: if name[0] and name[3] == TOGGLE:
renderer = gtk.CellRendererToggle() renderer = gtk.CellRendererToggle()
column = gtk.TreeViewColumn(name[0],renderer) column = gtk.TreeViewColumn(name[0],renderer)
column.add_attribute(renderer,'active',cnum) column.add_attribute(renderer,'active',cnum)
elif gtk26 and name[3] == COMBO: elif gtk26 and name[3] == COMBO:
store = gtk.ListStore(str)
model = gtk.ListStore(str,TYPE_OBJECT)
for val in name[4]:
model.append((val,store))
self.function[cnum] = name[5]
renderer = gtk.CellRendererCombo() renderer = gtk.CellRendererCombo()
renderer.set_property('model',model) renderer.set_property('model',model)
renderer.set_property('text_column',0) renderer.set_property('text_column',0)
renderer.set_property('editable',True)
renderer.set_fixed_height_from_font(True) renderer.set_fixed_height_from_font(True)
renderer.set_property('editable',True)
renderer.connect('edited',self.edited_cb, cnum) renderer.connect('edited',self.edited_cb, cnum)
column = gtk.TreeViewColumn(name[0],renderer,text=cnum) column = gtk.TreeViewColumn(name[0],renderer,text=cnum)
column.set_reorderable(True) column.set_reorderable(True)
else: else:
renderer = gtk.CellRendererText() renderer = gtk.CellRendererText()
renderer.set_property('editable',True)
renderer.set_fixed_height_from_font(True) renderer.set_fixed_height_from_font(True)
renderer.connect('edited',self.edited_cb, cnum) if name[5]:
renderer.set_property('editable',True)
renderer.connect('edited',self.edited_cb, cnum)
self.function[cnum] = name[5]
else:
renderer.set_property('editable',False)
column = gtk.TreeViewColumn(name[0],renderer,text=cnum) column = gtk.TreeViewColumn(name[0],renderer,text=cnum)
column.set_reorderable(True) column.set_reorderable(True)
column.set_min_width(name[2]) column.set_min_width(name[2])
@ -122,6 +134,8 @@ class ListModel:
def edited_cb(self, cell, path, new_text, col): def edited_cb(self, cell, path, new_text, col):
self.model[path][col] = new_text self.model[path][col] = new_text
if self.function.has_key(col):
self.function[col](int(path),new_text)
def unselect(self): def unselect(self):
self.selection.unselect_all() self.selection.unselect_all()