* src/DataViews/_SourceView.py: source merge support

svn: r6777
This commit is contained in:
Don Allingham 2006-05-25 20:35:04 +00:00
parent 081f5079d5
commit d5f33362ac
9 changed files with 113 additions and 36 deletions

View File

@ -1,4 +1,5 @@
2006-05-25 Don Allingham <don@gramps-project.org> 2006-05-25 Don Allingham <don@gramps-project.org>
* src/DataViews/_SourceView.py: source merge support
* src/DataViews/_PlaceView.py: place merge support * src/DataViews/_PlaceView.py: place merge support
* src/glade/mergedata.glade: place merge support * src/glade/mergedata.glade: place merge support
* src/MergeData.py: place merge support * src/MergeData.py: place merge support

View File

@ -154,7 +154,7 @@ class PersonView(PageView.PersonNavView):
ErrorDialog(msg,msg2) ErrorDialog(msg,msg2)
else: else:
from QuestionDialog import ErrorDialog from QuestionDialog import ErrorDialog
import MergePeople from Merge import MergePeople
p1 = self.db.get_person_from_handle(mlist[0]) p1 = self.db.get_person_from_handle(mlist[0])
p2 = self.db.get_person_from_handle(mlist[1]) p2 = self.db.get_person_from_handle(mlist[1])
if p1 and p2: if p1 and p2:
@ -176,12 +176,12 @@ class PersonView(PageView.PersonNavView):
"control key while clicking on the desired person.") "control key while clicking on the desired person.")
ErrorDialog(msg,msg2) ErrorDialog(msg,msg2)
else: else:
from MergePeople import MergePeopleUI from Merge import MergePeople
p1 = self.db.get_person_from_handle(mlist[0]) p1 = self.db.get_person_from_handle(mlist[0])
p2 = self.db.get_person_from_handle(mlist[1]) p2 = self.db.get_person_from_handle(mlist[1])
if p1 and p2: if p1 and p2:
MergePeopleUI(self.dbstate, self.uistate, p1, p2) MergePeople.MergePeopleUI(self.dbstate, self.uistate, p1, p2)
else: else:
msg = _("Cannot merge people") msg = _("Cannot merge people")
msg2 = _("Exactly two people must be selected to perform a merge. " msg2 = _("Exactly two people must be selected to perform a merge. "
@ -634,7 +634,8 @@ class PersonView(PageView.PersonNavView):
sel_data.set(sel_data.target, 8 ,pickle.dumps(data)) sel_data.set(sel_data.target, 8 ,pickle.dumps(data))
def person_added(self,handle_list): def person_added(self,handle_list):
self.model.clear_cache() if not self.model:
return
for node in handle_list: for node in handle_list:
person = self.dbstate.db.get_person_from_handle(node) person = self.dbstate.db.get_person_from_handle(node)
top = person.get_primary_name().get_group_name() top = person.get_primary_name().get_group_name()
@ -651,6 +652,9 @@ class PersonView(PageView.PersonNavView):
self.model.row_inserted(path,pnode) self.model.row_inserted(path,pnode)
def person_removed(self,handle_list): def person_removed(self,handle_list):
if not self.model:
return
self.model.clear_cache() self.model.clear_cache()
for node in handle_list: for node in handle_list:
person = self.dbstate.db.get_person_from_handle(node) person = self.dbstate.db.get_person_from_handle(node)
@ -669,6 +673,9 @@ class PersonView(PageView.PersonNavView):
self.model.assign_data() self.model.assign_data()
def person_updated(self,handle_list): def person_updated(self,handle_list):
if not self.model:
return
self.model.clear_cache() self.model.clear_cache()
for node in handle_list: for node in handle_list:
person = self.dbstate.db.get_person_from_handle(node) person = self.dbstate.db.get_person_from_handle(node)

View File

@ -217,12 +217,11 @@ class PlaceView(PageView.ListView):
if len(mlist) != 2: if len(mlist) != 2:
msg = _("Cannot merge places.") msg = _("Cannot merge places.")
msg2 = _("Exactly two places must be selected to perform a merge. " msg2 = _("Exactly two places must be selected to perform a merge. "
"A second place can be selected by holding down the " "A second place can be selected by holding down the "
"control key while clicking on the desired place.") "control key while clicking on the desired place.")
ErrorDialog(msg,msg2) ErrorDialog(msg,msg2)
else: else:
import MergeData import MergeData
MergeData.MergePlaces(self.dbstate, self.uistate, mlist[0], MergeData.MergePlaces(self.dbstate, self.uistate, mlist[0], mlist[1])
mlist[1], self.build_tree)

View File

@ -83,7 +83,7 @@ class SourceView(PageView.ListView):
self, _('Sources'), dbstate, uistate, column_names, self, _('Sources'), dbstate, uistate, column_names,
len(column_names), DisplayModels.SourceModel, signal_map, len(column_names), DisplayModels.SourceModel, signal_map,
dbstate.db.get_source_bookmarks(), dbstate.db.get_source_bookmarks(),
Bookmarks.SourceBookmarks) Bookmarks.SourceBookmarks, multiple=True)
def get_bookmarks(self): def get_bookmarks(self):
return self.dbstate.db.get_source_bookmarks() return self.dbstate.db.get_source_bookmarks()
@ -95,6 +95,8 @@ class SourceView(PageView.ListView):
PageView.ListView.define_actions(self) PageView.ListView.define_actions(self)
self.add_action('ColumnEdit', gtk.STOCK_PROPERTIES, self.add_action('ColumnEdit', gtk.STOCK_PROPERTIES,
_('_Column Editor'), callback=self.column_editor) _('_Column Editor'), callback=self.column_editor)
self.add_action('FastMerge', None, _('_Merge'),
callback=self.fast_merge)
def column_editor(self,obj): def column_editor(self,obj):
import ColumnOrder import ColumnOrder
@ -132,6 +134,9 @@ class SourceView(PageView.ListView):
<menuitem action="Remove"/> <menuitem action="Remove"/>
</placeholder> </placeholder>
<menuitem action="ColumnEdit"/> <menuitem action="ColumnEdit"/>
<placeholder name="Merge">
<menuitem action="FastMerge"/>
</placeholder>
</menu> </menu>
</menubar> </menubar>
<toolbar name="ToolBar"> <toolbar name="ToolBar">
@ -194,3 +199,17 @@ class SourceView(PageView.ListView):
except Errors.WindowActiveError: except Errors.WindowActiveError:
pass pass
def fast_merge(self, obj):
mlist = []
self.selection.selected_foreach(self.blist,mlist)
if len(mlist) != 2:
msg = _("Cannot merge sources.")
msg2 = _("Exactly two sources must be selected to perform a merge. "
"A second source can be selected by holding down the "
"control key while clicking on the desired source.")
ErrorDialog(msg,msg2)
else:
import MergeData
MergeData.MergeSources(self.dbstate, self.uistate, mlist[0], mlist[1])

