--- a/DataTypeEditor.py Wed Dec 14 15:13:36 2011 +0100
+++ b/DataTypeEditor.py Wed Dec 14 15:17:22 2011 +0100
@@ -27,7 +27,7 @@
from plcopen.structures import IEC_KEYWORDS, TestIdentifier
from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD
-from controls import CustomEditableListBox, CustomGrid, EditorPanel
+from controls import CustomEditableListBox, CustomGrid, CustomTable, EditorPanel
import re
@@ -47,40 +47,16 @@
_ = lambda x : x
return ["#", _("Name"), _("Type"), _("Initial Value")]
-class ElementsTable(wx.grid.PyGridTableBase):
+class ElementsTable(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:
@@ -95,51 +71,9 @@
self.old_value = self.data[row][colname]
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):
"""
wx.grid.Grid -> update the column attributes to add the
@@ -173,40 +107,8 @@
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 AppendRow(self, row_content):
- self.data.append(row_content)
-
- def InsertRow(self, row_index, row_content):
- self.data.insert(row_index, row_content)
-
- def RemoveRow(self, row_index):
- self.data.pop(row_index)
-
- def MoveRow(self, idx, move):
- new_idx = max(0, min(idx + move, len(self.data) - 1))
- if new_idx != idx:
- self.data.insert(new_idx, self.data.pop(idx))
- return new_idx
-
- def GetRow(self, row_index):
- return self.data[row_index]
-
- def Empty(self):
- self.data = []
- self.editors = []
-
+ self.ResizeRow(grid, row)
+
def AddHighlight(self, infos, highlight_type):
row_highlights = self.Highlights.setdefault(infos[0], {})
if infos[1] == "initial":
@@ -215,18 +117,6 @@
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)
-
#-------------------------------------------------------------------------------
# Datatype Editor class
#-------------------------------------------------------------------------------