>From what I remember, when I was dynamically changing combobox values, you can add to the end of the table, or remove from the end of the table, or change the name of a value in the table. If you want to remove a string from anywhere but the end, you have to rewrite the whole table of values without the one you want to remove, then remove the extra values from the end, which is how update_combobox_choices() came about. The other problem is that you can't create a table of values then do
my_combobox = dt.new_widget("combobox") { value = 1, table.unpack(table_of_values) } so if you have to determine the combobox values at run time and then load them, you either have to loop and load them one at a time or use update_combobox_choices() which does it for you. Bill On Thu, May 4, 2017 at 5:09 PM, William Ferguson <wpfergu...@gmail.com> wrote: > Thank you Christian. I was going to write an example similar to yours but > didn't have time at the moment. > > Bill > > On May 4, 2017 3:03 PM, "Christian Kanzian" <christian.kanz...@gmx.at> > wrote: > >> Am Donnerstag, 4. Mai 2017, 20:02:02 CEST schrieb Holger Klemm: >> > Thanks for the function. I do not understand how I must use that :-( >> > choice_table? >> >> AFAIK a combobox stores its entries like a lua table with indices. >> Updating lua table entries can only be done be looping over the entries? >> That >> is what Bill suggest in his reply. >> >> Merging your test.lua with Bill's answer like that works for me: >> >> local dt = require "darktable" >> >> test_combobox = dt.new_widget("combobox") >> { >> label = 'test combobox', >> tooltip ='', >> value = 1, >> editable=true, >> "1","2","3","4","5", >> reset_callback = function(self_reset) >> self_reset.value = 1 >> end >> } >> >> >> local function update_combobox_choices(combobox, choice_table, selected) >> local items = #combobox >> local choices = #choice_table >> for i, name in ipairs(choice_table) do >> combobox[i] = name >> end >> if choices < items then >> for j = items, choices + 1, -1 do >> combobox[j] = nil >> end >> end >> combobox.value = selected >> end >> >> local new_choices = {"XX","YY"} >> >> add_button = dt.new_widget("button") >> { >> label = 'change combobox', >> clicked_callback = function (x) >> update_combobox_choices(test_combobox,new_choices,2) >> dt.print("combobox changed") >> end >> } >> >> >> local import_widget = dt.new_widget("box") { >> test_combobox, >> add_button, >> >> } >> >> Christian >> >> > >> > Am Mittwoch, 3. Mai 2017, 15:55:42 CEST schrieb William Ferguson: >> > > local function update_combobox_choices(combobox, choice_table, >> selected) >> > > >> > > local items = #combobox >> > > local choices = #choice_table >> > > for i, name in ipairs(choice_table) do >> > > >> > > combobox[i] = name >> > > >> > > end >> > > if choices < items then >> > > >> > > for j = items, choices + 1, -1 do >> > > >> > > combobox[j] = nil >> > > >> > > end >> > > >> > > end >> > > combobox.value = selected >> > > >> > > end >> > >> > ____________________________________________________________ >> _______________ >> > darktable developer mailing list >> > to unsubscribe send a mail to darktable-dev+unsubscribe@list >> s.darktable.org >> >> >> ____________________________________________________________ >> _______________ >> darktable developer mailing list >> to unsubscribe send a mail to darktable-dev+unsubscribe@list >> s.darktable.org >> >> ___________________________________________________________________________ darktable developer mailing list to unsubscribe send a mail to darktable-dev+unsubscr...@lists.darktable.org