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

format_func not used when EnumEditor is initialized with static values #782

Closed
kitchoi opened this issue Apr 14, 2020 · 0 comments · Fixed by #848
Closed

format_func not used when EnumEditor is initialized with static values #782

kitchoi opened this issue Apr 14, 2020 · 0 comments · Fixed by #848
Assignees
Labels
ETS Backlog Good issue for ETS team members to look at
Milestone

Comments

@kitchoi
Copy link
Contributor

kitchoi commented Apr 14, 2020

To reproduce:


class Foo(HasTraits):

    true_or_false = Int()

    def default_traits_view(self):
        return View(
            Item(
                "true_or_false",
                editor=EnumEditor(
                    values=[0, 1],
                    format_func=lambda v: str(bool(v)).upper(),
                )
            )
        )

foo = Foo()
foo.configure_traits()

One expects to see the "TRUE" and "FALSE" in the dropdown. However one gets "0" and "1" in the view, which is unexpected.
Screenshot 2020-04-14 at 17 10 41

Printing the mapping:


ui = foo.edit_traits()
editor, = ui.get_editors("true_or_false")
print(editor.mapping)
ui.dispose()

We get:

{'0': 0, '1': 1}

If I create the editor first and then mutates the values, then I get the expected behaviour:

    def default_traits_view(self):
        editor = EnumEditor(
            format_func=lambda v: str(bool(v)).upper(),
        )
        # trigger _values_changed to fire
        editor.values = [0, 1] 
        return View(
            Item(
                "true_or_false",
                editor=editor,
            )
        )

Screenshot 2020-04-14 at 17 14 13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ETS Backlog Good issue for ETS team members to look at
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants