Skip to content

Fixing Issue #1236 Listbox Index#1995

Open
Mstpyt wants to merge 1 commit intohoffstadt:masterfrom
Mstpyt:issue_1236
Open

Fixing Issue #1236 Listbox Index#1995
Mstpyt wants to merge 1 commit intohoffstadt:masterfrom
Mstpyt:issue_1236

Conversation

@Mstpyt
Copy link
Collaborator

@Mstpyt Mstpyt commented Jan 5, 2023


name: Pull Request
about: Create a pull request to help us improve
title: Add options to listbox data
assignees: @hoffstadt


Closes #1236

Description:

Adding a new parameter to the Listbox; index_items when this parameter is set instead of giving the "item of the listbox" inside the user_data parameter the index of the item will be given.

Concerning Areas:

@bandit-masked
Copy link
Collaborator

Is it possible to review and merge this PR for the upcoming release?

return;
PyDict_SetItemString(outDict, "items", mvPyObject(ToPyList(inConfig.names)));
PyDict_SetItemString(outDict, "num_items", mvPyObject(ToPyInt(inConfig.itemsHeight)));
PyDict_SetItemString(outDict, "index", mvPyObject(ToPyBool(inConfig.sendindex)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the parser, the parameter is named "index_items". Here, its name is "index". Oops.

args.push_back({ mvPyDataType::StringList, "items", mvArgType::POSITIONAL_ARG, "()", "A tuple of items to be shown in the listbox. Can consist of any combination of types. All items will be displayed as strings." });
args.push_back({ mvPyDataType::String, "default_value", mvArgType::KEYWORD_ARG, "''", "String value of the item that will be selected by default." });
args.push_back({ mvPyDataType::Integer, "num_items", mvArgType::KEYWORD_ARG, "3", "Expands the height of the listbox to show specified number of items." });
args.push_back({ mvPyDataType::Bool, "index_items", mvArgType::KEYWORD_ARG, "False", "Set the user_data to the index of the clicked item and not the item itself" });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description says the index would be in user_data, but the code actually puts it to app_data. The description needs to be corrected.

config.disabled_value = config.names[config.index];
auto value = *config.value;
if (config.sendindex) {
*config.value = std::to_string(config.index);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like the idea of converting the index to a string here. I think mvListbox::getPyValue() should handle it and return a string if index_items is False, and a number (the index) if it's True. The same for the callback: instead of converting the index to a string, it should call ToPyInt and return an integer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants