Skip to content

Unintuitive behavior of RangeEditor when mode is explicitly set #1779

@pbrod

Description

@pbrod

Currently the actual range editor used in a "View" do not always conform to the one specified with the mode option, which is unintuitive.
For example if the range is given by low=0 and high=None the actual range editor used is always RangeTextEditor no matter if you specified mode='xslider' or mode='spinner'. That is unexpected. I would expect that explicit set mode would take precedence over automatic settings.

The lines controlling this behavior is given below in _get_simple_editor_class and _get_custom_editor_class methods:

def _get_simple_editor_class(self):
"""Returns the editor class to use for a simple style.
The type of editor depends on the type and extent of the range being
edited:
* One end of range is unspecified: RangeTextEditor
* **mode** is specified and not 'auto': editor corresponding to
**mode**
* Floating point range with extent > 100: LargeRangeSliderEditor
* Integer range or floating point range with extent <= 100:
SimpleSliderEditor
* All other cases: SimpleSpinEditor
"""
low, high, is_float = self._low_value, self._high_value, self.is_float
if (low is None) or (high is None):
return toolkit_object("range_editor:RangeTextEditor")
if (not is_float) and (abs(high - low) > 1000000000):
return toolkit_object("range_editor:RangeTextEditor")
if self.mode != "auto":
return toolkit_object("range_editor:SimpleEditorMap")[self.mode]
if is_float and (abs(high - low) > 100):
return toolkit_object("range_editor:LargeRangeSliderEditor")
if is_float or (abs(high - low) <= 100):
return toolkit_object("range_editor:SimpleSliderEditor")
return toolkit_object("range_editor:SimpleSpinEditor")

def _get_custom_editor_class(self):
"""Creates a custom style of range editor
The type of editor depends on the type and extent of the range being
edited:
* One end of range is unspecified: RangeTextEditor
* **mode** is specified and not 'auto': editor corresponding to
**mode**
* Floating point range: Same as "simple" style
* Integer range with extent > 15: Same as "simple" style
* Integer range with extent <= 15: CustomEnumEditor
"""
low, high, is_float = self._low_value, self._high_value, self.is_float
if (low is None) or (high is None):
return toolkit_object("range_editor:RangeTextEditor")
if self.mode != "auto":
return toolkit_object("range_editor:CustomEditorMap")[self.mode]
if is_float or (abs(high - low) > 15):
return self.simple_editor_class
return toolkit_object("range_editor:CustomEnumEditor")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions