diff --git a/src/Config/_GrampsConfigKeys.py b/src/Config/_GrampsConfigKeys.py index 833a10e97..2e2b2f1d6 100644 --- a/src/Config/_GrampsConfigKeys.py +++ b/src/Config/_GrampsConfigKeys.py @@ -173,6 +173,7 @@ PRIVATE_SURNAME_TEXT = ('preferences', 'private-surname-text', 2) PRIVATE_GIVEN_TEXT = ('preferences', 'private-given-text', 2) PRIVATE_RECORD_TEXT = ('preferences', 'private-record-text', 2) RELATION_DISPLAY_THEME= ('preferences', 'relation-display-theme', 2) +INVALID_DATE_FORMAT = ('preferences', 'invalid-date-format', 2) default_value = { DEFAULT_SOURCE : False, @@ -299,4 +300,5 @@ default_value = { PRIVATE_GIVEN_TEXT : "[%s]" % _("Living"), PRIVATE_RECORD_TEXT : "[%s]" % _("Private Record"), RELATION_DISPLAY_THEME: "CLASSIC", + INVALID_DATE_FORMAT : "%s", } diff --git a/src/DisplayModels/_PeopleModel.py b/src/DisplayModels/_PeopleModel.py index a7afb26b7..53ad3ce2a 100644 --- a/src/DisplayModels/_PeopleModel.py +++ b/src/DisplayModels/_PeopleModel.py @@ -66,6 +66,7 @@ from Filters import SearchFilter, ExactSearchFilter from Lru import LRU _CACHE_SIZE = 250 +invalid_date_format = Config.get(Config.INVALID_DATE_FORMAT) def locale_sort(mylist): """ @@ -549,7 +550,7 @@ class PeopleModel(gtk.GenericTreeModel): if date_str != "": retval = cgi.escape(date_str) if not DateHandler.get_date_valid(birth): - return u'%s' % retval + return invalid_date_format % retval else: return retval except: @@ -566,7 +567,7 @@ class PeopleModel(gtk.GenericTreeModel): and date_str != ""): retval = u"%s" % cgi.escape(date_str) if not DateHandler.get_date_valid(event): - return u'%s' % retval + return invalid_date_format % retval else: return retval @@ -593,7 +594,7 @@ class PeopleModel(gtk.GenericTreeModel): if date_str != "": retval = cgi.escape(date_str) if not DateHandler.get_date_valid(event): - return u'%s' % retval + return invalid_date_format % retval else: return retval except: @@ -610,7 +611,7 @@ class PeopleModel(gtk.GenericTreeModel): and date_str): retval = "%s" % cgi.escape(date_str) if not DateHandler.get_date_valid(event): - return u'%s' % retval + return invalid_date_format % retval else: return retval return u"" diff --git a/src/DisplayTabs/_EventRefModel.py b/src/DisplayTabs/_EventRefModel.py index cdd09c19d..0f6f95fa0 100644 --- a/src/DisplayTabs/_EventRefModel.py +++ b/src/DisplayTabs/_EventRefModel.py @@ -34,6 +34,14 @@ import cgi # #------------------------------------------------------------------------- import DateHandler +import Config + +#------------------------------------------------------------------------- +# +# Globals +# +#------------------------------------------------------------------------- +invalid_date_format = Config.get(Config.INVALID_DATE_FORMAT) #------------------------------------------------------------------------- # @@ -64,7 +72,7 @@ class EventRefModel(gtk.ListStore): event = self.db.get_event_from_handle(event_ref.ref) retval = DateHandler.get_date(event) if not DateHandler.get_date_valid(event): - return u'%s' % cgi.escape(retval) + return invalid_date_format % cgi.escape(retval) else: return retval diff --git a/src/Simple/_SimpleTable.py b/src/Simple/_SimpleTable.py index 057ca8354..be228d1ca 100644 --- a/src/Simple/_SimpleTable.py +++ b/src/Simple/_SimpleTable.py @@ -22,11 +22,13 @@ Provide a simplified table creation interface """ +import cgi import copy from gettext import gettext as _ import gen.lib import Errors +import Config import DateHandler class SimpleTable: @@ -41,6 +43,7 @@ class SimpleTable: self.access = access self.title = title self.__columns = [] + self.__cell_markup = {} # [col][row] = "data" self.__rows = [] self.__link = [] self.__sort_col = None @@ -172,6 +175,7 @@ class SimpleTable: """ retval = [] link = None + row = len(self.__rows) for col in range(len(data)): item = data[col] # FIXME: add better text representations of these objects @@ -228,12 +232,16 @@ class SimpleTable: link = ('Note', item.handle) elif isinstance(item, gen.lib.Date): text = DateHandler.displayer.display(item) + retval.append(text) if item.get_valid(): - retval.append(text) self.row_sort_val(col, item.sortval) else: - retval.append("Invalid: " + text) + # sort before others: self.row_sort_val(col, -1) + # give formatted version: + invalid_date_format = Config.get(Config.INVALID_DATE_FORMAT) + self.set_cell_markup(col, row, + invalid_date_format % text) if (self.__link_col == col or link == None): link = ('Date', item) elif isinstance(item, gen.lib.Span): @@ -309,7 +317,10 @@ class SimpleTable: sort_data_types = [] for col in self.__columns: types.append(type(col)) - column = gtk.TreeViewColumn(col,renderer,text=model_index) + if self.get_cell_markup(cnt): + column = gtk.TreeViewColumn(col,renderer,markup=model_index) + else: + column = gtk.TreeViewColumn(col,renderer,text=model_index) if self.__sort_vals[cnt] != []: sort_data.append(self.__sort_vals[cnt]) column.set_sort_column_id(len(self.__columns) + @@ -333,8 +344,41 @@ class SimpleTable: text_view.add_child_at_anchor(treeview, anchor) count = 0 for data in self.__rows: - model.append(row=([count] + list(data) + [col[count] for col in sort_data])) + col = 0 + rowdata = [] + for cell in data: + rowdata.append(self.get_cell_markup(col, count, cell)) + col += 1 + model.append(row=([count] + list(rowdata) + [col[count] for col in sort_data])) count += 1 text_view.show_all() self.simpledoc.paragraph("") self.simpledoc.paragraph("") + + def get_cell_markup(self, x, y=None, data=None): + """ + See if a column has formatting (if x and y are supplied) or + see if a cell has formatting. If it does, return the formatted + string, otherwise return data that is escaped (if that column + has formatting), or just the plain data. + """ + if x in self.__cell_markup: + if y == None: + return True # markup for this column + elif y in self.__cell_markup[x]: + return self.__cell_markup[x][y] + else: + return cgi.escape(data) + else: + if y == None: + return False # no markup for this column + else: + return data + + def set_cell_markup(self, x, y, data): + """ + Set the cell at position [x][y] to a formatted string. + """ + col_dict = self.__cell_markup.get(x, {}) + col_dict[y] = data + self.__cell_markup[x] = col_dict