PLCOpenEditor.py
changeset 604 5b42b4401e6b
parent 599 4bb7b132e15d
child 605 279c16d017f3
--- a/PLCOpenEditor.py	Wed Dec 14 15:13:36 2011 +0100
+++ b/PLCOpenEditor.py	Wed Dec 14 15:17:22 2011 +0100
@@ -113,9 +113,8 @@
 from RessourceEditor import *
 from DataTypeEditor import *
 from PLCControler import *
-from controls.VariablePanel import VariablePanel
 from SearchResultPanel import SearchResultPanel
-from controls import CustomGrid
+from controls import CustomGrid, CustomTable
 
 # Define PLCOpenEditor controls id
 [ID_PLCOPENEDITOR, ID_PLCOPENEDITORLEFTNOTEBOOK, 
@@ -3845,38 +3844,8 @@
     def GetValue(self):
         return self.Value
 
-class DebugVariableTable(wx.grid.PyGridTableBase):
-    
-    """
-    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
-        self.colnames = colnames
-        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
-
+class DebugVariableTable(CustomTable):
+    
     def GetValue(self, row, col):
         if row < self.GetNumberRows():
             return self.GetValueByName(row, self.GetColLabelValue(col, False))
@@ -3906,40 +3875,6 @@
             return self.data[row].IsForced()
         return False
     
-    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
@@ -3956,13 +3891,8 @@
                     else:
                         grid.SetCellTextColour(row, col, wx.BLACK)
                 grid.SetReadOnly(row, col, True)
+            self.ResizeRow(grid, row)
                 
-    def SetData(self, data):
-        self.data = data
-    
-    def GetData(self):
-        return self.data
-    
     def AppendItem(self, data):
         self.data.append(data)
     
@@ -3978,9 +3908,7 @@
     def GetItem(self, idx):
         return self.data[idx]
 
-    def Empty(self):
-        self.data = []
-    
+
 class DebugVariableDropTarget(wx.TextDropTarget):
     
     def __init__(self, parent):