Re: [darktable-dev] Lua combobox bug?

2017-05-04 Thread William Ferguson
>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 
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" 
> 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

Re: [darktable-dev] Lua combobox bug?

2017-05-04 Thread William Ferguson
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" 
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@
> lists.darktable.org
>
>
> 
> ___
> darktable developer mailing list
> to unsubscribe send a mail to darktable-dev+unsubscribe@
> lists.darktable.org
>
>

___
darktable developer mailing list
to unsubscribe send a mail to darktable-dev+unsubscr...@lists.darktable.org

Re: [darktable-dev] Lua combobox bug?

2017-05-04 Thread Christian Kanzian
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+unsubscr...@lists.darktable.org


___
darktable developer mailing list
to unsubscribe send a mail to darktable-dev+unsubscr...@lists.darktable.org



Re: [darktable-dev] Lua combobox bug?

2017-05-04 Thread Holger Klemm
Thanks for the function. I do not understand how I must use that :-(
choice_table?


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+unsubscr...@lists.darktable.org



Re: [darktable-dev] Lua combobox bug?

2017-05-03 Thread William Ferguson
The only way I've found to do this is to rewrite the whole list of choices,
trimming any extras off the 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


Regards,

Bill

On Wed, May 3, 2017 at 2:07 PM, Holger Klemm 
wrote:

> Hello,
> I want to remove in my Lua script entries from a combobox during runtime.
> Removes entries by setting them to nil does not work! What am I doing
> wrong?
> See attachement
>
> Holger
> 
> ___
> darktable developer mailing list
> to unsubscribe send a mail to darktable-dev+unsubscribe@
> lists.darktable.org

___
darktable developer mailing list
to unsubscribe send a mail to darktable-dev+unsubscr...@lists.darktable.org

[darktable-dev] Lua combobox bug?

2017-05-03 Thread Holger Klemm
Hello,
I want to remove in my Lua script entries from a combobox during runtime. 
Removes entries by setting them to nil does not work! What am I doing wrong?
See attachement

Holger
___
darktable developer mailing list
to unsubscribe send a mail to darktable-dev+unsubscr...@lists.darktable.org--[[


darktable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

darktable is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with darktable.  If not, see .
]]


local dt = require "darktable"
local gettext = dt.gettext
dt.configuration.check_version(...,{4,0,0})



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
} 



add_button = dt.new_widget("button")
{
  label = 'change combobox',
  clicked_callback = function (xxx)
test_combobox{nil}
test_combobox{"XX","YY",nil,nil,nil,}
 dt.print("combobox changed")
  end
}




local import_widget =   dt.new_widget("box") {
test_combobox,
add_button,

 }


dt.register_lib("test", "test", true, true, {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_LEFT_CENTER", 900}}, import_widget, nil, nil)