Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: mb-ABTech on February 02, 2022, 10:57:32 AM

Title: Edit Screen - Mutli-line textbox, label with scrollbar or table control?
Post by: mb-ABTech on February 02, 2022, 10:57:32 AM
We are customizing Mach4 to act partially as a data acquisition tool, and I am trying to display the contents of a Lua table on the screen. The table comprises several axis values, as well as a probe reading (that comes over Modbus), and might end up being 100+ "rows" long. In the screen editor I want to display this table in a control, but unfortunately it looks like none of the controls have the ability to display a 2D table very well.

Textboxes don't seem to natively support multi-line capability like it does in most languages (I am a C# software engineer). Maybe this can be done through a Lua script? I'm not familiar enough with the namespaces in Lua to know where to start, however.

Labels support multi-line, but do not have scroll bars if the contents extend beyond the bottom bounds of the label. Again, available through Lua?

There is no table control (aside from tool table, which is not very customizable).

Anyone know how to do any of the above? Add a scroll bar to a multi-line textbox, or maybe to a tab that contains a label that extends beyond the lower bounds of the tab control? Or just add a simple table/grid?
Title: Re: Edit Screen - Mutli-line textbox, label with scrollbar or table control?
Post by: joeaverage on February 02, 2022, 06:39:40 PM
Hi,
I rather think that requirement is outside of what Mach offers natively, but Mach itself offers only the very briefest subset of wx.Widgets.
I suspect what you want is eminentlty doable, try wxFormBuilder.

Craig
Title: Re: Edit Screen - Mutli-line textbox, label with scrollbar or table control?
Post by: mb-ABTech on February 10, 2022, 01:40:16 PM
I figured out how to add new windows with all the controls I am looking for, but if possible I would really like to add a multiline textbox to the "main" screen.

Does anyone know if there is function in the API that lets you get the resizers in the main screen? I couldn't find any function in the "scr" namespace that suits my needs, and asking for parent controls from existing controls never gives a reference to the sizer, just to the parent control (from what I can see the sizer is what is used to add controls). For instance asking for the parent for a textbox in a tab, the returned control is the tab page (wxNotebookPage), not the resizer.

I went through the API guide, but it only contains "mc" namespace functions, it doesn't even reference "scr" functions.

It almost seems like Mach4 specifically tries to encapsulate the front end so that scripts have limited or no access to the underlying controls.
Title: Re: Edit Screen - Mutli-line textbox, label with scrollbar or table control?
Post by: joeaverage on February 10, 2022, 02:15:43 PM
Hi,

Quote
I went through the API guide, but it only contains "mc" namespace functions, it doesn't even reference "scr" functions.

The API is almost entirely .mc namespace, the .scr namespace was really used during development only and was never intended for widespread user use.
You will find what little I can find here:

https://www.machsupport.com/forum/index.php?topic=40051.0 (https://www.machsupport.com/forum/index.php?topic=40051.0)

Really you are barking up the wrong tree here though....there is a perfectly excellent suite of graphic commands to do as you require in the form of wx.Widgets which
is fully supported by Lua and Mach. All of those functions have the namespace .wx. You need to make yourself familiar with them. Crafting .wx code is facilitated by wxFormBuilder.

Craig
Title: Re: Edit Screen - Mutli-line textbox, label with scrollbar or table control?
Post by: mb-ABTech on February 10, 2022, 02:19:24 PM
Like I said I was able to figure out how to create a separate window with all the necessary controls, but I was hoping to have all the information self contained in the main screen, not in separate windows.

After investigating this more it seems like there is simply no way to programmatically add custom controls to the main screen (i.e. get a reference to any of the main screen controls). Unfortunate, but I guess I'll have to just use custom windows.
Title: Re: Edit Screen - Mutli-line textbox, label with scrollbar or table control?
Post by: joeaverage on February 10, 2022, 02:37:40 PM
Hi,
Mach4 is a CNC program. Onscreen graphics is NOT the central theme here. That Mach4 offers a very comprehensive suite of graphics tools courtesy of
wxWidgets is very nice, and a major advance over Mach3 and in fact any other Windows based CNC solutions, it is just that....nice.

What I really care about is Mach's ability to control my machine, is the trajectory planner second order or third order?, how is the CV feature calculated? and how can you optimise CV
to your situation?,when can we expect multiple instances of Mach, what will be the comms between instances?....these are the important things. On-screen graphics are just icing on the cake...no more.

