this is poppabears code from the lua panel
 ------------------------Header Section---------------------------------------
-- Name:        JoyStick Status Bitmap display
-- Author:      S Shafer
-- Modified by:
-- Created:     10/13/2014
-- Copyright:   (c) 2014 S S Systems, LLC, can be freely used, modified, or 
--				derived from as long as this header section remains.
-- Licence:     BSD license
-- File Name:	(luapanel embedded script, NO FRAME)
------------------------Header Section----------------------------------------
local panel = nil
local m_id = 0
local mInst = 0; --Mach4 instance number
local inst = mc.mcGetInstance(mInst);
local gtimer1 = 0;
local BitMapPanel = 0;
local picToUse = 0;
local KeyPressed = "";
local window = 0;
function GetNextID()
    m_id = m_id+1;
    return m_id;
end 
function TimerTick()
    BitMapPanel:Refresh();
end
---the ID and its call to GetNextID has been moved to where the control is made.                           
function main()
    panel = mcLuaPanelParent;
    local window = panel:GetParent();
    window:SetBackgroundColour(wx.wxColour(230, 230, 230));
    --use the same color bg as the panel sits on in screen designer
    window:SetWindowStyleFlag(wx.wxBORDER_NONE);--removes sunken border of lua panel
    window:ClearBackground(); 
    window:Refresh();
    local wsize = window:GetSize();
    panel:SetSize(wsize); 
    gtimer1 = wx.wxTimer(panel);--start a timer to poll IO changes
    panel:Connect(wx.wxEVT_TIMER, TimerTick);
    gtimer1:Start(200); -- set poll rate to 1/5th a second        
    panel:Connect(wx.wxEVT_CLOSE_WINDOW,
        function (event)        
            gtimer1:Stop();                
            event:Skip();
        end);
        
    mainSizer = wx.wxBoxSizer(wx.wxVERTICAL); 
    GridSizer  = wx.wxFlexGridSizer( 2, 1, 0, 0 );--2 rows, 1 column, no x/y spacing between  
	local Path = mc.mcCntlGetCwd(inst); --Get Mach4's directory           
    local imagePathJoyCT =  Path .. "\\Wizards\\JoyStickResources\\JoyCenter.bmp";
	local imagePathJoyDN =  Path .. "\\Wizards\\JoyStickResources\\JoyDown.bmp";
	local imagePathJoyLT =  Path .. "\\Wizards\\JoyStickResources\\JoyLeft.bmp";
	local imagePathJoyRT =  Path .. "\\Wizards\\JoyStickResources\\JoyRight.bmp";
	local imagePathJoyUP =  Path .. "\\Wizards\\JoyStickResources\\JoyUp.bmp";
	
	imageCT = wx.wxImage();
	imageCT:LoadFile(imagePathJoyCT, wx.wxBITMAP_TYPE_BMP);	
    JoyBmpCT = wx.wxBitmap(imageCT);	
	wsizeCT = wx.wxSize(JoyBmpCT:GetWidth(), JoyBmpCT:GetHeight());
	imageDN = wx.wxImage();
	imageDN:LoadFile(imagePathJoyDN, wx.wxBITMAP_TYPE_BMP);	
    JoyBmpDN = wx.wxBitmap(imageDN);	
	wsizeDN = wx.wxSize(JoyBmpDN:GetWidth(), JoyBmpDN:GetHeight());
	imageLT = wx.wxImage();
	imageLT:LoadFile(imagePathJoyLT, wx.wxBITMAP_TYPE_BMP);	
    JoyBmpLT = wx.wxBitmap(imageLT);	
	wsizeLT = wx.wxSize(JoyBmpLT:GetWidth(), JoyBmpLT:GetHeight());
	imageRT = wx.wxImage();
	imageRT:LoadFile(imagePathJoyRT, wx.wxBITMAP_TYPE_BMP);	
    JoyBmpRT = wx.wxBitmap(imageRT);	
	wsizeRT = wx.wxSize(JoyBmpRT:GetWidth(), JoyBmpRT:GetHeight());	
   
	imageUP = wx.wxImage();
	imageUP:LoadFile(imagePathJoyUP, wx.wxBITMAP_TYPE_BMP);	
    JoyBmpUP = wx.wxBitmap(imageUP);	
	wsizeUP = wx.wxSize(JoyBmpUP:GetWidth(), JoyBmpUP:GetHeight());  
	
    BITMAPPANEL1_ID = GetNextID ();
    BitMapPanel = wx.wxPanel (  panel, 
                                BITMAPPANEL1_ID, 
                                wx.wxDefaultPosition, 
                                panel:GetSize(),
                                wx.wxWANTS_CHARS,''); 	
    GridSizer:Add(BitMapPanel, 0, wx.wxALIGN_LEFT+wx.wxALL, 2);
    mainSizer:Add(GridSizer, 0, wx.wxALIGN_LEFT+wx.wxALL,2);
    panel:SetSizer(mainSizer); 
    picToUse = JoyBmpCT;    
    BitMapPanel:SetFocus();    
    scr.SetProperty('DebugTB', 'Label', '');
    BitMapPanel:Connect(wx.wxEVT_PAINT, 
                         function (event)
                            local mInst = 0;
                            local rc = 0; local X = 0; local Y = 1; local DirP = 1; DirN = -1;
                            local iSigVal1 = 0;local iSigVal2 = 0;local iSigVal3 = 0;local iSigVal4 = 0;
                            local hsig1 = 0;local hsig2 = 0;local hsig3 = 0;local hsig4 = 0;                            
                            local inst = mc.mcGetInstance(mInst);
                            hsig1, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT1);--LT X-
                            iSigVal1 = mc.mcSignalGetState(hsig1);
                            hsig2, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT2);--RT X+
                            iSigVal2 = mc.mcSignalGetState(hsig2);
                            hsig3, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT3);--UP Y+
                            iSigVal3 = mc.mcSignalGetState(hsig3);
                            hsig4, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT4);--DN Y-
                            iSigVal4 = mc.mcSignalGetState(hsig4);                             
                            if iSigVal1 == 1 then 
                                picToUse = JoyBmpLT;--LT X-
                                mc.mcJogVelocityStart(inst, X, DirN);
                                scr.SetProperty('DebugTB', 'Label', 'input1 Active');
                                end
                            if iSigVal2 == 1 then 
                                picToUse = JoyBmpRT;--RT X+
                                mc.mcJogVelocityStart(inst, X, DirP);
                                scr.SetProperty('DebugTB', 'Label', 'input2 Active');
                                end
                            if iSigVal3 == 1 then 
                                picToUse = JoyBmpUP;
                                mc.mcJogVelocityStart(inst, Y, DirP); --UP Y+                             
                                scr.SetProperty('DebugTB', 'Label', 'input3 Active');
                            end  
                            if iSigVal4 == 1 then 
                                picToUse = JoyBmpDN;--DN Y-
                                mc.mcJogVelocityStart(inst, Y, DirN);
                                scr.SetProperty('DebugTB', 'Label', 'input4 Active');
                            end
                            if iSigVal1 == 0 and iSigVal2 == 0 and iSigVal3 == 0 and iSigVal4 == 0 then 
                                picToUse = JoyBmpCT; 
                                local IsBtnJog = scr.GetProperty('btnJogLED', 'Value');
                                local val = tonumber(IsBtnJog);
                                if val == 0 then
                                    mc.mcJogVelocityStop(inst, X);
                                    mc.mcJogVelocityStop(inst, Y);
                                end
                                scr.SetProperty('DebugTB', 'Label', '');
                            end
                            local dc = wx.wxPaintDC(BitMapPanel);                            
                            dc:DrawBitmap(picToUse, 0,0, true);
                            dc:delete (); 
                         end);
    panel:Fit();
    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
main();
wx.wxGetApp():MainLoop();