Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Issue #1236 Listbox Index #1995

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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?

@@ -341,6 +341,7 @@ DearPyGui::fill_configuration_dict(const mvListboxConfig& inConfig, PyObject* ou
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
Contributor

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.

@@ -2666,6 +2666,7 @@ DearPyGui::GetEntityParser(mvAppItemType type)
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
Contributor

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
Contributor

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add options to listbox data
3 participants