controls/LocationCellEditor.py
changeset 714 131ea7f237b9
parent 657 b286a16162fc
child 723 5df934c273e1
equal deleted inserted replaced
713:95a0a427f3ef 714:131ea7f237b9
    26 
    26 
    27 from dialogs.BrowseLocationsDialog import BrowseLocationsDialog
    27 from dialogs.BrowseLocationsDialog import BrowseLocationsDialog
    28 
    28 
    29 class LocationCellControl(wx.PyControl):
    29 class LocationCellControl(wx.PyControl):
    30     
    30     
    31     def _init_coll_MainSizer_Items(self, parent):
       
    32         parent.AddWindow(self.Location, 0, border=0, flag=wx.GROW)
       
    33         parent.AddWindow(self.BrowseButton, 0, border=0, flag=wx.GROW)
       
    34         
       
    35     def _init_coll_MainSizer_Growables(self, parent):
       
    36         parent.AddGrowableCol(0)
       
    37         parent.AddGrowableRow(0)
       
    38     
       
    39     def _init_sizers(self):
       
    40         self.MainSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0)
       
    41         
       
    42         self._init_coll_MainSizer_Items(self.MainSizer)
       
    43         self._init_coll_MainSizer_Growables(self.MainSizer)
       
    44         
       
    45         self.SetSizer(self.MainSizer)
       
    46     
       
    47     def _init_ctrls(self, prnt):
       
    48         wx.Control.__init__(self, id=-1, 
       
    49               name='LocationCellControl', parent=prnt,  
       
    50               size=wx.DefaultSize, style=0)
       
    51         
       
    52         # create location text control
       
    53         self.Location = wx.TextCtrl(id=-1, name='Location', parent=self,
       
    54               pos=wx.Point(0, 0), size=wx.Size(0, 0), style=wx.TE_PROCESS_ENTER)
       
    55         self.Location.Bind(wx.EVT_KEY_DOWN, self.OnLocationChar)
       
    56         
       
    57         # create browse button
       
    58         self.BrowseButton = wx.Button(id=-1, label='...', 
       
    59               name='BrowseButton', parent=self, pos=wx.Point(0, 0), 
       
    60               size=wx.Size(30, 0), style=0)
       
    61         self.BrowseButton.Bind(wx.EVT_BUTTON, self.OnBrowseButtonClick)
       
    62 
       
    63         self.Bind(wx.EVT_SIZE, self.OnSize)
       
    64         
       
    65         self._init_sizers()
       
    66 
       
    67     '''
    31     '''
    68     Custom cell editor control with a text box and a button that launches
    32     Custom cell editor control with a text box and a button that launches
    69     the BrowseLocationsDialog.
    33     the BrowseLocationsDialog.
    70     '''
    34     '''
    71     def __init__(self, parent):
    35     def __init__(self, parent):
    72         self._init_ctrls(parent)
    36         wx.Control.__init__(self, parent)
       
    37         
       
    38         main_sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0)
       
    39         main_sizer.AddGrowableCol(0)
       
    40         main_sizer.AddGrowableRow(0)
       
    41         
       
    42         # create location text control
       
    43         self.Location = wx.TextCtrl(self, style=wx.TE_PROCESS_ENTER)
       
    44         self.Location.Bind(wx.EVT_KEY_DOWN, self.OnLocationChar)
       
    45         main_sizer.AddWindow(self.Location, flag=wx.GROW)
       
    46         
       
    47         # create browse button
       
    48         self.BrowseButton = wx.Button(self, label='...', size=wx.Size(30, 0))
       
    49         self.BrowseButton.Bind(wx.EVT_BUTTON, self.OnBrowseButtonClick)
       
    50         main_sizer.AddWindow(self.BrowseButton, flag=wx.GROW)
       
    51         
       
    52         self.Bind(wx.EVT_SIZE, self.OnSize)
       
    53         
       
    54         self.SetSizer(main_sizer)
       
    55 
    73         self.Locations = None
    56         self.Locations = None
    74         self.VarType = None
    57         self.VarType = None
    75         self.Default = False
    58         self.Default = False
    76 
    59 
    77     def SetLocations(self, locations):
    60     def SetLocations(self, locations):
   121 
   104 
   122 class LocationCellEditor(wx.grid.PyGridCellEditor):
   105 class LocationCellEditor(wx.grid.PyGridCellEditor):
   123     '''
   106     '''
   124     Grid cell editor that uses LocationCellControl to display a browse button.
   107     Grid cell editor that uses LocationCellControl to display a browse button.
   125     '''
   108     '''
   126     def __init__(self, table, controler):
   109     def __init__(self, table, controller):
   127         wx.grid.PyGridCellEditor.__init__(self)
   110         wx.grid.PyGridCellEditor.__init__(self)
       
   111         
   128         self.Table = table
   112         self.Table = table
   129         self.Controler = controler
   113         self.Controller = controller
   130 
   114 
   131     def __del__(self):
   115     def __del__(self):
   132         self.CellControl = None
   116         self.CellControl = None
   133     
   117     
   134     def Create(self, parent, id, evt_handler):
   118     def Create(self, parent, id, evt_handler):
   137         if evt_handler:
   121         if evt_handler:
   138             self.CellControl.PushEventHandler(evt_handler)
   122             self.CellControl.PushEventHandler(evt_handler)
   139 
   123 
   140     def BeginEdit(self, row, col, grid):
   124     def BeginEdit(self, row, col, grid):
   141         self.CellControl.Enable()
   125         self.CellControl.Enable()
   142         self.CellControl.SetLocations(self.Controler.GetVariableLocationTree())
   126         self.CellControl.SetLocations(self.Controller.GetVariableLocationTree())
   143         self.CellControl.SetValue(self.Table.GetValueByName(row, 'Location'))
   127         self.CellControl.SetValue(self.Table.GetValueByName(row, 'Location'))
   144         if isinstance(self.CellControl, LocationCellControl):
   128         if isinstance(self.CellControl, LocationCellControl):
   145             self.CellControl.SetVarType(self.Controler.GetBaseType(self.Table.GetValueByName(row, 'Type')))
   129             self.CellControl.SetVarType(self.Controller.GetBaseType(self.Table.GetValueByName(row, 'Type')))
   146         self.CellControl.SetFocus()
   130         self.CellControl.SetFocus()
   147 
   131 
   148     def EndEdit(self, row, col, grid):
   132     def EndEdit(self, row, col, grid):
   149         loc = self.CellControl.GetValue()
   133         loc = self.CellControl.GetValue()
   150         old_loc = self.Table.GetValueByName(row, 'Location')
   134         old_loc = self.Table.GetValueByName(row, 'Location')
   158         self.CellControl.SetDimensions(rect.x + 1, rect.y,
   142         self.CellControl.SetDimensions(rect.x + 1, rect.y,
   159                                         rect.width, rect.height,
   143                                         rect.width, rect.height,
   160                                         wx.SIZE_ALLOW_MINUS_ONE)
   144                                         wx.SIZE_ALLOW_MINUS_ONE)
   161 
   145 
   162     def Clone(self):
   146     def Clone(self):
   163         return LocationCellEditor(self.Table, self.Controler)
   147         return LocationCellEditor(self.Table, self.Controller)
   164 
   148