* src/AddMedia.py: Remove unneeded update argument.

* src/ArgHandler.py (auto_save_load): Mysterious workaround :-).
* src/EditPlace.py (display_references): Drop media objects;
(DeletePlaceQuery.query_response): use proper handle removal.
* src/GrampsBSDDB.py (remove_object): emit media signal.
* src/GrampsDbBase.py (GrampsDbBase): Add media-related signals;
(commit_media_object,transaction_commit,undo): emit media signals.
* src/ImageSelect.py (GlobalMediaProperties,DeleteMediaQuery):
Remove unneeded update argument.
* src/MediaView.py (media_add,media_update,media_delete): Add
callbacks; (change_db): connect callbacks to signals;
(popup_change_description): Call property editor without callback param;
(on_add_clicked): Call AddMedia without callback param;
(add_object,update_display,add_to_display): Remove unneeded methods;
(on_edit_clicked): call property editor without callback param;
(on_delete_clicked): call deleter without callback param;
(on_drag_data_received): Call property editor without callback param.
* src/PlaceView.py (new_place_after_edit): Remove unneeded method;
(delete_place): Remove unneeded tree update; (is_used) Add method;
(on_delete_clicked): Use new detection method.


svn: r4287
This commit is contained in:
Alex Roitman 2005-04-04 00:27:06 +00:00
parent bfc4b88cda
commit 9c3bf10613
9 changed files with 118 additions and 127 deletions

View File

@ -1,3 +1,25 @@
2005-04-03 Alex Roitman <shura@gramps-project.org>
* src/AddMedia.py: Remove unneeded update argument.
* src/ArgHandler.py (auto_save_load): Mysterious workaround :-).
* src/EditPlace.py (display_references): Drop media objects;
(DeletePlaceQuery.query_response): use proper handle removal.
* src/GrampsBSDDB.py (remove_object): emit media signal.
* src/GrampsDbBase.py (GrampsDbBase): Add media-related signals;
(commit_media_object,transaction_commit,undo): emit media signals.
* src/ImageSelect.py (GlobalMediaProperties,DeleteMediaQuery):
Remove unneeded update argument.
* src/MediaView.py (media_add,media_update,media_delete): Add
callbacks; (change_db): connect callbacks to signals;
(popup_change_description): Call property editor without callback param;
(on_add_clicked): Call AddMedia without callback param;
(add_object,update_display,add_to_display): Remove unneeded methods;
(on_edit_clicked): call property editor without callback param;
(on_delete_clicked): call deleter without callback param;
(on_drag_data_received): Call property editor without callback param.
* src/PlaceView.py (new_place_after_edit): Remove unneeded method;
(delete_place): Remove unneeded tree update; (is_used) Add method;
(on_delete_clicked): Use new detection method.
2005-04-02 Don Allingham <don@gramps-project.org>
* src/ReadGedcom.py: emit proper signals to notify of a database
rebuild, handle parent/child relationships better - eliminate

View File

@ -70,12 +70,11 @@ class AddMediaObject:
a media object from the file system, while providing a description.
"""
def __init__(self,db,update=None):
def __init__(self,db):
"""
Creates and displays the dialog box
db - the database in which the new object is to be stored
update - a function to call to update the display
"""
self.db = db
self.glade = gtk.glade.XML(const.imageselFile,"imageSelect","gramps")
@ -85,7 +84,6 @@ class AddMediaObject:
self.file_text = self.glade.get_widget("fname")
self.internal = self.glade.get_widget('internal')
self.internal.connect('toggled',self.internal_toggled)
self.update = update
self.temp_name = ""
self.object = None
@ -145,8 +143,6 @@ class AddMediaObject:
self.object = mobj
self.db.commit_media_object(mobj,trans)
self.db.transaction_commit(trans,_("Add Media Object"))
if self.update:
self.update(mobj.get_handle())
def on_name_changed(self,*obj):
"""

View File

