* src/GrampsBSDDB.py: add remove_place function
* src/DisplayModels.py: added row deletion and updating functions * src/EditPlace.py: Make a distinction between update and new * src/EditSource.py: Make a distinction between update and new * src/PeopleModel.py: remove debugging code * src/PlaceView.py: better handling of updating and deleiting * src/SourceView.py: better handling of updating and deleiting svn: r3520
This commit is contained in:
parent
4ec5ccd047
commit
ec92261a5a
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
||||
2004-08-29 Don Allingham <dallingham@users.sourceforge.net>
|
||||
* src/GrampsBSDDB.py: add remove_place function
|
||||
* src/DisplayModels.py: added row deletion and updating
|
||||
functions
|
||||
* src/EditPlace.py: Make a distinction between update and
|
||||
new
|
||||
* src/EditSource.py: Make a distinction between update and
|
||||
new
|
||||
* src/PeopleModel.py: remove debugging code
|
||||
* src/PlaceView.py: better handling of updating and deleiting
|
||||
* src/SourceView.py: better handling of updating and deleiting
|
||||
|
||||
2004-08-28 Don Allingham <dallingham@users.sourceforge.net>
|
||||
* src/DbPrompter.py: cleanup dialogs
|
||||
* src/EditPerson.py: update screen properly
|
||||
|
@ -38,12 +38,10 @@ class BaseModel(gtk.GenericTreeModel):
|
||||
def __init__(self,db):
|
||||
|
||||
gtk.GenericTreeModel.__init__(self)
|
||||
self.set_property("leak_references",0)
|
||||
self.set_property("leak_references",False)
|
||||
|
||||
self.db = db
|
||||
self.rebuild_data()
|
||||
self.connect('row-inserted',self.on_row_inserted)
|
||||
self.connect('row-deleted',self.on_row_deleted)
|
||||
|
||||
def rebuild_data(self):
|
||||
self.datalist = []
|
||||
@ -56,8 +54,20 @@ class BaseModel(gtk.GenericTreeModel):
|
||||
def on_row_inserted(self,obj,path,iter):
|
||||
self.rebuild_data()
|
||||
|
||||
def on_row_deleted(self,obj,path):
|
||||
self.rebuild_data()
|
||||
def delete_row_by_handle(self,handle):
|
||||
index = self.datalist.index(handle)
|
||||
del self.datalist[index]
|
||||
self.row_deleted(index)
|
||||
|
||||
def delete_row_by_handle(self,handle):
|
||||
index = self.datalist.index(handle)
|
||||
del self.datalist[index]
|
||||
self.row_deleted(index)
|
||||
|
||||
def update_row_by_handle(self,handle):
|
||||
index = self.datalist.index(handle)
|
||||
iter = self.get_iter(index)
|
||||
self.row_changed(index,iter)
|
||||
|
||||
def on_get_flags(self):
|
||||
'''returns the GtkTreeModelFlags for this particular type of model'''
|
||||
@ -103,12 +113,12 @@ class BaseModel(gtk.GenericTreeModel):
|
||||
'''returns true if this node has children'''
|
||||
if node == None:
|
||||
return len(self.datalist) > 0
|
||||
return 0
|
||||
return False
|
||||
|
||||
def on_iter_n_children(self,node):
|
||||
if node == None:
|
||||
return len(self.datalist)
|
||||
return 0
|
||||
return False
|
||||
|
||||
def on_iter_nth_child(self,node,n):
|
||||
if node == None:
|
||||
|
@ -371,7 +371,10 @@ class EditPlace:
|
||||
self.update_lists()
|
||||
|
||||
trans = self.db.transaction_begin()
|
||||
self.db.commit_place(self.place,trans)
|
||||
if self.place.get_handle():
|
||||
self.db.commit_place(self.place,trans)
|
||||
else:
|
||||
self.db.add_place(self.place,trans)
|
||||
self.db.transaction_commit(trans,_("Edit Place (%s)") % self.place.get_title())
|
||||
|
||||
if self.callback:
|
||||
@ -578,4 +581,4 @@ class DeletePlaceQuery:
|
||||
self.db.commit_event(event,trans)
|
||||
|
||||
self.db.transaction_commit(trans,_("Delete Place (%s)") % self.place.get_title())
|
||||
self.update(None)
|
||||
self.update(self.place.get_handle())
|
||||
|
@ -38,6 +38,7 @@ import Utils
|
||||
import GrampsCfg
|
||||
import ImageSelect
|
||||
import ListModel
|
||||
import RelLib
|
||||
|
||||
from gettext import gettext as _
|
||||
|
||||
@ -50,7 +51,10 @@ from gettext import gettext as _
|
||||
class EditSource:
|
||||
|
||||
def __init__(self,source,db,parent,parent_window=None,func=None):
|
||||
self.source = source
|
||||
if source:
|
||||
self.source = source
|
||||
else:
|
||||
self.source = RelLib.Source()
|
||||
self.db = db
|
||||
self.parent = parent
|
||||
if source:
|
||||
@ -328,7 +332,10 @@ class EditSource:
|
||||
self.gallery_ok = 1
|
||||
|
||||
trans = self.db.transaction_begin()
|
||||
self.db.commit_source(self.source,trans)
|
||||
if self.source.get_handle() == None:
|
||||
self.db.add_source(self.source,trans)
|
||||
else:
|
||||
self.db.commit_source(self.source,trans)
|
||||
self.db.transaction_commit(trans,_("Edit Source (%s)") % title)
|
||||
|
||||
if self.callback:
|
||||
|
@ -196,6 +196,12 @@ class GrampsBSDDB(GrampsDbBase):
|
||||
transaction.add(EVENT_KEY,handle,old_data)
|
||||
self.event_map.delete(str(handle))
|
||||
|
||||
def remove_place(self,handle,transaction):
|
||||
if transaction != None:
|
||||
old_data = self.place_map.get(handle)
|
||||
transaction.add(PLACE_KEY,handle,old_data)
|
||||
self.place_map.delete(handle)
|
||||
|
||||
def get_person_from_gramps_id(self,val):
|
||||
"""finds a Person in the database from the passed gramps' ID.
|
||||
If no such Person exists, a new Person is added to the database."""
|
||||
|
@ -83,15 +83,8 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
else:
|
||||
self.rebuild_data()
|
||||
|
||||
# self.connect('row-deleted',self.on_row_deleted)
|
||||
# self.connect('row-inserted',self.on_row_inserted)
|
||||
|
||||
def rebuild_data(self):
|
||||
|
||||
import traceback
|
||||
|
||||
print traceback.print_stack()
|
||||
|
||||
self.top_path2iter = []
|
||||
self.iter2path = {}
|
||||
self.path2iter = {}
|
||||
|
@ -173,10 +173,18 @@ class PlaceView:
|
||||
EditPlace.EditPlace(self.parent,RelLib.Place(),self.new_place_after_edit)
|
||||
|
||||
def new_place_after_edit(self,place):
|
||||
self.parent.db.add_place(place)
|
||||
self.build_tree()
|
||||
|
||||
def update_display(self,place):
|
||||
self.build_tree()
|
||||
self.model.update_row_by_handle(place.get_handle())
|
||||
|
||||
def delete_place(self,place):
|
||||
trans = self.parent.db.transaction_begin()
|
||||
place_handle = place.get_handle()
|
||||
self.parent.db.remove_place(place_handle,trans)
|
||||
title_msg = _("Delete Place (%s)") % place.get_title()
|
||||
self.parent.db.transaction_commit(trans,title_msg)
|
||||
self.model.delete_row_by_handle(place_handle)
|
||||
|
||||
def on_delete_clicked(self,obj):
|
||||
mlist = []
|
||||
@ -184,7 +192,7 @@ class PlaceView:
|
||||
|
||||
trans = self.parent.db.transaction_begin()
|
||||
|
||||
for place in mlist:
|
||||
for place_handle in mlist:
|
||||
used = 0
|
||||
for key in self.parent.db.get_person_handles(sort_handles=False):
|
||||
p = self.parent.db.get_person_from_handle(key)
|
||||
@ -200,24 +208,27 @@ class PlaceView:
|
||||
if p.get_lds_sealing():
|
||||
event_list.append(p.get_lds_sealing())
|
||||
for event in event_list:
|
||||
if event.get_place_handle() == place.get_handle():
|
||||
used = 1
|
||||
if event:
|
||||
if event.get_place_handle() == place_handle:
|
||||
used = 1
|
||||
|
||||
for fid in self.parent.db.get_family_handles():
|
||||
f = self.parent.db.get_family_from_handle(fid)
|
||||
event_list = []
|
||||
for e in f.get_event_list():
|
||||
event = self.parent.db.get_event_from_handle(e)
|
||||
for event_id in f.get_event_list():
|
||||
event = self.parent.db.get_event_from_handle(event_id)
|
||||
if event:
|
||||
event_list.append(event)
|
||||
if f.get_lds_sealing():
|
||||
event_list.append(f.get_lds_sealing())
|
||||
for event in event_list:
|
||||
if event.get_place_handle() == place.get_handle():
|
||||
if event.get_place_handle() == place_handle:
|
||||
used = 1
|
||||
|
||||
place = self.parent.db.get_place_from_handle(place_handle)
|
||||
if used == 1:
|
||||
ans = EditPlace.DeletePlaceQuery(place,self.parent.db,self.update_display)
|
||||
ans = EditPlace.DeletePlaceQuery(place,self.parent.db,
|
||||
self.model.delete_row_by_handle)
|
||||
QuestionDialog(_('Delete %s?') % place.get_title(),
|
||||
_('This place is currently being used by at least one '
|
||||
'record in the database. Deleting it will remove it '
|
||||
@ -226,17 +237,15 @@ class PlaceView:
|
||||
_('_Delete Place'),
|
||||
ans.query_response)
|
||||
else:
|
||||
trans = self.parent.db.transaction_begin()
|
||||
self.parent.db.remove_place(place.get_handle(),trans)
|
||||
self.parent.db.transaction_commit(trans,_("Delete Place (%s)") % place.title())
|
||||
self.build_tree()
|
||||
|
||||
self.delete_place(place)
|
||||
|
||||
def on_edit_clicked(self,obj):
|
||||
"""Display the selected places in the EditPlace display"""
|
||||
mlist = []
|
||||
self.selection.selected_foreach(self.blist,mlist)
|
||||
|
||||
for place in mlist:
|
||||
for place_handle in mlist:
|
||||
place = self.parent.db.get_place_from_handle(place_handle)
|
||||
EditPlace.EditPlace(self.parent, place, self.update_display)
|
||||
|
||||
def blist(self,store,path,iter,list):
|
||||
|
@ -42,8 +42,6 @@ import const
|
||||
|
||||
from QuestionDialog import QuestionDialog
|
||||
|
||||
_HANDLE_COL = 7
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# internationalization
|
||||
@ -61,6 +59,8 @@ column_names = [
|
||||
_('Last Changed'),
|
||||
]
|
||||
|
||||
_HANDLE_COL = len(column_names)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# SouceView
|
||||
@ -94,7 +94,6 @@ class SourceView:
|
||||
self.list.append_column(column)
|
||||
self.columns = [column]
|
||||
|
||||
index = 1
|
||||
for pair in self.parent.db.get_source_column_order():
|
||||
if not pair[0]:
|
||||
continue
|
||||
@ -104,7 +103,6 @@ class SourceView:
|
||||
column.set_min_width(75)
|
||||
self.columns.append(column)
|
||||
self.list.append_column(column)
|
||||
index += 1
|
||||
|
||||
def on_click(self,column):
|
||||
self.click_col = column
|
||||
@ -126,18 +124,18 @@ class SourceView:
|
||||
source = self.parent.db.get_source_from_handle(handle)
|
||||
EditSource.EditSource(source,self.parent.db,self.parent,
|
||||
self.topWindow,self.update_display)
|
||||
return 1
|
||||
return True
|
||||
elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
|
||||
self.build_context_menu(event)
|
||||
return 1
|
||||
return 0
|
||||
return True
|
||||
return False
|
||||
|
||||
def key_press(self,obj,event):
|
||||
if event.keyval == gtk.gdk.keyval_from_name("Return") \
|
||||
and not event.state:
|
||||
self.on_edit_clicked(obj)
|
||||
return 1
|
||||
return 0
|
||||
return True
|
||||
return False
|
||||
|
||||
def build_context_menu(self,event):
|
||||
"""Builds the menu with editing operations on the source's list"""
|
||||
@ -168,6 +166,14 @@ class SourceView:
|
||||
EditSource.EditSource(RelLib.Source(),self.parent.db,self.parent,
|
||||
self.topWindow,self.new_after_edit)
|
||||
|
||||
def delete_source(self,source):
|
||||
trans = self.parent.db.transaction_begin()
|
||||
source_handle = source.get_handle()
|
||||
self.parent.db.remove_source(source_handle,trans)
|
||||
title_msg = _("Delete Source (%s)") % source.get_title()
|
||||
self.parent.db.transaction_commit(trans,title_msg)
|
||||
self.model.delete_row_by_handle(source_handle)
|
||||
|
||||
def on_delete_clicked(self,obj):
|
||||
store,node = self.selection.get_selected()
|
||||
if not node:
|
||||
@ -177,7 +183,8 @@ class SourceView:
|
||||
source = self.parent.db.get_source_from_handle(handle)
|
||||
|
||||
if self.is_used(source):
|
||||
ans = EditSource.DelSrcQuery(source,self.parent.db,self.build_tree)
|
||||
ans = EditSource.DelSrcQuery(source,self.parent.db,
|
||||
self.model.delete_row_by_handle)
|
||||
|
||||
QuestionDialog(_('Delete %s?') % source.get_title(),
|
||||
_('This source is currently being used. Deleting it '
|
||||
@ -186,18 +193,14 @@ class SourceView:
|
||||
_('_Delete Source'),
|
||||
ans.query_response,self.topWindow)
|
||||
else:
|
||||
trans = self.parent.db.transaction_begin()
|
||||
self.parent.db.remove_source(source.get_handle(),trans)
|
||||
n = source.get_title()
|
||||
self.parent.db.transaction_commit(trans,_("Delete Source (%s)") % n)
|
||||
self.build_tree()
|
||||
self.delete_source(source)
|
||||
|
||||
def is_used(self,source):
|
||||
for key in self.parent.db.get_place_handles():
|
||||
p = self.parent.db.get_place_from_handle(key)
|
||||
for sref in p.get_source_references():
|
||||
if sref.get_base_handle() == source.get_handle():
|
||||
return 1
|
||||
return True
|
||||
for key in self.parent.db.get_person_handles(sort_handles=False):
|
||||
p = self.parent.db.get_person_from_handle(key)
|
||||
for v_id in p.get_event_list() + [p.get_birth_handle(), p.get_death_handle()]:
|
||||
@ -205,24 +208,24 @@ class SourceView:
|
||||
if v:
|
||||
for sref in v.get_source_references():
|
||||
if sref.get_base_handle() == source.get_handle():
|
||||
return 1
|
||||
return True
|
||||
for v in p.get_attribute_list():
|
||||
for sref in v.get_source_references():
|
||||
if sref.get_base_handle() == source.get_handle():
|
||||
return 1
|
||||
return True
|
||||
for v in p.get_alternate_names() + [p.get_primary_name()]:
|
||||
for sref in v.get_source_references():
|
||||
if sref.get_base_handle() == source.get_handle():
|
||||
return 1
|
||||
return True
|
||||
for v in p.get_address_list():
|
||||
for sref in v.get_source_references():
|
||||
if sref.get_base_handle() == source.get_handle():
|
||||
return 1
|
||||
return True
|
||||
for p_id in self.parent.db.get_media_object_handles():
|
||||
p = self.parent.db.get_object_from_handle(p_id)
|
||||
for sref in p.get_source_references():
|
||||
if sref.get_base_handle() == source.get_handle():
|
||||
return 1
|
||||
return True
|
||||
for p_id in self.parent.db.get_family_handles():
|
||||
p = self.parent.db.get_family_from_handle(p_id)
|
||||
for v_id in p.get_event_list():
|
||||
@ -230,25 +233,23 @@ class SourceView:
|
||||
if v:
|
||||
for sref in v.get_source_references():
|
||||
if sref.get_base_handle() == source.get_handle():
|
||||
return 1
|
||||
return True
|
||||
for v in p.get_attribute_list():
|
||||
for sref in v.get_source_references():
|
||||
if sref.get_base_handle() == source.get_handle():
|
||||
return 1
|
||||
return 0
|
||||
return True
|
||||
return False
|
||||
|
||||
def on_edit_clicked(self,obj):
|
||||
list_store, node = self.selection.get_selected()
|
||||
if node:
|
||||
handle = list_store.get_value(node,_HANDLE_COL)
|
||||
print handle
|
||||
source = self.parent.db.get_source_from_handle(handle)
|
||||
EditSource.EditSource(source, self.parent.db, self.parent,
|
||||
self.topWindow, self.update_display)
|
||||
|
||||
def new_after_edit(self,source):
|
||||
self.parent.db.add_source(source)
|
||||
self.build_tree()
|
||||
|
||||
def update_display(self,place):
|
||||
self.build_tree()
|
||||
def update_display(self,source):
|
||||
self.model.update_row_by_handle(source.get_handle())
|
||||
|
Loading…
Reference in New Issue
Block a user