controls/DurationCellEditor.py
changeset 1275 8d4de18c9f29
parent 814 5743cbdff669
child 1499 8626bba4b2a8
equal deleted inserted replaced
1274:6b38acbe1fd0 1275:8d4de18c9f29
    96 
    96 
    97 class DurationCellEditor(wx.grid.PyGridCellEditor):
    97 class DurationCellEditor(wx.grid.PyGridCellEditor):
    98     '''
    98     '''
    99     Grid cell editor that uses DurationCellControl to display an edit button.
    99     Grid cell editor that uses DurationCellControl to display an edit button.
   100     '''
   100     '''
   101     def __init__(self, table):
   101     def __init__(self, table, colname):
   102         wx.grid.PyGridCellEditor.__init__(self)
   102         wx.grid.PyGridCellEditor.__init__(self)
   103         
   103         
   104         self.Table = table
   104         self.Table = table
       
   105         self.Colname = colname
   105     
   106     
   106     def __del__(self):
   107     def __del__(self):
   107         self.CellControl = None
   108         self.CellControl = None
   108     
   109     
   109     def Create(self, parent, id, evt_handler):
   110     def Create(self, parent, id, evt_handler):
   112         if evt_handler:
   113         if evt_handler:
   113             self.CellControl.PushEventHandler(evt_handler)
   114             self.CellControl.PushEventHandler(evt_handler)
   114 
   115 
   115     def BeginEdit(self, row, col, grid):
   116     def BeginEdit(self, row, col, grid):
   116         self.CellControl.Enable()
   117         self.CellControl.Enable()
   117         self.CellControl.SetValue(self.Table.GetValueByName(row, 'Interval'))
   118         self.CellControl.SetValue(self.Table.GetValueByName(row, self.Colname))
   118         self.CellControl.SetFocus()
   119         self.CellControl.SetFocus()
   119 
   120 
   120     def EndEdit(self, row, col, grid):
   121     def EndEdit(self, row, col, grid):
   121         duration = self.CellControl.GetValue()
   122         duration = self.CellControl.GetValue()
   122         old_duration = self.Table.GetValueByName(row, 'Interval')
   123         old_duration = self.Table.GetValueByName(row, self.Colname)
   123         changed = duration != old_duration
   124         changed = duration != old_duration
   124         if changed:
   125         if changed:
   125             self.Table.SetValueByName(row, 'Interval', duration)
   126             self.Table.SetValueByName(row, self.Colname, duration)
   126         self.CellControl.Disable()
   127         self.CellControl.Disable()
   127         return changed
   128         return changed
   128 
   129 
   129     def SetSize(self, rect):
   130     def SetSize(self, rect):
   130         self.CellControl.SetDimensions(rect.x + 1, rect.y,
   131         self.CellControl.SetDimensions(rect.x + 1, rect.y,