From 003912f3265a50883b97d005eb61f4cb353cb2ea Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Thu, 18 Nov 2004 20:21:06 +0000 Subject: [PATCH] * src/DisplayModels.py: Added ChildModel to handle the child list in the Family View * src/gramps_main.py: add column editor for Family View * src/GrampsDbBase.py: add storing/retrieving child column order * src/FamilyView.py: use new ChildModel * src/PlaceView.py: removed unused index svn: r3735 --- gramps2/ChangeLog | 8 +++ gramps2/src/DisplayModels.py | 89 ++++++++++++++++++++++++++++-- gramps2/src/FamilyView.py | 103 +++++++++++++++++------------------ gramps2/src/GrampsDbBase.py | 23 ++++++++ gramps2/src/PlaceView.py | 3 - gramps2/src/gramps_main.py | 8 +++ 6 files changed, 172 insertions(+), 62 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 10f99d464..783c47390 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,11 @@ +2004-11-18 Don Allingham + * src/DisplayModels.py: Added ChildModel to handle the + child list in the Family View + * src/gramps_main.py: add column editor for Family View + * src/GrampsDbBase.py: add storing/retrieving child column order + * src/FamilyView.py: use new ChildModel + * src/PlaceView.py: removed unused index + 2004-11-16 Don Allingham * src/MediaView.py: remove obsolete pexists check diff --git a/gramps2/src/DisplayModels.py b/gramps2/src/DisplayModels.py index 62d57652f..75f05f388 100644 --- a/gramps2/src/DisplayModels.py +++ b/gramps2/src/DisplayModels.py @@ -28,6 +28,8 @@ import time import gobject import gtk +_GENDER = [ _(u'female'), _(u'male'), _(u'unknown') ] + #------------------------------------------------------------------------- # # BaseModel @@ -45,11 +47,10 @@ class BaseModel(gtk.GenericTreeModel): return [] def rebuild_data(self): - self.datalist = [] - - if not self.db.is_open(): - return - self.datalist = self.sort_keys() + if self.db.is_open(): + self.datalist = self.sort_keys() + else: + self.datalist = [] def on_row_inserted(self,obj,path,node): self.rebuild_data() @@ -130,6 +131,83 @@ class BaseModel(gtk.GenericTreeModel): '''returns the parent of this node''' return None +#------------------------------------------------------------------------- +# +# ChildModel +# +#------------------------------------------------------------------------- +class ChildModel(gtk.ListStore): + + def __init__(self,child_list,db): + gtk.ListStore.__init__(self,int,str,str,str,str,str,str,str,str,str,int,int) + self.db = db + index = 1 + for child_handle in child_list: + child = db.get_person_from_handle(child_handle) + self.append(row=[index, + child.get_gramps_id(), + child.get_primary_name().get_name(), + _GENDER[child.get_gender()], + self.column_birth_day(child), + self.column_death_day(child), + self.column_birth_place(child), + self.column_death_place(child), + child.get_handle(), + child.get_primary_name().get_sort_name(), + self.column_birth_sort(child), + self.column_death_sort(child), + ]) + index += 1 + + def column_birth_day(self,data): + event_handle = data.get_birth_handle() + if event_handle: + return self.db.get_event_from_handle(event_handle).get_date() + else: + return u"" + + def column_birth_sort(self,data): + event_handle = data.get_birth_handle() + if event_handle: + return self.db.get_event_from_handle(event_handle).get_date_object().get_sort_value() + else: + return 0 + + def column_death_day(self,data): + event_handle = data.get_death_handle() + if event_handle: + return self.db.get_event_from_handle(event_handle).get_date() + else: + return u"" + + def column_death_sort(self,data): + event_handle = data.get_death_handle() + if event_handle: + return self.db.get_event_from_handle(event_handle).get_date_object().get_sort_value() + else: + return 0 + + def column_birth_place(self,data): + event_handle = data.get_birth_handle() + if event_handle: + event = self.db.get_event_from_handle(event_handle) + if event: + place_handle = event.get_place_handle() + if place_handle: + return self.db.get_place_from_handle(place_handle).get_title() + return u"" + + def column_death_place(self,data): + event_handle = data.get_death_handle() + if event_handle: + event = self.db.get_event_from_handle(event_handle) + if event: + place_handle = event.get_place_handle() + if place_handle: + return self.db.get_place_from_handle(place_handle).get_title() + return u"" + + #------------------------------------------------------------------------- # # SourceModel @@ -292,3 +370,4 @@ class MediaModel(BaseModel): def column_change(self,data): return unicode(time.asctime(time.localtime(data[8]))) + diff --git a/gramps2/src/FamilyView.py b/gramps2/src/FamilyView.py index 33ef6d015..8575adeb7 100644 --- a/gramps2/src/FamilyView.py +++ b/gramps2/src/FamilyView.py @@ -47,6 +47,7 @@ import ChooseParents import RelLib import EditPerson import DateHandler +import DisplayModels from gettext import gettext as _ from QuestionDialog import QuestionDialog,WarningDialog @@ -56,6 +57,19 @@ _DIED = _('d.') pycode_tgts = [('child', 0, 0)] +column_names = [ + (_('#'),0) , + (_('ID'),1) , + (_('Name'),9), + (_('Gender'),3), + (_('Birth Date'),10), + (_('Death Date'),11), + (_('Birth Place'),6), + (_('Death Place'),7), + ] + +_HANDLE_COL = 8 + #------------------------------------------------------------------------- # # FamilyView @@ -72,6 +86,8 @@ class FamilyView: def set_widgets(self,val): already_init = self.cadded[val] + + self.columns = [] if (val): self.ap_data = self.top.get_widget('ap_data2') self.swap_btn = self.top.get_widget('swap_btn2') @@ -203,13 +219,6 @@ class FamilyView: self.child_list.drag_source_set(BUTTON1_MASK, pycode_tgts, ACTION_COPY) self.child_list.connect('drag_data_get', self.drag_data_get) self.child_list.connect('drag_data_received',self.drag_data_received) - - self.child_model = gtk.ListStore(TYPE_INT, TYPE_STRING, - TYPE_STRING,TYPE_STRING, - TYPE_STRING,TYPE_STRING, - TYPE_STRING,TYPE_STRING) - - self.child_selection = self.child_list.get_selection() if not already_init: self.child_list.connect('button-press-event', @@ -221,16 +230,32 @@ class FamilyView: self.add_spouse_btn.connect('clicked',self.add_spouse) self.select_spouse_btn.connect('clicked',self.select_spouse) + if not already_init: + self.build_columns() + + self.child_model = DisplayModels.ChildModel([],self.parent.db) self.child_list.set_model(self.child_model) - self.child_list.set_search_column(0) + #self.child_list.set_search_column(2) self.child_selection = self.child_list.get_selection() - if not already_init: - Utils.build_columns(self.child_list, - [ (' ',30,0), (_('Name'),250,-1), (_('ID'),50,-1), - (_('Gender'),75,-1), (_('Birth date'),150,6), - (_('Status'),100,-1), ('',0,-1) ]) self.cadded[fv] = 1 + + def build_columns(self): + for column in self.columns: + self.child_list.remove_column(column) + self.columns = [] + + for pair in self.parent.db.get_child_column_order(): + if not pair[0]: + continue + name = column_names[pair[1]][0] + column = gtk.TreeViewColumn(name, gtk.CellRendererText(), + text=pair[1]) + column.set_resizable(gtk.TRUE) + column.set_min_width(40) + column.set_sort_column_id(column_names[pair[1]][1]) + self.columns.append(column) + self.child_list.append_column(column) def ap_button_press(self,obj,event): if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1: @@ -294,7 +319,7 @@ class FamilyView: model, node = self.child_selection.get_selected() if not node: return - handle = self.child_model.get_value(node,7) + handle = self.child_model.get_value(node,_HANDLE_COL) if event.keyval == gtk.gdk.keyval_from_name("Return") and not event.state: self.child_rel_by_id(handle) elif event.keyval == gtk.gdk.keyval_from_name("Return") \ @@ -434,7 +459,7 @@ class FamilyView: if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3: self.build_nav_menu(event) return - handle = self.child_model.get_value(node,7) + handle = self.child_model.get_value(node,_HANDLE_COL) if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1: self.child_rel_by_id(handle) elif event.state == gtk.gdk.SHIFT_MASK and \ @@ -487,7 +512,7 @@ class FamilyView: model, node = self.child_selection.get_selected() if not node: return - handle = self.child_model.get_value(node,7) + handle = self.child_model.get_value(node,_HANDLE_COL) child = self.parent.db.get_person_from_handle(handle) try: EditPerson.EditPerson(self.parent, child, self.parent.db, @@ -747,7 +772,7 @@ class FamilyView: if not node: return - handle = self.child_model.get_value(node,7) + handle = self.child_model.get_value(node,_HANDLE_COL) child = self.parent.db.get_person_from_handle(handle) trans = self.parent.db.transaction_begin() @@ -858,13 +883,15 @@ class FamilyView: def clear(self): self.spouse_model.clear() - self.child_model.clear() self.sp_parents_model.clear() self.ap_parents_model.clear() self.ap_model.clear() - + self.child_model = DisplayModels.ChildModel([],self.parent.db) + self.child_list.set_model(self.child_model) + def load_family(self,family=None): + self.build_columns() if self.parent.active_person: handle = self.parent.active_person.get_handle() self.person = self.parent.db.get_person_from_handle(handle) @@ -900,7 +927,6 @@ class FamilyView: self.selected_spouse = None self.spouse_model.clear() - self.child_model.clear() self.sp_parents_model.clear() splist = self.person.get_family_handle_list() @@ -1008,7 +1034,9 @@ class FamilyView: self.parent.db.transaction_commit(trans,_("Remove from family (%s)") % n) def display_marriage(self,family): - self.child_model.clear() + hlist = family.get_child_handle_list() + self.child_model = DisplayModels.ChildModel(hlist,self.parent.db) + self.child_list.set_model(self.child_model) if not family: self.family = None @@ -1032,39 +1060,6 @@ class FamilyView: self.update_list(self.sp_parents_model,self.sp_parents, self.selected_spouse) - i = 0 - fiter = None - child_list = list(self.family.get_child_handle_list()) - - self.child_map = {} - - for child_handle in child_list: - status = _("Unknown") - - child = self.parent.db.get_person_from_handle(child_handle) - for fam in child.get_parent_family_handle_list(): - if fam[0] == self.family.get_handle(): - if self.person == self.family.get_father_handle(): - status = "%s/%s" % (_(fam[2]),_(fam[1])) - else: - status = "%s/%s" % (_(fam[1]),_(fam[2])) - - node = self.child_model.append() - self.child_map[node] = child.get_handle() - - if fiter == None: - fiter = self.child_model.get_path(node) - val = child.get_display_info() - i += 1 - - event = self.parent.db.get_event_from_handle(val[3]) - if event: - dval = self.dd.display(event.get_date_object()) - else: - dval = u'' - self.child_model.set(node,0,i,1,val[0],2,val[1],3,val[2], - 4,dval,5,status,6,val[6],7,child.get_handle()) - def build_parents_menu(self,family,event): """Builds the menu that allows editing operations on the child list""" menu = gtk.Menu() diff --git a/gramps2/src/GrampsDbBase.py b/gramps2/src/GrampsDbBase.py index 34aa66ff2..f888047b9 100644 --- a/gramps2/src/GrampsDbBase.py +++ b/gramps2/src/GrampsDbBase.py @@ -1021,6 +1021,14 @@ class GrampsDbBase: if self.metadata != None: self.metadata['columns'] = list + def set_child_column_order(self,list): + """ + Stores the Person display common information in the + database's metadata. + """ + if self.metadata != None: + self.metadata['child_columns'] = list + def set_place_column_order(self,list): """ Stores the Place display common information in the @@ -1060,6 +1068,21 @@ class GrampsDbBase: else: return cols + def get_child_column_order(self): + """ + Returns the Person display common information stored in the + database's metadata. + """ + default = [(1,0),(1,1),(1,2),(1,3),(1,4),(1,5),(0,6),(0,7)] + if self.metadata == None: + return default + else: + cols = self.metadata.get('child_columns',default) + if len(cols) != len(default): + return cols + default[len(cols):] + else: + return cols + def get_place_column_order(self): """ Returns the Place display common information stored in the diff --git a/gramps2/src/PlaceView.py b/gramps2/src/PlaceView.py index aa03a03fb..cc1e637e3 100644 --- a/gramps2/src/PlaceView.py +++ b/gramps2/src/PlaceView.py @@ -59,7 +59,6 @@ column_names = [ ] _HANDLE_COL = len(column_names) - #------------------------------------------------------------------------- # # PlaceView class @@ -98,7 +97,6 @@ class PlaceView: self.list.append_column(column) self.columns = [column] - index = 1 for pair in self.parent.db.get_place_column_order(): if not pair[0]: continue @@ -108,7 +106,6 @@ class PlaceView: column.set_min_width(75) self.columns.append(column) self.list.append_column(column) - index += 1 def change_db(self,db): self.build_columns() diff --git a/gramps2/src/gramps_main.py b/gramps2/src/gramps_main.py index b112ea0d9..ba39c340f 100755 --- a/gramps2/src/gramps_main.py +++ b/gramps2/src/gramps_main.py @@ -445,6 +445,10 @@ class Gramps: self.db.set_person_column_order(list) self.people_view.build_columns() + def set_child_column_order(self,list): + self.db.set_child_column_order(list) + self.family_view.build_columns() + def set_place_column_order(self,list): self.db.set_place_column_order(list) self.place_view.build_columns() @@ -465,6 +469,10 @@ class Gramps: ColumnOrder.ColumnOrder(self.db.get_person_column_order(), PeopleView.column_names, self.set_person_column_order) + elif cpage == FAMILY_VIEW1 or cpage == FAMILY_VIEW2: + ColumnOrder.ColumnOrder(self.db.get_child_column_order(), + map(lambda x: x[0], FamilyView.column_names), + self.set_child_column_order) elif cpage == SOURCE_VIEW: ColumnOrder.ColumnOrder(self.db.get_source_column_order(), SourceView.column_names,