----------------------------------------------------------------------------- -- Name: SurfaceSpeeds -- Author: Ya-Nvr-No http://www.yanvrno.com -- Modified by: -- Created: 12/24/2014 -- Copyright: (c) 2014 Ya-Nvr-No. All rights reserved. -- Licence: BSD license ----------------------------------------------------------------------------- SurfaceSpeeds = wx.wxDialog (wx.NULL, wx.wxID_ANY, "Surface Speed / RPM Calc by Ya-Nvr-No", wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxDEFAULT_DIALOG_STYLE )--create and name the window with desired settings SurfaceSpeeds:SetSizeHints( wx.wxDefaultSize, wx.wxDefaultSize ) bSizer4 = wx.wxBoxSizer( wx.wxVERTICAL )--create a sizer to place elements in SurfaceSpeedsGrid = wx.wxGrid( SurfaceSpeeds, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxDefaultSize, 0 ) -------------------------GRID SETTINGS------------------------------------------ -- Grid SurfaceSpeedsGrid:CreateGrid( 18, 4 ) SurfaceSpeedsGrid:EnableDragGridSize( False ) SurfaceSpeedsGrid:SetMargins( 0, 0 ) -- Columns SurfaceSpeedsGrid:SetColSize( 0, 60 ) SurfaceSpeedsGrid:SetColSize( 1, 250 ) SurfaceSpeedsGrid:SetColSize( 2, 60 ) SurfaceSpeedsGrid:SetColSize( 3, 60 ) SurfaceSpeedsGrid:EnableDragColSize( True ) SurfaceSpeedsGrid:SetColLabelSize( 30 ) SurfaceSpeedsGrid:SetColLabelAlignment( wx.wxALIGN_CENTER, wx.wxALIGN_CENTER ) -- Rows SurfaceSpeedsGrid:AutoSizeRows() SurfaceSpeedsGrid:EnableDragRowSize( True ) SurfaceSpeedsGrid:SetRowLabelSize( 2 ) SurfaceSpeedsGrid:SetRowLabelAlignment( wx.wxALIGN_CENTRE, wx.wxALIGN_CENTRE ) -- Label Appearance -- Cell Defaults SurfaceSpeedsGrid:SetDefaultCellAlignment( wx.wxALIGN_LEFT, wx.wxALIGN_TOP+wx.wxSTAY_ON_TOP ) SurfaceSpeedsGrid:SetMinSize( wx.wxSize( 432, 380) ) SurfaceSpeedsGrid:SetMaxSize( wx.wxSize( -1, 500) ) -------------------------END GRID SETTINGS------------------------------------------ bSizer4:Add( SurfaceSpeedsGrid, 0, wx.wxALL + wx.wxALIGN_CENTER_HORIZONTAL, 5 ) sdbSizer2 = wx.wxStdDialogButtonSizer() sdbSizer2OK = wx.wxButton( SurfaceSpeeds, 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 ) SurfaceSpeeds:SetSizer(bSizer4 ) SurfaceSpeeds:Layout() bSizer4:Fit( SurfaceSpeeds ) SurfaceSpeeds:Centre(wx.wxBOTH ) function mainframe() function TimerTick() end TimerTick() local lastrow = 0 local lastcol = 0 SurfaceSpeedsGrid: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 SurfaceSpeedsGrid:SetCellBackgroundColour(tonumber(rownum), tonumber(colnum), wx.wxColour(wx.wxGREEN))--This code changes the new cell to green SurfaceSpeedsGrid:SetCellBackgroundColour(tonumber(lastrow), tonumber(lastcol), wx.wxColour(wx.wxWHITE))--This cell changes the old green cell to white. local RPM=1000 local SFM=SurfaceSpeedsGrid:GetCellValue(0, 2) local DIA=SurfaceSpeedsGrid:GetCellValue(1, 2) local PI=math.pi --3.141592654 RPM = (SFM * 12)/(DIA * PI) SFM = (DIA * PI * RPM)/12 RPM = string.format("%0.0f",tostring(RPM)) SurfaceSpeedsGrid:SetCellAlignment(3,3,wx.wxALIGN_CENTER, wx.wxALIGN_CENTER) SurfaceSpeedsGrid:SetCellAlignment(4,3,wx.wxALIGN_CENTER, wx.wxALIGN_CENTER) SurfaceSpeedsGrid:SetCellValue(3, 3, tostring(RPM)) SurfaceSpeedsGrid:SetCellValue(4, 3, tostring(SFM)) SurfaceSpeedsGrid:SetCellBackgroundColour(3, 3, wx.wxColour(230,230,230))--This code changes the new cell to gray SurfaceSpeedsGrid:SetCellTextColour(3, 3, wx.wxColour(wx.wxRED))--This code changes the new cell to Red SurfaceSpeedsGrid:SetCellFont(3, 3, wx.wxFont(14,0,0,0))--This code changes the font size SurfaceSpeedsGrid:SetCellBackgroundColour(4, 3, wx.wxColour(wx.wxGREEN))--This code changes the new cell to green lastrow = rownum lastcol = colnum SurfaceSpeedsGrid:ForceRefresh() end event:Skip() end ) end function SetupTapDrill() local i = 0 SurfaceSpeedsGrid:SetColLabelValue(0, " ") SurfaceSpeedsGrid:SetColLabelValue(1, "Formulas") SurfaceSpeedsGrid:SetColLabelValue(2, "Enter".."\n".. "Values") SurfaceSpeedsGrid:SetColLabelValue(3, "Result".."\n".. "Values") SurfaceSpeedsGrid:SetCellValue(0,0,"SFM:") SurfaceSpeedsGrid:SetCellValue(0,1,"Surface Feet per Minute,") SurfaceSpeedsGrid:SetCellValue(0,2,"300") SurfaceSpeedsGrid:SetCellValue(1,0,"DIA:") SurfaceSpeedsGrid:SetCellValue(1,1,"Diameter of cutter (Mill) or work piece (Lathe)") SurfaceSpeedsGrid:SetCellValue(1,2,"1") SurfaceSpeedsGrid:SetCellValue(3,0,"RPM =") SurfaceSpeedsGrid:SetCellValue(3,1,"(SFM x 12)/(DIA x PI)") SurfaceSpeedsGrid:SetCellValue(4,0,"SFM =") SurfaceSpeedsGrid:SetCellValue(4,1,"(DIA x PI x RPM)/12") SurfaceSpeedsGrid:SetCellValue(6,0,"SFM") SurfaceSpeedsGrid:SetCellValue(6,1,"Material to cut") SurfaceSpeedsGrid:SetCellValue(7,0,"300-400") SurfaceSpeedsGrid:SetCellValue(7,1,"Wood") SurfaceSpeedsGrid:SetCellValue(8,0,"300-400") SurfaceSpeedsGrid:SetCellValue(8,1,"Die Cast (Zinc alloy)") SurfaceSpeedsGrid:SetCellValue(9,0,"200-300") SurfaceSpeedsGrid:SetCellValue(9,1,"Aluminum") SurfaceSpeedsGrid:SetCellValue(10,0,"150-300") SurfaceSpeedsGrid:SetCellValue(10,1,"Brass") SurfaceSpeedsGrid:SetCellValue(11,0,"100-300") SurfaceSpeedsGrid:SetCellValue(11,1,"Plastic") SurfaceSpeedsGrid:SetCellValue(12,0,"100-150") SurfaceSpeedsGrid:SetCellValue(12,1,"Cast Iron") SurfaceSpeedsGrid:SetCellValue(13,0," 80-110") SurfaceSpeedsGrid:SetCellValue(13,1,"Steel (Low Carbon)") SurfaceSpeedsGrid:SetCellValue(14,0," 50-60") SurfaceSpeedsGrid:SetCellValue(14,1,"Steel (Tool grades)") SurfaceSpeedsGrid:SetCellValue(15,0," 30-80") SurfaceSpeedsGrid:SetCellValue(15,1,"Stainless (400 series)") SurfaceSpeedsGrid:SetCellValue(16,0," 15-50") SurfaceSpeedsGrid:SetCellValue(16,1,"Stainless (300 series)") SurfaceSpeedsGrid:SetCellValue(17,0," 7-15") SurfaceSpeedsGrid:SetCellValue(17,1,"Steel (Heat treated - hard)") SurfaceSpeedsGrid:SetCellAlignment(0,2,wx.wxALIGN_CENTER, wx.wxALIGN_CENTER) SurfaceSpeedsGrid:SetCellAlignment(1,2,wx.wxALIGN_CENTER, wx.wxALIGN_CENTER) SurfaceSpeedsGrid:SetCellAlignment(0,0,wx.wxALIGN_CENTER, wx.wxALIGN_CENTER) SurfaceSpeedsGrid:SetCellAlignment(1,0,wx.wxALIGN_CENTER, wx.wxALIGN_CENTER) SurfaceSpeedsGrid:SetCellAlignment(3,0,wx.wxALIGN_CENTER, wx.wxALIGN_CENTER) SurfaceSpeedsGrid:SetCellAlignment(4,0,wx.wxALIGN_CENTER, wx.wxALIGN_CENTER) SurfaceSpeedsGrid:SetCellAlignment(6,0,wx.wxALIGN_CENTER, wx.wxALIGN_CENTER) SurfaceSpeedsGrid:SetCellAlignment(6,1,wx.wxALIGN_CENTER, wx.wxALIGN_CENTER) SurfaceSpeedsGrid:SetCellBackgroundColour(0, 2, wx.wxColour(wx.wxGREEN)) SurfaceSpeedsGrid:SetCellBackgroundColour(6, 0, wx.wxColour(wx.wxGREEN)) SurfaceSpeedsGrid:SetCellBackgroundColour(6, 1, wx.wxColour(wx.wxGREEN)) for i = 7, 17 do --Loop through the last 10 rows column 0 SurfaceSpeedsGrid:SetCellAlignment(i,0,wx.wxALIGN_RIGHT,wx.wxALIGN_RIGHT) i=i+1 end end SetupTapDrill() mainframe() SurfaceSpeeds:Show()