Hello Guest it is April 26, 2024, 09:43:58 AM

Author Topic: Edit Screen - Mutli-line textbox, label with scrollbar or table control?  (Read 1254 times)

0 Members and 1 Guest are viewing this topic.

Re: Edit Screen - Mutli-line textbox, label with scrollbar or table control?
« Reply #10 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
« Last Edit: February 15, 2022, 05:50:28 AM by compewter_numerical »