00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 from wxPython.wx import *
00025 from wxPython.grid import *
00026 import wx
00027 import wx.grid
00028
00029 from types import *
00030
00031 from node import OD_Subindex, OD_MultipleSubindexes, OD_IdenticalSubindexes, OD_IdenticalIndexes
00032
00033 ColSizes = [75, 250, 150, 125, 100, 60, 250]
00034 ColAlignements = [wxALIGN_CENTER, wxALIGN_LEFT, wxALIGN_CENTER, wxALIGN_RIGHT, wxALIGN_CENTER, wxALIGN_CENTER, wxALIGN_LEFT]
00035 AccessList = "Read Only,Write Only,Read/Write"
00036 RAccessList = "Read Only,Read/Write"
00037 BoolList = "True,False"
00038 OptionList = "Yes,No"
00039
00040 DictionaryOrganisation = [
00041 {"minIndex" : 0x0001, "maxIndex" : 0x0FFF, "name" : "Data Type Definitions"},
00042 {"minIndex" : 0x1000, "maxIndex" : 0x1029, "name" : "Communication Parameters"},
00043 {"minIndex" : 0x1200, "maxIndex" : 0x12FF, "name" : "SDO Parameters"},
00044 {"minIndex" : 0x1400, "maxIndex" : 0x15FF, "name" : "Receive PDO Parameters"},
00045 {"minIndex" : 0x1600, "maxIndex" : 0x17FF, "name" : "Receive PDO Mapping"},
00046 {"minIndex" : 0x1800, "maxIndex" : 0x19FF, "name" : "Transmit PDO Parameters"},
00047 {"minIndex" : 0x1A00, "maxIndex" : 0x1BFF, "name" : "Transmit PDO Mapping"},
00048 {"minIndex" : 0x1C00, "maxIndex" : 0x1FFF, "name" : "Other Communication Parameters"},
00049 {"minIndex" : 0x2000, "maxIndex" : 0x5FFF, "name" : "Manufacturer Specific"},
00050 {"minIndex" : 0x6000, "maxIndex" : 0x9FFF, "name" : "Standardized Device Profile"},
00051 {"minIndex" : 0xA000, "maxIndex" : 0xBFFF, "name" : "Standardized Interface Profile"}]
00052
00053 class SubindexTable(wxPyGridTableBase):
00054
00055 """
00056 A custom wxGrid Table using user supplied data
00057 """
00058 def __init__(self, parent, data, editors, colnames):
00059
00060 wxPyGridTableBase.__init__(self)
00061 self.datadata = data
00062 self.editorseditors = editors
00063 self.CurrentIndexCurrentIndex = 0
00064 self.colnamescolnames = colnames
00065 self.ParentParent = parent
00066 self.EditableEditable = True
00067
00068
00069
00070 self._rows_rows = self.GetNumberRowsGetNumberRows()
00071 self._cols_cols = self.GetNumberColsGetNumberCols()
00072
00073 def Disable(self):
00074 self.EditableEditable = False
00075
00076 def Enable(self):
00077 self.EditableEditable = True
00078
00079 def GetNumberCols(self):
00080 return len(self.colnamescolnames)
00081
00082 def GetNumberRows(self):
00083 return len(self.datadata)
00084
00085 def GetColLabelValue(self, col):
00086 if col < len(self.colnamescolnames):
00087 return self.colnamescolnames[col]
00088
00089 def GetRowLabelValues(self, row):
00090 return row
00091
00092 def GetValue(self, row, col):
00093 if row < self.GetNumberRowsGetNumberRows():
00094 value = self.datadata[row].get(self.GetColLabelValueGetColLabelValue(col), "")
00095 if (type(value) == UnicodeType):
00096 return value
00097 else:
00098 return str(value)
00099
00100 def GetEditor(self, row, col):
00101 if row < self.GetNumberRowsGetNumberRows():
00102 return self.editorseditors[row].get(self.GetColLabelValueGetColLabelValue(col), "")
00103
00104 def GetValueByName(self, row, colname):
00105 return self.datadata[row].get(colname)
00106
00107 def SetValue(self, row, col, value):
00108 if col < len(self.colnamescolnames):
00109 self.datadata[row][self.GetColLabelValueGetColLabelValue(col)] = value
00110
00111 def ResetView(self, grid):
00112 """
00113 (wxGrid) -> Reset the grid view. Call this to
00114 update the grid if rows and columns have been added or deleted
00115 """
00116 grid.BeginBatch()
00117 for current, new, delmsg, addmsg in [
00118 (self._rows_rows, self.GetNumberRowsGetNumberRows(), wxGRIDTABLE_NOTIFY_ROWS_DELETED, wxGRIDTABLE_NOTIFY_ROWS_APPENDED),
00119 (self._cols_cols, self.GetNumberColsGetNumberCols(), wxGRIDTABLE_NOTIFY_COLS_DELETED, wxGRIDTABLE_NOTIFY_COLS_APPENDED),
00120 ]:
00121 if new < current:
00122 msg = wxGridTableMessage(self,delmsg,new,current-new)
00123 grid.ProcessTableMessage(msg)
00124 elif new > current:
00125 msg = wxGridTableMessage(self,addmsg,new-current)
00126 grid.ProcessTableMessage(msg)
00127 self.UpdateValuesUpdateValues(grid)
00128 grid.EndBatch()
00129
00130 self._rows_rows = self.GetNumberRowsGetNumberRows()
00131 self._cols_cols = self.GetNumberColsGetNumberCols()
00132
00133 self._updateColAttrs_updateColAttrs(grid)
00134
00135
00136 grid.AdjustScrollbars()
00137 grid.ForceRefresh()
00138
00139
00140 def UpdateValues(self, grid):
00141 """Update all displayed values"""
00142
00143 msg = wxGridTableMessage(self, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES)
00144 grid.ProcessTableMessage(msg)
00145
00146 def _updateColAttrs(self, grid):
00147 """
00148 wxGrid -> update the column attributes to add the
00149 appropriate renderer given the column name.
00150
00151 Otherwise default to the default renderer.
00152 """
00153
00154 for col in range(self.GetNumberColsGetNumberCols()):
00155 attr = wxGridCellAttr()
00156 attr.SetAlignment(ColAlignements[col], wxALIGN_CENTRE)
00157 grid.SetColAttr(col, attr)
00158 grid.SetColSize(col, ColSizes[col])
00159
00160 typelist = None
00161 maplist = None
00162 for row in range(self.GetNumberRowsGetNumberRows()):
00163 editors = self.editorseditors[row]
00164 for col in range(self.GetNumberColsGetNumberCols()):
00165 editor = None
00166 renderer = None
00167
00168 colname = self.GetColLabelValueGetColLabelValue(col)
00169 editortype = editors[colname]
00170 if editortype and self.EditableEditable:
00171 grid.SetReadOnly(row, col, False)
00172 if editortype == "string":
00173 editor = wxGridCellTextEditor()
00174 renderer = wxGridCellStringRenderer()
00175 if colname == "value" and "length" in editors:
00176 editor.SetParameters(editors["length"])
00177 elif editortype == "number":
00178 editor = wxGridCellNumberEditor()
00179 renderer = wxGridCellNumberRenderer()
00180 if colname == "value" and "min" in editors and "max" in editors:
00181 editor.SetParameters("%s,%s"%(editors["min"],editors["max"]))
00182 elif editortype == "real":
00183 editor = wxGridCellFloatEditor()
00184 renderer = wxGridCellFloatRenderer()
00185 if colname == "value" and "min" in editors and "max" in editors:
00186 editor.SetParameters("%s,%s"%(editors["min"],editors["max"]))
00187 elif editortype == "bool":
00188 editor = wxGridCellChoiceEditor()
00189 editor.SetParameters(BoolList)
00190 elif editortype == "access":
00191 editor = wxGridCellChoiceEditor()
00192 editor.SetParameters(AccessList)
00193 elif editortype == "raccess":
00194 editor = wxGridCellChoiceEditor()
00195 editor.SetParameters(RAccessList)
00196 elif editortype == "option":
00197 editor = wxGridCellChoiceEditor()
00198 editor.SetParameters(OptionList)
00199 elif editortype == "type":
00200 editor = wxGridCellChoiceEditor()
00201 if typelist == None:
00202 typelist = self.ParentParent.Manager.GetCurrentTypeList()
00203 editor.SetParameters(typelist)
00204 elif editortype == "map":
00205 editor = wxGridCellChoiceEditor()
00206 if maplist == None:
00207 maplist = self.ParentParent.Manager.GetCurrentMapList()
00208 editor.SetParameters(maplist)
00209 elif editortype == "time":
00210 editor = wxGridCellTextEditor()
00211 renderer = wxGridCellStringRenderer()
00212 elif editortype == "domain":
00213 editor = wxGridCellTextEditor()
00214 renderer = wxGridCellStringRenderer()
00215 else:
00216 grid.SetReadOnly(row, col, True)
00217
00218 grid.SetCellEditor(row, col, editor)
00219 grid.SetCellRenderer(row, col, renderer)
00220
00221 grid.SetCellBackgroundColour(row, col, wxWHITE)
00222
00223 def SetData(self, data):
00224 self.datadata = data
00225
00226 def SetEditors(self, editors):
00227 self.editorseditors = editors
00228
00229 def GetCurrentIndex(self):
00230 return self.CurrentIndexCurrentIndex
00231
00232 def SetCurrentIndex(self, index):
00233 self.CurrentIndexCurrentIndex = index
00234
00235 def AppendRow(self, row_content):
00236 self.datadata.append(row_content)
00237
00238 def Empty(self):
00239 self.datadata = []
00240 self.editorseditors = []
00241
00242 [wxID_EDITINGPANEL, wxID_EDITINGPANELADDBUTTON, wxID_EDITINGPANELINDEXCHOICE,
00243 wxID_EDITINGPANELINDEXLIST, wxID_EDITINGPANELINDEXLISTPANEL, wxID_EDITINGPANELPARTLIST,
00244 wxID_EDITINGPANELSECONDSPLITTER, wxID_EDITINGPANELSUBINDEXGRID,
00245 wxID_EDITINGPANELSUBINDEXGRIDPANEL, wxID_EDITINGPANELCALLBACKCHECK,
00246 ] = [wx.NewId() for _init_ctrls in range(10)]
00247
00248 [wxID_EDITINGPANELINDEXLISTMENUITEMS0, wxID_EDITINGPANELINDEXLISTMENUITEMS1,
00249 wxID_EDITINGPANELINDEXLISTMENUITEMS2,
00250 ] = [wx.NewId() for _init_coll_IndexListMenu_Items in range(3)]
00251
00252 [wxID_EDITINGPANELMENU1ITEMS0, wxID_EDITINGPANELMENU1ITEMS1,
00253 ] = [wx.NewId() for _init_coll_SubindexGridMenu_Items in range(2)]
00254
00255 class EditingPanel(wx.SplitterWindow):
00256 def _init_coll_AddToListSizer_Items(self, parent):
00257
00258
00259 parent.AddWindow(self.AddButtonAddButton, 0, border=0, flag=0)
00260 parent.AddWindow(self.IndexChoiceIndexChoice, 0, border=0, flag=wxGROW)
00261
00262 def _init_coll_SubindexGridSizer_Items(self, parent):
00263
00264
00265 parent.AddWindow(self.CallbackCheckCallbackCheck, 0, border=0, flag=0)
00266 parent.AddWindow(self.SubindexGridSubindexGrid, 0, border=0, flag=wxGROW)
00267
00268 def _init_coll_IndexListSizer_Items(self, parent):
00269
00270
00271 parent.AddWindow(self.IndexListIndexList, 0, border=0, flag=wxGROW)
00272 parent.AddSizer(self.AddToListSizer, 0, border=0, flag=wxGROW)
00273
00274 def _init_coll_AddToListSizer_Growables(self, parent):
00275
00276
00277 parent.AddGrowableCol(1)
00278
00279 def _init_coll_SubindexGridSizer_Growables(self, parent):
00280
00281
00282 parent.AddGrowableCol(0)
00283 parent.AddGrowableRow(1)
00284
00285 def _init_coll_IndexListSizer_Growables(self, parent):
00286
00287
00288 parent.AddGrowableCol(0)
00289 parent.AddGrowableRow(0)
00290
00291 def _init_coll_SubindexGridMenu_Items(self, parent):
00292
00293
00294 parent.Append(help='', id=wxID_EDITINGPANELMENU1ITEMS0,
00295 kind=wx.ITEM_NORMAL, text='Add')
00296 parent.Append(help='', id=wxID_EDITINGPANELMENU1ITEMS1,
00297 kind=wx.ITEM_NORMAL, text='Delete')
00298 self.Bind(wx.EVT_MENU, self.OnAddSubindexMenuOnAddSubindexMenu,
00299 id=wxID_EDITINGPANELMENU1ITEMS0)
00300 self.Bind(wx.EVT_MENU, self.OnDeleteSubindexMenuOnDeleteSubindexMenu,
00301 id=wxID_EDITINGPANELMENU1ITEMS1)
00302
00303 def _init_coll_IndexListMenu_Items(self, parent):
00304
00305
00306 parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS0,
00307 kind=wx.ITEM_NORMAL, text='Rename')
00308 parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS2,
00309 kind=wx.ITEM_NORMAL, text='Modify')
00310 parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS1,
00311 kind=wx.ITEM_NORMAL, text='Delete')
00312 self.Bind(wx.EVT_MENU, self.OnRenameIndexMenuOnRenameIndexMenu,
00313 id=wxID_EDITINGPANELINDEXLISTMENUITEMS0)
00314 self.Bind(wx.EVT_MENU, self.OnDeleteIndexMenuOnDeleteIndexMenu,
00315 id=wxID_EDITINGPANELINDEXLISTMENUITEMS1)
00316 self.Bind(wx.EVT_MENU, self.OnModifyIndexMenuOnModifyIndexMenu,
00317 id=wxID_EDITINGPANELINDEXLISTMENUITEMS2)
00318
00319 def _init_utils(self):
00320
00321 self.IndexListMenu = wx.Menu(title='')
00322
00323 self.SubindexGridMenu = wx.Menu(title='')
00324
00325 self._init_coll_IndexListMenu_Items_init_coll_IndexListMenu_Items(self.IndexListMenu)
00326 self._init_coll_SubindexGridMenu_Items_init_coll_SubindexGridMenu_Items(self.SubindexGridMenu)
00327
00328 def _init_sizers(self):
00329
00330 self.IndexListSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
00331
00332 self.SubindexGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
00333
00334 self.AddToListSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0)
00335
00336 self._init_coll_IndexListSizer_Growables_init_coll_IndexListSizer_Growables(self.IndexListSizer)
00337 self._init_coll_IndexListSizer_Items_init_coll_IndexListSizer_Items(self.IndexListSizer)
00338 self._init_coll_SubindexGridSizer_Growables_init_coll_SubindexGridSizer_Growables(self.SubindexGridSizer)
00339 self._init_coll_SubindexGridSizer_Items_init_coll_SubindexGridSizer_Items(self.SubindexGridSizer)
00340 self._init_coll_AddToListSizer_Growables_init_coll_AddToListSizer_Growables(self.AddToListSizer)
00341 self._init_coll_AddToListSizer_Items_init_coll_AddToListSizer_Items(self.AddToListSizer)
00342
00343 self.SubindexGridPanelSubindexGridPanel.SetSizer(self.SubindexGridSizer)
00344 self.IndexListPanelIndexListPanel.SetSizer(self.IndexListSizer)
00345
00346 def _init_ctrls(self, prnt):
00347 wx.SplitterWindow.__init__(self, id=wxID_EDITINGPANEL,
00348 name='MainSplitter', parent=prnt, point=wx.Point(0, 0),
00349 size=wx.Size(-1, -1), style=wx.SP_3D)
00350 self._init_utils_init_utils()
00351 self.SetNeedUpdating(True)
00352 self.SetMinimumPaneSize(1)
00353
00354 self.PartListPartList = wx.ListBox(choices=[], id=wxID_EDITINGPANELPARTLIST,
00355 name='PartList', parent=self, pos=wx.Point(0, 0),
00356 size=wx.Size(-1, -1), style=0)
00357 self.PartListPartList.Bind(wx.EVT_LISTBOX, self.OnPartListBoxClickOnPartListBoxClick,
00358 id=wxID_EDITINGPANELPARTLIST)
00359
00360 self.SecondSplitterSecondSplitter = wx.SplitterWindow(id=wxID_EDITINGPANELSECONDSPLITTER,
00361 name='SecondSplitter', parent=self, point=wx.Point(0,
00362 0), size=wx.Size(-1, -1), style=wx.SP_3D)
00363 self.SecondSplitterSecondSplitter.SetMinimumPaneSize(1)
00364 self.SplitHorizontally(self.PartListPartList, self.SecondSplitterSecondSplitter,
00365 110)
00366
00367 self.SubindexGridPanelSubindexGridPanel = wx.Panel(id=wxID_EDITINGPANELSUBINDEXGRIDPANEL,
00368 name='SubindexGridPanel', parent=self.SecondSplitterSecondSplitter, pos=wx.Point(0,
00369 0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL)
00370
00371 self.IndexListPanelIndexListPanel = wx.Panel(id=wxID_EDITINGPANELINDEXLISTPANEL,
00372 name='IndexListPanel', parent=self.SecondSplitterSecondSplitter, pos=wx.Point(0,
00373 0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL)
00374 self.SecondSplitterSecondSplitter.SplitVertically(self.IndexListPanelIndexListPanel,
00375 self.SubindexGridPanelSubindexGridPanel, 280)
00376
00377 self.SubindexGridSubindexGrid = wx.grid.Grid(id=wxID_EDITINGPANELSUBINDEXGRID,
00378 name='SubindexGrid', parent=self.SubindexGridPanelSubindexGridPanel, pos=wx.Point(0,
00379 0), size=wx.Size(-1, -1), style=0)
00380 self.SubindexGridSubindexGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False,
00381 'Sans'))
00382 self.SubindexGridSubindexGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL,
00383 False, 'Sans'))
00384 self.SubindexGridSubindexGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE,
00385 self.OnSubindexGridCellChangeOnSubindexGridCellChange)
00386 self.SubindexGridSubindexGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK,
00387 self.OnSubindexGridRightClickOnSubindexGridRightClick)
00388 self.SubindexGridSubindexGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL,
00389 self.OnSubindexGridSelectCellOnSubindexGridSelectCell)
00390
00391 self.CallbackCheckCallbackCheck = wx.CheckBox(id=wxID_EDITINGPANELCALLBACKCHECK,
00392 label='Have Callbacks', name='CallbackCheck',
00393 parent=self.SubindexGridPanelSubindexGridPanel, pos=wx.Point(0, 0), size=wx.Size(152,
00394 24), style=0)
00395 self.CallbackCheckCallbackCheck.Bind(wx.EVT_CHECKBOX, self.OnCallbackCheckOnCallbackCheck,
00396 id=wxID_EDITINGPANELCALLBACKCHECK)
00397
00398 self.IndexListIndexList = wx.ListBox(choices=[], id=wxID_EDITINGPANELINDEXLIST,
00399 name='IndexList', parent=self.IndexListPanelIndexListPanel, pos=wx.Point(0, 0),
00400 size=wx.Size(-1, -1), style=0)
00401 self.IndexListIndexList.Bind(wx.EVT_LISTBOX, self.OnIndexListClickOnIndexListClick,
00402 id=wxID_EDITINGPANELINDEXLIST)
00403 self.IndexListIndexList.Bind(wx.EVT_RIGHT_UP, self.OnIndexListRightUpOnIndexListRightUp)
00404
00405 self.AddButtonAddButton = wx.Button(id=wxID_EDITINGPANELADDBUTTON, label='Add',
00406 name='AddButton', parent=self.IndexListPanelIndexListPanel, pos=wx.Point(0, 0),
00407 size=wx.Size(50, 30), style=0)
00408 self.AddButtonAddButton.Bind(wx.EVT_BUTTON, self.OnAddButtonClickOnAddButtonClick,
00409 id=wxID_EDITINGPANELADDBUTTON)
00410
00411 self.IndexChoiceIndexChoice = wx.Choice(choices=[], id=wxID_EDITINGPANELINDEXCHOICE,
00412 name='IndexChoice', parent=self.IndexListPanelIndexListPanel, pos=wx.Point(50,
00413 0), size=wx.Size(-1, 30), style=0)
00414
00415 self._init_sizers_init_sizers()
00416
00417 def __init__(self, parent, manager, editable = True):
00418 self._init_ctrls_init_ctrls(parent.GetNoteBook())
00419 self.ParentParent = parent
00420 self.ManagerManager = manager
00421 self.ListIndexListIndex = []
00422 self.ChoiceIndexChoiceIndex = []
00423 self.FirstCallFirstCall = False
00424 self.EditableEditable = editable
00425 self.IndexIndex = None
00426
00427 for values in DictionaryOrganisation:
00428 text = " 0x%04X-0x%04X %s"%(values["minIndex"],values["maxIndex"],values["name"])
00429 self.PartListPartList.Append(text)
00430 self.TableTable = SubindexTable(self, [], [], ["subindex", "name", "type", "value", "access", "save", "comment"])
00431 self.SubindexGridSubindexGrid.SetTable(self.TableTable)
00432 self.SubindexGridSubindexGrid.SetRowLabelSize(0)
00433 self.CallbackCheckCallbackCheck.Disable()
00434 self.TableTable.ResetView(self.SubindexGridSubindexGrid)
00435
00436 if not self.EditableEditable:
00437 self.AddButtonAddButton.Disable()
00438 self.IndexChoiceIndexChoice.Disable()
00439 self.CallbackCheckCallbackCheck.Disable()
00440 self.TableTable.Disable()
00441
00442 def GetIndex(self):
00443 return self.IndexIndex
00444
00445 def SetIndex(self, index):
00446 self.IndexIndex = index
00447
00448 def GetSelection(self):
00449 selected = self.IndexListIndexList.GetSelection()
00450 if selected != wxNOT_FOUND:
00451 index = self.ListIndexListIndex[selected]
00452 subIndex = self.SubindexGridSubindexGrid.GetGridCursorRow()
00453 return index, subIndex
00454 return None
00455
00456 def OnAddButtonClick(self, event):
00457 if self.EditableEditable:
00458 self.SubindexGridSubindexGrid.SetGridCursor(0, 0)
00459 selected = self.IndexChoiceIndexChoice.GetStringSelection()
00460 if selected != "":
00461 if selected == "User Type":
00462 self.ParentParent.AddUserType()
00463 elif selected == "SDO Server":
00464 self.ManagerManager.AddSDOServerToCurrent()
00465 elif selected == "SDO Client":
00466 self.ManagerManager.AddSDOClientToCurrent()
00467 elif selected == "PDO Receive":
00468 self.ManagerManager.AddPDOReceiveToCurrent()
00469 elif selected == "PDO Transmit":
00470 self.ManagerManager.AddPDOTransmitToCurrent()
00471 elif selected == "Map Variable":
00472 self.ParentParent.AddMapVariable()
00473 elif selected in [menu for menu, indexes in self.ManagerManager.GetCurrentSpecificMenu()]:
00474 self.ManagerManager.AddSpecificEntryToCurrent(selected)
00475 else:
00476 index = self.ChoiceIndexChoiceIndex[self.IndexChoiceIndexChoice.GetSelection()]
00477 self.ManagerManager.ManageEntriesOfCurrent([index], [])
00478 self.ParentParent.RefreshBufferState()
00479 self.RefreshIndexListRefreshIndexList()
00480 event.Skip()
00481
00482 def OnPartListBoxClick(self, event):
00483 self.SubindexGridSubindexGrid.SetGridCursor(0, 0)
00484 self.RefreshIndexListRefreshIndexList()
00485 event.Skip()
00486
00487 def OnIndexListClick(self, event):
00488 self.SubindexGridSubindexGrid.SetGridCursor(0, 0)
00489 self.RefreshTableRefreshTable()
00490 event.Skip()
00491
00492 def OnSubindexGridSelectCell(self, event):
00493 wxCallAfter(self.ParentParent.RefreshStatusBar)
00494 event.Skip()
00495
00496
00497
00498
00499
00500 def RefreshIndexList(self):
00501 selected = self.IndexListIndexList.GetSelection()
00502 choice = self.IndexChoiceIndexChoice.GetStringSelection()
00503 choiceindex = self.IndexChoiceIndexChoice.GetSelection()
00504 if selected != wxNOT_FOUND:
00505 selectedindex = self.ListIndexListIndex[selected]
00506 self.IndexListIndexList.Clear()
00507 self.IndexChoiceIndexChoice.Clear()
00508 i = self.PartListPartList.GetSelection()
00509 if i < len(DictionaryOrganisation):
00510 values = DictionaryOrganisation[i]
00511 self.ListIndexListIndex = []
00512 for name, index in self.ManagerManager.GetCurrentValidIndexes(values["minIndex"], values["maxIndex"]):
00513 self.IndexListIndexList.Append("0x%04X %s"%(index, name))
00514 self.ListIndexListIndex.append(index)
00515 if self.EditableEditable:
00516 self.ChoiceIndexChoiceIndex = []
00517 if i == 0:
00518 self.IndexChoiceIndexChoice.Append("User Type")
00519 self.IndexChoiceIndexChoice.SetStringSelection("User Type")
00520 elif i == 2:
00521 self.IndexChoiceIndexChoice.Append("SDO Server")
00522 self.IndexChoiceIndexChoice.Append("SDO Client")
00523 if choiceindex != wxNOT_FOUND and choice == self.IndexChoiceIndexChoice.GetString(choiceindex):
00524 self.IndexChoiceIndexChoice.SetStringSelection(choice)
00525 elif i in (3, 4):
00526 self.IndexChoiceIndexChoice.Append("PDO Receive")
00527 self.IndexChoiceIndexChoice.SetStringSelection("PDO Receive")
00528 elif i in (5, 6):
00529 self.IndexChoiceIndexChoice.Append("PDO Transmit")
00530 self.IndexChoiceIndexChoice.SetStringSelection("PDO Transmit")
00531 elif i == 8:
00532 self.IndexChoiceIndexChoice.Append("Map Variable")
00533 self.IndexChoiceIndexChoice.SetStringSelection("Map Variable")
00534 else:
00535 for name, index in self.ManagerManager.GetCurrentValidChoices(values["minIndex"], values["maxIndex"]):
00536 if index:
00537 self.IndexChoiceIndexChoice.Append("0x%04X %s"%(index, name))
00538 else:
00539 self.IndexChoiceIndexChoice.Append(name)
00540 self.ChoiceIndexChoiceIndex.append(index)
00541 if choiceindex != wxNOT_FOUND and choice == self.IndexChoiceIndexChoice.GetString(choiceindex):
00542 self.IndexChoiceIndexChoice.SetStringSelection(choice)
00543 if self.EditableEditable:
00544 self.IndexChoiceIndexChoice.Enable(self.IndexChoiceIndexChoice.GetCount() != 0)
00545 self.AddButtonAddButton.Enable(self.IndexChoiceIndexChoice.GetCount() != 0)
00546 if selected == wxNOT_FOUND or selected >= len(self.ListIndexListIndex) or selectedindex != self.ListIndexListIndex[selected]:
00547 self.TableTable.Empty()
00548 self.CallbackCheckCallbackCheck.SetValue(False)
00549 self.CallbackCheckCallbackCheck.Disable()
00550 self.TableTable.ResetView(self.SubindexGridSubindexGrid)
00551 self.ParentParent.RefreshStatusBar()
00552 else:
00553 self.IndexListIndexList.SetSelection(selected)
00554 self.RefreshTableRefreshTable()
00555
00556 def RefreshTable(self):
00557 selected = self.IndexListIndexList.GetSelection()
00558 if selected != wxNOT_FOUND:
00559 index = self.ListIndexListIndex[selected]
00560 if index > 0x260 and self.EditableEditable:
00561 self.CallbackCheckCallbackCheck.Enable()
00562 self.CallbackCheckCallbackCheck.SetValue(self.ManagerManager.HasCurrentEntryCallbacks(index))
00563 result = self.ManagerManager.GetCurrentEntryValues(index)
00564 if result != None:
00565 self.TableTable.SetCurrentIndex(index)
00566 data, editors = result
00567 self.TableTable.SetData(data)
00568 self.TableTable.SetEditors(editors)
00569 self.TableTable.ResetView(self.SubindexGridSubindexGrid)
00570 self.ParentParent.RefreshStatusBar()
00571
00572
00573
00574
00575
00576 def OnSubindexGridCellChange(self, event):
00577 if self.EditableEditable:
00578 index = self.TableTable.GetCurrentIndex()
00579 subIndex = event.GetRow()
00580 col = event.GetCol()
00581 name = self.TableTable.GetColLabelValue(col)
00582 value = self.TableTable.GetValue(subIndex, col)
00583 editor = self.TableTable.GetEditor(subIndex, col)
00584 self.ManagerManager.SetCurrentEntry(index, subIndex, value, name, editor)
00585 self.ParentParent.RefreshBufferState()
00586 wxCallAfter(self.RefreshTableRefreshTable)
00587 event.Skip()
00588
00589 def OnCallbackCheck(self, event):
00590 if self.EditableEditable:
00591 index = self.TableTable.GetCurrentIndex()
00592 self.ManagerManager.SetCurrentEntryCallbacks(index, self.CallbackCheckCallbackCheck.GetValue())
00593 self.ParentParent.RefreshBufferState()
00594 wxCallAfter(self.RefreshTableRefreshTable)
00595 event.Skip()
00596
00597
00598
00599
00600
00601 def OnIndexListRightUp(self, event):
00602 if self.EditableEditable:
00603 if not self.FirstCallFirstCall:
00604 self.FirstCallFirstCall = True
00605 selected = self.IndexListIndexList.GetSelection()
00606 if selected != wxNOT_FOUND:
00607 index = self.ListIndexListIndex[selected]
00608 if index < 0x260:
00609 self.IndexListMenu.FindItemByPosition(0).Enable(False)
00610 self.IndexListMenu.FindItemByPosition(1).Enable(True)
00611 self.PopupMenu(self.IndexListMenu)
00612 elif 0x1000 <= index <= 0x1BFF:
00613 self.IndexListMenu.FindItemByPosition(0).Enable(False)
00614 self.IndexListMenu.FindItemByPosition(1).Enable(False)
00615 self.PopupMenu(self.IndexListMenu)
00616 elif 0x2000 <= index <= 0x5FFF:
00617 self.IndexListMenu.FindItemByPosition(0).Enable(True)
00618 self.IndexListMenu.FindItemByPosition(1).Enable(False)
00619 self.PopupMenu(self.IndexListMenu)
00620 elif index >= 0x6000:
00621 self.IndexListMenu.FindItemByPosition(0).Enable(False)
00622 self.IndexListMenu.FindItemByPosition(1).Enable(False)
00623 self.PopupMenu(self.IndexListMenu)
00624 else:
00625 self.FirstCallFirstCall = False
00626 event.Skip()
00627
00628 def OnSubindexGridRightClick(self, event):
00629 if self.EditableEditable:
00630 selected = self.IndexListIndexList.GetSelection()
00631 if selected != wxNOT_FOUND:
00632 index = self.ListIndexListIndex[selected]
00633 if self.ManagerManager.IsCurrentEntry(index):
00634 infos = self.ManagerManager.GetEntryInfos(index)
00635 if index >= 0x2000 and infos["struct"] & OD_MultipleSubindexes or infos["struct"] & OD_IdenticalSubindexes:
00636 self.PopupMenu(self.SubindexGridMenu)
00637 event.Skip()
00638
00639 def OnRenameIndexMenu(self, event):
00640 if self.EditableEditable:
00641 selected = self.IndexListIndexList.GetSelection()
00642 if selected != wxNOT_FOUND:
00643 index = self.ListIndexListIndex[selected]
00644 if self.ManagerManager.IsCurrentEntry(index):
00645 infos = self.ManagerManager.GetEntryInfos(index)
00646 dialog = wxTextEntryDialog(self, "Give a new name for index 0x%04X"%index,
00647 "Rename an index", infos["name"], wxOK|wxCANCEL)
00648 if dialog.ShowModal() == wxID_OK:
00649 self.ManagerManager.SetCurrentEntryName(index, dialog.GetValue())
00650 self.ParentParent.RefreshBufferState()
00651 self.RefreshIndexListRefreshIndexList()
00652 dialog.Destroy()
00653 event.Skip()
00654
00655 def OnModifyIndexMenu(self, event):
00656 if self.EditableEditable:
00657 selected = self.IndexListIndexList.GetSelection()
00658 if selected != wxNOT_FOUND:
00659 index = self.ListIndexListIndex[selected]
00660 if self.ManagerManager.IsCurrentEntry(index) and index < 0x260:
00661 values, valuetype = self.ManagerManager.GetCustomisedTypeValues(index)
00662 dialog = UserTypeDialog(self)
00663 dialog.SetTypeList(self.ManagerManager.GetCustomisableTypes(), values[1])
00664 if valuetype == 0:
00665 dialog.SetValues(min = values[2], max = values[3])
00666 elif valuetype == 1:
00667 dialog.SetValues(length = values[2])
00668 if dialog.ShowModal() == wxID_OK:
00669 type, min, max, length = dialog.GetValues()
00670 self.ManagerManager.SetCurrentUserType(index, type, min, max, length)
00671 self.ParentParent.RefreshBufferState()
00672 self.RefreshIndexListRefreshIndexList()
00673 event.Skip()
00674
00675 def OnDeleteIndexMenu(self, event):
00676 if self.EditableEditable:
00677 selected = self.IndexListIndexList.GetSelection()
00678 if selected != wxNOT_FOUND:
00679 index = self.ListIndexListIndex[selected]
00680 if self.ManagerManager.IsCurrentEntry(index):
00681 self.ManagerManager.ManageEntriesOfCurrent([],[index])
00682 self.ParentParent.RefreshBufferState()
00683 self.RefreshIndexListRefreshIndexList()
00684 event.Skip()
00685
00686 def OnAddSubindexMenu(self, event):
00687 if self.EditableEditable:
00688 selected = self.IndexListIndexList.GetSelection()
00689 if selected != wxNOT_FOUND:
00690 index = self.ListIndexListIndex[selected]
00691 if self.ManagerManager.IsCurrentEntry(index):
00692 dialog = wxTextEntryDialog(self, "Number of subindexes to add:",
00693 "Add subindexes", "1", wxOK|wxCANCEL)
00694 if dialog.ShowModal() == wxID_OK:
00695 try:
00696 number = int(dialog.GetValue())
00697 self.ManagerManager.AddSubentriesToCurrent(index, number)
00698 self.ParentParent.RefreshBufferState()
00699 self.RefreshIndexListRefreshIndexList()
00700 except:
00701 message = wxMessageDialog(self, "An integer is required!", "ERROR", wxOK|wxICON_ERROR)
00702 message.ShowModal()
00703 message.Destroy()
00704 dialog.Destroy()
00705 event.Skip()
00706
00707 def OnDeleteSubindexMenu(self, event):
00708 if self.EditableEditable:
00709 selected = self.IndexListIndexList.GetSelection()
00710 if selected != wxNOT_FOUND:
00711 index = self.ListIndexListIndex[selected]
00712 if self.ManagerManager.IsCurrentEntry(index):
00713 dialog = wxTextEntryDialog(self, "Number of subindexes to delete:",
00714 "Delete subindexes", "1", wxOK|wxCANCEL)
00715 if dialog.ShowModal() == wxID_OK:
00716 try:
00717 number = int(dialog.GetValue())
00718 self.ManagerManager.RemoveSubentriesFromCurrent(index, number)
00719 self.ParentParent.RefreshBufferState()
00720 self.RefreshIndexListRefreshIndexList()
00721 except:
00722 message = wxMessageDialog(self, "An integer is required!", "ERROR", wxOK|wxICON_ERROR)
00723 message.ShowModal()
00724 message.Destroy()
00725 dialog.Destroy()
00726 event.Skip()
00727