controls/LocationCellEditor.py
changeset 855 b30421d07e8c
parent 814 5743cbdff669
child 1004 bf3b6998f7b6
equal deleted inserted replaced
854:c10f2092c43a 855:b30421d07e8c
    52         
    52         
    53         self.Bind(wx.EVT_SIZE, self.OnSize)
    53         self.Bind(wx.EVT_SIZE, self.OnSize)
    54         
    54         
    55         self.SetSizer(main_sizer)
    55         self.SetSizer(main_sizer)
    56 
    56 
    57         self.Locations = None
    57         self.Controller = None
    58         self.VarType = None
    58         self.VarType = None
    59         self.Default = False
    59         self.Default = False
    60 
    60 
    61     def SetLocations(self, locations):
    61     def __del__(self):
    62         self.Locations = locations
    62         self.Controller = None
       
    63 
       
    64     def SetController(self, controller):
       
    65         self.Controller = controller
    63 
    66 
    64     def SetVarType(self, vartype):
    67     def SetVarType(self, vartype):
    65         self.VarType = vartype
    68         self.VarType = vartype
       
    69 
       
    70     def GetVarType(self):
       
    71         return self.VarType
    66 
    72 
    67     def SetValue(self, value):
    73     def SetValue(self, value):
    68         self.Default = value
    74         self.Default = value
    69         self.Location.SetValue(value)
    75         self.Location.SetValue(value)
    70     
    76     
    74     def OnSize(self, event):
    80     def OnSize(self, event):
    75         self.Layout()
    81         self.Layout()
    76 
    82 
    77     def OnBrowseButtonClick(self, event):
    83     def OnBrowseButtonClick(self, event):
    78         # pop up the location browser dialog
    84         # pop up the location browser dialog
    79         dialog = BrowseLocationsDialog(self, self.VarType, self.Locations)
    85         dialog = BrowseLocationsDialog(self, self.VarType, self.Controller)
    80         if dialog.ShowModal() == wx.ID_OK:
    86         if dialog.ShowModal() == wx.ID_OK:
    81             infos = dialog.GetValues()
    87             infos = dialog.GetValues()
    82 
    88 
    83             # set the location
    89             # set the location
    84             self.Location.SetValue(infos["location"])
    90             self.Location.SetValue(infos["location"])
       
    91             self.VarType = infos["IEC_type"]
    85 
    92 
    86         dialog.Destroy()
    93         dialog.Destroy()
    87 
    94 
    88         self.Location.SetFocus()
    95         self.Location.SetFocus()
    89 
    96 
   113         self.Table = table
   120         self.Table = table
   114         self.Controller = controller
   121         self.Controller = controller
   115 
   122 
   116     def __del__(self):
   123     def __del__(self):
   117         self.CellControl = None
   124         self.CellControl = None
       
   125         self.Controller = None
   118     
   126     
   119     def Create(self, parent, id, evt_handler):
   127     def Create(self, parent, id, evt_handler):
   120         self.CellControl = LocationCellControl(parent)
   128         self.CellControl = LocationCellControl(parent)
   121         self.SetControl(self.CellControl)
   129         self.SetControl(self.CellControl)
   122         if evt_handler:
   130         if evt_handler:
   123             self.CellControl.PushEventHandler(evt_handler)
   131             self.CellControl.PushEventHandler(evt_handler)
   124 
   132 
   125     def BeginEdit(self, row, col, grid):
   133     def BeginEdit(self, row, col, grid):
   126         self.CellControl.Enable()
   134         self.CellControl.Enable()
   127         self.CellControl.SetLocations(self.Controller.GetVariableLocationTree())
   135         self.CellControl.SetController(self.Controller)
   128         self.CellControl.SetValue(self.Table.GetValueByName(row, 'Location'))
   136         self.CellControl.SetValue(self.Table.GetValueByName(row, 'Location'))
   129         if isinstance(self.CellControl, LocationCellControl):
   137         if isinstance(self.CellControl, LocationCellControl):
   130             self.CellControl.SetVarType(self.Controller.GetBaseType(self.Table.GetValueByName(row, 'Type')))
   138             self.CellControl.SetVarType(self.Table.GetValueByName(row, 'Type'))
   131         self.CellControl.SetFocus()
   139         self.CellControl.SetFocus()
   132 
   140 
   133     def EndEdit(self, row, col, grid):
   141     def EndEdit(self, row, col, grid):
   134         loc = self.CellControl.GetValue()
   142         loc = self.CellControl.GetValue()
   135         old_loc = self.Table.GetValueByName(row, 'Location')
   143         old_loc = self.Table.GetValueByName(row, 'Location')
   136         changed = loc != old_loc
   144         changed = loc != old_loc
   137         if changed:
   145         if changed:
   138             self.Table.SetValueByName(row, 'Location', loc)
   146             self.Table.SetValueByName(row, 'Location', loc)
       
   147             self.Table.SetValueByName(row, 'Type', self.CellControl.GetVarType())
   139         self.CellControl.Disable()
   148         self.CellControl.Disable()
   140         return changed
   149         return changed
   141     
   150     
   142     def SetSize(self, rect):
   151     def SetSize(self, rect):
   143         self.CellControl.SetDimensions(rect.x + 1, rect.y,
   152         self.CellControl.SetDimensions(rect.x + 1, rect.y,