dialogs/ActionBlockDialog.py
changeset 604 5b42b4401e6b
parent 577 9dbb79722fbc
child 606 d65122c61eaf
--- a/dialogs/ActionBlockDialog.py	Wed Dec 14 15:13:36 2011 +0100
+++ b/dialogs/ActionBlockDialog.py	Wed Dec 14 15:17:22 2011 +0100
@@ -24,7 +24,7 @@
 import wx
 import wx.grid
 
-from controls import CustomGrid
+from controls import CustomGrid, CustomTable
 
 #-------------------------------------------------------------------------------
 #                            Action Block Dialog
@@ -38,39 +38,8 @@
     _ = lambda x: x
     return [_("Action"), _("Variable"), _("Inline")]
 
-class ActionTable(wx.grid.PyGridTableBase):
-    
-    """
-    A custom wx.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):
-            colname = self.colnames[col]
-            if translate:
-                return _(colname)
-        return colname
-
-    def GetRowLabelValues(self, row, translate=True):
-        return row
-
+class ActionTable(CustomTable):
+    
     def GetValue(self, row, col):
         if row < self.GetNumberRows():
             colname = self.GetColLabelValue(col, False)
@@ -79,9 +48,6 @@
                 return _(name)
             return name
     
-    def GetValueByName(self, row, colname):
-        return self.data[row].get(colname)
-
     def SetValue(self, row, col, value):
         if col < len(self.colnames):
             colname = self.GetColLabelValue(col, False)
@@ -89,40 +55,6 @@
                 value = self.Parent.TranslateType[value]
             self.data[row][colname] = value
         
-    def ResetView(self, grid):
-        """
-        (wx.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 -> update the column attributes to add the
@@ -171,41 +103,8 @@
                 grid.SetReadOnly(row, col, readonly)
                 
                 grid.SetCellBackgroundColour(row, col, wx.WHITE)
-            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 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, row_index, move):
-        new_index = max(0, min(row_index + move, len(self.data) - 1))
-        if new_index != row_index:
-            self.data.insert(new_index, self.data.pop(row_index))
-        return new_index
-
-    def Empty(self):
-        self.data = []
+            self.ResizeRow(grid, row)
+
 
 [ID_ACTIONBLOCKDIALOG, ID_ACTIONBLOCKDIALOGVARIABLESGRID, 
  ID_ACTIONBLOCKDIALOGSTATICTEXT1, ID_ACTIONBLOCKDIALOGADDBUTTON,