Skip to content

Colour constants are not tool friendly. #2049

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

Closed
Timmmm opened this issue Sep 15, 2021 · 0 comments · Fixed by #2050
Closed

Colour constants are not tool friendly. #2049

Timmmm opened this issue Sep 15, 2021 · 0 comments · Fixed by #2050
Labels
enhancement Additions and improvements in general

Comments

@Timmmm
Copy link
Contributor

Timmmm commented Sep 15, 2021

In color.py you have this code:

class Colors(Enum):
    white = "#FFFFFF"
    gray_a = "#DDDDDD"
    gray_b = "#BBBBBB"
   ...

# Create constants from Colors enum
constants_names = []
for name, value in Colors.__members__.items():
    name = name.upper()
    value = value.value
    constants_names.append(name)
    locals()[name] = value
    if "GRAY" in name:
        name = name.replace("GRAY", "GREY")
        locals()[name] = value
        constants_names.append(name)

__all__ += ...
    "WHITE",
    "GRAY_A",
    "GREY_A",
...

This is unfortunate because it means tools like IDEs, type checkers etc. do not know about WHITE, BLUE and so on.

There has been an attempt to make this work:

# Add constants to module exports. Simply adding constants_names would work fine, but
# would make it hard for IDEs to understand that colors are exported. Therefore the
# result of the following print statement is added instead.

Unfortunately it doesn't work with VSCode / Pyright. Given that you're already using codegen, we may as well just do it properly.

def print_constant_definitions():
    """
    A simple function used to generate the constant values below. To run it
    paste this function and the Colors class into a file and run them.
    """
    constants_names: list[str] = []
    for name in Colors.__members__.keys():
        name_upper = name.upper()

        constants_names.append(name_upper)
        print(f"{name_upper} = Colors.{name}")

        if "GRAY" in name_upper:
            name_upper = name_upper.replace("GRAY", "GREY")

            constants_names.append(name_upper)
            print(f"{name_upper} = Colors.{name}")

    constants_names_repr = "[\n    \"" + "\",\n    \"".join(constants_names) + "\",\n]"

    print(f"\n__all__ += {constants_names_repr}")


WHITE = "#FFFFFF"
GRAY_A = "#DDDDDD"
GREY_A = "#DDDDDD"
GRAY_B = "#BBBBBB"
GREY_B = "#BBBBBB"
GRAY_C = "#888888"
GREY_C = "#888888"
GRAY_D = "#444444"
GREY_D = "#444444"
GRAY_E = "#222222"
GREY_E = "#222222"
BLACK = "#000000"
LIGHTER_GRAY = "#DDDDDD"
LIGHTER_GREY = "#DDDDDD"
LIGHT_GRAY = "#BBBBBB"
LIGHT_GREY = "#BBBBBB"
GRAY = "#888888"
GREY = "#888888"
DARK_GRAY = "#444444"
DARK_GREY = "#444444"
DARKER_GRAY = "#222222"
DARKER_GREY = "#222222"
BLUE_A = "#C7E9F1"
BLUE_B = "#9CDCEB"
BLUE_C = "#58C4DD"
BLUE_D = "#29ABCA"
BLUE_E = "#236B8E"
PURE_BLUE = "#0000FF"
BLUE = "#58C4DD"
DARK_BLUE = "#236B8E"
TEAL_A = "#ACEAD7"
TEAL_B = "#76DDC0"
TEAL_C = "#5CD0B3"
TEAL_D = "#55C1A7"
TEAL_E = "#49A88F"
TEAL = "#5CD0B3"
GREEN_A = "#C9E2AE"
GREEN_B = "#A6CF8C"
GREEN_C = "#83C167"
GREEN_D = "#77B05D"
GREEN_E = "#699C52"
PURE_GREEN = "#00FF00"
GREEN = "#83C167"
YELLOW_A = "#FFF1B6"
YELLOW_B = "#FFEA94"
YELLOW_C = "#FFFF00"
YELLOW_D = "#F4D345"
YELLOW_E = "#E8C11C"
YELLOW = "#FFFF00"
GOLD_A = "#F7C797"
GOLD_B = "#F9B775"
GOLD_C = "#F0AC5F"
GOLD_D = "#E1A158"
GOLD_E = "#C78D46"
GOLD = "#F0AC5F"
RED_A = "#F7A1A3"
RED_B = "#FF8080"
RED_C = "#FC6255"
RED_D = "#E65A4C"
RED_E = "#CF5044"
PURE_RED = "#FF0000"
RED = "#FC6255"
MAROON_A = "#ECABC1"
MAROON_B = "#EC92AB"
MAROON_C = "#C55F73"
MAROON_D = "#A24D61"
MAROON_E = "#94424F"
MAROON = "#C55F73"
PURPLE_A = "#CAA3E8"
PURPLE_B = "#B189C6"
PURPLE_C = "#9A72AC"
PURPLE_D = "#715582"
PURPLE_E = "#644172"
PURPLE = "#9A72AC"
PINK = "#D147BD"
LIGHT_PINK = "#DC75CD"
ORANGE = "#FF862F"
LIGHT_BROWN = "#CD853F"
DARK_BROWN = "#8B4513"
GRAY_BROWN = "#736357"
GREY_BROWN = "#736357"

__all__ += [
    "WHITE",
    "GRAY_A",
    "GREY_A",
    "GRAY_B",
    "GREY_B",
    "GRAY_C",
    "GREY_C",
    "GRAY_D",
    "GREY_D",
    "GRAY_E",
    "GREY_E",
    "BLACK",
    "LIGHTER_GRAY",
    "LIGHTER_GREY",
    "LIGHT_GRAY",
    "LIGHT_GREY",
    "GRAY",
    "GREY",
    "DARK_GRAY",
    "DARK_GREY",
    "DARKER_GRAY",
    "DARKER_GREY",
    "BLUE_A",
    "BLUE_B",
    "BLUE_C",
    "BLUE_D",
    "BLUE_E",
    "PURE_BLUE",
    "BLUE",
    "DARK_BLUE",
    "TEAL_A",
    "TEAL_B",
    "TEAL_C",
    "TEAL_D",
    "TEAL_E",
    "TEAL",
    "GREEN_A",
    "GREEN_B",
    "GREEN_C",
    "GREEN_D",
    "GREEN_E",
    "PURE_GREEN",
    "GREEN",
    "YELLOW_A",
    "YELLOW_B",
    "YELLOW_C",
    "YELLOW_D",
    "YELLOW_E",
    "YELLOW",
    "GOLD_A",
    "GOLD_B",
    "GOLD_C",
    "GOLD_D",
    "GOLD_E",
    "GOLD",
    "RED_A",
    "RED_B",
    "RED_C",
    "RED_D",
    "RED_E",
    "PURE_RED",
    "RED",
    "MAROON_A",
    "MAROON_B",
    "MAROON_C",
    "MAROON_D",
    "MAROON_E",
    "MAROON",
    "PURPLE_A",
    "PURPLE_B",
    "PURPLE_C",
    "PURPLE_D",
    "PURPLE_E",
    "PURPLE",
    "PINK",
    "LIGHT_PINK",
    "ORANGE",
    "LIGHT_BROWN",
    "DARK_BROWN",
    "GRAY_BROWN",
    "GREY_BROWN",
]

]

@Timmmm Timmmm added the enhancement Additions and improvements in general label Sep 15, 2021
Timmmm added a commit to Timmmm/manim that referenced this issue Sep 15, 2021
behackl pushed a commit that referenced this issue Oct 2, 2021
* Make colour aliases IDE-friendly

Fixes #2049

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Additions and improvements in general
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant