From 8ec6242dd7ac69f65d43721a970b5cb226e0a452 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Fri, 26 May 2006 20:48:40 +0000 Subject: [PATCH] 2006-05-26 Don Allingham * src/DataViews/_RelationView.py: build skip list for SelectFamily so that * a person cannot be his own parent * src/Editors/_EditFamily.py: don't allow a person to be his own parent * src/Selectors/_BaseSelector.py: Add skipping of handles * src/DisplayModels/_BaseModel.py: Add skipping of handles * src/DisplayModels/_MediaModel.py: Add skipping of handles * src/DisplayModels/_RepositoryModel.py: Add skipping of handles * src/DisplayModels/_SourceModel.py: Add skipping of handles * src/DisplayModels/_EventModel.py: Add skipping of handles * src/DisplayModels/_FamilyModel.py: Add skipping of handles * src/DisplayModels/_PlaceModel.py: Add skipping of handles svn: r6790 --- ChangeLog | 13 +++++++++++++ src/DataViews/_RelationView.py | 6 +++++- src/DisplayModels/_BaseModel.py | 20 +++++++++++++------- src/DisplayModels/_EventModel.py | 9 +++++++-- src/DisplayModels/_FamilyModel.py | 10 ++++++++-- src/DisplayModels/_MediaModel.py | 10 ++++++++-- src/DisplayModels/_PlaceModel.py | 10 ++++++++-- src/DisplayModels/_RepositoryModel.py | 10 ++++++++-- src/DisplayModels/_SourceModel.py | 11 +++++++++-- src/Editors/_EditFamily.py | 26 ++++++++++++++++++++++++++ src/Selectors/_BaseSelector.py | 9 +++++++-- 11 files changed, 112 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 212f583c3..8b1c480f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2006-05-26 Don Allingham + * src/DataViews/_RelationView.py: build skip list for SelectFamily so that + * a person cannot be his own parent + * src/Editors/_EditFamily.py: don't allow a person to be his own parent + * src/Selectors/_BaseSelector.py: Add skipping of handles + * src/DisplayModels/_BaseModel.py: Add skipping of handles + * src/DisplayModels/_MediaModel.py: Add skipping of handles + * src/DisplayModels/_RepositoryModel.py: Add skipping of handles + * src/DisplayModels/_SourceModel.py: Add skipping of handles + * src/DisplayModels/_EventModel.py: Add skipping of handles + * src/DisplayModels/_FamilyModel.py: Add skipping of handles + * src/DisplayModels/_PlaceModel.py: Add skipping of handles + 2006-05-25 Don Allingham * src/DisplayTabs/_NoteTab.py (NoteTab.flow_changed): save flow status in Note diff --git a/src/DataViews/_RelationView.py b/src/DataViews/_RelationView.py index dbad67d24..08b211887 100644 --- a/src/DataViews/_RelationView.py +++ b/src/DataViews/_RelationView.py @@ -801,7 +801,11 @@ class RelationshipView(PageView.PersonNavView): from Selectors import selector_factory SelectFamily = selector_factory('Family') - dialog = SelectFamily(self.dbstate, self.uistate) + phandle = self.dbstate.get_active_person().handle + person = self.dbstate.db.get_person_from_handle(phandle) + skip = set(person.get_family_handle_list()) + + dialog = SelectFamily(self.dbstate, self.uistate, skip=skip) family = dialog.run() if family: diff --git a/src/DisplayModels/_BaseModel.py b/src/DisplayModels/_BaseModel.py index 6608cd464..d35627781 100644 --- a/src/DisplayModels/_BaseModel.py +++ b/src/DisplayModels/_BaseModel.py @@ -25,7 +25,11 @@ # #------------------------------------------------------------------------- import locale - +try: + set() +except: + from sets import Set as set + #------------------------------------------------------------------------- # # GNOME/GTK modules @@ -48,7 +52,7 @@ from Filters import SearchFilter class BaseModel(gtk.GenericTreeModel): def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, - tooltip_column=None, search=None): + tooltip_column=None, search=None, skip=set()): gtk.GenericTreeModel.__init__(self) self.prev_handle = None self.prev_data = None @@ -56,7 +60,8 @@ class BaseModel(gtk.GenericTreeModel): self.db = db self.sort_func = self.smap[scol] self.sort_col = scol - + self.skip = skip + if search: col = search[0] text = search[1] @@ -95,14 +100,15 @@ class BaseModel(gtk.GenericTreeModel): if self.db.is_open(): if self.search: self.datalist = [h for h in self.sort_keys()\ - if self.search.match(h)] + if self.search.match(h) and h not in self.skip] else: - self.datalist = self.sort_keys() + self.datalist = [h for h in self.sort_keys() if h not in self.skip] i = 0 self.indexlist = {} for key in self.datalist: - self.indexlist[key] = i - i += 1 + if key not in self.skip: + self.indexlist[key] = i + i += 1 else: self.datalist = [] self.indexlist = {} diff --git a/src/DisplayModels/_EventModel.py b/src/DisplayModels/_EventModel.py index 758c2b2df..b54fc3efc 100644 --- a/src/DisplayModels/_EventModel.py +++ b/src/DisplayModels/_EventModel.py @@ -27,6 +27,10 @@ import time import logging log = logging.getLogger(".") +try: + set() +except: + from sets import Set as set #------------------------------------------------------------------------- # @@ -54,7 +58,8 @@ from _BaseModel import BaseModel #------------------------------------------------------------------------- class EventModel(BaseModel): - def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None): + def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None, + skip=set()): self.gen_cursor = db.get_event_cursor self.map = db.get_raw_event_data @@ -81,7 +86,7 @@ class EventModel(BaseModel): self.column_tooltip, ] BaseModel.__init__(self, db, scol, order, tooltip_column=8, - search=search) + search=search, skip=skip) def on_get_n_columns(self): return len(self.fmap)+1 diff --git a/src/DisplayModels/_FamilyModel.py b/src/DisplayModels/_FamilyModel.py index c67ccb50b..79602efcb 100644 --- a/src/DisplayModels/_FamilyModel.py +++ b/src/DisplayModels/_FamilyModel.py @@ -28,6 +28,11 @@ import time import logging log = logging.getLogger(".") +try: + set() +except: + from sets import Set as set + #------------------------------------------------------------------------- # # GNOME/GTK modules @@ -55,7 +60,8 @@ from _BaseModel import BaseModel #------------------------------------------------------------------------- class FamilyModel(BaseModel): - def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None): + def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None, + skip=set()): self.gen_cursor = db.get_family_cursor self.map = db.get_raw_family_data self.fmap = [ @@ -77,7 +83,7 @@ class FamilyModel(BaseModel): self.column_tooltip ] BaseModel.__init__(self, db, scol, order, tooltip_column=6, - search=search) + search=search, skip=skip) def on_get_n_columns(self): return len(self.fmap)+1 diff --git a/src/DisplayModels/_MediaModel.py b/src/DisplayModels/_MediaModel.py index be99421ec..073706bf8 100644 --- a/src/DisplayModels/_MediaModel.py +++ b/src/DisplayModels/_MediaModel.py @@ -29,6 +29,11 @@ from gettext import gettext as _ import logging log = logging.getLogger(".") +try: + set() +except: + from sets import Set as set + #------------------------------------------------------------------------- # # GNOME/GTK modules @@ -55,7 +60,8 @@ from _BaseModel import BaseModel #------------------------------------------------------------------------- class MediaModel(BaseModel): - def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None): + def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None, + skip=set()): self.gen_cursor = db.get_media_cursor self.map = db.get_raw_object_data @@ -79,7 +85,7 @@ class MediaModel(BaseModel): self.column_handle, ] BaseModel.__init__(self, db, scol, order, tooltip_column=7, - search=search) + search=search, skip=skip) def on_get_n_columns(self): return len(self.fmap)+1 diff --git a/src/DisplayModels/_PlaceModel.py b/src/DisplayModels/_PlaceModel.py index de3d5027d..10bdb3396 100644 --- a/src/DisplayModels/_PlaceModel.py +++ b/src/DisplayModels/_PlaceModel.py @@ -28,6 +28,11 @@ import time import logging log = logging.getLogger(".") +try: + set() +except: + from sets import Set as set + #------------------------------------------------------------------------- # # GNOME/GTK modules @@ -52,7 +57,8 @@ from _BaseModel import BaseModel #------------------------------------------------------------------------- class PlaceModel(BaseModel): - def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING,search=None): + def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING,search=None, + skip=set()): self.gen_cursor = db.get_place_cursor self.map = db.get_raw_place_data self.fmap = [ @@ -85,7 +91,7 @@ class PlaceModel(BaseModel): self.column_handle, ] BaseModel.__init__(self, db, scol, order, tooltip_column=12, - search=search) + search=search, skip=skip) def on_get_n_columns(self): return len(self.fmap)+1 diff --git a/src/DisplayModels/_RepositoryModel.py b/src/DisplayModels/_RepositoryModel.py index cc4cbc9b7..d670dc71a 100644 --- a/src/DisplayModels/_RepositoryModel.py +++ b/src/DisplayModels/_RepositoryModel.py @@ -28,6 +28,11 @@ import time import logging log = logging.getLogger(".") +try: + set() +except: + from sets import Set as set + #------------------------------------------------------------------------- # # GNOME/GTK modules @@ -53,7 +58,8 @@ from _BaseModel import BaseModel #------------------------------------------------------------------------- class RepositoryModel(BaseModel): - def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None): + def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None, + skip=set()): self.gen_cursor = db.get_repository_cursor self.get_handles = db.get_repository_handles self.map = db.get_raw_repository_data @@ -91,7 +97,7 @@ class RepositoryModel(BaseModel): ] BaseModel.__init__(self, db, scol, order, tooltip_column=12, - search=search) + search=search, skip=skip) def on_get_n_columns(self): return len(self.fmap)+1 diff --git a/src/DisplayModels/_SourceModel.py b/src/DisplayModels/_SourceModel.py index f0cc236e2..09fd7d6ac 100644 --- a/src/DisplayModels/_SourceModel.py +++ b/src/DisplayModels/_SourceModel.py @@ -28,6 +28,11 @@ import time import logging log = logging.getLogger(".") +try: + set() +except: + from sets import Set as set + #------------------------------------------------------------------------- # # GNOME/GTK modules @@ -52,7 +57,8 @@ from _BaseModel import BaseModel #------------------------------------------------------------------------- class SourceModel(BaseModel): - def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING,search=None): + def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING,search=None, + skip=set()): self.map = db.get_raw_source_data self.gen_cursor = db.get_source_cursor self.fmap = [ @@ -73,7 +79,8 @@ class SourceModel(BaseModel): self.column_pubinfo, self.sort_change, ] - BaseModel.__init__(self,db,scol,order,tooltip_column=7,search=search) + BaseModel.__init__(self,db,scol,order,tooltip_column=7,search=search, + skip=skip) def on_get_n_columns(self): return len(self.fmap)+1 diff --git a/src/Editors/_EditFamily.py b/src/Editors/_EditFamily.py index 8cc386b23..62a126638 100644 --- a/src/Editors/_EditFamily.py +++ b/src/Editors/_EditFamily.py @@ -734,6 +734,32 @@ class EditFamily(EditPrimary): else: original = None + # do some basic checks + + child_list = [ ref.ref for ref in self.obj.get_child_ref_list() ] + + if self.obj.get_father_handle() in child_list: + from QuestionDialog import ErrorDialog + + father = db.get_person_from_handle(self.obj.get_father_handle()) + name = "%s [%s]" % (NameDisplay.displayer.display(father), + father.gramps_id) + ErrorDialog(_("A father cannot be his own child"), + _("%s is listed as both the father and child of " + "of the family.") % name) + return + elif self.obj.get_mother_handle() in child_list: + from QuestionDialog import ErrorDialog + + mother = db.get_person_from_handle(self.obj.get_mother_handle()) + name = "%s [%s]" % (NameDisplay.displayer.display(mother), + mother.gramps_id) + ErrorDialog(_("A mother cannot be her own child"), + _("%s is listed as both the mother and child of " + "of the family.") % name) + return + + if not original and not self.object_is_empty(): trans = self.db.transaction_begin() diff --git a/src/Selectors/_BaseSelector.py b/src/Selectors/_BaseSelector.py index b8c97e457..47cde1e75 100644 --- a/src/Selectors/_BaseSelector.py +++ b/src/Selectors/_BaseSelector.py @@ -20,6 +20,11 @@ # $Id$ +try: + set() +except: + from sets import Set as set + #------------------------------------------------------------------------- # # GTK/Gnome modules @@ -48,7 +53,7 @@ class BaseSelector(ManagedWindow.ManagedWindow): MARKUP = 1 IMAGE = 2 - def __init__(self, dbstate, uistate, track=[], filter=None, skip=[]): + def __init__(self, dbstate, uistate, track=[], filter=None, skip=set()): self.title = self.get_window_title() ManagedWindow.ManagedWindow.__init__(self, uistate, track, self) @@ -64,7 +69,7 @@ class BaseSelector(ManagedWindow.ManagedWindow): self.set_window(window,title_label,self.title) - self.model = self.get_model_class()(self.db) + self.model = self.get_model_class()(self.db,skip=skip) self.selection = self.tree.get_selection() self.tree.set_model(self.model)