View File

@ -7,6 +7,7 @@ SUBDIRS = \
Editors \ Editors \
Filters \ Filters \
GrampsDb \ GrampsDb \
Merge \
DisplayTabs \ DisplayTabs \
DisplayModels \ DisplayModels \
GrampsLogger \ GrampsLogger \

22
src/Merge/Makefile.am Normal file
View File

@ -0,0 +1,22 @@
# This is the src/RelLib level Makefile for Gramps
# We could use GNU make's ':=' syntax for nice wildcard use,
# but that is not necessarily portable.
# If not using GNU make, then list all .py files individually
pkgdatadir = $(datadir)/@PACKAGE@/Merge
pkgdata_PYTHON = \
__init__.py \
_MergePerson.py \
pkgpyexecdir = @pkgpyexecdir@/Merge
pkgpythondir = @pkgpythondir@/Merge
# Clean up all the byte-compiled files
MOSTLYCLEANFILES = *pyc *pyo
GRAMPS_PY_MODPATH = "../"
pycheck:
(export PYTHONPATH=$(GRAMPS_PY_MODPATH); \
pychecker $(pkgdata_PYTHON));

26
src/Merge/__init__.py Normal file
View File

@ -0,0 +1,26 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2004-2006 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: __init__.py 6169 2006-03-18 01:30:23Z dallingham $
"""
"""
from MergePeople import MergePeople

View File

@ -39,7 +39,6 @@ import gtk
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import Utils
import const import const
import GrampsDisplay import GrampsDisplay
import ManagedWindow import ManagedWindow
@ -54,7 +53,7 @@ class MergePlaces(ManagedWindow.ManagedWindow):
Merges to places into a single place. Displays a dialog box that Merges to places into a single place. Displays a dialog box that
allows the places to be combined into one. allows the places to be combined into one.
""" """
def __init__(self, dbstate, uistate, new_handle, old_handle, update): def __init__(self, dbstate, uistate, new_handle, old_handle):
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self.__class__) ManagedWindow.ManagedWindow.__init__(self, uistate, [], self.__class__)
@ -63,7 +62,6 @@ class MergePlaces(ManagedWindow.ManagedWindow):
self.old_handle = old_handle self.old_handle = old_handle
self.p1 = self.db.get_place_from_handle(self.new_handle) self.p1 = self.db.get_place_from_handle(self.new_handle)
self.p2 = self.db.get_place_from_handle(self.old_handle) self.p2 = self.db.get_place_from_handle(self.old_handle)
self.update = update
self.glade = gtk.glade.XML(const.merge_glade,"merge_places","gramps") self.glade = gtk.glade.XML(const.merge_glade,"merge_places","gramps")
self.set_window(self.glade.get_widget("merge_places"), self.set_window(self.glade.get_widget("merge_places"),
@ -79,7 +77,7 @@ class MergePlaces(ManagedWindow.ManagedWindow):
self.glade.get_widget('ok').connect('clicked', self.merge) self.glade.get_widget('ok').connect('clicked', self.merge)
self.glade.get_widget('help').connect('clicked', self.help) self.glade.get_widget('help').connect('clicked', self.help)
self.window.show() self.show()
def close_window(self, obj): def close_window(self, obj):
self.close() self.close()
@ -169,7 +167,6 @@ class MergePlaces(ManagedWindow.ManagedWindow):
self.db.commit_event(event,trans) self.db.commit_event(event,trans)
self.db.transaction_commit(trans,_("Merge Places")) self.db.transaction_commit(trans,_("Merge Places"))
self.update()
self.close() self.close()
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -177,23 +174,27 @@ class MergePlaces(ManagedWindow.ManagedWindow):
# Merge Sources # Merge Sources
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class MergeSources: class MergeSources(ManagedWindow.ManagedWindow):
""" """
Merges to sources into a single source. Displays a dialog box that Merges to sources into a single source. Displays a dialog box that
allows the sources to be combined into one. allows the sources to be combined into one.
""" """
def __init__(self,database,new_handle,old_handle,update): def __init__(self, dbstate, uistate, new_handle, old_handle):
self.db = database
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self.__class__)
self.db = dbstate.db
self.new_handle = new_handle self.new_handle = new_handle
self.old_handle = old_handle self.old_handle = old_handle
self.src1 = self.db.get_source_from_handle(self.new_handle) self.src1 = self.db.get_source_from_handle(self.new_handle)
self.src2 = self.db.get_source_from_handle(self.old_handle) self.src2 = self.db.get_source_from_handle(self.old_handle)
self.update = update
self.glade = gtk.glade.XML(const.merge_glade,"merge_sources","gramps") self.glade = gtk.glade.XML(const.merge_glade,"merge_sources","gramps")
self.top = self.glade.get_widget("merge_sources")
Utils.set_titles(self.top,self.glade.get_widget('title'), self.set_window(self.glade.get_widget("merge_sources"),
_("Merge Sources")) self.glade.get_widget('title'),
_("Merge Sources"))
self.title1 = self.glade.get_widget("title1") self.title1 = self.glade.get_widget("title1")
self.title2 = self.glade.get_widget("title2") self.title2 = self.glade.get_widget("title2")
@ -221,13 +222,12 @@ class MergeSources:
self.gramps2.set_text(self.src2.get_gramps_id()) self.gramps2.set_text(self.src2.get_gramps_id())
self.glade.get_widget('ok').connect('clicked',self.merge) self.glade.get_widget('ok').connect('clicked',self.merge)
self.glade.get_widget('cancel').connect('clicked',self.close) self.glade.get_widget('cancel').connect('clicked',self.close_window)
self.glade.get_widget('help').connect('clicked',self.help) self.glade.get_widget('help').connect('clicked',self.help)
trans = self.db.transaction_begin() self.show()
self.top.show()
def close(self,obj): def close_window(self,obj):
self.top.destroy() self.close()
def help(self,obj): def help(self,obj):
"""Display the relevant portion of GRAMPS manual""" """Display the relevant portion of GRAMPS manual"""
@ -278,8 +278,10 @@ class MergeSources:
src1_map[key] = src2_map[key] src1_map[key] = src2_map[key]
# replace references in other objetcs # replace references in other objetcs
self.db.remove_source(self.old_handle,self.trans) trans = self.db.transaction_begin()
self.db.commit_source(self.src1,self.trans)
self.db.remove_source(self.old_handle,trans)
self.db.commit_source(self.src1,trans)
# replace handles # replace handles
@ -288,42 +290,42 @@ class MergeSources:
person = self.db.get_person_from_handle(handle) person = self.db.get_person_from_handle(handle)
if person.has_source_reference(self.old_handle): if person.has_source_reference(self.old_handle):
person.replace_source_references(self.old_handle,self.new_handle) person.replace_source_references(self.old_handle,self.new_handle)
self.db.commit_person(person,self.trans) self.db.commit_person(person,trans)
# family # family
for handle in self.db.get_family_handles(): for handle in self.db.get_family_handles():
family = self.db.get_family_from_handle(handle) family = self.db.get_family_from_handle(handle)
if family.has_source_reference(self.old_handle): if family.has_source_reference(self.old_handle):
family.replace_source_references(self.old_handle,self.new_handle) family.replace_source_references(self.old_handle,self.new_handle)
self.db.commit_family(family,self.trans) self.db.commit_family(family,trans)
# events # events
for handle in self.db.get_event_handles(): for handle in self.db.get_event_handles():
event = self.db.get_event_from_handle(handle) event = self.db.get_event_from_handle(handle)
if event.has_source_reference(self.old_handle): if event.has_source_reference(self.old_handle):
event.replace_source_references(self.old_handle,self.new_handle) event.replace_source_references(self.old_handle,self.new_handle)
self.db.commit_event(event,self.trans) self.db.commit_event(event,trans)
# sources # sources
for handle in self.db.get_source_handles(): for handle in self.db.get_source_handles():
source = self.db.get_source_from_handle(handle) source = self.db.get_source_from_handle(handle)
if source.has_source_reference(self.old_handle): if source.has_source_reference(self.old_handle):
source.replace_source_references(self.old_handle,self.new_handle) source.replace_source_references(self.old_handle,self.new_handle)
self.db.commit_source(source,self.trans) self.db.commit_source(source,trans)
# places # places
for handle in self.db.get_place_handles(): for handle in self.db.get_place_handles():
place = self.db.get_place_from_handle(handle) place = self.db.get_place_from_handle(handle)
if place.has_source_reference(self.old_handle): if place.has_source_reference(self.old_handle):
place.replace_source_references(self.old_handle,self.new_handle) place.replace_source_references(self.old_handle,self.new_handle)
self.db.commit_place(place,self.trans) self.db.commit_place(place,trans)
# media # media
for handle in self.db.get_media_object_handles(): for handle in self.db.get_media_object_handles():
obj = self.db.get_object_from_handle(handle) obj = self.db.get_object_from_handle(handle)
if obj.has_source_reference(self.old_handle): if obj.has_source_reference(self.old_handle):
obj.replace_source_references(self.old_handle,self.new_handle) obj.replace_source_references(self.old_handle,self.new_handle)
self.db.commit_media_object(obj,self.trans) self.db.commit_media_object(obj,trans)
self.db.transaction_commit(self.trans,_("Merge Sources")) self.db.transaction_commit(trans,_("Merge Sources"))
self.top.destroy() self.close()