import wx.grid
from types import *
+from commondialogs import *
from node import OD_Subindex, OD_MultipleSubindexes, OD_IdenticalSubindexes, OD_IdenticalIndexes
renderer = wx.grid.GridCellNumberRenderer()
if colname == "value" and "min" in editors and "max" in editors:
editor.SetParameters("%s,%s"%(editors["min"],editors["max"]))
- elif editortype == "real":
- editor = wx.grid.GridCellFloatEditor()
- renderer = wx.grid.GridCellFloatRenderer()
- if colname == "value" and "min" in editors and "max" in editors:
- editor.SetParameters("%s,%s"%(editors["min"],editors["max"]))
+ elif editortype == "float":
+ editor = wx.grid.GridCellTextEditor()
+ renderer = wx.grid.GridCellStringRenderer()
elif editortype == "bool":
editor = wx.grid.GridCellChoiceEditor()
editor.SetParameters(BoolList)
elif editortype == "domain":
editor = wx.grid.GridCellTextEditor()
renderer = wx.grid.GridCellStringRenderer()
+ elif editortype == "dcf":
+ editor = wx.grid.GridCellTextEditor()
+ renderer = wx.grid.GridCellStringRenderer()
else:
grid.SetReadOnly(row, col, True)
] = [wx.NewId() for _init_coll_IndexListMenu_Items in range(3)]
[ID_EDITINGPANELMENU1ITEMS0, ID_EDITINGPANELMENU1ITEMS1,
-] = [wx.NewId() for _init_coll_SubindexGridMenu_Items in range(2)]
+ ID_EDITINGPANELMENU1ITEMS3, ID_EDITINGPANELMENU1ITEMS4,
+] = [wx.NewId() for _init_coll_SubindexGridMenu_Items in range(4)]
class EditingPanel(wx.SplitterWindow):
def _init_coll_AddToListSizer_Items(self, parent):
def _init_coll_SubindexGridMenu_Items(self, parent):
parent.Append(help='', id=ID_EDITINGPANELMENU1ITEMS0,
- kind=wx.ITEM_NORMAL, text='Add')
+ kind=wx.ITEM_NORMAL, text='Add subindexes')
parent.Append(help='', id=ID_EDITINGPANELMENU1ITEMS1,
- kind=wx.ITEM_NORMAL, text='Delete')
+ kind=wx.ITEM_NORMAL, text='Delete subindexes')
+ parent.AppendSeparator()
+ parent.Append(help='', id=ID_EDITINGPANELMENU1ITEMS3,
+ kind=wx.ITEM_NORMAL, text='Default value')
+ if not self.Editable:
+ parent.Append(help='', id=ID_EDITINGPANELMENU1ITEMS4,
+ kind=wx.ITEM_NORMAL, text='Add to DCF')
self.Bind(wx.EVT_MENU, self.OnAddSubindexMenu,
id=ID_EDITINGPANELMENU1ITEMS0)
self.Bind(wx.EVT_MENU, self.OnDeleteSubindexMenu,
id=ID_EDITINGPANELMENU1ITEMS1)
+ self.Bind(wx.EVT_MENU, self.OnDefaultValueSubindexMenu,
+ id=ID_EDITINGPANELMENU1ITEMS3)
+ if not self.Editable:
+ self.Bind(wx.EVT_MENU, self.OnAddToDCFSubindexMenu,
+ id=ID_EDITINGPANELMENU1ITEMS4)
def _init_coll_IndexListMenu_Items(self, parent):
parent.Append(help='', id=ID_EDITINGPANELINDEXLISTMENUITEMS0,
self.OnSubindexGridRightClick)
self.SubindexGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL,
self.OnSubindexGridSelectCell)
- self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnSubindexGridCellLeftClick)
+ self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK,
+ self.OnSubindexGridCellLeftClick)
+ self.SubindexGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN,
+ self.OnSubindexGridEditorShown)
self.CallbackCheck = wx.CheckBox(id=ID_EDITINGPANELCALLBACKCHECK,
label='Have Callbacks', name='CallbackCheck',
self._init_sizers()
- def __init__(self, parent, manager, editable = True):
- self._init_ctrls(parent.GetNoteBook())
- self.Parent = parent
+ def __init__(self, parent, window, manager, editable = True):
+ self.Editable = editable
+ self._init_ctrls(parent)
+ self.ParentWindow = window
self.Manager = manager
self.ListIndex = []
self.ChoiceIndex = []
self.FirstCall = False
- self.Editable = editable
self.Index = None
for values in DictionaryOrganisation:
- text = " 0x%04X-0x%04X %s"%(values["minIndex"],values["maxIndex"],values["name"])
+ text = " 0x%04X-0x%04X %s"%(values["minIndex"], values["maxIndex"], values["name"])
self.PartList.Append(text)
self.Table = SubindexTable(self, [], [], ["subindex", "name", "type", "value", "access", "save", "comment"])
self.SubindexGrid.SetTable(self.Table)
return None
def OnSubindexGridCellLeftClick(self, event):
- wx.CallAfter(self.BeginDrag)
+ if not self.ParentWindow.ModeSolo:
+ col = event.GetCol()
+ if not self.Editable and col == 0:
+ selected = self.IndexList.GetSelection()
+ if selected != wx.NOT_FOUND:
+ index = self.ListIndex[selected]
+ subindex = event.GetRow()
+ entry_infos = self.Manager.GetEntryInfos(index)
+ if not entry_infos["struct"] & OD_MultipleSubindexes or subindex != 0:
+ subentry_infos = self.Manager.GetSubentryInfos(index, subindex)
+ typeinfos = self.Manager.GetEntryInfos(subentry_infos["type"])
+ if subentry_infos["pdo"] and typeinfos:
+ bus_id = '.'.join(map(str, self.ParentWindow.GetBusId()))
+ node_id = self.ParentWindow.GetCurrentNodeId()
+ size = typeinfos["size"]
+ data = wx.TextDataObject(str(("%s%s.%d.%d.%d"%(SizeConversion[size], bus_id, node_id, index, subindex), "location")))
+ dragSource = wx.DropSource(self.SubindexGrid)
+ dragSource.SetData(data)
+ dragSource.DoDragDrop()
event.Skip()
def OnAddButtonClick(self, event):
selected = self.IndexChoice.GetStringSelection()
if selected != "":
if selected == "User Type":
- self.Parent.AddUserType()
+ self.ParentWindow.AddUserType()
elif selected == "SDO Server":
self.Manager.AddSDOServerToCurrent()
elif selected == "SDO Client":
elif selected == "PDO Transmit":
self.Manager.AddPDOTransmitToCurrent()
elif selected == "Map Variable":
- self.Parent.AddMapVariable()
+ self.ParentWindow.AddMapVariable()
elif selected in [menu for menu, indexes in self.Manager.GetCurrentSpecificMenu()]:
self.Manager.AddSpecificEntryToCurrent(selected)
else:
index = self.ChoiceIndex[self.IndexChoice.GetSelection()]
self.Manager.ManageEntriesOfCurrent([index], [])
- self.Parent.RefreshBufferState()
+ self.ParentWindow.RefreshBufferState()
self.RefreshIndexList()
event.Skip()
event.Skip()
def OnSubindexGridSelectCell(self, event):
- wx.CallAfter(self.BeginDrag)
- wx.CallAfter(self.Parent.RefreshStatusBar)
+ wx.CallAfter(self.ParentWindow.RefreshStatusBar)
event.Skip()
- def BeginDrag(self):
- if not self.Parent.ModeSolo:
- row = self.SubindexGrid.GetGridCursorRow()
- col = self.SubindexGrid.GetGridCursorCol()
- if not self.Editable and col == 0:
- selected = self.IndexList.GetSelection()
- if selected != wx.NOT_FOUND:
- index = self.ListIndex[selected]
- subindex = self.SubindexGrid.GetGridCursorRow()
- entry_infos = self.Manager.GetEntryInfos(index)
- if not entry_infos["struct"] & OD_MultipleSubindexes or row != 0:
- subentry_infos = self.Manager.GetSubentryInfos(index, subindex)
- typeinfos = self.Manager.GetEntryInfos(subentry_infos["type"])
- if subentry_infos["pdo"] and typeinfos:
- bus_id = '.'.join(map(str,self.Parent.GetBusId()))
- node_id = self.Parent.GetCurrentNodeId()
- size = typeinfos["size"]
- data = wx.TextDataObject(str(("%s%s.%d.%d.%d"%(SizeConversion[size], bus_id, node_id, index, subindex), "location")))
- dragSource = wx.DropSource(self.SubindexGrid)
- dragSource.SetData(data)
- dragSource.DoDragDrop()
-
#-------------------------------------------------------------------------------
# Refresh Functions
#-------------------------------------------------------------------------------
else:
self.IndexChoice.Append(name)
self.ChoiceIndex.append(index)
- if choiceindex != wx.NOT_FOUND and choice == self.IndexChoice.GetString(choiceindex):
+ if choiceindex != wx.NOT_FOUND and choiceindex < self.IndexChoice.GetCount() and choice == self.IndexChoice.GetString(choiceindex):
self.IndexChoice.SetStringSelection(choice)
if self.Editable:
self.IndexChoice.Enable(self.IndexChoice.GetCount() != 0)
self.CallbackCheck.SetValue(False)
self.CallbackCheck.Disable()
self.Table.ResetView(self.SubindexGrid)
- self.Parent.RefreshStatusBar()
+ self.ParentWindow.RefreshStatusBar()
else:
self.IndexList.SetSelection(selected)
self.RefreshTable()
self.Table.SetData(data)
self.Table.SetEditors(editors)
self.Table.ResetView(self.SubindexGrid)
- self.Parent.RefreshStatusBar()
+ self.ParentWindow.RefreshStatusBar()
#-------------------------------------------------------------------------------
# Editing Table value function
#-------------------------------------------------------------------------------
+ def OnSubindexGridEditorShown(self, event):
+ row, col = event.GetRow(), event.GetCol()
+ if self.Table.GetEditor(row, col) == "dcf":
+ wx.CallAfter(self.ShowDCFEntryDialog, row, col)
+ event.Veto()
+ else:
+ event.Skip()
+
+ def ShowDCFEntryDialog(self, row, col):
+ if self.Editable:
+ selected = self.IndexList.GetSelection()
+ if selected != wx.NOT_FOUND:
+ index = self.ListIndex[selected]
+ if self.Manager.IsCurrentEntry(index):
+ dialog = DCFEntryValuesDialog(self)
+ dialog.SetValues(self.Table.GetValue(row, col).decode("hex_codec"))
+ if dialog.ShowModal() == wx.ID_OK:
+ value = dialog.GetValues()
+ self.Manager.SetCurrentEntry(index, row, value, "value", "dcf")
+ self.ParentWindow.RefreshBufferState()
+ wx.CallAfter(self.RefreshTable)
+
def OnSubindexGridCellChange(self, event):
if self.Editable:
index = self.Table.GetCurrentIndex()
value = self.Table.GetValue(subIndex, col)
editor = self.Table.GetEditor(subIndex, col)
self.Manager.SetCurrentEntry(index, subIndex, value, name, editor)
- self.Parent.RefreshBufferState()
+ self.ParentWindow.RefreshBufferState()
wx.CallAfter(self.RefreshTable)
event.Skip()
if self.Editable:
index = self.Table.GetCurrentIndex()
self.Manager.SetCurrentEntryCallbacks(index, self.CallbackCheck.GetValue())
- self.Parent.RefreshBufferState()
+ self.ParentWindow.RefreshBufferState()
wx.CallAfter(self.RefreshTable)
event.Skip()
self.IndexListMenu.FindItemByPosition(0).Enable(False)
self.IndexListMenu.FindItemByPosition(1).Enable(True)
self.PopupMenu(self.IndexListMenu)
- elif 0x1000 <= index <= 0x1BFF:
+ elif 0x1000 <= index <= 0x1FFF:
self.IndexListMenu.FindItemByPosition(0).Enable(False)
self.IndexListMenu.FindItemByPosition(1).Enable(False)
self.PopupMenu(self.IndexListMenu)
event.Skip()
def OnSubindexGridRightClick(self, event):
+ self.SubindexGrid.SetGridCursor(event.GetRow(), event.GetCol())
if self.Editable:
selected = self.IndexList.GetSelection()
if selected != wx.NOT_FOUND:
index = self.ListIndex[selected]
if self.Manager.IsCurrentEntry(index):
+ showpopup = False
infos = self.Manager.GetEntryInfos(index)
- if index >= 0x2000 and infos["struct"] & OD_MultipleSubindexes or infos["struct"] & OD_IdenticalSubindexes:
+ if 0x2000 <= index <= 0x5FFF and infos["struct"] & OD_MultipleSubindexes or infos["struct"] & OD_IdenticalSubindexes:
+ showpopup = True
+ self.SubindexGridMenu.FindItemByPosition(0).Enable(True)
+ self.SubindexGridMenu.FindItemByPosition(1).Enable(True)
+ else:
+ self.SubindexGridMenu.FindItemByPosition(0).Enable(False)
+ self.SubindexGridMenu.FindItemByPosition(1).Enable(False)
+ if self.Table.GetColLabelValue(event.GetCol()) == "value":
+ showpopup = True
+ self.SubindexGridMenu.FindItemByPosition(3).Enable(True)
+ else:
+ self.SubindexGridMenu.FindItemByPosition(3).Enable(False)
+ if showpopup:
+ self.PopupMenu(self.SubindexGridMenu)
+ elif self.Table.GetColLabelValue(event.GetCol()) == "value":
+ selected = self.IndexList.GetSelection()
+ if selected != wx.NOT_FOUND:
+ index = self.ListIndex[selected]
+ if self.Manager.IsCurrentEntry(index):
+ infos = self.Manager.GetEntryInfos(index)
+ if not infos["struct"] & OD_MultipleSubindexes or event.GetRow() > 0:
+ self.SubindexGridMenu.FindItemByPosition(0).Enable(False)
+ self.SubindexGridMenu.FindItemByPosition(1).Enable(False)
+ self.SubindexGridMenu.FindItemByPosition(3).Enable(False)
+ self.SubindexGridMenu.FindItemByPosition(4).Enable(True)
self.PopupMenu(self.SubindexGridMenu)
event.Skip()
+ def OnAddToDCFSubindexMenu(self, event):
+ if not self.Editable:
+ selected = self.IndexList.GetSelection()
+ if selected != wx.NOT_FOUND:
+ index = self.ListIndex[selected]
+ subindex = self.SubindexGrid.GetGridCursorRow()
+ entry_infos = self.Manager.GetEntryInfos(index)
+ if not entry_infos["struct"] & OD_MultipleSubindexes or subindex != 0:
+ subentry_infos = self.Manager.GetSubentryInfos(index, subindex)
+ typeinfos = self.Manager.GetEntryInfos(subentry_infos["type"])
+ if typeinfos:
+ node_id = self.ParentWindow.GetCurrentNodeId()
+ value = self.Table.GetValueByName(subindex, "value")
+ if value == "True":
+ value = 1
+ elif value == "False":
+ value = 0
+ elif value.isdigit():
+ value = int(value)
+ elif value.startswith("0x"):
+ value = int(value, 16)
+ else:
+ value = int(value.encode("hex_codec"), 16)
+ self.Manager.AddToMasterDCF(node_id, index, subindex, max(1, typeinfos["size"] / 8), value)
+ self.ParentWindow.OpenMasterDCFDialog(node_id)
+
+ def OpenDCFDialog(self, node_id):
+ self.PartList.SetSelection(7)
+ self.RefreshIndexList()
+ self.IndexList.SetSelection(self.ListIndex.index(0x1F22))
+ self.RefreshTable()
+ self.SubindexGrid.SetGridCursor(node_id, 3)
+ self.ShowDCFEntryDialog(node_id, 3)
+
def OnRenameIndexMenu(self, event):
if self.Editable:
selected = self.IndexList.GetSelection()
"Rename an index", infos["name"], wx.OK|wx.CANCEL)
if dialog.ShowModal() == wx.ID_OK:
self.Manager.SetCurrentEntryName(index, dialog.GetValue())
- self.Parent.RefreshBufferState()
+ self.ParentWindow.RefreshBufferState()
self.RefreshIndexList()
dialog.Destroy()
event.Skip()
if dialog.ShowModal() == wx.ID_OK:
type, min, max, length = dialog.GetValues()
self.Manager.SetCurrentUserType(index, type, min, max, length)
- self.Parent.RefreshBufferState()
+ self.ParentWindow.RefreshBufferState()
self.RefreshIndexList()
event.Skip()
index = self.ListIndex[selected]
if self.Manager.IsCurrentEntry(index):
self.Manager.ManageEntriesOfCurrent([],[index])
- self.Parent.RefreshBufferState()
+ self.ParentWindow.RefreshBufferState()
self.RefreshIndexList()
event.Skip()
try:
number = int(dialog.GetValue())
self.Manager.AddSubentriesToCurrent(index, number)
- self.Parent.RefreshBufferState()
+ self.ParentWindow.RefreshBufferState()
self.RefreshIndexList()
except:
message = wx.MessageDialog(self, "An integer is required!", "ERROR", wx.OK|wx.ICON_ERROR)
try:
number = int(dialog.GetValue())
self.Manager.RemoveSubentriesFromCurrent(index, number)
- self.Parent.RefreshBufferState()
+ self.ParentWindow.RefreshBufferState()
self.RefreshIndexList()
except:
message = wx.MessageDialog(self, "An integer is required!", "ERROR", wx.OK|wx.ICON_ERROR)
dialog.Destroy()
event.Skip()
+ def OnDefaultValueSubindexMenu(self, event):
+ if self.Editable:
+ selected = self.IndexList.GetSelection()
+ if selected != wx.NOT_FOUND:
+ index = self.ListIndex[selected]
+ if self.Manager.IsCurrentEntry(index):
+ row = self.SubindexGrid.GetGridCursorRow()
+ self.Manager.SetCurrentEntryToDefault(index, row)
+ self.ParentWindow.RefreshBufferState()
+ self.RefreshIndexList()
+ event.Skip()