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

A RangeEditor editing a Range trait will not use the trait's low and high settings #2005

Open
nicolasap-dm opened this issue Mar 31, 2023 · 3 comments

Comments

@nicolasap-dm
Copy link
Contributor

nicolasap-dm commented Mar 31, 2023

Using qt (pyside6 6.2.3) with the latest traitsui release (7.4.3).

A RangeEditor that edits a Range trait will ignore the trait's low and high and will default to 0.0 - 1.0 instead:

from traits.api import HasStrictTraits, Range
from traitsui.api import View, Item, RangeEditor

class FixedRange(HasStrictTraits):
    a_range = Range(low=0, high=72, value=1)

    def default_traits_view(self):
        return View(
            Item("a_range", style="custom", editor=RangeEditor(mode="slider")),
            width=330, height=60,
            title="Editor will not inherit low/high"
        )

FixedRange().configure_traits()

image

(Expected: slider going from 0 to 72 instead of 0.0 to 1.0)

The same happens with other modes ("spinner").

Known workaround: assign low and high manually.
Limitation: this is unfeasible if the Range trait uses extended trait names for low and high.


Addendum. I should also point out that if the RangeEditor is then used, it will likely generate invalid trait values (in this case, Range is validating to int because high, low and value are ints; RangeEditor however produces floats because it ignored these parameters).

It surprised me that the exception is displayed to the user with a dialog rather than with a "failed validation" color.

image

@corranwebster
Copy link
Contributor

Digging into this a bit, if you just do Item("a_range", style="custom") without adding a RangeEditor things work as expected.

@nicolasap-dm
Copy link
Contributor Author

nicolasap-dm commented Apr 6, 2023

That's true, although this syntax would not allow selecting any other mode than the default one (here it would be "slider")

Edit: Just learned that the Range trait also has mode!

@corranwebster
Copy link
Contributor

Key things from the looking into this:

So probably not going to fix this in the near-future.

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

No branches or pull requests

2 participants