----------------------------------------------------------------------------- -- Name: DarwinHZ -- Author: Ya-Nvr-No http://www.yanvrno.com -- Modified by: -- Created: 12/23/2014 -- Copyright: (c) 2014 Ya-Nvr-No. All rights reserved. -- Licence: BSD license ----------------------------------------------------------------------------- DarwinHZ = wx.wxDialog (wx.NULL, wx.wxID_ANY, "Darwin Hz Calc by Ya-Nvr-No", wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxDEFAULT_DIALOG_STYLE )--create and name the window with desired settings DarwinHZ:SetSizeHints( wx.wxDefaultSize, wx.wxDefaultSize ) bSizer4 = wx.wxBoxSizer( wx.wxVERTICAL ) DarwinHZGrid = wx.wxGrid( DarwinHZ, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxDefaultSize, 0 ) -------------------------GRID SETTINGS------------------------------------------ -- Grid DarwinHZGrid:CreateGrid( 11, 4 ) DarwinHZGrid:EnableDragGridSize( False ) DarwinHZGrid:SetMargins( 0, 0 ) -- Columns DarwinHZGrid:SetColSize( 0, 62 ) DarwinHZGrid:SetColSize( 1, 62 ) DarwinHZGrid:SetColSize( 2, 65 ) DarwinHZGrid:SetColSize( 3, 60 ) DarwinHZGrid:EnableDragColSize( True ) DarwinHZGrid:SetColLabelSize( 30 ) DarwinHZGrid:SetColLabelAlignment( wx.wxALIGN_CENTER, wx.wxALIGN_CENTER ) -- Rows DarwinHZGrid:AutoSizeRows() DarwinHZGrid:EnableDragRowSize( True ) DarwinHZGrid:SetRowLabelSize( 2 ) DarwinHZGrid:SetRowLabelAlignment( wx.wxALIGN_CENTRE, wx.wxALIGN_CENTRE ) -- Label Appearance -- Cell Defaults DarwinHZGrid:SetDefaultCellAlignment( wx.wxALIGN_LEFT, wx.wxALIGN_TOP+wx.wxSTAY_ON_TOP ) DarwinHZGrid:SetMinSize( wx.wxSize( 252, 250) ) DarwinHZGrid:SetMaxSize( wx.wxSize( -1, 300) ) -------------------------END GRID SETTINGS------------------------------------------ bSizer4:Add( DarwinHZGrid, 0, wx.wxALL + wx.wxALIGN_CENTER_HORIZONTAL, 5 ) sdbSizer2 = wx.wxStdDialogButtonSizer() sdbSizer2OK = wx.wxButton( DarwinHZ, wx.wxID_OK, "" )--Add an "OK" button to the bottom of the dialog. sdbSizer2:AddButton( sdbSizer2OK ) sdbSizer2:Realize(); bSizer4:Add( sdbSizer2, 1, wx.wxALIGN_CENTER_HORIZONTAL, 5 ) DarwinHZ:SetSizer( bSizer4 ) DarwinHZ:Layout() bSizer4:Fit( DarwinHZ ) DarwinHZ:Centre( wx.wxBOTH ) -- Connect Events lastrow = 0 lastcol = 0 row = 0 function mainframe() DarwinHZGrid:SetCellAlignment(1,3,wx.wxALIGN_CENTER, wx.wxALIGN_CENTER) DarwinHZGrid:SetCellBackgroundColour(1, 3, wx.wxColour(100,230,230))--This code changes the new cell to gray for i = 2, 8 do --Loop DarwinHZGrid:SetCellBackgroundColour(i, 1, wx.wxColour(wx.wxGREEN))--This code changes the new cell to green DarwinHZGrid:SetCellBackgroundColour(i, 2, wx.wxColour(wx.wxGREEN))--This code changes the new cell to green i=i+1 end function TimerTick() end TimerTick() local i = 0; DarwinHZGrid:Connect( wx.wxEVT_GRID_CELL_LEFT_CLICK, function(event) --This is an event handler that happens when the user clicks in a cell. local rownum = event:GetRow() local colnum = event:GetCol() if(lastrow ~= rownum or lastcol ~= colnum) then DarwinHZGrid:SetCellBackgroundColour(tonumber(rownum), tonumber(colnum), wx.wxColour(wx.wxGREEN))--This code changes the new cell to green DarwinHZGrid:SetCellBackgroundColour(tonumber(lastrow), tonumber(lastcol), wx.wxColour(wx.wxWHITE))--This cell changes the old green cell to white. local SEC=60 local counts0=DarwinHZGrid:GetCellValue(2, 1) local counts1=DarwinHZGrid:GetCellValue(3, 1) local counts2=DarwinHZGrid:GetCellValue(4, 1) local counts3=DarwinHZGrid:GetCellValue(5, 1) local counts4=DarwinHZGrid:GetCellValue(6, 1) local counts5=DarwinHZGrid:GetCellValue(7, 1) local counts6=DarwinHZGrid:GetCellValue(8, 1) local vel0=DarwinHZGrid:GetCellValue(2, 2) local vel1=DarwinHZGrid:GetCellValue(3, 2) local vel2=DarwinHZGrid:GetCellValue(4, 2) local vel3=DarwinHZGrid:GetCellValue(5, 2) local vel4=DarwinHZGrid:GetCellValue(6, 2) local vel5=DarwinHZGrid:GetCellValue(7, 2) local vel6=DarwinHZGrid:GetCellValue(8, 2) hz0 = (counts0 * vel0)/SEC hz1 = (counts1 * vel1)/SEC hz2 = (counts2 * vel2)/SEC hz3 = (counts3 * vel3)/SEC hz4 = (counts4 * vel4)/SEC hz5 = (counts5 * vel5)/SEC hz6 = (counts6 * vel6)/SEC hz0 = string.format("%0.0f",tostring(hz0)) hz1 = string.format("%0.0f",tostring(hz1)) hz2 = string.format("%0.0f",tostring(hz2)) hz3 = string.format("%0.0f",tostring(hz3)) hz4 = string.format("%0.0f",tostring(hz4)) hz5 = string.format("%0.0f",tostring(hz5)) hz6 = string.format("%0.0f",tostring(hz6)) DarwinHZGrid:SetCellValue(2, 3, tostring(hz0)) DarwinHZGrid:SetCellValue(3, 3, tostring(hz1)) DarwinHZGrid:SetCellValue(4, 3, tostring(hz2)) DarwinHZGrid:SetCellValue(5, 3, tostring(hz3)) DarwinHZGrid:SetCellValue(6, 3, tostring(hz4)) DarwinHZGrid:SetCellValue(7, 3, tostring(hz5)) DarwinHZGrid:SetCellValue(8, 3, tostring(hz6)) for i = 2, 8 do --Loop DarwinHZGrid:SetCellBackgroundColour(i, 3, wx.wxColour(230,230,230))--This code changes the new cell to gray end for i = 2, 8 do --Loop DarwinHZGrid:SetCellBackgroundColour(i, 1, wx.wxColour(wx.wxGREEN))--This code changes the new cell to green DarwinHZGrid:SetCellBackgroundColour(i, 2, wx.wxColour(wx.wxGREEN))--This code changes the new cell to green i=i+1 end lastrow = rownum lastcol = colnum DarwinHZGrid:ForceRefresh() end event:Skip() end ) end function SetupDarwinHZ() local i = 0 local k = 0 local j = 0 DarwinHZGrid:SetColLabelValue(0, " ") DarwinHZGrid:SetColLabelValue(1, "Enter".."\n".. "Counts") DarwinHZGrid:SetColLabelValue(2, "Enter".."\n".. "Velocity") DarwinHZGrid:SetColLabelValue(3, "Result".."\n".. "Values") DarwinHZGrid:SetCellValue(0, 0, "Enter in the Counts/unit and the Velocity") DarwinHZGrid:SetCellValue(1, 3, "Hz") for i = 2, 8 do --Loop DarwinHZGrid:SetCellValue(i, 0, "Motor "..i-2) end for i = 2, 8 do --Loop DarwinHZGrid:SetCellValue(i, 1, tostring(k)) DarwinHZGrid:SetCellValue(i, 2, tostring(j)) end DarwinHZGrid:SetCellValue(10, 0, "Set Darwin Slider Hz just above the lowest Hz") end SetupDarwinHZ() mainframe() DarwinHZ:Show()