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

Add item_factory callable for specifying creation of new list items #1634

Merged
merged 21 commits into from
May 5, 2021

Conversation

aaronayres35
Copy link
Contributor

follow up PR to #1559
closes #1627

This PR adds a default_factory Callable trait on the ListEditor factory class. Then it uses this callable to create a new item in the add_item methods of the toolkit specific editors if it was specified. Otherwise, it defaults back to the old behavior of using the default value for the trait type in the list.

@rahulporuri rahulporuri self-requested a review May 3, 2021 06:04
@aaronayres35 aaronayres35 changed the title [WIP] Add default factory callable Add default factory callable May 3, 2021
Copy link
Contributor

@corranwebster corranwebster left a comment

Choose a reason for hiding this comment

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

LGTM

@corranwebster
Copy link
Contributor

Actually, although this is good, might want to pass additional arguments to the default factory in case what you create depends on the context.

Copy link
Contributor

@rahulporuri rahulporuri left a comment

Choose a reason for hiding this comment

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

Mostly LGTM with comments regarding the new trait names

traitsui/editors/list_editor.py Outdated Show resolved Hide resolved
traitsui/editors/list_editor.py Outdated Show resolved Hide resolved
traitsui/editors/list_editor.py Outdated Show resolved Hide resolved
traitsui/editors/list_editor.py Outdated Show resolved Hide resolved
Comment on lines +354 to +360
try:
self.value = list[:index] + [value] + list[index:]
# if the default new item is invalid, we just don't add it to the list.
# traits will still give an error message, but we don't want to crash
except TraitError:
from traitsui.api import raise_to_debug
raise_to_debug()
Copy link
Contributor

Choose a reason for hiding this comment

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

question : looks like we missed this in the earlier PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah wx got neglected before 😞

@aaronayres35 aaronayres35 merged commit ba53ada into master May 5, 2021
@aaronayres35 aaronayres35 deleted the add-default_factory-callable branch May 5, 2021 13:53
@aaronayres35 aaronayres35 changed the title Add default factory callable Add item_factory callable for specifying creation of new list items May 5, 2021
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.

Allow specifying callable for generating new item in List
3 participants