@ -225,6 +225,12 @@ class ArgHandler:
filename = os.path.normpath(os.path.abspath(filename))
filetype = GrampsMime.get_type(filename)
if filetype == const.app_gramps:
# FIXME: For some reason the following two lines are needed
# to prevent source view from getting out of sync. Makes no
# sense to me right now, but it seems to fix a problem and
# make no harm otherwise. Should remove when understood.
import GrampsBSDDB
self.parent.db = GrampsBSDDB.GrampsBSDDB()
self.parent.read_file(filename)
return 1
elif filetype == const.app_gramps_xml:

View File

@ -497,7 +497,6 @@ class EditPlace:
def display_references(self):
pevent = []
fevent = []
mlist = []
msg = ""
for key in self.db.get_person_handles(sort_handles=False):
p = self.db.get_person_from_handle(key)
@ -511,10 +510,6 @@ class EditPlace:
event = self.db.get_event_from_handle(event_handle)
if event and event.get_place_handle() == self.place.get_handle():
fevent.append((f,event))
for media_handle in self.db.get_media_object_handles():
obj = self.db.get_object_from_handle(media_handle)
if obj and obj.get_place_handle() == self.place.get_handle():
mlist.append(object)
any = 0
if len(pevent) > 0:
@ -546,15 +541,6 @@ class EditPlace:
msg = msg + ( t % (fname,e[0].get_gramps_id(),_(e[1].get_name())))
if len(mlist) > 0:
any = 1
msg = msg + "\n%s\n" % _("Media Objects")
msg = msg + "_________________________\n\n"
t = _("%s [%s]\n")
for o in mlist:
msg = msg + ( t % (o.get_description(),o.get_gramps_id()))
self.refinfo.get_buffer().set_text(msg)
if any:
Utils.bold_label(self.refs_label)
@ -591,23 +577,26 @@ class DeletePlaceQuery:
def query_response(self):
trans = self.db.transaction_begin()
self.db.remove_place(self.place.get_handle(),trans)
place_handle = self.place.get_handle()
self.db.remove_place(place_handle,trans)
for key in self.db.get_person_handles(sort_handles=False):
p = self.db.get_person_from_handle(key)
for event_handle in [p.get_birth_handle(), p.get_death_handle()] + p.get_event_list():
event = self.db.get_event_from_handle(event_handle)
if event and event.get_place_handle() == self.place.get_handle():
event.set_place_handle(None)
self.db.commit_event(event,trans)
for handle in self.db.get_person_handles(sort_handles=False):
person = self.db.get_person_from_handle(handle)
if person.has_handle_reference('Place',place_handle):
person.remove_handle_references('Place',place_handle)
self.db.commit_person(person,trans)
for fid in self.db.get_family_handles():
f = self.db.get_family_from_handle(fid)
for event_handle in f.get_event_list():
event = self.db.get_event_from_handle(event_handle)
if event and event.get_place_handle() == self.place.get_handle():
event.set_place_handle(None)
self.db.commit_event(event,trans)
for handle in self.db.get_family_handles():
family = self.db.get_family_from_handle(handle)
if family.has_handle_reference('Place',place_handle):
family.remove_handle_references('Place',place_handle)
self.db.commit_family(family,trans)
for handle in self.db.get_event_handles():
event = self.db.get_event_from_handle(handle)
if event.has_handle_reference('Place',place_handle):
event.remove_handle_references('Place',place_handle)
self.db.commit_event(event,trans)
self.db.transaction_commit(trans,
_("Delete Place (%s)") % self.place.get_title())

View File

@ -277,8 +277,8 @@ class GrampsBSDDB(GrampsDbBase):
self.genderStats.uncount_person (person)
if transaction != None:
transaction.add(PERSON_KEY,handle,person.serialize())
if transaction and not transaction.batch:
self.emit('person-delete',([str(handle)],))
if not transaction.batch:
self.emit('person-delete',([str(handle)],))
self.person_map.delete(str(handle))
def remove_source(self,handle,transaction):
@ -286,8 +286,8 @@ class GrampsBSDDB(GrampsDbBase):
if transaction != None:
old_data = self.source_map.get(str(handle))
transaction.add(SOURCE_KEY,handle,old_data)
if transaction and not transaction.batch:
self.emit('source-delete',([handle],))
if not transaction.batch:
self.emit('source-delete',([handle],))
self.source_map.delete(str(handle))
def remove_family(self,handle,transaction):
@ -295,8 +295,8 @@ class GrampsBSDDB(GrampsDbBase):
if transaction != None:
old_data = self.family_map.get(str(handle))
transaction.add(FAMILY_KEY,handle,old_data)
if transaction and not transaction.batch:
self.emit('family-delete',([str(handle)],))
if not transaction.batch:
self.emit('family-delete',([str(handle)],))
self.family_map.delete(str(handle))
def remove_event(self,handle,transaction):
@ -311,8 +311,8 @@ class GrampsBSDDB(GrampsDbBase):
if transaction != None:
old_data = self.place_map.get(handle)
transaction.add(PLACE_KEY,handle,old_data)
if transaction and not transaction.batch:
self.emit('place-delete',([handle],))
if not transaction.batch:
self.emit('place-delete',([handle],))
self.place_map.delete(str(handle))
def remove_object(self,handle,transaction):
@ -320,6 +320,8 @@ class GrampsBSDDB(GrampsDbBase):
if transaction != None:
old_data = self.media_map.get(handle)
transaction.add(PLACE_KEY,handle,old_data)
if not transaction.batch:
self.emit('media-delete',([handle],))
self.media_map.delete(str(handle))
def get_person_from_gramps_id(self,val):

View File

@ -127,7 +127,11 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback):
'place-add' : (list,),
'place-update' : (list,),
'place-delete' : (list,),
'place-rebuild' : None
'place-rebuild' : None,
'media-add' : (list,),
'media-update' : (list,),
'media-delete' : (list,),
'media-rebuild' : None,
}
def __init__(self):
@ -285,6 +289,11 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback):
old_data = self.media_map.get(handle)
transaction.add(MEDIA_KEY,handle,old_data)
self.media_map[handle] = obj.serialize()
if transaction and not transaction.batch:
if old_data:
self.emit('media-update',([handle],))
else:
self.emit('media-add',([handle],))
def commit_source(self,source,transaction,change_time=None):
"""
@ -690,8 +699,6 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback):
if place.get_gramps_id() == None:
place.set_gramps_id(self.find_next_place_gramps_id())
self.commit_place(place,transaction)
if transaction and not transaction.batch:
self.emit('place-add',([place.handle],))
return place.get_handle()
def add_object(self,obj,transaction):
@ -955,6 +962,7 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback):
self.emit('family-rebuild')
self.emit('place-rebuild')
self.emit('source-rebuild')
self.emit('media-rebuild')
def undo(self):
"""
@ -1005,8 +1013,10 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback):
self.emit('place-update',([str(handle),]))
elif key == MEDIA_KEY:
if data == None:
self.emit('media-delete',([str(handle),]))
del self.media_map[str(handle)]
else:
self.emit('media-update',([str(handle),]))
self.media_map[str(handle)] = data
if self.undo_callback:

View File

