From dcf4c6f2a2b89b31f4ead56fb7f5d56585a2cc32 Mon Sep 17 00:00:00 2001 From: Martin Hawlisch Date: Wed, 22 Mar 2006 21:19:32 +0000 Subject: [PATCH] Add wrappers for displaying the tuple types to unify their usage. svn: r6193 --- gramps2/ChangeLog | 8 +++ gramps2/src/DataViews/_PedigreeView.py | 2 +- gramps2/src/DisplayModels.py | 23 +------ gramps2/src/DisplayTabs.py | 65 +++----------------- gramps2/src/PluginUtils/_ReportUtils.py | 16 ----- gramps2/src/ScratchPad.py | 18 +++--- gramps2/src/Utils.py | 81 +++++++++++++++++++++++++ 7 files changed, 110 insertions(+), 103 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 9f7ad72ec..ce5debd52 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,11 @@ +2006-03-22 Martin Hawlisch + * src/Utils.py: Add wrappers for displaying the tuple types + * src/DataViews/_PedigreeView.py, + * src/PluginUtils/_ReportUtils.py, + * src/DisplayModels.py, + * src/DisplayTabs.py, + * src/ScratchPad.py: Use the new wrapers + 2006-03-21 Don Allingham * src/Config/_GramspGconfKeys.py: family_warn flag * src/Config/_GramspIniKeys.py: family_warn flag diff --git a/gramps2/src/DataViews/_PedigreeView.py b/gramps2/src/DataViews/_PedigreeView.py index e65efb682..888c317df 100644 --- a/gramps2/src/DataViews/_PedigreeView.py +++ b/gramps2/src/DataViews/_PedigreeView.py @@ -346,7 +346,7 @@ class FormattingHelper: return text; break if not text: - text = ReportUtils.relationship_name(family.get_relationship()) + text = Utils.format_family_relation(family.get_relationship()) return text def get_place_name( self, place_handle): diff --git a/gramps2/src/DisplayModels.py b/gramps2/src/DisplayModels.py index 0b039a9b8..42b325b6b 100644 --- a/gramps2/src/DisplayModels.py +++ b/gramps2/src/DisplayModels.py @@ -455,12 +455,7 @@ class FamilyModel(BaseModel): return u"" def column_type(self,data): - t = data[5] - if t[0] == RelLib.Family.CUSTOM: - val = t[1] - else: - val = Utils.family_relations[t[0]] - return unicode(val) + return Utils.format_family_relation(data[5]) def column_id(self,data): return unicode(data[1]) @@ -616,14 +611,7 @@ class EventModel(BaseModel): return u'' def column_type(self,data): - (code,val) = data[2] - if code == RelLib.Event.CUSTOM: - return unicode(val) - else: - val = Utils.personal_events.get(code) - if not val: - val = Utils.family_events.get(code,_("Unknown")) - return val + return Utils.format_event(data[2]) def column_id(self,data): return unicode(data[1]) @@ -709,12 +697,7 @@ class RepositoryModel(BaseModel): return unicode(data[1]) def column_type(self,data): - rtype = data[2] - if rtype[0] == RelLib.Event.CUSTOM or rtype[0] not in Utils.repository_types: - name = rtype[1] - else: - name = Utils.repository_types[rtype[0]] - return unicode(name) + return Utils.format_repository_type(data[2]) def column_name(self,data): return unicode(data[3]) diff --git a/gramps2/src/DisplayTabs.py b/gramps2/src/DisplayTabs.py index b977ca333..8e8e87ba8 100644 --- a/gramps2/src/DisplayTabs.py +++ b/gramps2/src/DisplayTabs.py @@ -1534,31 +1534,18 @@ class ChildModel(gtk.ListStore): def get_data(self): return self.family.get_child_handle_list() - def display_rel(self,rtype): - if type(rtype) == tuple: - rel = rtype[0] - val = rtype[1] - else: - rel = rtype - val = "???" - - if rel == RelLib.Family.CUSTOM: - return unicode(val) - else: - return Utils.child_relations[rel] - def column_father_rel(self,data): fhandle = self.family.handle for (handle, mrel, frel) in data.get_parent_family_handle_list(): if handle == fhandle: - return self.display_rel(frel) + return Utils.format_child_relation(frel) return "" def column_mother_rel(self,data): fhandle = self.family.handle for (handle, mrel, frel) in data.get_parent_family_handle_list(): if handle == fhandle: - return self.display_rel(mrel) + return Utils.format_child_relation(mrel) return "" def column_birth_day(self,data): @@ -1636,24 +1623,10 @@ class EventRefModel(gtk.ListStore): ]) def column_type(self,event): - t,v = event.get_type() - if t == RelLib.Event.CUSTOM: - return v - else: - if Utils.personal_events.has_key(t): - return Utils.personal_events[t] - else: - return Utils.family_events[t] + return Utils.format_event(event.get_type()) def column_role(self,event_ref): - t,v = event_ref.get_role() - if t == RelLib.EventRef.CUSTOM: - return v - else: - try: - return Utils.event_roles[t] - except: - return Utils.family_event_roles.get(t,"error %d" % t) + return Utils.format_event_role(event_ref.get_role()) def column_date(self,event_ref): event = self.db.get_event_from_handle(event_ref.ref) @@ -1686,13 +1659,7 @@ class AttrModel(gtk.ListStore): ]) def type_name(self, attr): - t,v = attr.get_type() - if t == RelLib.Attribute.CUSTOM: - return v - elif Utils.personal_attributes.has_key(t): - return Utils.personal_attributes[t] - else: - return Utils.family_attributes[t] + return Utils.format_attribute( attr.get_type()) #------------------------------------------------------------------------- # @@ -1712,11 +1679,7 @@ class NameModel(gtk.ListStore): ]) def type_name(self, obj): - t,v = obj.get_type() - if t == RelLib.Name.CUSTOM: - return v - else: - return Utils.name_types[t] + return Utils.format_name_type(obj.get_type()) #------------------------------------------------------------------------- # @@ -1767,12 +1730,7 @@ class WebModel(gtk.ListStore): obj.path, obj.desc, obj]) def show_type(self,rtype): - rel = rtype[0] - val = rtype[1] - if rel == RelLib.Url.CUSTOM: - return val - else: - return Utils.web_types[rel] + return Utils.format_web_type(rtype) #------------------------------------------------------------------------- # @@ -1818,12 +1776,7 @@ class RepoRefModel(gtk.ListStore): self.type_of(repo), ref,]) def type_of(self,ref): - v,s = ref.get_type() - - if v == RelLib.RepoRef.CUSTOM: - return unicode(s) - else: - return Utils.source_media_types.get(v,"error %s" % v) + return Utils.format_source_media_type(ref.get_type()) #------------------------------------------------------------------------- # @@ -1890,5 +1843,3 @@ class BackRefModel(gtk.ListStore): self.append(row=[dtype,gid,name,handle]) yield True yield False - - diff --git a/gramps2/src/PluginUtils/_ReportUtils.py b/gramps2/src/PluginUtils/_ReportUtils.py index 70ae7cbcf..53d19b354 100644 --- a/gramps2/src/PluginUtils/_ReportUtils.py +++ b/gramps2/src/PluginUtils/_ReportUtils.py @@ -2101,22 +2101,6 @@ def list_person_str(database,person,empty_date="",empty_place=""): return text -#------------------------------------------------------------------------- -# -# relationship_name -# -#------------------------------------------------------------------------- -_rtype = { - RelLib.Family.MARRIED : _("Married"), - RelLib.Family.UNMARRIED : _("Unmarried"), - RelLib.Family.CIVIL_UNION : _("Civil Union"), - RelLib.Family.UNKNOWN : _("Unknown"), - RelLib.Family.CUSTOM : _("Other"), - } - -def relationship_name(rtype): - return _rtype.get(rtype) - def old_calc_age(database,person): """ Calulate age. diff --git a/gramps2/src/ScratchPad.py b/gramps2/src/ScratchPad.py index b8c724f12..4759ccd2f 100644 --- a/gramps2/src/ScratchPad.py +++ b/gramps2/src/ScratchPad.py @@ -45,6 +45,7 @@ from gtk.gdk import ACTION_COPY, BUTTON1_MASK # #------------------------------------------------------------------------- import const +import Utils import TreeTips import DateHandler import GrampsDisplay @@ -183,7 +184,7 @@ class ScratchPadEvent(ScratchPadGrampsTypeWrapper): def __init__(self,dbstate,obj): ScratchPadGrampsTypeWrapper.__init__(self,dbstate,obj) self._type = _("Event") - self._title = const.display_pevent(self._obj.get_name()) + self._title = Utils.format_personal_event(self._obj.get_name()) self._value = self._obj.get_description() @@ -197,7 +198,7 @@ class ScratchPadEvent(ScratchPadGrampsTypeWrapper): "\t%s:\t%s\n"\ "\t%s:\t%s\n" % ( _("Event"), - _("Type"),escape(const.display_pevent(self._obj.get_name())), + _("Type"),escape(Utils.format_personal_event(self._obj.get_name())), _("Date"),escape(DateHander.get_date(self._obj)), _("Place"),escape(place_title(self._db,self._obj)), _("Cause"),escape(self._obj.get_cause()), @@ -225,7 +226,7 @@ class ScratchPadFamilyEvent(ScratchPadGrampsTypeWrapper): def __init__(self,dbstate,obj): ScratchPadGrampsTypeWrapper.__init__(self,dbstate,obj) self._type = _("Family Event") - self._title = const.display_fevent(self._obj.get_name()) + self._title = Utils.format_family_event(self._obj.get_name()) self._value = self._obj.get_description() @@ -239,7 +240,7 @@ class ScratchPadFamilyEvent(ScratchPadGrampsTypeWrapper): "\t%s:\t%s\n"\ "\t%s:\t%s\n" % ( _("Family Event"), - _("Type"),escape(const.display_fevent(self._obj.get_name())), + _("Type"),escape(Utils.format_family_event(self._obj.get_name())), _("Date"),escape(DateHander.get_date(self._obj)), _("Place"),escape(place_title(self.db,self._obj)), _("Cause"),escape(self._obj.get_cause()), @@ -290,7 +291,7 @@ class ScratchPadAttribute(ScratchPadGrampsTypeWrapper): def __init__(self,dbstate,obj): ScratchPadGrampsTypeWrapper.__init__(self,dbstate,obj) self._type = _("Attribute") - self._title = const.display_pattr(self._obj.get_type()) + self._title = Utils.format_personal_attribute(self._obj.get_type()) self._value = self._obj.get_value() def tooltip(self): @@ -299,7 +300,7 @@ class ScratchPadAttribute(ScratchPadGrampsTypeWrapper): "\t%s:\t%s\n"\ "\t%s:\t%s" % (_("Attribute"), _("Type"), - escape(const.display_pattr(self._obj.get_type())), + escape(Utils.format_personal_attribute(self._obj.get_type())), _("Value"), escape(self._obj.get_value())) @@ -323,7 +324,7 @@ class ScratchPadFamilyAttribute(ScratchPadGrampsTypeWrapper): def __init__(self,dbstate,obj): ScratchPadGrampsTypeWrapper.__init__(self,dbstate,obj) self._type = _("Family Attribute") - self._title = const.display_fattr(self._obj.get_type()) + self._title = Utils.format_family_attribute(self._obj.get_type()) self._value = self._obj.get_value() def tooltip(self): @@ -332,7 +333,7 @@ class ScratchPadFamilyAttribute(ScratchPadGrampsTypeWrapper): "\t%s:\t%s\n"\ "\t%s:\t%s" % (_("Family Attribute"), _("Type"), - escape(const.display_fattr(self._obj.get_type())), + escape(Utils.format_family_attribute(self._obj.get_type())), _("Value"), escape(self._obj.get_value())) @@ -931,4 +932,3 @@ def place_title(db,event): #------------------------------------------------------------------------- def ScratchPad(database,person,callback,parent=None): ScratchPadWindow(database,parent) - diff --git a/gramps2/src/Utils.py b/gramps2/src/Utils.py index 61ce1bbe0..576675f68 100644 --- a/gramps2/src/Utils.py +++ b/gramps2/src/Utils.py @@ -66,6 +66,8 @@ gender = { RelLib.Person.FEMALE : _("female"), RelLib.Person.UNKNOWN : _("unknown"), } +def format_gender( type): + return gender.get(type[0],_("Invalid")) child_relations = { RelLib.Person.CHILD_NONE : _("None"), @@ -77,6 +79,10 @@ child_relations = { RelLib.Person.CHILD_UNKNOWN : _("Unknown"), RelLib.Person.CHILD_CUSTOM : _("Custom"), } +def format_child_relation( type): + if type[0] == RelLib.Person.CHILD_CUSTOM: + return type[1] + return child_relations.get(type[0],_("Invalid id %d ('%s')")%type) confidence = { RelLib.SourceRef.CONF_VERY_HIGH : _("Very High"), @@ -85,6 +91,8 @@ confidence = { RelLib.SourceRef.CONF_LOW : _("Low"), RelLib.SourceRef.CONF_VERY_LOW : _("Very Low"), } +def format_confidence( type): + return confidence.get(type[0],_("Invalid id %d ('%s')")%type) family_events = { RelLib.Event.UNKNOWN : _("Unknown"), @@ -100,6 +108,10 @@ family_events = { RelLib.Event.ANNULMENT : _("Annulment"), RelLib.Event.MARR_ALT : _("Alternate Marriage"), } +def format_family_event( type): + if type[0] == RelLib.Event.CUSTOM: + return type[1] + return family_events.get(type[0],_("Invalid id %d ('%s')")%type) personal_events = { RelLib.Event.UNKNOWN : _("Unknown"), @@ -140,6 +152,18 @@ personal_events = { RelLib.Event.RETIREMENT : _("Retirement"), RelLib.Event.WILL : _("Will") } +def format_personal_event( type): + if type[0] == RelLib.Event.CUSTOM: + return type[1] + return personal_events.get(type[0],_("Invalid id %d ('%s')")%type) + +def format_event( type): + if type[0] == RelLib.Event.CUSTOM: + return type[1] + val = personal_events.get(type[0]) + if not val: + val = family_events.get(type[0],_("Invalid id %d ('%s')")%type) + return val personal_attributes = { RelLib.Attribute.UNKNOWN : _("Unknown"), @@ -151,12 +175,28 @@ personal_attributes = { RelLib.Attribute.NUM_CHILD : _("Number of Children"), RelLib.Attribute.SSN : _("Social Security Number"), } +def format_personal_attribute( type): + if type[0] == RelLib.Attribute.CUSTOM: + return type[1] + return personal_attributes.get(type[0],_("Invalid id %d ('%s')")%type) family_attributes = { RelLib.Attribute.UNKNOWN : _("Unknown"), RelLib.Attribute.CUSTOM : _("Custom"), RelLib.Attribute.NUM_CHILD : _("Number of Children"), } +def format_family_attribute( type): + if type[0] == RelLib.Attribute.CUSTOM: + return type[1] + return family_attributes.get(type[0],_("Invalid id %d ('%s')")%type) + +def format_attribute( type): + if type[0] == RelLib.Attribute.CUSTOM: + return type[1] + val = personal_attributes.get(type[0]) + if not val: + val = family_attributes.get(type[0],_("Invalid id %d ('%s')")%type) + return val family_relations = { RelLib.Family.MARRIED : _("Married"), @@ -165,6 +205,10 @@ family_relations = { RelLib.Family.UNKNOWN : _("Unknown"), RelLib.Family.CUSTOM : _("Other"), } +def format_family_relation( type): + if type[0] == RelLib.Family.CUSTOM: + return type[1] + return family_relations.get(type[0],_("Invalid id %d ('%s')")%type) family_rel_descriptions = { RelLib.Family.MARRIED : _("A legal or common-law relationship " @@ -186,6 +230,10 @@ name_types = { RelLib.Name.BIRTH : _("Birth Name"), RelLib.Name.MARRIED : _("Married Name"), } +def format_name_type( type): + if type[0] == RelLib.Name.CUSTOM: + return type[1] + return name_types.get(type[0],_("Invalid id %d ('%s')")%type) web_types = { RelLib.Url.UNKNOWN : _("Unknown"), @@ -195,6 +243,10 @@ web_types = { RelLib.Url.WEB_SEARCH : _("Web Search"), RelLib.Url.WEB_FTP : _("FTP"), } +def format_web_type( type): + if type[0] == RelLib.Url.CUSTOM: + return type[1] + return web_types.get(type[0],_("Invalid id %d ('%s')")%type) source_media_types = { RelLib.RepoRef.UNKNOWN : _("Unknown"), @@ -213,6 +265,10 @@ source_media_types = { RelLib.RepoRef.TOMBSTONE : _("Tombstone"), RelLib.RepoRef.VIDEO : _("Video"), } +def format_source_media_type( type): + if type[0] == RelLib.RepoRef.CUSTOM: + return type[1] + return source_media_types.get(type[0],_("Invalid id %d ('%s')")%type) event_roles = { RelLib.EventRef.UNKNOWN : _("Unknown"), @@ -225,12 +281,28 @@ event_roles = { RelLib.EventRef.GROOM : _("Groom"), RelLib.EventRef.WITNESS : _("Witness"), } +def format_personal_event_role( type): + if type[0] == RelLib.EventRef.CUSTOM: + return type[1] + return event_roles.get(type[0],_("Invalid id %d ('%s')")%type) family_event_roles = { RelLib.EventRef.UNKNOWN : _("Unknown"), RelLib.EventRef.CUSTOM : _("Custom"), RelLib.EventRef.FAMILY : _("Family"), } +def format_family_event_role( type): + if type[0] == RelLib.EventRef.CUSTOM: + return type[1] + return family_event_roles.get(type[0],_("Invalid id %d ('%s')")%type) + +def format_event_role( type): + if type[0] == RelLib.EventRef.CUSTOM: + return type[1] + val = event_roles.get(type[0]) + if not val: + val = family_event_roles.get(type[0],_("Invalid id %d ('%s')")%type) + return val repository_types = { RelLib.Repository.UNKNOWN : _("Unknown"), @@ -245,6 +317,10 @@ repository_types = { RelLib.Repository.COLLECTION : _("Collection"), RelLib.Repository.SAFE : _("Safe"), } +def format_repository_type( type): + if type[0] == RelLib.Repository.CUSTOM: + return type[1] + return repository_types.get(type[0],_("Invalid id %d ('%s')")%type) marker_types = { @@ -253,6 +329,11 @@ marker_types = { RelLib.PrimaryObject.MARKER_COMPLETE : _("Information is complete"), RelLib.PrimaryObject.MARKER_TODO : _("TODO"), } +def format_marker_type( type): + if type[0] == RelLib.PrimaryObject.MARKER_CUSTOM: + return type[1] + return marker_types.get(type[0],_("Invalid id %d ('%s')")%type) + #------------------------------------------------------------------------- # # Integer to GEDCOM tag mappings for constants