etherlab/ConfigEditor.py
changeset 2095 6733a7c5c897
parent 2089 3f5c41f3d47f
child 2097 58d07e039896
equal deleted inserted replaced
2094:72b74099b873 2095:6733a7c5c897
    39 ] = [wx.NewId() for _init_ctrls in range(13)]
    39 ] = [wx.NewId() for _init_ctrls in range(13)]
    40 
    40 
    41 class NodeEditor(ConfTreeNodeEditor):
    41 class NodeEditor(ConfTreeNodeEditor):
    42     
    42     
    43     ID = ID_NODEEDITOR
    43     ID = ID_NODEEDITOR
       
    44     CONFNODEEDITOR_TABS = [
       
    45         (_("Ethercat node"), "_create_EthercatNodeEditor")]
    44     
    46     
    45     def _init_coll_MainSizer_Items(self, parent):
    47     def _init_coll_MainSizer_Items(self, parent):
    46         parent.AddSizer(self.SlaveInfosDetailsSizer, 0, border=5, flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.GROW)
    48         parent.AddSizer(self.SlaveInfosDetailsSizer, 0, border=5, flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.GROW)
    47         parent.AddWindow(self.SyncManagersLabel, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.GROW)
    49         parent.AddWindow(self.SyncManagersLabel, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.GROW)
    48         parent.AddWindow(self.SyncManagersGrid, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.GROW)
    50         parent.AddWindow(self.SyncManagersGrid, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.GROW)
    75         self._init_coll_MainSizer_Growables(self.MainSizer)
    77         self._init_coll_MainSizer_Growables(self.MainSizer)
    76         self._init_coll_MainSizer_Items(self.MainSizer)
    78         self._init_coll_MainSizer_Items(self.MainSizer)
    77         self._init_coll_SlaveInfosDetailsSizer_Growables(self.SlaveInfosDetailsSizer)
    79         self._init_coll_SlaveInfosDetailsSizer_Growables(self.SlaveInfosDetailsSizer)
    78         self._init_coll_SlaveInfosDetailsSizer_Items(self.SlaveInfosDetailsSizer)
    80         self._init_coll_SlaveInfosDetailsSizer_Items(self.SlaveInfosDetailsSizer)
    79         
    81         
    80         self.ConfNodeEditor.SetSizer(self.MainSizer)
    82         self.EthercatNodeEditor.SetSizer(self.MainSizer)
    81 
    83 
    82     def _init_ConfNodeEditor(self, prnt):
    84     def _create_EthercatNodeEditor(self, prnt):
    83         self.ConfNodeEditor = wx.ScrolledWindow(id=-1, name='SlavePanel', parent=prnt,
    85         self.EthercatNodeEditor = wx.ScrolledWindow(id=-1, name='SlavePanel', parent=prnt,
    84               size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL)
    86               size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL)
    85         self.ConfNodeEditor.Bind(wx.EVT_SIZE, self.OnConfNodeEditorResize)
    87         self.EthercatNodeEditor.Bind(wx.EVT_SIZE, self.OnEthercatNodeEditorResize)
    86         
    88         
    87         self.VendorLabel = wx.StaticText(id=ID_NODEEDITORVENDORLABEL,
    89         self.VendorLabel = wx.StaticText(id=ID_NODEEDITORVENDORLABEL,
    88               label=_('Vendor:'), name='VendorLabel', parent=self.ConfNodeEditor,
    90               label=_('Vendor:'), name='VendorLabel', parent=self.EthercatNodeEditor,
    89               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
    91               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
    90         
    92         
    91         self.Vendor = wx.TextCtrl(id=ID_NODEEDITORVENDOR, value='',
    93         self.Vendor = wx.TextCtrl(id=ID_NODEEDITORVENDOR, value='',
    92               name='Vendor', parent=self.ConfNodeEditor, pos=wx.Point(0, 0),
    94               name='Vendor', parent=self.EthercatNodeEditor, pos=wx.Point(0, 0),
    93               size=wx.Size(0, 24), style=wx.TE_READONLY)
    95               size=wx.Size(0, 24), style=wx.TE_READONLY)
    94         
    96         
    95         self.ProductCodeLabel = wx.StaticText(id=ID_NODEEDITORPRODUCTCODELABEL,
    97         self.ProductCodeLabel = wx.StaticText(id=ID_NODEEDITORPRODUCTCODELABEL,
    96               label=_('Product code:'), name='ProductCodeLabel', parent=self.ConfNodeEditor,
    98               label=_('Product code:'), name='ProductCodeLabel', parent=self.EthercatNodeEditor,
    97               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
    99               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
    98         
   100         
    99         self.ProductCode = wx.TextCtrl(id=ID_NODEEDITORPRODUCTCODE, value='',
   101         self.ProductCode = wx.TextCtrl(id=ID_NODEEDITORPRODUCTCODE, value='',
   100               name='ProductCode', parent=self.ConfNodeEditor, pos=wx.Point(0, 0),
   102               name='ProductCode', parent=self.EthercatNodeEditor, pos=wx.Point(0, 0),
   101               size=wx.Size(0, 24), style=wx.TE_READONLY)
   103               size=wx.Size(0, 24), style=wx.TE_READONLY)
   102         
   104         
   103         self.RevisionNumberLabel = wx.StaticText(id=ID_NODEEDITORREVISIONNUMBERLABEL,
   105         self.RevisionNumberLabel = wx.StaticText(id=ID_NODEEDITORREVISIONNUMBERLABEL,
   104               label=_('Revision number:'), name='RevisionNumberLabel', parent=self.ConfNodeEditor,
   106               label=_('Revision number:'), name='RevisionNumberLabel', parent=self.EthercatNodeEditor,
   105               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
   107               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
   106         
   108         
   107         self.RevisionNumber = wx.TextCtrl(id=ID_NODEEDITORREVISIONNUMBER, value='',
   109         self.RevisionNumber = wx.TextCtrl(id=ID_NODEEDITORREVISIONNUMBER, value='',
   108               name='RevisionNumber', parent=self.ConfNodeEditor, pos=wx.Point(0, 0),
   110               name='RevisionNumber', parent=self.EthercatNodeEditor, pos=wx.Point(0, 0),
   109               size=wx.Size(0, 24), style=wx.TE_READONLY)
   111               size=wx.Size(0, 24), style=wx.TE_READONLY)
   110         
   112         
   111         self.PhysicsLabel = wx.StaticText(id=ID_NODEEDITORPHYSICSLABEL,
   113         self.PhysicsLabel = wx.StaticText(id=ID_NODEEDITORPHYSICSLABEL,
   112               label=_('Physics:'), name='PhysicsLabel', parent=self.ConfNodeEditor,
   114               label=_('Physics:'), name='PhysicsLabel', parent=self.EthercatNodeEditor,
   113               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
   115               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
   114         
   116         
   115         self.Physics = wx.TextCtrl(id=ID_NODEEDITORPHYSICS, value='',
   117         self.Physics = wx.TextCtrl(id=ID_NODEEDITORPHYSICS, value='',
   116               name='Physics', parent=self.ConfNodeEditor, pos=wx.Point(0, 0),
   118               name='Physics', parent=self.EthercatNodeEditor, pos=wx.Point(0, 0),
   117               size=wx.Size(0, 24), style=wx.TE_READONLY)
   119               size=wx.Size(0, 24), style=wx.TE_READONLY)
   118         
   120         
   119         self.SyncManagersLabel =  wx.StaticText(id=ID_NODEEDITORSYNCMANAGERSLABEL,
   121         self.SyncManagersLabel =  wx.StaticText(id=ID_NODEEDITORSYNCMANAGERSLABEL,
   120               label=_('Sync managers:'), name='SyncManagersLabel', parent=self.ConfNodeEditor,
   122               label=_('Sync managers:'), name='SyncManagersLabel', parent=self.EthercatNodeEditor,
   121               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
   123               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
   122         
   124         
   123         self.SyncManagersGrid = CustomGrid(id=ID_NODEEDITORSYNCMANAGERSGRID,
   125         self.SyncManagersGrid = CustomGrid(id=ID_NODEEDITORSYNCMANAGERSGRID,
   124               name='SyncManagersGrid', parent=self.ConfNodeEditor, pos=wx.Point(0, 0), 
   126               name='SyncManagersGrid', parent=self.EthercatNodeEditor, pos=wx.Point(0, 0), 
   125               size=wx.Size(0, 200), style=wx.VSCROLL)
   127               size=wx.Size(0, 200), style=wx.VSCROLL)
   126         
   128         
   127         self.VariablesLabel =  wx.StaticText(id=ID_NODEEDITORVARIABLESLABEL,
   129         self.VariablesLabel =  wx.StaticText(id=ID_NODEEDITORVARIABLESLABEL,
   128               label=_('Variable entries:'), name='VariablesLabel', parent=self.ConfNodeEditor,
   130               label=_('Variable entries:'), name='VariablesLabel', parent=self.EthercatNodeEditor,
   129               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
   131               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
   130         
   132         
   131         self.VariablesGrid = wx.gizmos.TreeListCtrl(id=ID_NODEEDITORVARIABLESGRID,
   133         self.VariablesGrid = wx.gizmos.TreeListCtrl(id=ID_NODEEDITORVARIABLESGRID,
   132               name='VariablesGrid', parent=self.ConfNodeEditor, pos=wx.Point(0, 0), 
   134               name='VariablesGrid', parent=self.EthercatNodeEditor, pos=wx.Point(0, 0), 
   133               size=wx.Size(0, 400), style=wx.TR_DEFAULT_STYLE |
   135               size=wx.Size(0, 400), style=wx.TR_DEFAULT_STYLE |
   134                                           wx.TR_ROW_LINES |
   136                                           wx.TR_ROW_LINES |
   135                                           wx.TR_COLUMN_LINES |
   137                                           wx.TR_COLUMN_LINES |
   136                                           wx.TR_HIDE_ROOT |
   138                                           wx.TR_HIDE_ROOT |
   137                                           wx.TR_FULL_ROW_HIGHLIGHT)
   139                                           wx.TR_FULL_ROW_HIGHLIGHT)
   138         self.VariablesGrid.GetMainWindow().Bind(wx.EVT_LEFT_DOWN, self.OnVariablesGridLeftClick)
   140         self.VariablesGrid.GetMainWindow().Bind(wx.EVT_LEFT_DOWN, self.OnVariablesGridLeftClick)
   139                 
   141                 
   140         self._init_sizers()
   142         self._init_sizers()
       
   143     
       
   144         return self.EthercatNodeEditor
   141     
   145     
   142     def __init__(self, parent, controler, window):
   146     def __init__(self, parent, controler, window):
   143         ConfTreeNodeEditor.__init__(self, parent, controler, window)
   147         ConfTreeNodeEditor.__init__(self, parent, controler, window)
   144     
   148     
   145         self.SyncManagersTable = SyncManagersTable(self, [], GetSyncManagersTableColnames())
   149         self.SyncManagersTable = SyncManagersTable(self, [], GetSyncManagersTableColnames())
   257                 dragSource.DoDragDrop()
   261                 dragSource.DoDragDrop()
   258                 return
   262                 return
   259             
   263             
   260         event.Skip()
   264         event.Skip()
   261 
   265 
   262     def OnConfNodeEditorResize(self, event):
   266     def OnEthercatNodeEditorResize(self, event):
   263         self.ConfNodeEditor.GetBestSize()
   267         self.EthercatNodeEditor.GetBestSize()
   264         xstart, ystart = self.ConfNodeEditor.GetViewStart()
   268         xstart, ystart = self.EthercatNodeEditor.GetViewStart()
   265         window_size = self.ConfNodeEditor.GetClientSize()
   269         window_size = self.EthercatNodeEditor.GetClientSize()
   266         maxx, maxy = self.ConfNodeEditor.GetMinSize()
   270         maxx, maxy = self.EthercatNodeEditor.GetMinSize()
   267         posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
   271         posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
   268         posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
   272         posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
   269         self.ConfNodeEditor.Scroll(posx, posy)
   273         self.EthercatNodeEditor.Scroll(posx, posy)
   270         self.ConfNodeEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
   274         self.EthercatNodeEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
   271                 maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
   275                 maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
   272         event.Skip()
   276         event.Skip()
   273 
   277 
   274 CIA402NodeEditor = NodeEditor
   278 CIA402NodeEditor = NodeEditor