I tried some more and I think I got close, but still couldn’t get it right. Below the space are various things I tried, with comments on outcome:

       

for cat in pairs(cats) do

                modtree.addbranch = cat --add a branch for each module category

                for _,module in pairs(cats[cat]) do --iter thru each category and populate branches with modules

                       local leaffunc = module.bindsettings

                       modtree.addleaf1 = module.label

-- iup.Message("",tostring(leaffunc)) --returns a different function each iteration like it should

 

                        --[[ function modtree:executeleaf_cb(id)  --automatically grabs current leaf's node id

                       --     iup.Message(id,modtree.title)  --test that prints mod name (SUCCESS)

                       --     leaffunc(t)  --OPENS SAME DLG

                       --     module.bindsettings(t)  --BROKEN

                       end ]]

                --     modtree.executeleaf_cb = function(_) leaffunc(t) end  --OPENS SAME DLG

                --     modtree.executeleaf_cb = function(_) module.bindsettings(t) end  --OPENS SAME DLG

                --     modtree.executeleaf_cb = module.bindsettings(t)  --BROKEN (spams mod dlgs on open and crashes)

                --     modtree.executeleaf_cb = leaffunc(t)  --BROKEN (spam and crash)

                end

        end

 

Something about nodes seems to keep the callbacks from sticking. Maybe because the object in question seems to be the tree rather than the nodes, I imagine the callback gets assigned to the whole tree instead. Then I tried making an array to store the info, but it’s making the app crash. I don’t think I’m handling calling a function with a parameter from an array correctly. I need to get “t” into module.bindsettings().

 

        local modarray = {}

 

        for cat in pairs(cats) do

                modtree.addbranch = cat --add a branch for each module category

                table.insert(modarray, cat) --placeholders so leaf indices will match their IDs

                for _,module in pairs(cats[cat]) do

                       local leaffunc = module.bindsettings

                --     iup.Message("",tostring(leaffunc)) --returns a different function id each iteration like it should

                       modtree.addleaf1 = module.label

                       table.insert(modarray, leaffunc) --is the name enough? It didn’t work when I tried adding parameters or wrapping the variable in an anonymous function

                end

        end

        modtree.executeleaf_cb = function(id)

                modarray[id](t) -- crashes here

        end

 

 

From: Antonio Scuri
Sent: Friday, December 3, 2021 8:01 AM
To: IUP discussion list.
Subject: Re: [Iup-users] Problem with Executeleaf_cb Callback

 

  I suggest you to store in each node some information that will allow you to retrieve the correct module and be able to show it.

 

Best,

Scuri

 

 

Em seg., 29 de nov. de 2021 às 23:11, Kaz F <kaz.fox...@gmail.com> escreveu:

I’m trying to populate a tree with the names of modules (leaves) so when you double-click on the name, the module dialog should pop up.

It almost works, but for some reason, every leaf opens the same module. How can I fix that?

This is the part of the code I have:

       

local modtree = iup.flattree{rastersize = "400x500"} --are there any more-flexible options than rastersize?

        modtree["addbranch-1"] = "MODULES" --add root node

 

        for cat in pairs(cats) do

                modtree.addbranch = cat --add a branch for each module category

                for _,module in pairs(cats[cat]) do --populate branches with modules

                       modtree.addleaf1 = module.label     

                       function modtree:executeleaf_cb() module.bindsettings(t) end

                end

        end

 

Each module script starts with this code:

 

local module = {}

function module.bindsettings(profile)

…contains code about the dialog

_______________________________________________
Iup-users mailing list
Iup-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/iup-users

 

_______________________________________________
Iup-users mailing list
Iup-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/iup-users

Reply via email to