enthought / enthought/traits

Move default traitsui editors over to traitsui

Open
#1,004 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
462
Forks
90
PR merge metrics
No merged PRs in 30d

Description

After #932, traits will still have some dependency on traitsui caused by implementations of `BaseTraitHandler.get_editor` that imports traitsui, e.g.:
https://github.com/enthought/traits/blob/30758651ae1a7bd0546d7d84f9b20c54f1bb42cc/traits/base_trait_handler.py#L150-L155
https://github.com/enthought/traits/blob/30758651ae1a7bd0546d7d84f9b20c54f1bb42cc/traits/trait_handlers.py#L156-L178
There are many like these. This causes cycle dependency between traits and traitsui in mission critical usage. This makes testing and deployment more difficult. There are already existing efforts for removing traitsui dependency from traits, e.g. https://github.com/enthought/traits/issues/610

My understanding is that (1) this `get_editor` is only called by `traitsui`, i.e. `traitsui` is the sole consumer, but (2) users of traits can override the method to provide a different default editor, instead of writing `default_trait_view` (`default_trait_view` is preferred, I think).

For backward compatibility, we need to keep `get_editor` for use case (2). But if the assumption in (1) is right, we can move the default implementation over to traitsui.

Here are what I think should happen:
(i) Add a warning in all the default implementations of `get_editor`. This is to test the assumption in (1). Make a traits release with this.
(ii) Copy the many default implementation of `create_editor` or `get_editor` over to traitsui.
I imagine it would involve a mapping from TraitType to the default implementation as a function.
I believe this would copy the entire `traits.editor_factories` over to traitsui as well.
(iii) In traitsui's `ui_panel`, anticipate `trait.get_editor` to raise `NotImplementedError`, and use the default implementation in (ii) for that. In fact, the wx implementation already does it:
https://github.com/enthought/traitsui/blob/b7a409d4e869d1857fcf77e8be47de581e864d41/traitsui/wx/ui_panel.py#L879-L882
The Qt implementation does not.
(iv) Release traitsui
(v) Replace all default implementations of `get_editor` with a plain `raise NotImplementedError`. This should remove all the remaining dependency on traitsui (I think).

A few of these steps should happen in traitsui. If this plan sounds good, there should be another issue in traitsui associated with this one.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.