RessourceEditor.py
changeset 604 5b42b4401e6b
parent 588 4876fedbe9df
child 606 d65122c61eaf
--- a/RessourceEditor.py	Wed Dec 14 15:13:36 2011 +0100
+++ b/RessourceEditor.py	Wed Dec 14 15:17:22 2011 +0100
@@ -26,7 +26,7 @@
 import wx.grid
 
 from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD
-from controls import CustomGrid, EditorPanel, DurationCellEditor
+from controls import CustomGrid, CustomTable, EditorPanel, DurationCellEditor
 
 #-------------------------------------------------------------------------------
 #                          Configuration Editor class
@@ -74,27 +74,17 @@
     _ = lambda x : x
     return [_("Name"), _("Type"), _("Task")]
 
-class ResourceTable(wx.grid.PyGridTableBase):
+class ResourceTable(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
-        self.colnames = colnames
-        self.Highlights = {}
-        self.Parent = parent
-        
+        CustomTable.__init__(self, parent, data, colnames)
         self.ColAlignements = []
         self.ColSizes = []
-        # 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 GetColAlignements(self):
         return self.ColAlignements
     
@@ -107,21 +97,6 @@
     def SetColSizes(self, list):
         self.ColSizes = list
 
-    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():
             colname = self.GetColLabelValue(col, False)
@@ -130,9 +105,6 @@
                 return _(value)
             return value
         
-    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)
@@ -140,44 +112,6 @@
                 value = TASKTRIGGERINGOPTIONS_DICT[value]
             self.data[row][colname] = value
     
-    def SetValueByName(self, row, colname, value):
-        if colname in self.colnames:
-            self.data[row][colname] = 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
@@ -231,41 +165,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 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, index, row_content):
-        self.data.insert(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)
+
     
 #-------------------------------------------------------------------------------
 #                        Highlights showing functions