From 455a723b7b908defea702a820640482709c45a34 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Wed, 1 Jun 2005 13:14:29 +0000 Subject: [PATCH] * src/AutoComp.py (StandardCustomSelector): Provide an option to use an existing ComboBoxEntry instance; add set_values method. * src/RelLib.py (Family.__init__): Use tuple for type. * src/Utils.py: Add event_roles mapping. * src/AddSpouse.py, src/EditPerson.py, src/FamilyView.py, src/ListBox.py, src/Marriage.py, src/NameEdit.py: Support tuple types. * src/gramps.glade: Replace ComboBox with ComboBoxEntry; add icons. svn: r4748 --- ChangeLog | 11 ++ src/AddSpouse.py | 12 +- src/AutoComp.py | 65 ++++++-- src/EditPerson.py | 25 ++- src/FamilyView.py | 15 +- src/ListBox.py | 8 +- src/Marriage.py | 38 +++-- src/NameEdit.py | 29 ++-- src/RelLib.py | 2 +- src/Utils.py | 11 ++ src/gramps.glade | 393 +++++++++++++++++++++++++++++++++++----------- 11 files changed, 442 insertions(+), 167 deletions(-) diff --git a/ChangeLog b/ChangeLog index f5577103c..cb8e8b2e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-06-01 Alex Roitman + * src/AutoComp.py (StandardCustomSelector): Provide an option to + use an existing ComboBoxEntry instance; add set_values method. + * src/RelLib.py (Family.__init__): Use tuple for type. + * src/Utils.py: Add event_roles mapping. + * src/AddSpouse.py, src/EditPerson.py, src/FamilyView.py, + src/ListBox.py, src/Marriage.py, src/NameEdit.py: Support tuple + types. + * src/gramps.glade: Replace ComboBox with ComboBoxEntry; add icons. + + 2005-05-31 Martin Hawlisch * src/EditSource.py, src/ListBox.py, src/ReadGedcom.py, src/WriteGedcom.py: Constants moved from const to Utils and RelLib diff --git a/src/AddSpouse.py b/src/AddSpouse.py index 949baad5e..482f30541 100644 --- a/src/AddSpouse.py +++ b/src/AddSpouse.py @@ -127,7 +127,7 @@ class AddSpouse: "destroy_passed_object" : Utils.destroy_passed_object }) - self.rel_combo.set_active(const.MARRIED) + self.rel_combo.set_active(RelLib.Family.MARRIED) self.update_data() def build_all(self): @@ -136,8 +136,8 @@ class AddSpouse: return filt def build_likely(self,gender): - birth_handle = self.person.get_birth_handle() - death_handle = self.person.get_death_handle() + birth_ref = self.person.get_birth_ref() + death_ref = self.person.get_death_ref() filt = GenericFilter.GenericFilter() if gender == RelLib.Person.MALE: @@ -145,8 +145,8 @@ class AddSpouse: else: filt.add_rule(GenericFilter.IsMale([])) - if birth_handle: - birth = self.db.get_event_from_handle(birth_handle) + if birth_ref: + birth = self.db.get_event_from_handle(birth_ref.ref) date_obj = Date.Date(birth.get_date_object()) year = date_obj.get_year() if year: @@ -310,7 +310,7 @@ class AddSpouse: self.active_family.set_mother_handle(self.person.get_handle()) rtype = self.rel_combo.get_active() - self.active_family.set_relationship(rtype) + self.active_family.set_relationship((rtype,Utils.family_relations[rtype])) self.db.commit_family(self.active_family,trans) self.db.transaction_commit(trans,_("Add Spouse")) diff --git a/src/AutoComp.py b/src/AutoComp.py index 3b0295c55..32d208636 100644 --- a/src/AutoComp.py +++ b/src/AutoComp.py @@ -76,11 +76,18 @@ class StandardCustomSelector: options or entering custom string. The typical usage should be: - scs = StandardCustomSelector(mapping,custom_key,active_key) - whatever_table.attach(scs,...) + type_sel = StandardCustomSelector(mapping,None,custom_key,active_key) + whatever_table.attach(type_sel,...) + or + type_sel = StandardCustomSelector(mapping,cbe,custom_key,active_key) + with the existing ComboBoxEntry cbe. + + To set up the combo box, specify the active key at creation time, + or later (or with custom text) use: + type_sel.set_values(i,s) and later, when or before the dialog is closed, do: - (i,s) = scs.get_values() + (i,s) = type_sel.get_values() to obtain the tuple of (int,str) corresponding to the user selection. @@ -93,10 +100,12 @@ class StandardCustomSelector: (active_key,mapping[active_key]) tuple. """ - def __init__(self,mapping,custom_key=None,active_key=None): + def __init__(self,mapping,cbe=None,custom_key=None,active_key=None): """ Constructor for the StandardCustomSelector class. + @param cbe: Existing ComboBoxEntry widget to use. + @type cbe: gtk.ComboBoxEntry @param mapping: The mapping between integer and string constants. @type mapping: dict @param custom_key: The key corresponding to the custom string entry @@ -118,7 +127,12 @@ class StandardCustomSelector: self.fill() # create combo box entry - self.selector = gtk.ComboBoxEntry(self.store,1) + if cbe: + self.selector = cbe + self.selector.set_model(self.store) + self.selector.set_text_column(1) + else: + self.selector = gtk.ComboBoxEntry(self.store,1) if self.active_key: self.selector.set_active(self.active_index) @@ -159,9 +173,40 @@ class StandardCustomSelector: if ai: i = self.store.get_value(ai,0) s = self.store.get_value(ai,1) - return (i,s) - entry = self.selector.child - return (self.custom_key,entry.get_text()) + if s != self.mapping[i]: + s = self.selector.child.get_text().strip() + else: + i = self.custom_key + s = self.selector.child.get_text().strip() + if s in self.mapping.values(): + for key in self.mapping.keys(): + if s == self.mapping[key]: + i = key + break + else: + i = self.custom_key + return (i,s) + + def set_values(self,val): + """ + Set values according to given tuple. + + @param val: (int,str) tuple with the values to set. + @type val: tuple + """ + i,s = val + if i in self.mapping.keys() and i != self.custom_key: + self.store.foreach(self.set_int_value,i) + elif self.custom_key != None: + self.selector.child.set_text(s) + else: + print "StandardCustomSelector.set(): Option not available:", val + + def set_int_value(self,model,path,iter,val): + if model.get_value(iter,0) == val: + self.selector.set_active_iter(iter) + return True + return False #------------------------------------------------------------------------- @@ -174,8 +219,8 @@ if __name__ == "__main__": print s.get_values() gtk.main_quit() - - s = StandardCustomSelector({0:'abc',1:'abd',2:'bbe'},0) + s = StandardCustomSelector({0:'abc',1:'abd',2:'bbe'},None,0,1) + s.set_values((2,'bbe')) w = gtk.Dialog() w.child.add(s.selector) w.connect('delete-event',here) diff --git a/src/EditPerson.py b/src/EditPerson.py index 6a1e4167b..ec673f638 100644 --- a/src/EditPerson.py +++ b/src/EditPerson.py @@ -266,9 +266,11 @@ class EditPerson: or (not self.lds_sealing.is_empty()): Utils.bold_label(self.lds_tab) - types = const.NameTypesMap.values() - types.sort() - AutoComp.fill_combo(self.ntype_field,types) + self.ntype_selector = \ + AutoComp.StandardCustomSelector(Utils.name_types, + self.ntype_field, + RelLib.Name.CUSTOM, + RelLib.Name.BIRTH) self.write_primary_name() self.load_person_image() @@ -715,7 +717,7 @@ class EditPerson: surname = unicode(self.surname.get_text()) - ntype = unicode(self.ntype_field.child.get_text()) + ntype = self.ntype_selector.get_values() suffix = unicode(self.suffix.get_text()) prefix = unicode(self.prefix.get_text()) given = unicode(self.given.get_text()) @@ -748,7 +750,7 @@ class EditPerson: changed = True if surname.upper() != name.get_surname().upper(): changed = True - if ntype != const.NameTypesMap.find_value(name.get_type()): + if ntype != name.get_type(): changed = True if given != name.get_first_name(): changed = True @@ -883,7 +885,7 @@ class EditPerson: surname = unicode(self.surname.get_text()) suffix = unicode(self.suffix.get_text()) prefix = unicode(self.prefix.get_text()) - ntype = unicode(self.ntype_field.child.get_text()) + ntype = self.ntype_selector.get_values() given = unicode(self.given.get_text()) title = unicode(self.title.get_text()) idval = unicode(self.gid.get_text()) @@ -912,11 +914,6 @@ class EditPerson: if prefix != name.get_surname_prefix(): name.set_surname_prefix(prefix) - if const.NameTypesMap.has_value(ntype): - ntype = const.NameTypesMap.find_key(ntype) - else: - ntype = "Birth Name" - if ntype != name.get_type(): name.set_type(ntype) @@ -1068,8 +1065,8 @@ class EditPerson: return u"" def on_edit_name_clicked(self,obj): - ntype = unicode(self.ntype_field.child.get_text()) - self.pname.set_type(const.NameTypesMap.find_value(ntype)) + ntype = self.ntype_selector.get_values() + self.pname.set_type(ntype) self.pname.set_suffix(unicode(self.suffix.get_text())) self.pname.set_surname(unicode(self.surname.get_text())) if self.use_patronymic: @@ -1182,7 +1179,7 @@ class EditPerson: self.surname.set_text(self.pname.get_surname()) self.given.set_text(self.pname.get_first_name()) - self.ntype_field.child.set_text(_(self.pname.get_type())) + self.ntype_selector.set_values(self.pname.get_type()) self.title.set_text(self.pname.get_title()) def birth_dates_in_order(self,list): diff --git a/src/FamilyView.py b/src/FamilyView.py index bf3747a0d..2a3785520 100644 --- a/src/FamilyView.py +++ b/src/FamilyView.py @@ -1044,10 +1044,15 @@ class FamilyView: mdate = " - %s" % DateHandler.displayer.display(dobj) else: mdate = "" + i,s = fm.get_relationship() + if Utils.family_relations.has_key(i) \ + and i != RelLib.Family.CUSTOM: + disp_rel = Utils.family_relations[i] + else: + disp_rel = s v = "%s [%s]\n\t%s%s" % ( NameDisplay.displayer.display(sp), - sp.get_gramps_id(), - const.family_relations[fm.get_relationship()][0], mdate) + sp.get_gramps_id(), disp_rel, mdate) self.spouse_model.set(node,0,v) self.spouse_model.set(node,1,f) else: @@ -1076,9 +1081,9 @@ class FamilyView: self.update_list(self.ap_parents_model,self.ap_parents,person) def find_marriage(self,family): - for event_handle in family.get_event_list(): - if event_handle: - event = self.parent.db.get_event_from_handle(event_handle) + for event_ref in family.get_event_ref_list(): + if event_ref: + event = self.parent.db.get_event_from_handle(event_ref.ref) if event.get_name() == "Marriage": return event return None diff --git a/src/ListBox.py b/src/ListBox.py index d09b50b86..b75aa7ad4 100644 --- a/src/ListBox.py +++ b/src/ListBox.py @@ -331,8 +331,7 @@ class NameListBox(ReorderListBox): def __init__(self,parent,person,obj,label,button_list): surnames = parent.db.get_surname_list() - types = const.NameTypesMap.values() - types.sort() + types = Utils.name_types.values() titles = [ # Title Sort Col Size, Type @@ -362,8 +361,7 @@ class NameListBox(ReorderListBox): self.data[index].set_suffix(value) def set_type(self,index,value): - ntype = const.NameTypesMap.find_value(value) - self.data[index].set_type(value) + self.data[index].set_type(value[1]) def add(self,obj): NameEdit.NameEditor(self.parent, None, self.edit_callback, @@ -380,7 +378,7 @@ class NameListBox(ReorderListBox): has_source = len(name.get_source_references())> 0 return [name.get_surname(),name.get_surname_prefix(), name.get_first_name(), name.get_suffix(), - _(name.get_type()),has_source,has_note] + name.get_type()[1],has_source,has_note] def unpickle(self, data): foo = pickle.loads(data); diff --git a/src/Marriage.py b/src/Marriage.py index 3d183584b..390f658d2 100644 --- a/src/Marriage.py +++ b/src/Marriage.py @@ -201,7 +201,7 @@ class Marriage: self.preform = self.get_widget("mar_preform") self.preform.set_sensitive(mode) - self.elist = family.get_event_list()[:] + self.ereflist = family.get_event_ref_list()[:] self.alist = family.get_attribute_list()[:] self.lists_changed = 0 @@ -220,13 +220,12 @@ class Marriage: self.on_attr_list_select_row, self.on_update_attr_clicked) - rel_list = [] - for (val,junk) in const.family_relations: - rel_list.append(val) - AutoComp.fill_option_text(self.type_field,rel_list) + self.type_selector = AutoComp.StandardCustomSelector( \ + Utils.family_relations,self.type_field, + RelLib.Family.CUSTOM,RelLib.Name.MARRIED) frel = family.get_relationship() - self.type_field.set_active(frel) + self.type_selector.set_values(frel) self.gid.set_text(family.get_gramps_id()) @@ -458,8 +457,8 @@ class Marriage: foo = pickle.loads(data[2]); if family == self.family.get_handle() and \ - foo.get_handle() in self.elist: - self.move_element(self.elist,self.etree.get_selected_row(), + foo.get_handle() in [ref.ref for ref in self.ereflist]: + self.move_element(self.ereflist,self.etree.get_selected_row(), row) else: for src in foo.get_source_references(): @@ -470,7 +469,12 @@ class Marriage: if place: foo.set_place_handle( self.db.get_place_from_handle(place.get_handle()).get_handle()) - self.elist.insert(row,foo.get_handle()) + eref = RelLib.EventRef() + eref.set_ref = foo.get_handle() + eref.set_role(RelLib.EventRef.PRIMARY, + Utils.event_roles(RelLib.EventRef.PRIMARY)) + + self.ereflist.insert(row,) self.lists_changed = 1 self.redraw_event_list() @@ -520,7 +524,7 @@ class Marriage: selection_data.set(selection_data.target, bits_per, data) def update_lists(self): - self.family.set_event_list(self.elist) + self.family.set_event_ref_list(self.ereflist) self.family.set_attribute_list(self.alist) def attr_edit_callback(self,attr): @@ -543,10 +547,10 @@ class Marriage: def redraw_event_list(self): self.etree.clear() self.emap = {} - for event_handle in self.elist: - event = self.db.get_event_from_handle(event_handle) - if not event: + for event_ref in self.ereflist: + if not event_ref: continue + event = self.db.get_event_from_handle(event_ref.ref) place_handle = event.get_place_handle() if place_handle: @@ -556,7 +560,7 @@ class Marriage: node = self.etree.add([const.display_fevent(event.get_name()), event.get_quote_date(),place_name],event) self.emap[str(event)] = node - if self.elist: + if self.ereflist: self.etree.select_row(0) Utils.bold_label(self.events_label) else: @@ -567,7 +571,7 @@ class Marriage: def did_data_change(self): changed = 0 - if self.type_field.get_active() != self.family.get_relationship(): + if self.type_selector.get_values() != self.family.get_relationship(): changed = 1 if self.complete.get_active() != self.family.get_complete_flag(): @@ -655,7 +659,7 @@ class Marriage: _('The GRAMPS ID that you chose for this ' 'relationship is already being used.')) - relation = self.type_field.get_active() + relation = self.type_selector.get_values() father = self.family.get_father_handle() mother = self.family.get_mother_handle() if father and mother: @@ -740,7 +744,7 @@ class Marriage: None, 0,self.event_edit_callback, None, self.db.readonly) def on_delete_clicked(self,obj): - if Utils.delete_selected(obj,self.elist): + if Utils.delete_selected(obj,self.ereflist): self.lists_changed = 1 self.redraw_event_list() diff --git a/src/NameEdit.py b/src/NameEdit.py index 87f7bf5e0..f74f06825 100644 --- a/src/NameEdit.py +++ b/src/NameEdit.py @@ -112,12 +112,12 @@ class NameEditor: self.preform = self.top.get_widget("alt_preform") self.group_over = self.top.get_widget('group_over') - types = const.NameTypesMap.get_values() - types.sort() - AutoComp.fill_combo(self.type_combo,types) - self.type_field = self.type_combo.get_child() - self.type_field.set_text(types[0]) - + self.type_selector = \ + AutoComp.StandardCustomSelector(Utils.name_types, + self.type_combo, + RelLib.Name.CUSTOM, + RelLib.Name.BIRTH) + full_name = NameDisplay.displayer.display_name(name) alt_title = self.top.get_widget("title") @@ -151,7 +151,7 @@ class NameEditor: self.title_field.set_text(name.get_title()) self.suffix_field.set_text(name.get_suffix()) self.prefix_field.set_text(name.get_surname_prefix()) - self.type_field.set_text(_(name.get_type())) + self.type_selector.set_values(name.set_type()) self.patronymic_field.set_text(name.get_patronymic()) self.priv.set_active(name.get_privacy()) Utils.bold_label(self.general_label) @@ -259,13 +259,8 @@ class NameEditor: format = self.preform.get_active() priv = self.priv.get_active() - mtype = unicode(self.type_field.get_text()) + the_type = self.type_selector.get_values() - if const.NameTypesMap.has_value(mtype): - mtype = const.NameTypesMap.find_key(mtype) - else: - mtype = "Also Known As" - if self.name == None: self.name = RelLib.Name() self.parent.nlist.append(self.name) @@ -312,13 +307,13 @@ class NameEditor: self.name.set_group_as(grp_as) self.parent.lists_changed = 1 - self.update_name(first,last,suffix,patronymic,title,mtype,note,format,priv) + self.update_name(first,last,suffix,patronymic,title,the_type,note,format,priv) self.parent.lists_changed = 1 self.callback(self.name) self.close(obj) - def update_name(self,first,last,suffix,patronymic,title,type,note,format,priv): + def update_name(self,first,last,suffix,patronymic,title,the_type,note,format,priv): if self.name.get_first_name() != first: self.name.set_first_name(first) @@ -340,8 +335,8 @@ class NameEditor: self.name.set_title(title) self.parent.lists_changed = 1 - if self.name.get_type() != type: - self.name.set_type(type) + if self.name.get_type() != the_type: + self.name.set_type(the_type) self.parent.lists_changed = 1 if self.name.get_note() != note: diff --git a/src/RelLib.py b/src/RelLib.py index c5116588d..f604fda58 100644 --- a/src/RelLib.py +++ b/src/RelLib.py @@ -1768,7 +1768,7 @@ class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase): self.father_handle = None self.mother_handle = None self.child_list = [] - self.type = Family.MARRIED + self.type = (Family.MARRIED,'') self.event_ref_list = [] self.lds_seal = None self.complete = 0 diff --git a/src/Utils.py b/src/Utils.py index 4289025d2..78737a473 100644 --- a/src/Utils.py +++ b/src/Utils.py @@ -203,6 +203,17 @@ source_media_types = { RelLib.RepoRef.VIDEO : _("Video"), } +event_roles = { + RelLib.EventRef.UNKNOWN : _("Unknown"), + RelLib.EventRef.CUSTOM : _("Custom"), + RelLib.EventRef.PRIMARY : _("Primary"), + RelLib.EventRef.CLERGY : _("Clergy"), + RelLib.EventRef.CELEBRANT : _("Celebrant"), + RelLib.EventRef.AIDE : _("Aide"), + RelLib.EventRef.BRIDE : _("Bride"), + RelLib.EventRef.GROOM : _("Groom"), + RelLib.EventRef.WITNESS : _("Witness"), + } #------------------------------------------------------------------------- # # Integer to GEDCOM tag mappings for constants diff --git a/src/gramps.glade b/src/gramps.glade index ea5121443..b4501e28d 100644 --- a/src/gramps.glade +++ b/src/gramps.glade @@ -12588,21 +12588,6 @@ Other - - - True - - - - 1 - 2 - 0 - 1 - fill - fill - - - True @@ -12672,6 +12657,20 @@ Other + + + + True + + + 1 + 2 + 0 + 1 + fill + fill + + 5 @@ -12687,18 +12686,48 @@ Other - + True - <b>General</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 + False + 0 + + + + True + gtk-file + 4 + 0.5 + 0.5 + 0 + 0 + + + 0 + True + True + + + + + + True + <b>General</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + tab @@ -13254,18 +13283,48 @@ Other - + True - Events - False - False - GTK_JUSTIFY_RIGHT - False - False - 0.5 - 0.5 - 0 - 0 + False + 0 + + + + True + gtk-file + 4 + 0.5 + 0.5 + 0 + 0 + + + 0 + True + True + + + + + + True + Events + False + False + GTK_JUSTIFY_RIGHT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + tab @@ -13679,18 +13738,48 @@ Other - + True - Attributes - False - False - GTK_JUSTIFY_CENTER - False - False - 0.5 - 0.5 - 0 - 0 + False + 0 + + + + True + gtk-file + 4 + 0.5 + 0.5 + 0 + 0 + + + 0 + True + True + + + + + + True + Attributes + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + tab @@ -13833,18 +13922,48 @@ Other - + True - Notes - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 + False + 0 + + + + True + gtk-file + 4 + 0.5 + 0.5 + 0 + 0 + + + 0 + True + True + + + + + + True + Notes + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + tab @@ -13985,18 +14104,48 @@ Other - + True - Sources - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 + False + 0 + + + + True + gtk-file + 4 + 0.5 + 0.5 + 0 + 0 + + + 0 + True + True + + + + + + True + Sources + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + tab @@ -14170,18 +14319,48 @@ Other - + True - Gallery - False - False - GTK_JUSTIFY_CENTER - False - False - 0.5 - 0.5 - 0 - 0 + False + 0 + + + + True + gtk-file + 4 + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + Gallery + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + tab @@ -14456,18 +14635,48 @@ Other - + True - LDS - False - False - GTK_JUSTIFY_CENTER - False - False - 0.5 - 0.5 - 0 - 0 + False + 0 + + + + True + gtk-file + 4 + 0.5 + 0.5 + 0 + 0 + + + 0 + True + True + + + + + + True + LDS + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + tab