local frame = nil local panel = nil local m_id = 0 local mInst = 0; --Mach4 instance number local inst = mc.mcGetInstance(mInst); local frameStyleDefault = wx.wxDEFAULT_FRAME_STYLE; local frameStyleOnTop = wx.wxDEFAULT_FRAME_STYLE+wx.wxSTAY_ON_TOP; local luaPanelColour = wx.wxColour(230, 230, 230); --default Mach4 background grey local disableLuaPanel3Dborder = true; local m_iniName = "My Wizard Name"; function GetNextID() m_id = m_id+1; return m_id; end ---the ID and its call to GetNextID has been moved to where the control is made. function main() function GetConfiguration()-- get control values, choices and/or settings local textl = mc.mcProfileGetString(0, tostring(m_iniName), "TextBoxl", "Default Text"); textCtrl1:SetValue(textl); --optional Line compact version --textCtrl1:SetValue(mc.mcProfileGetString(0, tostring(m_iniName), "TextBoxl", "Default Text")); end function SaveConfiguration()-- save control values, choices and/or settings local textl = textCtrl1:GetValue(); mc.mcProfileWriteString(0, tostring(m_iniName), "TextBoxl", textl); --optional Line compact version --mc.mcProfileWriteString(0, tostring(m_iniName), "TextBoxl", textCtrl1:GetValue()); end if(mcLuaPanelParent == nil)then frame = wx.wxFrame( wx.NULL, -- no parent wx.wxID_ANY, -- whatever for wxWindow ID "Frame Caption", -- frame caption wx.wxDefaultPosition, -- place the frame in default position wx.wxDefaultSize, -- default frame size frameStyleOnTop); -- FrameStyle vars at top panel = wx.wxPanel(frame, wx.wxID_ANY); fileMenu = wx.wxMenu(); fileMenu:Append(wx.wxID_EXIT, "E&xit", "Exit Message"); local menuBar = wx.wxMenuBar(); frame:SetMenuBar(menuBar); frame:CreateStatusBar(1); frame:SetStatusText("Status OK!"); frame:Connect( wx.wxID_EXIT, wx.wxEVT_COMMAND_MENU_SELECTED, function (event) frame:Close(true); end); frame:Connect( wx.wxEVT_CLOSE_WINDOW, function (event) event:Skip(); end); else panel = mcLuaPanelParent; local window = panel:GetParent(); window:SetBackgroundColour(luaPanelColour); --use the same color bg as the panel sits on in screen designer if disableLuaPanel3Dborder then--if true removes sunken border of luapanel window:SetWindowStyleFlag(wx.wxBORDER_NONE); end window:ClearBackground(); window:Refresh(); local wsize = window:GetSize(); panel:SetSize(wsize); panel:Connect( wx.wxEVT_CLOSE_WINDOW, function (event) event:Skip(); end); end local mainSizer = wx.wxBoxSizer(wx.wxVERTICAL); local GridSizer = wx.wxFlexGridSizer( 2, 1, 0, 0 );--2 rows, 1 column, no x/y spacing between --************************** Start Controls ********************************* TEXTBOX1_ID = GetNextID(); textCtrl1 = wx.wxTextCtrl( panel, -- Example Text Control TEXTBOX1_ID, -- control ID "", -- Default Text (none here) wx.wxDefaultPosition, -- wx Decides best place wx.wxSize(200, -1), -- Width, Hight is growable(-1) wx.wxTE_PROCESS_ENTER+wx.wxTE_MULTILINE -- allows multi-lines ); GridSizer:Add(textCtrl1, 0, wx.wxALIGN_CENTER+wx.wxALL+wx.wxALIGN_LEFT, 2)-- Optional wx.wxGROW+ --*************************** End Controls ********************************* --/////////////////// Load Saved Settings if any ///////////////////////////// GetConfiguration(); --Populate your controls with their saved values, this will need to be --called after your controls are set up, UNLESS your building your controls at the time --that your getting your saved values, like Bolt Hole Circle does. --/////////////////////////////////////////////////////////////////////////// local buttonSizer = wx.wxBoxSizer(wx.wxHORIZONTAL); local closeButton = 0; SAVE_BUTTON_ID = GetNextID(); local saveButton = wx.wxButton(panel, SAVE_BUTTON_ID, "Sa&ve"); buttonSizer:Add(saveButton, 0, wx.wxALIGN_LEFT+wx.wxALL, 1); if (mcLuaPanelParent == nil) then-- Only add if this not a panel script. CLOSE_BUTTON_ID = GetNextID(); closeButton = wx.wxButton(panel, CLOSE_BUTTON_ID, "E&xit"); buttonSizer:Add(closeButton, 0, wx.wxALIGN_CENTER+wx.wxALL, 1); end mainSizer:Add(GridSizer, 0, wx.wxALIGN_CENTER+wx.wxLEFT+wx.wxRIGHT, 100); --value of 100 above for left/right is so the window will be wide enough to see frame caption. --If your using this in a panel, you might need to decrease that value for a small panel if (mcLuaPanelParent == nil) then mainSizer:Add(buttonSizer, 0, wx.wxALIGN_RIGHT+wx.wxRIGHT,8); end panel:SetSizer(mainSizer); panel:Fit(); --************************** Start Event Handlers ********************************* panel:Connect(TEXTBOX1_ID, wx.wxEVT_COMMAND_TEXT_ENTER,--enter key pressed after text was entered function(event) local content = textCtrl1:GetValue(); frame:SetStatusText("Enter Key Pressed this is text box contents!"); wx.wxMessageBox(content); wx.wxSleep(2);--2 second pause before status message reset frame:SetStatusText("Status OK!"); end); panel:Connect(SAVE_BUTTON_ID, wx.wxEVT_COMMAND_BUTTON_CLICKED, function(event) SaveConfiguration(); frame:SetStatusText("Text Was Saved to profile!"); wx.wxSleep(1);--2 second pause before status message reset frame:SetStatusText("Status OK!"); end); --*************************** End Event Handlers ********************************* if(mcLuaPanelParent == nil) then panel:Connect( CLOSE_BUTTON_ID, wx.wxEVT_COMMAND_BUTTON_CLICKED, function(event) frame:Destroy(); end); frame:Fit(); frame:Show(true); else local window = panel:GetParent(); window:Connect( wx.wxID_ANY, wx.wxEVT_SIZE, function(event) local wsize = event:GetSize(); panel:SetSize(wsize); panel:FitInside(); end); end end main(); wx.wxGetApp():MainLoop();