+_ = getattr(translations, 'ugettext', None) or translations.gettext
+
+
+class BooksDataTable(wx.grid.GridTableBase):
+ def __init__(self, rows_count, column_names):
+ wx.grid.GridTableBase.__init__(self)
+ self.rows_count = rows_count
+ self.column_names = column_names
+ self.data = []
+ for row in range(rows_count + 1):
+ row_data = []
+ self.data.append(row_data)
+ for col in range(len(column_names)):
+ row_data.append('')
+
+ # required methods for the wxPyGridTableBase interface
+
+ def GetNumberRows(self):
+ return self.rows_count
+
+ def GetNumberCols(self):
+ return len(self.column_names)
+
+ def IsEmptyCell(self, row, col):
+ return False
+
+ # Get/Set values in the table. The Python version of these
+ # methods can handle any data-type, (as long as the Editor and
+ # Renderer understands the type too,) not just strings as in the
+ # C++ version.
+ def GetValue(self, row, col):
+ return self.data[row][col]
+
+ def SetValue(self, row, col, value):
+ self.data[row][col] = value
+
+ # Optional methods
+
+ # Called when the grid needs to display labels
+ def GetRowLabelValue(self, row):
+ return str(row)
+
+ def GetColLabelValue(self, col):
+ return _(self.column_names[col])
+
+ # Called to determine the kind of editor/renderer to use by
+ # default, doesn't necessarily have to be the same type used
+ # natively by the editor/renderer if they know how to convert.
+ def GetTypeName(self, row, col):
+ if col == 0:
+ return wx.grid.GRID_VALUE_BOOL
+ else:
+ return wx.grid.GRID_VALUE_STRING
+
+ # Called to determine how the data can be fetched and stored by the
+ # editor and renderer. This allows you to enforce some type-safety
+ # in the grid.
+ def CanGetValueAs(self, row, col, typeName):
+ colType = self.GetTypeName(row, col)
+ if typeName == colType:
+ return True
+ else:
+ return False
+
+ def CanSetValueAs(self, row, col, typeName):
+ return self.CanGetValueAs(row, col, typeName)
+
+