diff -r 25c92309cdae -r 5b42b4401e6b controls/VariablePanel.py --- a/controls/VariablePanel.py Wed Dec 14 15:13:36 2011 +0100 +++ b/controls/VariablePanel.py Wed Dec 14 15:17:22 2011 +0100 @@ -31,6 +31,7 @@ from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD from dialogs.ArrayTypeDialog import ArrayTypeDialog from CustomGrid import CustomGrid +from CustomTable import CustomTable from LocationCellEditor import LocationCellEditor # Compatibility function for wx versions < 2.6 @@ -84,40 +85,16 @@ "External": lambda x: {"Constant": "Constant"}.get(x, "") } -class VariableTable(wx.grid.PyGridTableBase): +class VariableTable(CustomTable): """ A custom wx.grid.Grid Table using user supplied data """ def __init__(self, parent, data, colnames): # The base class must be initialized *first* - wx.grid.PyGridTableBase.__init__(self) - self.data = data + CustomTable.__init__(self, parent, data, colnames) self.old_value = None - self.colnames = colnames - self.Highlights = {} - self.Parent = parent - # XXX - # we need to store the row length and collength to - # see if the table has changed size - self._rows = self.GetNumberRows() - self._cols = self.GetNumberCols() - - def GetNumberCols(self): - return len(self.colnames) - - def GetNumberRows(self): - return len(self.data) - - def GetColLabelValue(self, col, translate=True): - if col < len(self.colnames): - if translate: - return _(self.colnames[col]) - return self.colnames[col] - - def GetRowLabelValues(self, row, translate=True): - return row - + def GetValue(self, row, col): if row < self.GetNumberRows(): if col == 0: @@ -146,51 +123,9 @@ elif colname == "Option": value = OPTIONS_DICT[value] self.data[row][colname] = value - - def GetValueByName(self, row, colname): - if row < self.GetNumberRows(): - return self.data[row].get(colname) - - def SetValueByName(self, row, colname, value): - if row < self.GetNumberRows(): - self.data[row][colname] = value def GetOldValue(self): return self.old_value - - def ResetView(self, grid): - """ - (wx.grid.Grid) -> Reset the grid view. Call this to - update the grid if rows and columns have been added or deleted - """ - grid.BeginBatch() - for current, new, delmsg, addmsg in [ - (self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED), - (self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED), - ]: - if new < current: - msg = wx.grid.GridTableMessage(self,delmsg,new,current-new) - grid.ProcessTableMessage(msg) - elif new > current: - msg = wx.grid.GridTableMessage(self,addmsg,new-current) - grid.ProcessTableMessage(msg) - self.UpdateValues(grid) - grid.EndBatch() - - self._rows = self.GetNumberRows() - self._cols = self.GetNumberCols() - # update the column rendering scheme - self._updateColAttrs(grid) - - # update the scrollbars and the displayed part of the grid - grid.AdjustScrollbars() - grid.ForceRefresh() - - def UpdateValues(self, grid): - """Update all displayed values""" - # This sends an event to the grid table to update all of the values - msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES) - grid.ProcessTableMessage(msg) def _updateColAttrs(self, grid): """ @@ -263,53 +198,7 @@ highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1] grid.SetCellBackgroundColour(row, col, highlight_colours[0]) grid.SetCellTextColour(row, col, highlight_colours[1]) - if wx.Platform == '__WXMSW__': - grid.SetRowMinimalHeight(row, 20) - else: - grid.SetRowMinimalHeight(row, 28) - grid.AutoSizeRow(row, False) - - def SetData(self, data): - self.data = data - - def GetData(self): - return self.data - - def GetCurrentIndex(self): - return self.CurrentIndex - - def SetCurrentIndex(self, index): - self.CurrentIndex = index - - def AppendRow(self, row_content): - self.data.append(row_content) - - def RemoveRow(self, row_index): - self.data.pop(row_index) - - def GetRow(self, row_index): - return self.data[row_index] - - def Empty(self): - self.data = [] - self.editors = [] - - def AddHighlight(self, infos, highlight_type): - row_highlights = self.Highlights.setdefault(infos[0], {}) - col_highlights = row_highlights.setdefault(infos[1], []) - col_highlights.append(highlight_type) - - def ClearHighlights(self, highlight_type=None): - if highlight_type is None: - self.Highlights = {} - else: - for row, row_highlights in self.Highlights.iteritems(): - row_items = row_highlights.items() - for col, col_highlights in row_items: - if highlight_type in col_highlights: - col_highlights.remove(highlight_type) - if len(col_highlights) == 0: - row_highlights.pop(col) + self.ResizeRow(grid, row) class VariableDropTarget(wx.TextDropTarget):