wxGrid issue in Lua help requested
Posted: Thu Jun 28, 2018 1:58 pm
I have been trying to use wxGrid to create an editor for CAN DBC messages. This has worked fine up to the point that I have two remaining problems that I hope someone can explain. First problem is cell editing, for some reason I just can't figure out, when editing a cell value or after inserting a new row, the editor will not accept the input of the lower case "x". Second issue is again after edit of a cell , the new value is displayed , but when I retrieve the cell values using GetCewllValue(self,row,col) , which should contain the edited values, I get back the original values not the edited "new" values. What am I missing? Help Please. attached is my grid code there is more code but it's just helper functions.
Code: Select all
local frame = wx.wxFrame(wx.NULL, wx.wxID_ANY, "HBM(HBK) Lua Based DBC Editor",
wx.wxPoint(25, 25), wx.wxSize(900, 700))
local fileMenu = wx.wxMenu("", wx.wxMENU_TEAROFF)
fileMenu:Append(wx.wxID_EXIT, "E&xit\tCtrl-X", "Quit the program")
fileMenu:Append(wx.wxID_OPEN, "O&pen\tCtrl-x", "Open New DBC File")
fileMenu:Append(wx.wxID_SAVEAS, "Save &as...\tAlt+S", "Save DBC File As")
local editMenu=wx.wxMenu("",wx.wxMENU_TEAROFF)
editMenu:Append(wx.wxID_ADD, "A&dd ROW\tCtrl-x", "Add New Row")
editMenu:Append(wx.wxID_DELETE, "D&elete Row\tCtr-l-x","Delete Selected Row")
local helpMenu = wx.wxMenu("", wx.wxMENU_TEAROFF)
helpMenu:Append(wx.wxID_ABOUT, "&About\tCtrl-A", "About the Application")
local menuBar = wx.wxMenuBar()
menuBar:Append(fileMenu, "&File")
menuBar:Append(editMenu, "&Edit")
menuBar:Append(helpMenu, "&Help")
frame:SetMenuBar(menuBar)
frame:CreateStatusBar(1)
frame:SetStatusText("Welcome to HBM(HBK) DBC Editor. This editor does not work for CCP/XCP or CAN FD!!!")
frame:Connect(wx.wxID_EXIT, wx.wxEVT_COMMAND_MENU_SELECTED,
function (event)
frame:Close()
end )
frame:Connect(wx.wxID_OPEN, wx.wxEVT_COMMAND_MENU_SELECTED,
function(event)
fileDialog = wx.wxFileDialog(frame,"Open Vector DBC file","","","Vector files(*.dbc)|*.dbc|All files(*)|*",wx.wxFD_OPEN + wx.wxFD_FILE_MUST_EXIST)
if fileDialog:ShowModal() == wx.wxID_OK then
fileNameOpen = fileDialog:GetPath()
rawdata=readdbc(fileNameOpen) --todo get outp[ut from file dialog "C:\\Users\\McDermith\\Desktop\\Current\\AU_CAN\\old\\AU_CX23R_CAN.dbc"
filttable=FilterData(rawdata)
messages=doSignals(filttable)
n=table.getn(messages)
grid = wx.wxGrid(frame, wx.wxID_ANY)
grid:CreateGrid(n, 11)
--grid:SetColLabelValue(0,"Reserved")
grid:SetColLabelValue(0,"MSG(Hex)")
grid:SetColLabelValue(1,"Signal Name")
grid:SetColLabelValue(2,"Start Bit")
grid:SetColLabelValue(3,"Bit Length")
grid:SetColLabelValue(4,"Scale")
grid:SetColLabelValue(5,"OffSet")
grid:SetColLabelValue(6,"Min")
grid:SetColLabelValue(7,"Max")
grid:SetColLabelValue(8,"Units")
grid:SetColLabelValue(9,"Format")
grid:SetColLabelValue(10,"Messasge")
for k,v in pairs(messages) do
for s,d in pairs(v) do
grid:SetCellValue(k-1,s-1,d)
end
end
grid:AutoSize()
end
fileDialog:Destroy()
return fileNameOpen
end)
frame:Connect(wx.wxID_SAVEAS, wx.wxEVT_COMMAND_MENU_SELECTED,
function(event)
local fileDialog = wx.wxFileDialog(frame,"Save Vector DBC file","","","Vector DBC files(*.dbc)|*.dbc|All files(*)|*",wx.wxFD_SAVE + wx.wxFD_OVERWRITE_PROMPT)
local result = false
if fileDialog:ShowModal() == wx.wxID_OK then
fileNameSave = fileDialog:GetPath()
result = savefileas()
if result then
frame:SetStatusText("Vector DBC - " .. fileName .. "Saved!")
end
end
fileDialog:Destroy()
return fileNameSave
end)
frame:Connect(wx.wxID_ADD, wx.wxEVT_COMMAND_MENU_SELECTED,
function(event)
grid.AppendRows(grid,1,true)
end)
frame:Connect(wx.wxID_DELETE, wx.wxEVT_COMMAND_MENU_SELECTED,
function(event)
--get selected row(s) number(s) remember zero based here in wxGrid
nmrs=grid.GetNumberRows(grid)
if grid.IsSelection(grid)==true then
for i=0,nmrs do
if grid.IsInSelection(grid,i,1)==true then
grid:DeleteRows(i,1,true)
end
end
end
end)
frame:Connect(wx.wxID_ABOUT, wx.wxEVT_COMMAND_MENU_SELECTED,
function (event)
wx.wxMessageBox('This is the "About" dialog of the Application.\n'..
wxlua.wxLUA_VERSION_STRING.." built with "..wx.wxVERSION_STRING,
"About DBCEditor",
wx.wxOK + wx.wxICON_INFORMATION,
frame )
end )
frame:Show(true)
wx.wxGetApp():MainLoop()