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

Add html colors "grey" in addition to "gray" #3671

Merged
merged 1 commit into from
Jan 28, 2023
Merged

Add html colors "grey" in addition to "gray" #3671

merged 1 commit into from
Jan 28, 2023

Conversation

Aztah
Copy link
Contributor

@Aztah Aztah commented Jan 20, 2023

HTML supports both spellings "gray" and "grey" (https://www.w3schools.com/colors/colors_names.asp)

There are 7 different types of gray/grey but attempting to use any of the grey versions will raise:

TraitError: The 'value' trait of a ColorPicker instance expected a valid HTML color, not the str 'grey'.

The affected colors are: ['darkgrey', 'darkslategrey', 'dimgrey', 'grey', 'lightgrey', 'lightslategrey', 'slategrey']

For the ColorPicker widget the default behavior in case of a wrong color (eg. "asdf") is to do nothing, but inputting any of the greys will raise the above exception.

Adding the grey versions of to _color_names in trait_types.py will allow the grey names to go through the name check and render the same way as the gray counterpart.

Simple test code

import ipywidgets
import traitlets
import IPython

print(f'{ipywidgets.__version__ = }')
print(f'{traitlets.__version__ = }')
print(f'{IPython.__version__ = }')

grays = ['darkgray', 'darkslategray', 'dimgray', 'gray', 'lightgray', 'lightslategray', 'slategray']
greys = ['darkgrey', 'darkslategrey', 'dimgrey', 'grey', 'lightgrey', 'lightslategrey', 'slategrey']

for gray, grey in zip(grays, greys):
    try:
        display(ipywidgets.ColorPicker(value=gray))
    except ipywidgets.TraitError as e:
        print(e)
    try:
        display(ipywidgets.ColorPicker(value=grey))
    except traitlets.TraitError as e:
        print(e)

Output from current version:
image

Output from new version:
image

HTML supports both spellings "gray" and "grey" (https://www.w3schools.com/colors/colors_names.asp)

There are 7 different types of gray/grey but attempting to use any of the grey versions will raise:

    TraitError: The 'value' trait of a ColorPicker instance expected a valid HTML color, not the str 'grey'.

The affected colors are: `['darkgrey', 'darkslategrey', 'dimgrey', 'grey', 'lightgrey', 'lightslategrey', 'slategrey']`

For the ColorPicker widget the default behavior in case of a wrong color (eg. "asdf") is to do nothing, but inputting any of the greys will raise the above exception.

Adding the grey versions of to `_color_names` in `trait_types.py` will allow the grey names to go through the name check and render the same way as the gray counterpart.
@github-actions
Copy link

Binder 👈 Launch a binder notebook on branch Aztah/ipywidgets/add_html_color_grey

Copy link
Member

@jasongrout jasongrout left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jasongrout jasongrout merged commit 4021572 into jupyter-widgets:main Jan 28, 2023
@maartenbreddels
Copy link
Member

meeseeksdev please backport to 7.x

meeseeksmachine pushed a commit to meeseeksmachine/ipywidgets that referenced this pull request Mar 21, 2023
maartenbreddels pushed a commit that referenced this pull request Mar 21, 2023
Co-authored-by: Jason Grout <jasongrout@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

None yet

3 participants