--Basic Empty Wizard local frame = nil local panel = nil local m_id = 0 local mInst = 0; --Mach4 instance number local inst = mc.mcGetInstance(mInst); MPGSwitchPosition = 1; MPGPosition = 2; JogIncrSwitchPosition = 1; --Function sed to create widget ids function GetNextID() m_id = m_id+1; return m_id; end --Define Functions Here function main() panel = mcLuaPanelParent; mc.mcCntlSetLastError(0, 'panel is parent!!!'); panel:SetBackgroundColour(wx.wxColour(255,255,255)); local window = panel:GetParent(); window:SetWindowStyleFlag(wx.wxBORDER_NONE);--removes sunken border of lua panel -- mc.mcCntlSetLastError(0, 'window = '..window); window:Connect( wx.wxID_ANY, wx.wxEVT_SIZE, --was window:Connect function(event) local wsize = event:GetSize(); panel:SetSize(wsize); panel:FitInside(); end); window:ClearBackground(); window:Refresh(); --///////////////////////////////// BitMap function //////////////////////////////////////// function MakeBitMap( ImagePath, --"Image Path" to the picture and its "name.extension" ImageType) --type of picture, "BMP" = BitMap, "JPG" = J-Peg, --"PNG" = PNG, "ICO" = Icon, "XPM" = xpm resource --if not used: param = "nil"(default is BMP) local ImageStyle = 0; if ImagePath == nil then return; end --must have path to the Picture if ImageType == "BMP" or ImageType == nil then ImageStyle = wx.wxBITMAP_TYPE_BMP; end if ImageType == "JPG" then ImageStyle = wx.wxBITMAP_TYPE_JPEG; end if ImageType == "PNG" then ImageStyle = wx.wxBITMAP_TYPE_PNG; end if ImageType == "ICO" then ImageStyle = wx.wxBITMAP_TYPE_ICO; end if ImageType == "XPM" then ImageStyle = wx.wxBITMAP_TYPE_XPM; end local bitmap = wx.wxBitmap(ImagePath, ImageStyle); return bitmap; end -- local Path = "..\\Mach4Hobby" local Path = mc.mcCntlGetCwd(inst); --Get Mach4 current working directory local imagepathBMP = Path .. "\\Wizards\\images\\";--Path to your Picture with name and extension --MPG Switch Images -- local imagepathBMP1 = "F:\\CNC\\MACH4 SDK\\Mach4\\Wizards\\images\\OFF.png";--Path to your Picture with name and extension local imagepathBMP1 = imagepathBMP .. "OFF.png";--Path to your Picture with name and extension local imagepathBMP2 = imagepathBMP .. "X.png";--Path to your Picture with name and extension local imagepathBMP3 = imagepathBMP .. "Y.png";--Path to your Picture with name and extension local imagepathBMP4 = imagepathBMP .. "Z.png";--Path to your Picture with name and extension local imagepathBMP5 = imagepathBMP .. "A.png";--Path to your Picture with name and extension MPGSwitchBMPs = {[1] = MakeBitMap(imagepathBMP1, "PNG"), [2] = MakeBitMap(imagepathBMP2, "PNG"), [3] = MakeBitMap(imagepathBMP3, "PNG"), [4] = MakeBitMap(imagepathBMP4, "PNG"), [5] = MakeBitMap(imagepathBMP5, "PNG")}; --MPG Images local imagepathBMP21 = imagepathBMP .. "MPGCCW.png";--Path to your Picture with name and extension local imagepathBMP22 = imagepathBMP .. "MPG.png";--Path to your Picture with name and extension local imagepathBMP23 = imagepathBMP .. "MPGCW.png";--Path to your Picture with name and extension MPGBMPs = {[1] = MakeBitMap(imagepathBMP21, "PNG"), [2] = MakeBitMap(imagepathBMP22, "PNG"), [3] = MakeBitMap(imagepathBMP23, "PNG")}; --Jog Increment Switch Images local imagepathBMP31 = imagepathBMP .. "INC1.png";--Path to your Picture with name and extension local imagepathBMP32 = imagepathBMP .. "INCDot1.png";--Path to your Picture with name and extension local imagepathBMP33 = imagepathBMP .. "INCDot01.png";--Path to your Picture with name and extension local imagepathBMP34 = imagepathBMP .. "INCDot001.png";--Path to your Picture with name and extension local imagepathBMP35 = imagepathBMP .. "INCDot0001.png";--Path to your Picture with name and extension JogIncrSwitchBMPs = {[1] = MakeBitMap(imagepathBMP31, "PNG"), [2] = MakeBitMap(imagepathBMP32, "PNG"), [3] = MakeBitMap(imagepathBMP33, "PNG"), [4] = MakeBitMap(imagepathBMP34, "PNG"), [5] = MakeBitMap(imagepathBMP35, "PNG")}; local staticTxtinstruction1 = wx.wxStaticText( panel, wx.wxID_ANY, "MPG Setting"); local staticTxtinstruction2 = wx.wxStaticText( panel, wx.wxID_ANY, "MPG"); local staticTxtinstruction3 = wx.wxStaticText( panel, wx.wxID_ANY, "Increment Setting"); --Layout panel using wxSizers mainSizer = wx.wxBoxSizer(wx.wxVERTICAL); Sizer1 = wx.wxGridSizer( 1, 3, 0, 30 );--1 row, 3 columns, 30 x/y spacing between Sizer2 = wx.wxGridSizer( 1, 3, 0, 10 );--1 row, 3 columns, 10 x/y spacing between Sizer3 = wx.wxGridSizer( 1, 3, 0, 10 );--1 row, 3 columns, 10 x/y spacing between Sizer1:Add(staticTxtinstruction1, 1, wx.wxALIGN_CENTER, 0); Sizer1:Add(staticTxtinstruction2, 1, wx.wxALIGN_CENTER, 0); Sizer1:Add(staticTxtinstruction3, 1, wx.wxALIGN_CENTER, 0); MPGSETPANEL1_ID = GetNextID (); BitMapPanel1 = wx.wxPanel ( panel, MPGSETPANEL1_ID, wx.wxDefaultPosition, wx.wxSize(MPGSwitchBMPs[MPGSwitchPosition]:GetWidth(), MPGSwitchBMPs[MPGSwitchPosition]:GetHeight()), 0, ''); MPGSETPANEL2_ID = GetNextID (); BitMapPanel2 = wx.wxPanel ( panel, MPGSETPANEL2_ID, wx.wxDefaultPosition, wx.wxSize(MPGBMPs[MPGPosition]:GetWidth(), MPGBMPs[MPGPosition]:GetHeight()), 0, ''); MPGSETPANEL3_ID = GetNextID (); BitMapPanel3 = wx.wxPanel ( panel, MPGSETPANEL3_ID, wx.wxDefaultPosition, wx.wxSize(JogIncrSwitchBMPs[JogIncrSwitchPosition]:GetWidth(), JogIncrSwitchBMPs[JogIncrSwitchPosition]:GetHeight()), 0, ''); Sizer2:Add(BitMapPanel1, 1, wx.wxGROW+wx.wxALIGN_CENTER+wx.wxALL, 0); Sizer2:Add(BitMapPanel2, 1, wx.wxGROW+wx.wxALIGN_CENTER+wx.wxALL, 0); Sizer2:Add(BitMapPanel3, 1, wx.wxGROW+wx.wxALIGN_CENTER+wx.wxALL, 0); mc.mcCntlSetLastError(0, 'Draw Panels!!!'); --Draw the Panels BitMapPanel1:Connect(wx.wxEVT_PAINT, function (event) local dc = wx.wxPaintDC(BitMapPanel1); dc:DrawBitmap (MPGSwitchBMPs[MPGSwitchPosition], 0,0, true); dc:delete (); end) BitMapPanel2:Connect(wx.wxEVT_PAINT, function (event) local dc = wx.wxPaintDC(BitMapPanel2); dc:DrawBitmap (MPGBMPs[MPGPosition], 0,0, true); dc:delete (); end) BitMapPanel3:Connect(wx.wxEVT_PAINT, function (event) local dc = wx.wxPaintDC(BitMapPanel3); dc:DrawBitmap (JogIncrSwitchBMPs[JogIncrSwitchPosition], 0,0, true); dc:delete (); end) --///////////////////////////////// Radio Button function /////////////////////////////// --NOTE!!! IF radio buttons are grouped, then all further radio buttons made after that --are attached to the same panel or sizer and will be in the group, unless another radio button group --is made, or it is the end of the controls on that panel or sizer. local window = panel:GetParent(); function RadioButton( panel, --frame or panel handle RBname_string, --string label of the radio button boolGrp, --Put this and following radio btn in mutually exclusive group(default) for "nil" or true. RADIOBUTTON_ID) --Radio Button ID number, if not used: param = "nil" local rb = 0; if panel == nil then return; end --must have frame or panel to hook to if (RBname_string == nil) then RBname_string = ""; end if (RADIOBUTTON_ID == nil) then RADIOBUTTON_ID = wx.wxID_ANY; end if boolGrp == nil or boolGrp == 1 or boolGrp == true then rb = wx.wxRadioButton(panel,RADIOBUTTON_ID,RBname_string,wx.wxDefaultPosition,wx.wxDefaultSize,wx.wxRB_GROUP); end if boolGrp == 0 or boolGrp == false then rb = wx.wxRadioButton(panel,RADIOBUTTON_ID,RBname_string,wx.wxDefaultPosition,wx.wxDefaultSize); end return rb; end --MPG Axis Select Radio Button Definition local buttonSizer5 = wx.wxStaticBoxSizer( wx.wxVERTICAL, panel, "MPG Axis" ); local RADIOBTN1_ID = GetNextID(); local RADIOBTN2_ID = GetNextID(); local RADIOBTN3_ID = GetNextID(); local RADIOBTN4_ID = GetNextID(); local RADIOBTN5_ID = GetNextID(); local rbtns1 = RadioButton(panel, "OFF", true, RADIOBTN1_ID);--button one is set for Group local rbtns2 = RadioButton(panel, "X_Axis", false, RADIOBTN2_ID);--button two is set for no group since it will attach to the group. local rbtns3 = RadioButton(panel, "Y_Axis", false, RADIOBTN3_ID);--button three is set for no group since it will attach to the group. local rbtns4 = RadioButton(panel, "Z_Axis", false, RADIOBTN4_ID);--button four is set for no group since it will attach to the group. local rbtns5 = RadioButton(panel, "A_Axis", false, RADIOBTN5_ID);--button five is set for no group since it will attach to the group. buttonSizer5:Add(rbtns1, 0, wx.wxALIGN_LEFT+wx.wxRIGHT+wx.wxLEFT+wx.wxTOP, 10 ); buttonSizer5:Add(rbtns2, 0, wx.wxALIGN_LEFT+wx.wxRIGHT+wx.wxLEFT+wx.wxTOP, 10 ); buttonSizer5:Add(rbtns3, 0, wx.wxALIGN_LEFT+wx.wxRIGHT+wx.wxLEFT+wx.wxTOP, 10 ); buttonSizer5:Add(rbtns4, 0, wx.wxALIGN_LEFT+wx.wxRIGHT+wx.wxLEFT+wx.wxTOP, 10 ); buttonSizer5:Add(rbtns5, 0, wx.wxALIGN_LEFT+wx.wxRIGHT+wx.wxLEFT+wx.wxTOP, 10 ); rbtns1:SetValue(true);--put dot in the 1st RadioButton --MPG Dial Definition local buttonSizer3 = wx.wxStaticBoxSizer( wx.wxVERTICAL, panel, "MPG" ); local RADIOBTN21_ID = GetNextID(); local RADIOBTN22_ID = GetNextID(); local RADIOBTN23_ID = GetNextID(); local rbtns21 = RadioButton(panel, "CCW", true, RADIOBTN21_ID);--button one is set for Group local rbtns22 = RadioButton(panel, "STOP", false, RADIOBTN22_ID);--button two is set for no group since it will attach to the group. local rbtns23 = RadioButton(panel, "CW", false, RADIOBTN23_ID);--button three is set for no group since it will attach to the group. buttonSizer3:Add(rbtns21, 0, wx.wxALIGN_LEFT+wx.wxRIGHT+wx.wxLEFT+wx.wxTOP, 10 ); buttonSizer3:Add(rbtns22, 0, wx.wxALIGN_LEFT+wx.wxRIGHT+wx.wxLEFT+wx.wxTOP, 10 ); buttonSizer3:Add(rbtns23, 0, wx.wxALIGN_LEFT+wx.wxRIGHT+wx.wxLEFT+wx.wxTOP, 10 ); rbtns22:SetValue(true);--put dot in the 2nd RadioButton --Jog Increment Select Radio Button Definition local buttonSizer6 = wx.wxStaticBoxSizer( wx.wxVERTICAL, panel, "Jog Increment" ); local RADIOBTN31_ID = GetNextID(); local RADIOBTN32_ID = GetNextID(); local RADIOBTN33_ID = GetNextID(); local RADIOBTN34_ID = GetNextID(); local RADIOBTN35_ID = GetNextID(); local rbtns31 = RadioButton(panel, "1.0000", true, RADIOBTN31_ID);--button one is set for Group local rbtns32 = RadioButton(panel, "0.1000", false, RADIOBTN32_ID);--button two is set for no group since it will attach to the group. local rbtns33 = RadioButton(panel, "0.0100", false, RADIOBTN33_ID);--button three is set for no group since it will attach to the group. local rbtns34 = RadioButton(panel, "0.0010", false, RADIOBTN34_ID);--button four is set for no group since it will attach to the group. local rbtns35 = RadioButton(panel, "0.0001", false, RADIOBTN35_ID);--button five is set for no group since it will attach to the group. buttonSizer6:Add(rbtns31, 0, wx.wxALIGN_LEFT+wx.wxRIGHT+wx.wxLEFT+wx.wxTOP, 10 ); buttonSizer6:Add(rbtns32, 0, wx.wxALIGN_LEFT+wx.wxRIGHT+wx.wxLEFT+wx.wxTOP, 10 ); buttonSizer6:Add(rbtns33, 0, wx.wxALIGN_LEFT+wx.wxRIGHT+wx.wxLEFT+wx.wxTOP, 10 ); buttonSizer6:Add(rbtns34, 0, wx.wxALIGN_LEFT+wx.wxRIGHT+wx.wxLEFT+wx.wxTOP, 10 ); buttonSizer6:Add(rbtns35, 0, wx.wxALIGN_LEFT+wx.wxRIGHT+wx.wxLEFT+wx.wxTOP, 10 ); rbtns31:SetValue(true);--put dot in the 1st RadioButton -- Connect to MPG Axis Select Events panel:Connect(RADIOBTN1_ID, wx.wxEVT_COMMAND_RADIOBUTTON_SELECTED, function(event) local Selected = rbtns1:GetValue(); if Selected then MPGSwitchPosition = 1; local dc = wx.wxPaintDC(BitMapPanel1); -- wx.wxMessageBox("MPG OFF Switch Position "..MPGSwitchPosition);--troubleshooting dc:DrawBitmap (MPGSwitchBMPs[MPGSwitchPosition], 0,0, true); dc:delete (); panel:Refresh(); end mc.mcCntlSetLastError(0, 'Button1 MPG OFF Selected.'); end); panel:Connect(RADIOBTN2_ID, wx.wxEVT_COMMAND_RADIOBUTTON_SELECTED, function(event) local Selected = rbtns2:GetValue(); if Selected then MPGSwitchPosition = 2; -- wx.wxMessageBox("MPG X-Axis Switch Position "..MPGSwitchPosition); --troubleshooting local dc = wx.wxPaintDC(BitMapPanel1); dc:DrawBitmap (MPGSwitchBMPs[MPGSwitchPosition], 0,0, true); dc:delete (); panel:Refresh(); end mc.mcCntlSetLastError(0, 'Button2 MPG X-Axis Selected.'); end); panel:Connect(RADIOBTN3_ID, wx.wxEVT_COMMAND_RADIOBUTTON_SELECTED, function(event) local Selected = rbtns3:GetValue(); if Selected then MPGSwitchPosition = 3; -- wx.wxMessageBox("MPG Y-Axis Switch Position "..MPGSwitchPosition); --troubleshooting local dc = wx.wxPaintDC(BitMapPanel1); dc:DrawBitmap (MPGSwitchBMPs[MPGSwitchPosition], 0,0, true); dc:delete (); panel:Refresh(); end mc.mcCntlSetLastError(0, 'Button3 MPG Y-Axis Selected.'); end); panel:Connect(RADIOBTN4_ID, wx.wxEVT_COMMAND_RADIOBUTTON_SELECTED, function(event) local Selected = rbtns4:GetValue(); if Selected then MPGSwitchPosition = 4; -- wx.wxMessageBox("MPG Z-Axis Switch Position "..MPGSwitchPosition); --troubleshooting local dc = wx.wxPaintDC(BitMapPanel1); dc:DrawBitmap (MPGSwitchBMPs[MPGSwitchPosition], 0,0, true); dc:delete (); panel:Refresh(); end mc.mcCntlSetLastError(0, 'Button4 MPG Z-Axis Selected.'); end); panel:Connect(RADIOBTN5_ID, wx.wxEVT_COMMAND_RADIOBUTTON_SELECTED, function(event) local Selected = rbtns5:GetValue(); if Selected then MPGSwitchPosition = 5; -- wx.wxMessageBox("MPG A-Axis Switch Position "..MPGSwitchPosition); --troubleshooting local dc = wx.wxPaintDC(BitMapPanel1); dc:DrawBitmap (MPGSwitchBMPs[MPGSwitchPosition], 0,0, true); dc:delete (); panel:Refresh(); end mc.mcCntlSetLastError(0, 'Button5 MPG A-Axis Selected.'); end); -- Connect to MPG Events panel:Connect(RADIOBTN21_ID, wx.wxEVT_COMMAND_RADIOBUTTON_SELECTED, function(event) local Selected = rbtns21:GetValue(); if Selected then MPGPosition = 1; local dc = wx.wxPaintDC(BitMapPanel1); dc:DrawBitmap (MPGBMPs[MPGPosition], 0,0, true); dc:delete (); panel:Refresh(); end mc.mcCntlSetLastError(0, "MPG Moving CCW"); end); panel:Connect(RADIOBTN22_ID, wx.wxEVT_COMMAND_RADIOBUTTON_SELECTED, function(event) local Selected = rbtns22:GetValue(); if Selected then MPGPosition = 2; local dc = wx.wxPaintDC(BitMapPanel1); dc:DrawBitmap (MPGBMPs[MPGPosition], 0,0, true); dc:delete (); panel:Refresh(); end mc.mcCntlSetLastError(0, "MPG Moving CW"); end); panel:Connect(RADIOBTN23_ID, wx.wxEVT_COMMAND_RADIOBUTTON_SELECTED, function(event) local Selected = rbtns23:GetValue(); if Selected then MPGPosition = 3; local dc = wx.wxPaintDC(BitMapPanel1); dc:DrawBitmap (MPGBMPs[MPGPosition], 0,0, true); dc:delete (); panel:Refresh(); end mc.mcCntlSetLastError(0, "MPG Moving "); end); -- Connect to Increment Select Events panel:Connect(RADIOBTN31_ID, wx.wxEVT_COMMAND_RADIOBUTTON_SELECTED, function(event) local Selected = rbtns31:GetValue(); if Selected then JogIncrSwitchPosition = 1; local dc = wx.wxPaintDC(BitMapPanel3); dc:DrawBitmap (JogIncrSwitchBMPs[JogIncrSwitchPosition], 0,0, true); dc:delete (); panel:Refresh(); end mc.mcCntlSetLastError(0, "Jog Increment = 1.0000"); end); panel:Connect(RADIOBTN32_ID, wx.wxEVT_COMMAND_RADIOBUTTON_SELECTED, function(event) local Selected = rbtns32:GetValue(); if Selected then JogIncrSwitchPosition = 2; local dc = wx.wxPaintDC(BitMapPanel3); dc:DrawBitmap (JogIncrSwitchBMPs[JogIncrSwitchPosition], 0,0, true); dc:delete (); panel:Refresh(); end mc.mcCntlSetLastError(0, "Jog Increment = 0.1000"); end); panel:Connect(RADIOBTN33_ID, wx.wxEVT_COMMAND_RADIOBUTTON_SELECTED, function(event) local Selected = rbtns33:GetValue(); if Selected then JogIncrSwitchPosition = 3; local dc = wx.wxPaintDC(BitMapPanel3); dc:DrawBitmap (JogIncrSwitchBMPs[JogIncrSwitchPosition], 0,0, true); dc:delete (); panel:Refresh(); end mc.mcCntlSetLastError(0, "Jog Increment = 0.0100"); end); panel:Connect(RADIOBTN34_ID, wx.wxEVT_COMMAND_RADIOBUTTON_SELECTED, function(event) local Selected = rbtns34:GetValue(); if Selected then JogIncrSwitchPosition = 4; local dc = wx.wxPaintDC(BitMapPanel3); dc:DrawBitmap (JogIncrSwitchBMPs[JogIncrSwitchPosition], 0,0, true); dc:delete (); panel:Refresh(); end mc.mcCntlSetLastError(0, "Jog Increment = 0.0010"); end); panel:Connect(RADIOBTN35_ID, wx.wxEVT_COMMAND_RADIOBUTTON_SELECTED, function(event) local Selected = rbtns35:GetValue(); if Selected then JogIncrSwitchPosition = 5; local dc = wx.wxPaintDC(BitMapPanel3); dc:DrawBitmap (JogIncrSwitchBMPs[JogIncrSwitchPosition], 0,0, true); dc:delete (); panel:Refresh(); end mc.mcCntlSetLastError(0, "Jog Increment = 0.0001"); end); --Add all sizers to mainSizer mainSizer:Add(Sizer1, 0, wx.wxALIGN_TOP+wx.wxCENTER, 20); mainSizer:Add(Sizer2, 0, wx.wxALIGN_CENTER, 20); Sizer3:Add(buttonSizer5, 1, wx.wxALIGN_CENTER, 20); Sizer3:Add(buttonSizer3, 1, wx.wxALIGN_CENTER, 20); Sizer3:Add(buttonSizer6, 1, wx.wxALIGN_CENTER, 20); mainSizer:Add(Sizer3, 0, wx.wxALIGN_BOTTOM+wx.wxCENTER+wx.wxALL, 20); panel:SetSizer(mainSizer); panel:Fit(); end main(); wx.wxGetApp():MainLoop(); -- Call wx.wxGetApp():MainLoop() last to start the wxWidgets event loop, -- otherwise the wxLua program will exit immediately. -- Does nothing if running from wxLua, wxLuaFreeze, or wxLuaEdit since the -- MainLoop is already running or will be started by the C++ program. --wx.wxGetApp():MainLoop()