94 message.ShowModal() |
94 message.ShowModal() |
95 message.Destroy() |
95 message.Destroy() |
96 else: |
96 else: |
97 self.EndModal(wx.ID_OK) |
97 self.EndModal(wx.ID_OK) |
98 |
98 |
|
99 def GetSyncManagersTableColnames(): |
|
100 _ = lambda x : x |
|
101 return ["#", _("Name"), _("Start Address"), _("Default Size"), _("Control Byte"), _("Enable")] |
|
102 |
|
103 class SyncManagersTable(CustomTable): |
|
104 |
|
105 def GetValue(self, row, col): |
|
106 if row < self.GetNumberRows(): |
|
107 if col == 0: |
|
108 return row |
|
109 return self.data[row].get(self.GetColLabelValue(col, False), "") |
99 |
110 |
100 def GetVariablesTableColnames(): |
111 def GetVariablesTableColnames(): |
101 _ = lambda x : x |
112 _ = lambda x : x |
102 return ["#", _("Index"), _("SubIndex"), _("Name"), _("Type"), _("PDO index"), _("PDO name"), _("PDO type")] |
113 return ["#", _("Index"), _("SubIndex"), _("Name"), _("Type"), _("PDO index"), _("PDO name"), _("PDO type")] |
103 |
|
104 class PDOsTable(CustomTable): |
|
105 |
|
106 def GetValue(self, row, col): |
|
107 if row < self.GetNumberRows(): |
|
108 if col == 0: |
|
109 return row + 1 |
|
110 colname = self.GetColLabelValue(col, False) |
|
111 value = self.data[row].get(colname, "") |
|
112 if colname == "Type": |
|
113 value = _(value) |
|
114 return value |
|
115 |
114 |
116 class VariablesTable(CustomTable): |
115 class VariablesTable(CustomTable): |
117 |
116 |
118 def GetValue(self, row, col): |
117 def GetValue(self, row, col): |
119 if row < self.GetNumberRows(): |
118 if row < self.GetNumberRows(): |
120 if col == 0: |
119 if col == 0: |
121 return row + 1 |
120 return row + 1 |
122 return self.data[row].get(self.GetColLabelValue(col, False), "") |
121 return self.data[row].get(self.GetColLabelValue(col, False), "") |
|
122 |
|
123 def _updateColAttrs(self, grid): |
|
124 """ |
|
125 wx.grid.Grid -> update the column attributes to add the |
|
126 appropriate renderer given the column name. |
|
127 |
|
128 Otherwise default to the default renderer. |
|
129 """ |
|
130 for row in range(self.GetNumberRows()): |
|
131 row_highlights = self.Highlights.get(row, {}) |
|
132 access = self.GetValueByName(row, "Access") |
|
133 for col in range(self.GetNumberCols()): |
|
134 colname = self.GetColLabelValue(col, False) |
|
135 |
|
136 if colname in ["PDO index", "PDO name", "PDO type"] and access == "": |
|
137 highlight_colours = (wx.LIGHT_GREY, wx.WHITE) |
|
138 else: |
|
139 highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1] |
|
140 grid.SetReadOnly(row, col, True) |
|
141 grid.SetCellEditor(row, col, None) |
|
142 grid.SetCellRenderer(row, col, None) |
|
143 |
|
144 grid.SetCellBackgroundColour(row, col, highlight_colours[0]) |
|
145 grid.SetCellTextColour(row, col, highlight_colours[1]) |
|
146 self.ResizeRow(grid, row) |
123 |
147 |
124 [ID_SLAVEPANEL, ID_SLAVEPANELTYPELABEL, |
148 [ID_SLAVEPANEL, ID_SLAVEPANELTYPELABEL, |
125 ID_SLAVEPANELTYPE, ID_SLAVEPANELTYPEBROWSE, |
149 ID_SLAVEPANELTYPE, ID_SLAVEPANELTYPEBROWSE, |
126 ID_SLAVEPANELALIASLABEL, ID_SLAVEPANELALIAS, |
150 ID_SLAVEPANELALIASLABEL, ID_SLAVEPANELALIAS, |
127 ID_SLAVEPANELPOSLABEL, ID_SLAVEPANELPOS, |
151 ID_SLAVEPANELPOSLABEL, ID_SLAVEPANELPOS, |
128 ID_SLAVEPANELSLAVEINFOSSTATICBOX, ID_SLAVEPANELVENDORLABEL, |
152 ID_SLAVEPANELSLAVEINFOSSTATICBOX, ID_SLAVEPANELVENDORLABEL, |
129 ID_SLAVEPANELVENDOR, ID_SLAVEPANELPRODUCTCODELABEL, |
153 ID_SLAVEPANELVENDOR, ID_SLAVEPANELPRODUCTCODELABEL, |
130 ID_SLAVEPANELPRODUCTCODE, ID_SLAVEPANELREVISIONNUMBERLABEL, |
154 ID_SLAVEPANELPRODUCTCODE, ID_SLAVEPANELREVISIONNUMBERLABEL, |
131 ID_SLAVEPANELREVISIONNUMBER, ID_SLAVEPANELPHYSICSLABEL, |
155 ID_SLAVEPANELREVISIONNUMBER, ID_SLAVEPANELPHYSICSLABEL, |
132 ID_SLAVEPANELPHYSICS, ID_SLAVEPANELPDOSLABEL, |
156 ID_SLAVEPANELPHYSICS, ID_SLAVEPANELSYNCMANAGERSLABEL, |
133 ID_SLAVEPANELPDOSGRID, ID_SLAVEPANELVARIABLESLABEL, |
157 ID_SLAVEPANELSYNCMANAGERSGRID, ID_SLAVEPANELVARIABLESLABEL, |
134 ID_SLAVEPANELVARIABLESGRID, |
158 ID_SLAVEPANELVARIABLESGRID, |
135 ] = [wx.NewId() for _init_ctrls in range(21)] |
159 ] = [wx.NewId() for _init_ctrls in range(21)] |
136 |
160 |
137 class SlavePanel(wx.Panel): |
161 class SlavePanel(wx.Panel): |
138 |
162 |
172 def _init_coll_SlaveInfosBoxSizer_Items(self, parent): |
196 def _init_coll_SlaveInfosBoxSizer_Items(self, parent): |
173 parent.AddSizer(self.SlaveInfosSizer, 1, border=5, flag=wx.GROW|wx.ALL) |
197 parent.AddSizer(self.SlaveInfosSizer, 1, border=5, flag=wx.GROW|wx.ALL) |
174 |
198 |
175 def _init_coll_SlaveInfosSizer_Items(self, parent): |
199 def _init_coll_SlaveInfosSizer_Items(self, parent): |
176 parent.AddSizer(self.SlaveInfosDetailsSizer, 0, border=0, flag=wx.GROW) |
200 parent.AddSizer(self.SlaveInfosDetailsSizer, 0, border=0, flag=wx.GROW) |
|
201 parent.AddWindow(self.SyncManagersLabel, 0, border=0, flag=wx.GROW) |
|
202 parent.AddWindow(self.SyncManagersGrid, 0, border=0, flag=wx.GROW) |
177 parent.AddWindow(self.VariablesLabel, 0, border=0, flag=wx.GROW) |
203 parent.AddWindow(self.VariablesLabel, 0, border=0, flag=wx.GROW) |
178 parent.AddWindow(self.VariablesGrid, 0, border=0, flag=wx.GROW) |
204 parent.AddWindow(self.VariablesGrid, 0, border=0, flag=wx.GROW) |
179 |
205 |
180 def _init_coll_SlaveInfosSizer_Growables(self, parent): |
206 def _init_coll_SlaveInfosSizer_Growables(self, parent): |
181 parent.AddGrowableCol(0) |
207 parent.AddGrowableCol(0) |
182 parent.AddGrowableRow(2) |
208 parent.AddGrowableRow(2, 1) |
|
209 parent.AddGrowableRow(4, 2) |
183 |
210 |
184 def _init_coll_SlaveInfosDetailsSizer_Items(self, parent): |
211 def _init_coll_SlaveInfosDetailsSizer_Items(self, parent): |
185 parent.AddWindow(self.VendorLabel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.GROW) |
212 parent.AddWindow(self.VendorLabel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.GROW) |
186 parent.AddWindow(self.Vendor, 0, border=0, flag=wx.GROW) |
213 parent.AddWindow(self.Vendor, 0, border=0, flag=wx.GROW) |
187 parent.AddWindow(self.ProductCodeLabel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.GROW) |
214 parent.AddWindow(self.ProductCodeLabel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.GROW) |
198 def _init_sizers(self): |
225 def _init_sizers(self): |
199 self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
226 self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
200 self.PositionSizer = wx.FlexGridSizer(cols=6, hgap=5, rows=1, vgap=0) |
227 self.PositionSizer = wx.FlexGridSizer(cols=6, hgap=5, rows=1, vgap=0) |
201 self.TypeSizer = wx.BoxSizer(wx.HORIZONTAL) |
228 self.TypeSizer = wx.BoxSizer(wx.HORIZONTAL) |
202 self.SlaveInfosBoxSizer = wx.StaticBoxSizer(self.SlaveInfosStaticBox, wx.VERTICAL) |
229 self.SlaveInfosBoxSizer = wx.StaticBoxSizer(self.SlaveInfosStaticBox, wx.VERTICAL) |
203 self.SlaveInfosSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=5) |
230 self.SlaveInfosSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=5, vgap=5) |
204 self.SlaveInfosDetailsSizer = wx.FlexGridSizer(cols=4, hgap=5, rows=2, vgap=5) |
231 self.SlaveInfosDetailsSizer = wx.FlexGridSizer(cols=4, hgap=5, rows=2, vgap=5) |
205 |
232 |
206 self._init_coll_MainSizer_Growables(self.MainSizer) |
233 self._init_coll_MainSizer_Growables(self.MainSizer) |
207 self._init_coll_MainSizer_Items(self.MainSizer) |
234 self._init_coll_MainSizer_Items(self.MainSizer) |
208 self._init_coll_PositionSizer_Growables(self.PositionSizer) |
235 self._init_coll_PositionSizer_Growables(self.PositionSizer) |
285 |
312 |
286 self.Physics = wx.TextCtrl(id=ID_SLAVEPANELPHYSICS, value='', |
313 self.Physics = wx.TextCtrl(id=ID_SLAVEPANELPHYSICS, value='', |
287 name='Physics', parent=self, pos=wx.Point(0, 0), |
314 name='Physics', parent=self, pos=wx.Point(0, 0), |
288 size=wx.Size(0, 24), style=wx.TE_READONLY) |
315 size=wx.Size(0, 24), style=wx.TE_READONLY) |
289 |
316 |
|
317 self.SyncManagersLabel = wx.StaticText(id=ID_SLAVEPANELSYNCMANAGERSLABEL, |
|
318 label=_('Sync managers:'), name='SyncManagersLabel', parent=self, |
|
319 pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
|
320 |
|
321 self.SyncManagersGrid = CustomGrid(id=ID_SLAVEPANELSYNCMANAGERSGRID, |
|
322 name='SyncManagersGrid', parent=self, pos=wx.Point(0, 0), |
|
323 size=wx.Size(0, 0), style=wx.VSCROLL) |
|
324 |
290 self.VariablesLabel = wx.StaticText(id=ID_SLAVEPANELVARIABLESLABEL, |
325 self.VariablesLabel = wx.StaticText(id=ID_SLAVEPANELVARIABLESLABEL, |
291 label=_('Variable entries:'), name='VariablesLabel', parent=self, |
326 label=_('Variable entries:'), name='VariablesLabel', parent=self, |
292 pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
327 pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
293 |
328 |
294 self.VariablesGrid = CustomGrid(id=ID_SLAVEPANELPDOSGRID, |
329 self.VariablesGrid = CustomGrid(id=ID_SLAVEPANELVARIABLESGRID, |
295 name='PDOsGrid', parent=self, pos=wx.Point(0, 0), |
330 name='VariablesGrid', parent=self, pos=wx.Point(0, 0), |
296 size=wx.Size(0, 0), style=wx.VSCROLL) |
331 size=wx.Size(0, 0), style=wx.VSCROLL) |
297 if wx.VERSION >= (2, 5, 0): |
332 if wx.VERSION >= (2, 5, 0): |
298 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick) |
333 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick) |
299 else: |
334 else: |
300 wx.grid.EVT_GRID_CELL_LEFT_CLICK(self.VariablesGrid, self.OnVariablesGridCellLeftClick) |
335 wx.grid.EVT_GRID_CELL_LEFT_CLICK(self.VariablesGrid, self.OnVariablesGridCellLeftClick) |
305 self._init_ctrls(parent) |
340 self._init_ctrls(parent) |
306 |
341 |
307 self.Controler = controler |
342 self.Controler = controler |
308 self.ParentWindow = window |
343 self.ParentWindow = window |
309 self.Slave = slave |
344 self.Slave = slave |
|
345 |
|
346 self.SyncManagersTable = SyncManagersTable(self, [], GetSyncManagersTableColnames()) |
|
347 self.SyncManagersGrid.SetTable(self.SyncManagersTable) |
|
348 self.SyncManagersGridColAlignements = [wx.ALIGN_RIGHT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, |
|
349 wx.ALIGN_RIGHT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT] |
|
350 self.SyncManagersGridColSizes = [40, 150, 100, 100, 100, 100] |
|
351 self.SyncManagersGrid.SetRowLabelSize(0) |
|
352 for col in range(self.SyncManagersTable.GetNumberCols()): |
|
353 attr = wx.grid.GridCellAttr() |
|
354 attr.SetAlignment(self.SyncManagersGridColAlignements[col], wx.ALIGN_CENTRE) |
|
355 self.SyncManagersGrid.SetColAttr(col, attr) |
|
356 self.SyncManagersGrid.SetColMinimalWidth(col, self.SyncManagersGridColSizes[col]) |
|
357 self.SyncManagersGrid.AutoSizeColumn(col, False) |
310 |
358 |
311 self.VariablesTable = VariablesTable(self, [], GetVariablesTableColnames()) |
359 self.VariablesTable = VariablesTable(self, [], GetVariablesTableColnames()) |
312 self.VariablesGrid.SetTable(self.VariablesTable) |
360 self.VariablesGrid.SetTable(self.VariablesTable) |
313 self.VariablesGridColAlignements = [wx.ALIGN_RIGHT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT, |
361 self.VariablesGridColAlignements = [wx.ALIGN_RIGHT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT, |
314 wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, |
362 wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, |
392 wx.CallAfter(self.ParentWindow.RefreshParentWindow) |
442 wx.CallAfter(self.ParentWindow.RefreshParentWindow) |
393 dialog.Destroy() |
443 dialog.Destroy() |
394 event.Skip() |
444 event.Skip() |
395 |
445 |
396 def OnVariablesGridCellLeftClick(self, event): |
446 def OnVariablesGridCellLeftClick(self, event): |
397 if event.GetCol() == 0: |
447 row = event.GetRow() |
398 row = event.GetRow() |
448 |
399 data_type = self.VariablesTable.GetValueByName(row, "Type") |
449 data_type = self.VariablesTable.GetValueByName(row, "Type") |
400 var_name = self.VariablesTable.GetValueByName(row, "Name") |
450 access = self.VariablesTable.GetValueByName(row, "Access") |
|
451 if (event.GetCol() == 0 and access != "" and |
|
452 self.Controler.GetSizeOfType(data_type) is not None): |
|
453 |
401 entry_index = self.Controler.ExtractHexDecValue(self.VariablesTable.GetValueByName(row, "Index")) |
454 entry_index = self.Controler.ExtractHexDecValue(self.VariablesTable.GetValueByName(row, "Index")) |
402 entry_subindex = self.VariablesTable.GetValueByName(row, "SubIndex") |
455 entry_subindex = self.Controler.ExtractHexDecValue(self.VariablesTable.GetValueByName(row, "SubIndex")) |
403 if self.VariablesTable.GetValueByName(row, "PDO type") == "Transmit": |
456 var_name = "%s_%4.4x_%2.2x" % (self.Type.GetValue(), entry_index, entry_subindex) |
|
457 if access in ["ro"]: |
404 dir = "%I" |
458 dir = "%I" |
405 else: |
459 else: |
406 dir = "%Q" |
460 dir = "%Q" |
407 location = "%s%s" % (dir, self.Controler.GetSizeOfType(data_type)) + \ |
461 location = "%s%s" % (dir, self.Controler.GetSizeOfType(data_type)) + \ |
408 ".".join(map(lambda x:str(x), self.Controler.GetCurrentLocation() + self.Slave + (entry_index, entry_subindex))) |
462 ".".join(map(lambda x:str(x), self.Controler.GetCurrentLocation() + self.Slave + (entry_index, entry_subindex))) |
|
463 |
409 data = wx.TextDataObject(str((location, "location", data_type, var_name, ""))) |
464 data = wx.TextDataObject(str((location, "location", data_type, var_name, ""))) |
410 dragSource = wx.DropSource(self.VariablesGrid) |
465 dragSource = wx.DropSource(self.VariablesGrid) |
411 dragSource.SetData(data) |
466 dragSource.SetData(data) |
412 dragSource.DoDragDrop() |
467 dragSource.DoDragDrop() |
|
468 |
413 event.Skip() |
469 event.Skip() |
414 |
470 |
415 [ID_CONFIGEDITOR, ID_CONFIGEDITORADDSLAVEBUTTON, |
471 [ID_CONFIGEDITOR, ID_CONFIGEDITORADDSLAVEBUTTON, |
416 ID_CONFIGEDITORDELETESLAVEBUTTON, ID_CONFIGEDITORSLAVENODES, |
472 ID_CONFIGEDITORDELETESLAVEBUTTON, ID_CONFIGEDITORSLAVENODES, |
417 ] = [wx.NewId() for _init_ctrls in range(4)] |
473 ] = [wx.NewId() for _init_ctrls in range(4)] |