Craig
Title: Re: Edit Screen - Mutli-line textbox, label with scrollbar or table control?
Post by: jbuehn on February 10, 2022, 03:03:37 PM
Quote
Like I said I was able to figure out how to create a separate window with all the necessary controls, but I was hoping to have all the information self contained in the main screen, not in separate windows.

Are you using a Lua panel (in the screen editor) for your custom controls? You can basically use any wxLua elements on the main screen if it's in a panel.
Title: Re: Edit Screen - Mutli-line textbox, label with scrollbar or table control?
Post by: mb-ABTech on February 10, 2022, 03:10:52 PM
Quote
Like I said I was able to figure out how to create a separate window with all the necessary controls, but I was hoping to have all the information self contained in the main screen, not in separate windows.

Are you using a Lua panel (in the screen editor) for your custom controls? You can basically use any wxLua elements on the main screen if it's in a panel.

How do you get a control reference from the main screen? scr doesn't seem to provide that functionality, it only returns strings.
Title: Re: Edit Screen - Mutli-line textbox, label with scrollbar or table control?
Post by: mb-ABTech on February 10, 2022, 04:02:24 PM
Success!

Thank you jbuehn for pointing me in the right direction. I ended up using wx.wxFindWindowByName function to get the control reference, then it was only a matter of adding the panel with sizers and controls.
Title: Re: Edit Screen - Mutli-line textbox, label with scrollbar or table control?
Post by: jbuehn on February 10, 2022, 04:08:31 PM
If you look in C:\Mach4Hobby\Wizards\panelscript.mcs you'll see a reference to mcLuaPanelParent - which you can call GetParent() on.
Title: Re: Edit Screen - Mutli-line textbox, label with scrollbar or table control?
Post by: compewter_numerical on February 15, 2022, 05:31:37 AM
Using wxFormBuilder, you can easily create a visual of your data in any way you want to present it.

The tricky part about this, is passing the data to/from the LUA panel.
It really all depends on how you are getting the data and how often or when it needs to be updated.

If it can all be extracted from one LUA table, then you can just create a global register and connect the
wx.wxEVT_UPDATE_UI event to the panel you created. The global register would control the flow of execution if
it's a one-off update.

mcLuaPanelParent is global to everything in Mach4, so you don't need to reference it from anywhere if using it in a panel.
You don't need to use frames in LUA panels, and if you are creating form data, it looks kinda weird imho.

so, if you wanted a listbox, you could do something like this in the LUA panel script:

Code: [Select]
        panel = mcLuaPanelParent
        listbox = wx.wxListBox(panel, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxDefaultSize, {}, wx.wxLB_HSCROLL+wx.wxLB_SINGLE)
listbox:SetFont(wx.wxFont(14, wx.wxMODERN, wx.wxNORMAL, wx.wxNORMAL, 0, "Arial"))

local boxSizer = wx.wxBoxSizer(wx.wxVERTICAL)
boxSizer:Add(listbox, 1, wx.wxALL+wx.wxGROW, 5)
panel:SetSizer(boxSizer)
boxSizer:SetSizeHints(panel)
panel:SetBackgroundColour(wx.wxColour(115, 115, 115))
panel:Fit()

panel:Connect(wx.wxEVT_UPDATE_UI, function (event)
    local updateReg = mc.mcRegGetHandle(inst, "gRegs0/updateReg")
local updateVal = mc.mcRegGetValueLong(updateReg)

mc.mcRegSetValueLong(editorNumItemsReg, listbox:GetCount())

if tonumber(updateVal) == 1 then -- add to the listbox
for key, value in ipairs(someGlobalTable) do
listbox:Append(tostring(key) .. tostring(value))
end
end

event:Skip()
end)

So, when the gReg is 1 then update the form, otherwise do .... something else. It's all code from here.

Thanks to jbuehn for helping me with the update UI event a long time ago.
That's kinda how you pass data in real time. Might be a better solution. Might be a better way to display it too.
Just use the wxformbuilder and create what you need.

Here is an example with video and screenset demonstrating the passing of data between the panel and the main interface:

https://www.machsupport.com/forum/index.php?topic=43263.msg279701#msg279701