Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Analias on August 14, 2014, 01:14:34 AM

Title: Lua Panels and events
Post by: Analias on August 14, 2014, 01:14:34 AM
Steve (aka smurph), is there something that is causing mouse events not to work in Lua Panels that are dropped into a screen set?  I have panel that I plan to show an image in, and have event handlers capture the mouse X & Y coordinates on left clicks.  I copied and simplified some code from one of the wizards and dropped it into the script property of the Lua Panel.  The onPaint() event is working, but the onLeftUp() event handler is not.  Is there something blocking events from happening on

Code: [Select]
-- 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")

-- paint event handler for the frame that's called by wxEVT_PAINT
function onPaint(event)
    -- must always create a wxPaintDC in a wxEVT_PAINT handler
    local dc = wx.wxPaintDC(panel)
    -- call some drawing functions
    dc:DrawRectangle(10, 10, 300, 300);
    dc:DrawRoundedRectangle(20, 20, 280, 280, 20);
    dc:DrawEllipse(30, 30, 260, 260);
    dc:DrawText("A test string", 50, 150);
    dc:delete() -- ALWAYS delete() any wxDCs created when done
end

function onLeftUp (event)
    local mouseX = event.GetX();
    local mouseY = event.GetY();

    mc.mcCntlSetLastError("LEFT CLICK - X: "..tostring(mouseX)..", Y: "..tostring(mouseY));
end

panel = mcLuaPanelParent

-- connect the paint event handler function with the paint event
panel:Connect(wx.wxEVT_PAINT, onPaint)
panel:Connect(wx.wxEVT_LEFT_UP, onLeftUp);

Hmmm... I just tried modifying the original wizard code and it's not showing left clicks either :(  I wonder what I'm missing?


-Freeman
Title: Re: Lua Panels and events
Post by: poppabear on August 14, 2014, 02:24:44 PM
Hey freeman,

you don't have to "import" wx as a module it is already in M4.

so just do things like wx.w*************************** (what ever call)

Scott
Title: Re: Lua Panels and events
Post by: smurph on August 27, 2014, 07:38:20 PM
I would add a panel on top of the parent panel.  The parent panel actually resides in mach4gui and any click events are going to be eaten by the GUI. 

Steve