Machsupport Forum

Mach Discussion => Mach4 General Discussion => Mach4 Toolbox => Topic started by: kane17752 on June 07, 2017, 11:05:19 PM

Title: Help with opening up a new screen from wxFormBuilder New to all this.
Post by: kane17752 on June 07, 2017, 11:05:19 PM
I created a simple screen in wxformBuilder and just trying to get it to open with a new button press I created in Mach4.  I modified the code in the touch button script as follows:


   
Code: [Select]


inst = mc.mcGetInstance()
local profile = mc.mcProfileGetName(inst)
    local path = mc.mcCntlGetMachDir(inst)
   
    package.path = path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.lua;"

 
    package.loaded.yyy = nil
    tou = require "yyy"
    Tframe = tou.Dialog()
end

I have attached the wxFormbuilder lua code file.  Just cannot figure out what I am doing wrong.  the yyy.lua file is in the modules folder.  Do I need the compiled file there also?

Any assistance would be appreciated.   
Title: Re: Help with opening up a new screen from wxFormBuilder New to all this.
Post by: DazTheGas on June 08, 2017, 02:05:49 AM
This should help you on your way 

 http://www.machsupport.com/forum/index.php/topic,35007.0.html

DazTheGas
Title: Re: Help with opening up a new screen from wxFormBuilder New to all this.
Post by: kane17752 on June 10, 2017, 01:11:42 PM
This video was very useful I followed along and everything worked great.  So now I added a basic screen, using wxFormBuilder and the screen will not show.  In fact when I step through and on the return of the UI I get an error, per attachment. 

Code for the button event is as follows:

Code: [Select]
local inst = mc.mcGetInstance()
local profile = mc.mcProfileGetName(inst)
local path = mc.mcCntlGetMachDir(inst)
package.path = path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.lua;"

--CustFunc Module
package.loaded.mcTouchOff = nil


cf = require "mcTouchOff"
   
    Tframe = cf.Dialog()

Code for the custom function is as follows:

Code: [Select]
local mcTouchOff = {}   -- start of module   Declare Module table
local inst = mc.mcGetInstance()
--require("wx")

--[[function mcTouchOff.GetSigState(sig)   -- adds  function to table
    local hSig = mc.mcSignalGetHandle(inst,sig)
    local state = mc.mcSignalGetState(hSig)  -- get handle
    return hSig

end


function mcTouchOff.SetSigState (sig, state) 

    local hSig = mc.mcSignalGetHandle(inst,sig)
    mc.mcSignalSetState(hSig,state)
end]]


function mcTouchOff.Dialog()


UI = {}

    UI.frameMain = wx.wxFrame (wx.NULL, wx.wxID_ANY, "TouchOff UI", wx.wxDefaultPosition, wx.wxSize( 900,530 ), wx.wxCAPTION + wx.wxCLOSE_BOX + wx.wxRESIZE_BORDER )
UI.frameMain:SetSizeHints( wx.wxSize( 900,530 ), wx.wxDefaultSize )
UI.frameMain :SetBackgroundColour( wx.wxColour( 255, 255, 255 ) )

return (UI.frameMain)
end

return mcTouchOff   -- end of module

Your guidance would be appreciated. 
Warm Regards,
Title: Re: Help with opening up a new screen from wxFormBuilder New to all this.
Post by: django013 on June 10, 2017, 11:33:56 PM
Hi Allan,

as far as I understood Steve in this post (http://www.machsupport.com/forum/index.php/topic,35020.msg240705.html#msg240705), your way won't work.

So I think, you would need at least a luapanel in your screen. Place the button that opens the dialog in that panel. It might work then.
To get your luapanel to work, you'll need mcLuaPanelParent.
So when your button in the luapanel appears, you have your new thread, your lua instance. Of cause, the code for the button must be in your lua-module too.

hth Reinhard
Title: Re: Help with opening up a new screen from wxFormBuilder New to all this.
Post by: kane17752 on June 11, 2017, 10:06:14 AM
solved my problem.   I made a rookie mistake. Forgot 1 line of code!!

UI.frameMain:Show(true)

Never called Show
Title: Re: Help with opening up a new screen from wxFormBuilder New to all this.
Post by: django013 on June 11, 2017, 10:10:53 AM
So you created a lua dialog from a mach4-screen button?
Duh - didn't know that that would be possible. Good to know ;)
Title: Re: Help with opening up a new screen from wxFormBuilder New to all this.
Post by: django013 on June 11, 2017, 10:59:36 PM
Hi,

what about your error about unwritable memory? That can't be related to a forgotten Show()
For me that error looked like a threading issue.
How did you solved that error?
Title: Re: Help with opening up a new screen from wxFormBuilder New to all this.
Post by: kane17752 on June 12, 2017, 07:52:21 AM
The Show resolved the error