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 [email protected]
___________________________________________________________________________
darktable developer mailing list
to unsubscribe send a mail to [email protected]