From 30aa40eb2174ca376540c9c38cfc6ffacf0ae3e9 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Mon, 13 Jan 2003 03:59:10 +0000 Subject: [PATCH] Event reordering for marriage svn: r1255 --- configure | 2 +- configure.in | 2 +- gramps.spec | 2 +- src/EditPerson.py | 2 +- src/FamilyView.py | 135 +++++++++++++++++++--------------------------- src/Marriage.py | 90 +++++++++++++++++++------------ src/const.py | 5 +- src/const.py.in | 3 +- 8 files changed, 118 insertions(+), 123 deletions(-) diff --git a/configure b/configure index e9cbdbebe..053f1de8a 100755 --- a/configure +++ b/configure @@ -1567,7 +1567,7 @@ INSTALL_STRIP_PROGRAM="\${SHELL} \$(install_sh) -c -s" -RELEASE=rc1 +RELEASE=rc2 VERSIONSTRING=$VERSION if test x"$RELEASE" != "x" diff --git a/configure.in b/configure.in index fd8f91aae..6ec0afa20 100644 --- a/configure.in +++ b/configure.in @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. dnl May need to run automake && aclocal first AC_INIT(src/gramps.py) AM_INIT_AUTOMAKE(gramps, 0.9.0) -RELEASE=rc1 +RELEASE=rc2 VERSIONSTRING=$VERSION if test x"$RELEASE" != "x" diff --git a/gramps.spec b/gramps.spec index 3c3515a83..d14576665 100644 --- a/gramps.spec +++ b/gramps.spec @@ -1,5 +1,5 @@ %define ver 0.9.0 -%define rel rc1 +%define rel rc2 %define prefix /usr Summary: Genealogical Research and Analysis Management Programming System. diff --git a/src/EditPerson.py b/src/EditPerson.py index f1fef4a57..2009f1a57 100644 --- a/src/EditPerson.py +++ b/src/EditPerson.py @@ -266,7 +266,7 @@ class EditPerson: self.addr_list.drag_source_set(BUTTON1_MASK, pycode_tgts,ACTION_COPY) self.addr_list.connect('drag_data_get', self.ad_drag_data_get) self.addr_list.connect('drag_data_received',self.ad_drag_data_received) - self.addr_list.connect('drag_begin', self.ev_drag_begin) + self.addr_list.connect('drag_begin', self.ad_drag_begin) self.bdate_check = DateEdit(self.bdate,self.get_widget("birth_stat")) self.bdate_check.set_calendar(self.birth.getDateObj().get_calendar()) diff --git a/src/FamilyView.py b/src/FamilyView.py index a4713acba..a25d6776e 100644 --- a/src/FamilyView.py +++ b/src/FamilyView.py @@ -136,9 +136,9 @@ class FamilyView: self.child_selection = self.child_list.get_selection() Utils.build_columns(self.child_list, - [ (_(''),30,0), (_('Name'),250,1), (_('ID'),50,2), - (_('Gender'),100,3), (_('Birth Date'),150,4), - (_('Status'),150,5), ('',0,6) ]) + [ (_(''),30,-1), (_('Name'),250,-1), (_('ID'),50,-1), + (_('Gender'),100,-1), (_('Birth Date'),150,-1), + (_('Status'),150,-1), ('',0,-1) ]) def on_child_list_button_press(self,obj,event): if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1: @@ -524,76 +524,12 @@ class FamilyView: Utils.modified() self.load_family() - def child_list_reordered(self,path,iter): - print path,iter - - def on_child_list_row_move(self,clist,fm,to): - """Validate whether or not this child can be moved within the clist. - This routine is called in the middle of the clist's callbacks, so - the state can be confusing. If the code is being debugged, the - display at this point shows that the list has been reordered when in - actuality it hasn't. All accesses to the clist data structure - reference the state just prior to the move. - - This routine must keep/compute its own list indices as the functions - list.remove(), list.insert(), list.reverse() etc. do not affect the - values returned from the list.index() routine.""" - - family = clist.get_data("f") - - # Create a list based upon the current order of the clist - clist_order = [] - for i in range(clist.rows): - clist_order = clist_order + [clist.get_row_data(i)] - child = clist_order[fm] - - # This function deals with ascending order lists. Convert if - # necessary. - if (self.child_sort.sort_direction() == GTK.SORT_DESCENDING): - clist_order.reverse() - max_index = len(clist_order) - 1 - fm = max_index - fm - to = max_index - to - - # Create a new list to match the requested order - desired_order = clist_order[:fm] + clist_order[fm+1:] - desired_order = desired_order[:to] + [child] + desired_order[to:] - - # Check birth date order in the new list - if (EditPerson.birth_dates_in_order(desired_order) == 0): - clist.emit_stop_by_name("row_move") - msg = _("Invalid move. Children must be ordered by birth date.") - WarningDialog(msg) - return - - # OK, this birth order works too. Update the family data structures. - family.setChildList(desired_order) - - # Build a mapping of child item to list position. This would not - # be necessary if indices worked properly - i = 0 - new_order = {} - for tmp in desired_order: - new_order[tmp] = i - i = i + 1 - - # Convert the original list back to whatever ordering is being - # used by the clist itself. - if self.child_sort.sort_direction() == GTK.SORT_DESCENDING: - clist_order.reverse() - - # Update the clist indices so any change of sorting works - i = 0 - for tmp in clist_order: - clist.set_text(i,0,"%2d"%(new_order[tmp]+1)) - i = i + 1 - - # Need to save the changed order - Utils.modified() - - def drag_data_received(self,widget,context,x,y,sel_data,info,time): - row = self.child_list.get_row_at(x,y) + path = self.child_list.get_path_at_pos(x,y) + if path == None: + row = len(self.family.getChildList()) + else: + row = path[0][0] -1 if sel_data and sel_data.data: exec 'data = %s' % sel_data.data @@ -601,17 +537,58 @@ class FamilyView: exec 'person = "%s"' % data[1] if mytype != 'child': return - elif person == self.person.getId(): - print row - # self.move_element(self.elist,self.etree.get_selected_row(),row) + s,i = self.child_selection.get_selected() + if not i: + return + spath = s.get_path(i) + src = spath[0] + list = self.family.getChildList() + obj = list[src] + list.remove(obj) + list.insert(row,obj) + + if (birth_dates_in_order(list) == 0): + msg = _("Invalid move. Children must be ordered by birth date.") + WarningDialog(msg) + return + self.family.setChildList(list) + self.load_family() + Utils.modified() + def drag_data_get(self,widget, context, sel_data, info, time): - ev = self.child_list.get_selected_objects() - + store,iter = self.child_selection.get_selected() + if not iter: + return + id = self.child_model.get_value(iter,2) + person = self.parent.db.getPerson(id) bits_per = 8; # we're going to pass a string - pickled = pickle.dumps(ev[0]); - data = str(('child',self.person.getId(),pickled)); + pickled = pickle.dumps(person); + data = str(('child',id,pickled)); sel_data.set(sel_data.target, bits_per, data) def drag_begin(self, context, a): return + +#------------------------------------------------------------------------- +# +# birth_dates_in_order +# +# Check any *valid* birthdates in the list to insure that they are in +# numerically increasing order. +# +#------------------------------------------------------------------------- +def birth_dates_in_order(list): + inorder = 1 + prev_date = "00000000" + for i in range(len(list)): + child = list[i] + bday = child.getBirth().getDateObj() + child_date = sort.build_sort_date(bday) + if (child_date == "99999999"): + continue + if (prev_date <= child_date): # <= allows for twins + prev_date = child_date + else: + inorder = 0 + return inorder diff --git a/src/Marriage.py b/src/Marriage.py index 8c81b3ffb..5d5deadeb 100644 --- a/src/Marriage.py +++ b/src/Marriage.py @@ -135,8 +135,8 @@ class Marriage: # set initial data self.gallery.load_images() - etitles = [(_('Event'),0,150),(_('Date'),1,150),(_('Place'),2,150)] - atitles = [(_('Attribute'),0,150),(_('Value'),1,150)] + etitles = [(_('Event'),-1,150),(_('Date'),-1,150),(_('Place'),-1,150)] + atitles = [(_('Attribute'),-1,150),(_('Value'),-1,150)] self.etree = ListModel.ListModel(self.event_list, etitles, self.on_select_row, @@ -171,21 +171,17 @@ class Marriage: self.build_seal_menu() - self.event_list.drag_dest_set(gtk.DEST_DEFAULT_ALL, - pycode_tgts,gtk.gdk.ACTION_COPY) - self.event_list.drag_source_set(gtk.gdk.BUTTON1_MASK, - pycode_tgts, gtk.gdk.ACTION_COPY) + self.event_list.drag_dest_set(gtk.DEST_DEFAULT_ALL,pycode_tgts,gtk.gdk.ACTION_COPY) + self.event_list.drag_source_set(gtk.gdk.BUTTON1_MASK,pycode_tgts, gtk.gdk.ACTION_COPY) self.event_list.connect('drag_data_get', self.ev_source_drag_data_get) - self.event_list.connect('drag_data_received', - self.ev_dest_drag_data_received) + self.event_list.connect('drag_data_received',self.ev_dest_drag_data_received) + self.event_list.connect('drag_begin', self.ev_drag_begin) - self.attr_list.drag_dest_set(gtk.DEST_DEFAULT_ALL,pycode_tgts, - gtk.gdk.ACTION_COPY) - self.attr_list.drag_source_set(gtk.gdk.BUTTON1_MASK, pycode_tgts, - gtk.gdk.ACTION_COPY) + self.attr_list.drag_dest_set(gtk.DEST_DEFAULT_ALL,pycode_tgts,gtk.gdk.ACTION_COPY) + self.attr_list.drag_source_set(gtk.gdk.BUTTON1_MASK, pycode_tgts,gtk.gdk.ACTION_COPY) self.attr_list.connect('drag_data_get', self.at_source_drag_data_get) - self.attr_list.connect('drag_data_received', - self.at_dest_drag_data_received) + self.attr_list.connect('drag_data_received',self.at_dest_drag_data_received) + self.attr_list.connect('drag_begin', self.at_drag_begin) # set notes data self.notes_buffer = self.notes_field.get_buffer() @@ -195,6 +191,12 @@ class Marriage: self.redraw_attr_list() top_window.show() + def ev_drag_begin(self, context, a): + return + + def at_drag_begin(self, context, a): + return + def build_seal_menu(self): menu = gtk.Menu() index = 0 @@ -262,52 +264,63 @@ class Marriage: self.atree.select_row(row+1) def ev_dest_drag_data_received(self,widget,context,x,y,selection_data,info,time): + row = self.etree.get_row_at(x,y) if selection_data and selection_data.data: exec 'data = %s' % selection_data.data exec 'mytype = "%s"' % data[0] exec 'family = "%s"' % data[1] - if family == self.family.getId() or mytype != 'fevent': + if mytype != 'fevent': return - foo = pickle.loads(data[2]); - for src in foo.getSourceRefList(): - base = src.getBase() - newbase = self.db.findSourceNoMap(base.getId()) - src.setBase(newbase) - place = foo.getPlace() - if place: - foo.setPlace(self.db.findPlaceNoMap(place.getId())) - self.elist.append(foo) + elif family == self.family.getId(): + self.move_element(self.elist,self.etree.get_selected_row(),row) + else: + foo = pickle.loads(data[2]); + for src in foo.getSourceRefList(): + base = src.getBase() + newbase = self.db.findSourceNoMap(base.getId()) + src.setBase(newbase) + place = foo.getPlace() + if place: + foo.setPlace(self.db.findPlaceNoMap(place.getId())) + self.elist.insert(row,foo) + self.lists_changed = 1 self.redraw_event_list() def ev_source_drag_data_get(self,widget, context, selection_data, info, time): - ev = widget.get_row_data(widget.focus_row) + ev = self.etree.get_selected_objects() bits_per = 8; # we're going to pass a string - pickled = pickle.dumps(ev); + pickled = pickle.dumps(ev[0]); data = str(('fevent',self.family.getId(),pickled)); selection_data.set(selection_data.target, bits_per, data) def at_dest_drag_data_received(self,widget,context,x,y,selection_data,info,time): + row = self.atree.get_row_at(x,y) if selection_data and selection_data.data: exec 'data = %s' % selection_data.data exec 'mytype = "%s"' % data[0] exec 'family = "%s"' % data[1] - if family == self.family.getId() or mytype != 'fattr': + if mytype != 'fevent': return - foo = pickle.loads(data[2]); - for src in foo.getSourceRefList(): - base = src.getBase() - newbase = self.db.findSourceNoMap(base.getId()) - src.setBase(newbase) - self.alist.append(foo) + elif family == self.family.getId(): + self.move_element(self.elist,self.etree.get_selected_row(),row) + else: + foo = pickle.loads(data[2]); + for src in foo.getSourceRefList(): + base = src.getBase() + newbase = self.db.findSourceNoMap(base.getId()) + src.setBase(newbase) + self.alist.insert(row,foo) + self.lists_changed = 1 self.redraw_attr_list() def at_source_drag_data_get(self,widget, context, selection_data, info, time): - ev = widget.get_row_data(widget.focus_row) + ev = self.atree.get_selected_objects() + bits_per = 8; # we're going to pass a string - pickled = pickle.dumps(ev); + pickled = pickle.dumps(ev[0]); data = str(('fattr',self.family.getId(),pickled)); selection_data.set(selection_data.target, bits_per, data) @@ -566,3 +579,10 @@ class Marriage: name = mother.getPrimaryName().getName() AttrEdit.AttributeEditor(self,None,name,const.familyAttributes) + def move_element(self,list,src,dest): + if src == -1: + return + obj = list[src] + list.remove(obj) + list.insert(dest,obj) + diff --git a/src/const.py b/src/const.py index a7ac6303f..1dec868d8 100644 --- a/src/const.py +++ b/src/const.py @@ -30,8 +30,7 @@ import os # internationalization # #------------------------------------------------------------------------- -from intl import gettext -_ = gettext +from intl import gettext as _ #------------------------------------------------------------------------- # @@ -101,7 +100,7 @@ startup = 1 # #------------------------------------------------------------------------- progName = "GRAMPS" -version = "0.9.0-rc1" +version = "0.9.0-rc2" copyright = "© 2001-2002 Donald N. Allingham" authors = ["Donald N. Allingham", "David Hampton","Donald A. Peterson"] comments = _("GRAMPS (Genealogical Research and Analysis " diff --git a/src/const.py.in b/src/const.py.in index dc5b57ddf..f90cab1f7 100644 --- a/src/const.py.in +++ b/src/const.py.in @@ -30,8 +30,7 @@ import os # internationalization # #------------------------------------------------------------------------- -from intl import gettext -_ = gettext +from intl import gettext as _ #------------------------------------------------------------------------- #