I made some progress (figured out how to get the current node id) but I think I’m somehow calling the “leaffunc(t)” function wrong.

 

I adapted it from this old code that created a button for each module:

 

local dlg = {}

        for cat in pairs(cats) do

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

                       local modbtnfunc = module.bindsettings

                       local modbtn = iup.button{title = module.label}

                        modbtn.action = "" modbtnfunc(t) end  --"t" is the current profile table, which gets passed to module.bindsettings(profile)

                       table.insert(dlg, modbtn)

                end

end

 

Those buttons worked fine, but when I tried to adapt it into a tree, I couldn’t figure out how to write the equivalent of the “modbtn” line.

The closest I can come is this:

 

        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

                       modtree.addleaf1 = module.label

                       local leaffunc = module.bindsettings

                       function modtree:executeleaf_cb(id)

                               iup.Message(id,modtree.title) -- this works and gives me the module name and the node id

                               leaffunc(t) --this doesn’t work and all leaves only open the same module

                       end

                end

        end

 

I tried a few ways of typing the function, but it didn’t work. How do I make it work like the button version?

 

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