@ -484,7 +484,7 @@ class Gallery(ImageSelect):
photo.set_path(name)
self.parent.lists_changed = 1
if GrampsKeys.get_media_global():
GlobalMediaProperties(self.db,photo,None,
GlobalMediaProperties(self.db,photo,
self,self.parent_window)
elif protocol != "":
import urllib
@ -512,7 +512,7 @@ class Gallery(ImageSelect):
self.add_thumbnail(oref)
self.parent.lists_changed = 1
if GrampsKeys.get_media_global():
GlobalMediaProperties(self.db,photo,None,
GlobalMediaProperties(self.db,photo,
self,self.parent_window)
else:
if self.db.has_object_handle(data.data):
@ -873,7 +873,7 @@ class LocalMediaProperties:
#-------------------------------------------------------------------------
class GlobalMediaProperties:
def __init__(self,db,obj,update,parent,parent_window=None):
def __init__(self,db,obj,parent,parent_window=None):
self.parent = parent
self.dp = DateHandler.parser
self.dd = DateHandler.displayer
@ -890,7 +890,6 @@ class GlobalMediaProperties:
self.alist = self.obj.get_attribute_list()[:]
self.lists_changed = 0
self.db = db
self.update = update
self.refs = 0
if obj:
self.date_object = Date.Date(self.obj.get_date_object())
@ -923,11 +922,6 @@ class GlobalMediaProperties:
build_dropdown(self.place,self.place_list)
if self.obj:
handle = self.obj.get_place_handle()
pobj = self.db.get_place_from_handle(handle)
if pobj:
self.place.set_text(pobj.get_title())
self.date_entry.set_text(self.dd.display(self.date_object))
Utils.set_titles(self.window,
@ -1207,8 +1201,6 @@ class GlobalMediaProperties:
trans = self.db.transaction_begin()
self.db.commit_media_object(self.obj,trans)
self.db.transaction_commit(trans,_("Edit Media Object"))
if self.update != None:
self.update(self.obj)
def on_help_clicked(self, obj):
"""Display the relevant portion of GRAMPS manual"""
@ -1256,11 +1248,10 @@ class GlobalMediaProperties:
class DeleteMediaQuery:
def __init__(self,media_handle,db,the_lists,update):
def __init__(self,media_handle,db,the_lists):
self.db = db
self.media_handle = media_handle
self.the_lists = the_lists
self.update = update
def query_response(self):
trans = self.db.transaction_begin()
@ -1305,8 +1296,6 @@ class DeleteMediaQuery:
self.db.remove_object(self.media_handle,trans)
self.db.transaction_commit(trans,_("Remove Media Object"))
if self.update:
self.update(self.media_handle)
def build_dropdown(entry,strings):
store = gtk.ListStore(str)

View File

@ -25,9 +25,9 @@
# standard python modules
#
#-------------------------------------------------------------------------
import string
import os
import gc
from gettext import gettext as _
#-------------------------------------------------------------------------
#
@ -51,16 +51,8 @@ import ImgManip
import RelImage
import DisplayModels
import GrampsMime
from QuestionDialog import QuestionDialog, ErrorDialog, WarningDialog
#-------------------------------------------------------------------------
#
# internationalization
#
#-------------------------------------------------------------------------
from gettext import gettext as _
column_names = [
_('Title'),
_('ID'),
@ -160,7 +152,24 @@ class MediaView:
self.list.append_column(column)
index += 1
def media_add(self,handle_list):
for handle in handle_list:
self.model.add_row_by_handle(handle)
def media_update(self,handle_list):
for handle in handle_list:
self.model.update_row_by_handle(handle)
def media_delete(self,handle_list):
for handle in handle_list:
self.model.delete_row_by_handle(handle)
def change_db(self,db):
db.connect('media-add', self.media_add)
db.connect('media-update', self.media_update)
db.connect('media-delete', self.media_delete)
db.connect('media-rebuild',self.build_tree)
self.db = db
self.build_columns()
self.build_tree()
@ -192,7 +201,7 @@ class MediaView:
image = Utils.find_mime_type_pixbuf('text/plain')
type_name = _('Note')
self.preview.set_from_pixbuf(image)
del image
del image
gc.collect()
self.mid.set_text(mobj.get_gramps_id())
@ -267,24 +276,14 @@ class MediaView:
os.execvp(const.editor,[const.editor, self.obj.get_path()])
def popup_change_description(self, obj):
ImageSelect.GlobalMediaProperties(
self.db, self.obj, self.update_display, self,self.topWindow)
ImageSelect.GlobalMediaProperties(self.db,self.obj,self,self.topWindow)
def on_add_clicked(self,obj):
"""Add a new media object to the media list"""
import AddMedia
am = AddMedia.AddMediaObject(self.db,self.add_object)
am = AddMedia.AddMediaObject(self.db)
am.run()
def add_object(self,mobj_handle):
self.model.add_row_by_handle(mobj_handle)
def update_display(self,mobj):
self.model.update_row_by_handle(mobj.get_handle())
def add_to_display(self,mobj):
self.model.add_row_by_handle(mobj.get_handle())
def on_edit_clicked(self,obj):
"""Edit the properties of an existing media object in the media list"""
@ -293,9 +292,7 @@ class MediaView:
handle = list_store.get_value(node,_HANDLE_COL)
obj = self.db.get_object_from_handle(handle)
if obj.get_mime_type():
ImageSelect.GlobalMediaProperties(
self.db,obj, self.update_display,
self,self.topWindow)
ImageSelect.GlobalMediaProperties(self.db,obj,self,self.topWindow)
else:
import NoteEdit
NoteEdit.NoteEditor(obj,self.parent,self.topWindow,
@ -314,8 +311,7 @@ class MediaView:
handle = store.get_value(node,_HANDLE_COL)
the_lists = Utils.get_media_referents(handle,self.db)
ans = ImageSelect.DeleteMediaQuery(handle,self.db,the_lists,
self.model.delete_row_by_handle)
ans = ImageSelect.DeleteMediaQuery(handle,self.db,the_lists)
if filter(None,the_lists): # quick test for non-emptiness
msg = _('This media object is currently being used. '
'If you delete this object, it will be removed from '
@ -358,7 +354,7 @@ class MediaView:
self.list.emit_stop_by_name('drag-data-received')
if data and data.format == 8:
d = string.strip(string.replace(data.data,'\0',' '))
d = data.data.replace('\0',' ').strip()
protocol,site,name, j,k,l = urlparse.urlparse(d)
if protocol == "file":
mime = GrampsMime.get_type(name)
@ -375,7 +371,6 @@ class MediaView:
self.build_tree()
if GrampsKeys.get_media_global():
ImageSelect.GlobalMediaProperties(self.db,photo,
self.update_display,
self,self.topWindow)
elif protocol != "":
import urllib
@ -399,5 +394,5 @@ class MediaView:
self.db.transaction_commit(trans,_("Add Media Object"))
if GrampsKeys.get_media_global():
ImageSelect.GlobalMediaProperties(self.db,photo,None,
ImageSelect.GlobalMediaProperties(self.db,photo,
self,self.topWindow)

View File

@ -183,56 +183,38 @@ class PlaceView:
def on_add_place_clicked(self,obj):
EditPlace.EditPlace(self.parent,RelLib.Place())
def new_place_after_edit(self,place):
self.model.add_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 is_used(self,place_handle):
for handle in self.parent.db.get_person_handles(sort_handles=False):
person = self.parent.db.get_person_from_handle(handle)
if person.has_handle_reference('Place',place_handle):
return True
for handle in self.parent.db.get_family_handles():
family = self.parent.db.get_family_from_handle(handle)
if family.has_handle_reference('Place',place_handle):
return True
for handle in self.parent.db.get_event_handles():
event = self.parent.db.get_event_from_handle(handle)
if event.has_handle_reference('Place',place_handle):
return True
return False
def on_delete_clicked(self,obj):
mlist = []
self.selection.selected_foreach(self.blist,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)
event_list = []
for e in [p.get_birth_handle(),p.get_death_handle()] + p.get_event_list():
event = self.parent.db.get_event_from_handle(e)
if event:
event_list.append(event)
if p.get_lds_baptism():
event_list.append(p.get_lds_baptism())
if p.get_lds_endowment():
event_list.append(p.get_lds_endowment())
if p.get_lds_sealing():
event_list.append(p.get_lds_sealing())
for event in event_list:
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 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_handle:
used = 1
place = self.parent.db.get_place_from_handle(place_handle)
if used == 1:
if self.is_used(place_handle):
ans = EditPlace.DeletePlaceQuery(place,self.parent.db)
QuestionDialog(
_('Delete %s?') % place.get_title(),