66 |
66 |
67 ''' |
67 ''' |
68 Custom cell editor control with a text box and a button that launches |
68 Custom cell editor control with a text box and a button that launches |
69 the BrowseLocationsDialog. |
69 the BrowseLocationsDialog. |
70 ''' |
70 ''' |
71 def __init__(self, parent, locations): |
71 def __init__(self, parent): |
72 self._init_ctrls(parent) |
72 self._init_ctrls(parent) |
73 self.Locations = locations |
73 self.Locations = None |
74 self.VarType = None |
74 self.VarType = None |
75 self.Default = False |
75 self.Default = False |
|
76 |
|
77 def SetLocations(self, locations): |
|
78 self.Locations = locations |
76 |
79 |
77 def SetVarType(self, vartype): |
80 def SetVarType(self, vartype): |
78 self.VarType = vartype |
81 self.VarType = vartype |
79 |
82 |
80 def SetValue(self, value): |
83 def SetValue(self, value): |
127 |
130 |
128 def __del__(self): |
131 def __del__(self): |
129 self.CellControl = None |
132 self.CellControl = None |
130 |
133 |
131 def Create(self, parent, id, evt_handler): |
134 def Create(self, parent, id, evt_handler): |
132 locations = self.Controler.GetVariableLocationTree() |
135 self.CellControl = LocationCellControl(parent) |
133 if len(locations) > 0: |
|
134 self.CellControl = LocationCellControl(parent, locations) |
|
135 else: |
|
136 self.CellControl = wx.TextCtrl(parent, -1) |
|
137 self.SetControl(self.CellControl) |
136 self.SetControl(self.CellControl) |
138 if evt_handler: |
137 if evt_handler: |
139 self.CellControl.PushEventHandler(evt_handler) |
138 self.CellControl.PushEventHandler(evt_handler) |
140 |
139 |
141 def BeginEdit(self, row, col, grid): |
140 def BeginEdit(self, row, col, grid): |
|
141 self.CellControl.Enable() |
|
142 self.CellControl.SetLocations(self.Controler.GetVariableLocationTree()) |
142 self.CellControl.SetValue(self.Table.GetValueByName(row, 'Location')) |
143 self.CellControl.SetValue(self.Table.GetValueByName(row, 'Location')) |
143 if isinstance(self.CellControl, LocationCellControl): |
144 if isinstance(self.CellControl, LocationCellControl): |
144 self.CellControl.SetVarType(self.Controler.GetBaseType(self.Table.GetValueByName(row, 'Type'))) |
145 self.CellControl.SetVarType(self.Controler.GetBaseType(self.Table.GetValueByName(row, 'Type'))) |
145 self.CellControl.SetFocus() |
146 self.CellControl.SetFocus() |
146 |
147 |
147 def EndEdit(self, row, col, grid): |
148 def EndEdit(self, row, col, grid): |
148 loc = self.CellControl.GetValue() |
149 loc = self.CellControl.GetValue() |
149 old_loc = self.Table.GetValueByName(row, 'Location') |
150 old_loc = self.Table.GetValueByName(row, 'Location') |
150 if loc != old_loc: |
151 changed = loc != old_loc |
|
152 if changed: |
151 self.Table.SetValueByName(row, 'Location', loc) |
153 self.Table.SetValueByName(row, 'Location', loc) |
152 return True |
154 self.CellControl.Disable() |
153 return False |
155 return changed |
154 |
156 |
155 def SetSize(self, rect): |
157 def SetSize(self, rect): |
156 self.CellControl.SetDimensions(rect.x + 1, rect.y, |
158 self.CellControl.SetDimensions(rect.x + 1, rect.y, |
157 rect.width, rect.height, |
159 rect.width, rect.height, |
158 wx.SIZE_ALLOW_MINUS_ONE) |
160 wx.SIZE_ALLOW_MINUS_ONE) |