Not sure if this is a bug, but thought I`d mention it here.
If you change the .items for a popup to a table of fewer total values AND the popup is selecting a value greater than the number of new items. The popup .value remains at a now non existant value and the popup shows the default “None” entry until changed manually.
You might expect the value would default to 1 or 0 or nil?
DEMO CODE, works in testpad
–here we reduce the number of popup items from 3 to 2 while 3 is selected. 3 remains as selection value even though it doesn`t exist.
--global variables for gui
local my_dialog = nil
local vb = nil
--assign global vb to viewbuilder
vb = renoise.ViewBuilder()
local items = {"1","2","3"}
local main_column =
vb:column{
vb:popup{
id = "popup",
items = items,
value = 3,
}
}
local dialog_content = main_column
--Show Script dialog
my_dialog = renoise.app():show_custom_dialog("Test Popup", dialog_content)
--Now make a new table with one less item
local less_items = {"1","2"}
--update popup to have one less item
vb.views["popup"].items = less_items
--print the popup value
print(vb.views["popup"].value)
--this prints that the popup is still at its original value of 3.
--Also the popup shows the default entry "None" until it is changed by the user or script.
I do not think it’s an error. Maybe you need to set the “value” of the popup for your new table “less_items” <=to the number of items:
--now make a new table with one less item
local less_items = {"1","2"}
--update popup to have one less item
local vws = vb.views
vws.popup.items = less_items
vws.popup.value = 2 --or 1 (<= #less_items)
The previous table continues to exist, it is a “local”. Therefore, item 3 of the previous table is still there: items[3] = 3
If you change the number of items in a popup, make sure that the selection value of the popup (“value”) belongs to an item in the table.In this case, the “value” index can not be greater than 2.
On the other hand, most objects of the API that need a range of values or items have a minimum and maximum values. For example, in a slider, I think it’s from 0 to 1.You must set the values to change the ones that are by default.In the case of the popup, if the table of items is empty, “None” appears in the drop-down list.In theory, if the popup accesses to less_items[3],“None” should appear.
I’m just deducting things. I have not tried any of this, but if you add the last line of the code (vws.popup.value = 2), it should work correctly…
Edit :so as not to complicate things, if you use popups with varying tables, setfrom the start vws.popup.value = 1:
local main_column = vb:column {
vb:popup {
id = "popup",
items = items,
value = 1, -- <----here!
}
}
You can also add or remove items from the same table. The API has several ways to proceed to modify tables. Once the original table “items” has been modified, it would be possible to set value = #items. Thus, the code makes sure of always select the last item of the table.
Yes, you can of course change the value after changing the items table, and it turns out to be necessary. However the point is that if you print vb.views[“popup”].value you have no idea that what you have is an invalid index unless doing checking against .items manually.
You have what looks like a valid index “hanging around” that you can get but would not be allowed to set.
This results in the popup showing the defult entry of “None”, which you can`t cause from scripting unless you set .items = 0
Its more like the error is shown in the popup gui rather than in a print/script error.