-
Notifications
You must be signed in to change notification settings - Fork 95
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
Conversation
…hought/traitsui into add-default_factory-callable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Actually, although this is good, might want to pass additional arguments to the default factory in case what you create depends on the context. |
There was a problem hiding this 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
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() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 😞
follow up PR to #1559
closes #1627
This PR adds a
default_factory
Callable
trait on theListEditor
factory class. Then it uses this callable to create a new item in theadd_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.