Fixed DurationCellEditor to make it reusable
authorLaurent Bessard
Fri, 05 Jul 2013 00:11:21 +0200
changeset 1275 8d4de18c9f29
parent 1274 6b38acbe1fd0
child 1276 29bfd39e8e7a
Fixed DurationCellEditor to make it reusable
controls/DurationCellEditor.py
editors/ResourceEditor.py
--- a/controls/DurationCellEditor.py	Fri Jul 05 00:10:29 2013 +0200
+++ b/controls/DurationCellEditor.py	Fri Jul 05 00:11:21 2013 +0200
@@ -98,10 +98,11 @@
     '''
     Grid cell editor that uses DurationCellControl to display an edit button.
     '''
-    def __init__(self, table):
+    def __init__(self, table, colname):
         wx.grid.PyGridCellEditor.__init__(self)
         
         self.Table = table
+        self.Colname = colname
     
     def __del__(self):
         self.CellControl = None
@@ -114,15 +115,15 @@
 
     def BeginEdit(self, row, col, grid):
         self.CellControl.Enable()
-        self.CellControl.SetValue(self.Table.GetValueByName(row, 'Interval'))
+        self.CellControl.SetValue(self.Table.GetValueByName(row, self.Colname))
         self.CellControl.SetFocus()
 
     def EndEdit(self, row, col, grid):
         duration = self.CellControl.GetValue()
-        old_duration = self.Table.GetValueByName(row, 'Interval')
+        old_duration = self.Table.GetValueByName(row, self.Colname)
         changed = duration != old_duration
         if changed:
-            self.Table.SetValueByName(row, 'Interval', duration)
+            self.Table.SetValueByName(row, self.Colname, duration)
         self.CellControl.Disable()
         return changed
 
--- a/editors/ResourceEditor.py	Fri Jul 05 00:10:29 2013 +0200
+++ b/editors/ResourceEditor.py	Fri Jul 05 00:11:21 2013 +0200
@@ -140,7 +140,7 @@
                     editor = wx.grid.GridCellTextEditor()
                     renderer = wx.grid.GridCellStringRenderer()
                 elif colname == "Interval":
-                    editor = DurationCellEditor(self)
+                    editor = DurationCellEditor(self, colname)
                     renderer = wx.grid.GridCellStringRenderer()
                     if self.GetValueByName(row, "Triggering") != "Cyclic":
                         grid.SetReadOnly(row, col, True)