-- Load the wxLua module, does nothing if running from wxLua, wxLuaFreeze, or wxLuaEdit -- package.cpath = package.cpath..";./?.dll;./?.so;../lib/?.so;../lib/vc_dll/?.dll;../lib/bcc_dll/?.dll;../lib/mingw_dll/?.dll;" -- require("wx") local frame = nil local panel = nil local m_id = 0 local mInst = 0; --Mach4 instance number local inst = mc.mcGetInstance(mInst); function GetNextID() m_id = m_id+1; return m_id; end local imageFileName = 'MSM_Probe_1.png'; local imageBasePath = './screens/MyStdMill/images/'; if (mcLuaPanelParent == nil) then imageBasePath = '../screens/MyStdMill/images/'; end -- [[ local image = wx.wxImage(); if (not image:LoadFile(imageBasePath..imageFileName, wx.wxBITMAP_TYPE_PNG)) then wx.wxLogError("Could not load image from '%s'!", imageFileName); dc:delete(); return; end --image:Resize(panel.getSize()); local bitmap = wx.wxBitmap(image); local wsize = wx.wxSize(image:GetWidth(), image:GetHeight()) --[ []]-- --[[ local wxXmlResource = wx.wxXmlResource:Get(); wxXmlResource:InitAllHandlers(); local bitmap = wxXmlResource:LoadBitmap (imageFileName); if (not bitmap or not bitmap:Ok()) then wx.wxLogError("Could not load image from '%s'!", imageFileName); return; end --]] function main() if(mcLuaPanelParent == nil)then frame = wx.wxFrame( wx.NULL, -- no parent wx.wxID_ANY, -- whatever for wxWindow ID "My Frame Caption", -- frame caption wx.wxDefaultPosition, -- place the frame in default position wsize, -- wx.wxDefaultSize, -- default frame size wx.wxDEFAULT_FRAME_STYLE+wx.wxSTAY_ON_TOP); -- def, stay on top --remove +wx.wxSTAY_ON_TOP if you want them to NOT stay on top panel = wx.wxPanel(frame, wx.wxID_ANY); fileMenu = wx.wxMenu(); fileMenu:Append(wx.wxID_EXIT, "E&xit", "Some Exit Message"); local menuBar = wx.wxMenuBar(); frame:SetMenuBar(menuBar); frame:CreateStatusBar(1); frame:SetStatusText("Some Status Text"); 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(); local wsize = window:GetSize(); panel:SetSize(wsize); panel:Connect( wx.wxEVT_CLOSE_WINDOW, function (event) event:Skip(); end ); end mainSizer = wx.wxBoxSizer(wx.wxVERTICAL); GridSizer = wx.wxFlexGridSizer( 2, 1, 0, 0 );--2 rows, 1 column, no x/y spacing between local ID_PROBING_PANEL = GetNextID (); local probingPanel = wx.wxPanel ( panel, ID_PROBING_PANEL, wx.wxDefaultPosition, panel:GetSize(), --wx.wxSize(520, 520), 0, ''); GridSizer:Add( probingPanel, 0, wx.wxGROW+wx.wxALIGN_CENTER+wx.wxALL+wx.wxALIGN_LEFT, 2) buttonSizer = wx.wxBoxSizer( wx.wxHORIZONTAL ); if (mcLuaPanelParent == nil) then-- Only add if this not a panel script. ID_CLOSE_BUTTON = GetNextID(); closeButton = wx.wxButton( panel, ID_CLOSE_BUTTON, "E&xit"); buttonSizer:Add( closeButton, 0, wx.wxALIGN_CENTER+wx.wxALL, 1 ); end mainSizer:Add(GridSizer, 0, wx.wxALIGN_CENTER+wx.wxLEFT+wx.wxRIGHT, 0 ); mainSizer:Add(buttonSizer, 0, wx.wxALIGN_RIGHT+wx.wxRIGHT, 8); panel:SetSizer( mainSizer ); panel:Fit(); if(mcLuaPanelParent == nil) then panel:Connect(ID_CLOSE_BUTTON, 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(); probingPanel:setSize(wsize); probingPanel:FitInside(); end); end probingPanel:Connect(wx.wxEVT_PAINT, function (event) local dc = wx.wxPaintDC(probingPanel); dc:DrawBitmap (bitmap, 0,0, true); dc:delete (); end) probingPanel:Connect(wx.wxEVT_LEFT_UP, function (event) local mouseX = event:GetX(); local mouseY = event:GetY(); wx.wxMessageBox("LEFT CLICK - X: "..tostring(mouseX)..", Y: "..tostring(mouseY)); end); end main(); wx.wxGetApp():MainLoop();